如何设置具有深度附件的多采样渲染通道?
How to set multisample renderpass with depth attachment?
首先,我没有从验证层中发现任何错误,并且多重采样正在运行。
但是当我复制深度解析图像时,我明白它是空的。
当复制深度 msaa 图像时,我看到它不是空的。(但正如预期的那样,验证层给出了错误,因为我将 VK_SAMPLE_COUNT_4_BIT 复制到 VK_SAMPLE_COUNT_1_BIT 但仍然很有趣。这就是我的方式发现深度msaa图像没有问题)
因此这里应该是深度解析问题,我犯了错误:
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;
无法在原版 Vulkan 中解析深度。它需要 VK_KHR_depth_stencil_resolve 扩展名,resp。凡尔康 1.2。它将 VkSubpassDescriptionDepthStencilResolve::pDepthStencilResolveAttachment
添加到 API.
首先,我没有从验证层中发现任何错误,并且多重采样正在运行。 但是当我复制深度解析图像时,我明白它是空的。
当复制深度 msaa 图像时,我看到它不是空的。(但正如预期的那样,验证层给出了错误,因为我将 VK_SAMPLE_COUNT_4_BIT 复制到 VK_SAMPLE_COUNT_1_BIT 但仍然很有趣。这就是我的方式发现深度msaa图像没有问题)
因此这里应该是深度解析问题,我犯了错误:
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;
无法在原版 Vulkan 中解析深度。它需要 VK_KHR_depth_stencil_resolve 扩展名,resp。凡尔康 1.2。它将 VkSubpassDescriptionDepthStencilResolve::pDepthStencilResolveAttachment
添加到 API.