How to set multisample renderpass with depth attachment?
Firstly i have taking no error from validation layers and multisample is working. But when i copy depth resolved image , I understand that it is empty.
When copy depth msaa image , I saw that it is not empty.( but as expected validation layers gave error because i copied VK_SAMPLE_COUNT_4_BIT to VK_SAMPLE_COUNT_1_BIT but still worked interesting . This is how I found out that there is no problem in depth msaa image)
Therefore here should be depth resolving problem , where i am making mistake :
VkAttachmentDescription colorAttachment_MSAA{};
colorAttachment_MSAA.samples = VK_SAMPLE_COUNT_4_BIT;
...
VkAttachmentDescription colorAttachment_Resolve{};
colorAttachment_Resolve.samples = VK_SAMPLE_COUNT_1_BIT;
...
VkAttachmentDescription depthAttachment_MSAA{};
depthAttachment_MSAA.samples = VK_SAMPLE_COUNT_4_BIT;
...
VkAttachmentDescription depthAttachment_Resolve{};
depthAttachment_Resolve.samples = VK_SAMPLE_COUNT_1_BIT;
depthAttachment_Resolve.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
depthAttachment_Resolve.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
depthAttachment_Resolve.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
depthAttachment_Resolve.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
...
VkAttachmentReference colorAttachment_MSAA_Ref{};
colorAttachment_MSAA_Ref.attachment = 0;
colorAttachment_MSAA_Ref.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
VkAttachmentReference depthAttachment_MSAA_Ref{};
depthAttachment_MSAA_Ref.attachment = 1;
depthAttachment_MSAA_Ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
VkAttachmentReference colorAttachment_Resolve_Ref{};
colorAttachment_MSAA_Ref.attachment = 2;
colorAttachment_MSAA_Ref.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
//i created depthAttachment_Resolve_Ref but I couldn't find a place to use.
VkAttachmentReference depthAttachment_Resolve_Ref{};
depthAttachment_MSAA_Ref.attachment = 3;
depthAttachment_MSAA_Ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
VkSubpassDescription subpass{};
subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
subpass.colorAttachmentCount = 1;
subpass.pColorAttachments = &colorAttachment_MSAA_Ref;
subpass.pDepthStencilAttachment = &depthAttachment_MSAA_Ref;
subpass.pResolveAttachments = &colorAttachment_Resolve_Ref;
VkSubpassDependency dependency{};
dependency.srcSubpass = VK_SUBPASS_EXTERNAL;
dependency.dstSubpass = 0;
dependency.srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT;
dependency.srcAccessMask = 0;
dependency.dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT;
dependency.dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
array<VkAttachmentDescription, 4> attachments = { colorAttachment_MSAA , depthAttachment_MSAA,
colorAttachment_Resolve, depthAttachment_Resolve};
VkRenderPassCreateInfo renderPassInfo{};
renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
renderPassInfo.attachmentCount = static_cast<uint32_t>(attachments.size());
renderPassInfo.pAttachments = attachments.data();
renderPassInfo.subpassCount = 1;
renderPassInfo.pSubpasses = &subpass;
renderPassInfo.dependencyCount = 1;
renderPassInfo.pDependencies = &dependency;
Comments
Post a Comment