So I just tried the VK_RENDERING_CONTENTS_SECONDARY_COMMAND_BUFFERS_BIT
approach.
I’ve setup both VkCommandBufferInheritanceRenderingInfo
and VkCommandBufferInheritanceInfo
, set VkCommandBufferInheritanceInfo::pNext
to VkCommandBufferInheritanceRenderingInfo
VkCommandBufferBeginInfo::pInheritanceInfo
to VkCommandBufferInheritanceInfo
.
I also have VkRenderingInfo::flags
set to VK_RENDERING_CONTENTS_SECONDARY_COMMAND_BUFFERS_BIT
.
That’s the setup:
VkRenderingAttachmentInfo colorAttachmentInfo{};
colorAttachmentInfo.sType = VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO;
colorAttachmentInfo.pNext = nullptr;
colorAttachmentInfo.imageView = GState.ColorImageView;
colorAttachmentInfo.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
colorAttachmentInfo.resolveMode = VK_RESOLVE_MODE_AVERAGE_BIT;
colorAttachmentInfo.resolveImageView = GState.SwapChainImageViews[i];
colorAttachmentInfo.resolveImageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
colorAttachmentInfo.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
colorAttachmentInfo.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
colorAttachmentInfo.clearValue.color = { 0, 0, 0, 1 };
VkRenderingAttachmentInfo depthStencilAttachmentInfo{};
depthStencilAttachmentInfo.sType = VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO;
depthStencilAttachmentInfo.pNext = nullptr;
depthStencilAttachmentInfo.imageView = GState.DepthBufferImageView;
depthStencilAttachmentInfo.imageLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
depthStencilAttachmentInfo.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
depthStencilAttachmentInfo.resolveImageView = VK_NULL_HANDLE;
depthStencilAttachmentInfo.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
depthStencilAttachmentInfo.clearValue.depthStencil = { 1, 0 };
depthStencilAttachmentInfo.resolveMode = VK_RESOLVE_MODE_NONE;
VkRenderingInfo renderingInfo{};
renderingInfo.sType = VK_STRUCTURE_TYPE_RENDERING_INFO;
renderingInfo.pNext = nullptr;
renderingInfo.flags = VK_RENDERING_CONTENTS_SECONDARY_COMMAND_BUFFERS_BIT;
renderingInfo.renderArea.offset = { 0, 0 };
renderingInfo.renderArea.extent = GState.SwapChainExtent;
renderingInfo.layerCount = 1;
renderingInfo.viewMask = 0;
renderingInfo.colorAttachmentCount = 1;
renderingInfo.pColorAttachments = &colorAttachmentInfo;
renderingInfo.pDepthAttachment = &depthStencilAttachmentInfo;
renderingInfo.pStencilAttachment = VK_NULL_HANDLE;
TransitionImageLayout(GState.ColorImage, GState.SwapChainFormat.format, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1);
TransitionImageLayout(GState.SwapChainImages[i], GState.SwapChainFormat.format, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1);
TransitionImageLayout(GState.DepthBufferImage, DepthFormat, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, 1, true);
VkCommandBufferInheritanceRenderingInfo dynamicRenderingInheritanceInfo{};
dynamicRenderingInheritanceInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_RENDERING_INFO;
dynamicRenderingInheritanceInfo.pNext = nullptr;
dynamicRenderingInheritanceInfo.flags = 0;
dynamicRenderingInheritanceInfo.viewMask = 0;
dynamicRenderingInheritanceInfo.colorAttachmentCount = 1;
dynamicRenderingInheritanceInfo.pColorAttachmentFormats = &GState.SwapChainFormat.format;
dynamicRenderingInheritanceInfo.depthAttachmentFormat = DepthFormat;
dynamicRenderingInheritanceInfo.stencilAttachmentFormat = VK_FORMAT_UNDEFINED;
dynamicRenderingInheritanceInfo.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
VkCommandBufferInheritanceInfo inheritanceInfo{};
inheritanceInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
inheritanceInfo.pNext = &dynamicRenderingInheritanceInfo;
inheritanceInfo.renderPass = VK_NULL_HANDLE;
VkCommandBufferBeginInfo CommandBufferBeginInfo{};
CommandBufferBeginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
CommandBufferBeginInfo.pNext = nullptr;
CommandBufferBeginInfo.pInheritanceInfo = &inheritanceInfo;
vkCmdBeginRendering(GState.CommandBuffers[i], &renderingInfo);
{
vkBeginCommandBuffer(GState.SecondaryCommandBuffers[i], &CommandBufferBeginInfo);
vkCmdBindPipeline(GState.SecondaryCommandBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, GState.GraphicsPipeline);
vkCmdBindVertexBuffers(GState.SecondaryCommandBuffers[i], 0, 1, &GState.VertexBufferAllocation.Buffer, Offsets);
vkCmdBindIndexBuffer(GState.SecondaryCommandBuffers[i], GState.IndexBufferAllocation.Buffer, Offsets[0], VK_INDEX_TYPE_UINT32);
vkCmdBindDescriptorSets(
GState.SecondaryCommandBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, GState.PipelineLayout, 0, 1, &GState.DescriptorSets[i], 0, nullptr);
vkCmdDrawIndexed(GState.SecondaryCommandBuffers[i], Indices.size(), 1, 0, 0, 0);
vkEndCommandBuffer(GState.SecondaryCommandBuffers[i]);
}
vkCmdExecuteCommands(GState.CommandBuffers[i], 1, &GState.SecondaryCommandBuffers[i]);
vkCmdEndRendering(GState.CommandBuffers[i]);
The application craches in the validation layers, particulary in the vkCmdBeginRendering
, looks like it’s trying to dereference a nullptr. Any ideas?