From 5403bfedc839cc9c49c67a170726695f989087e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Brooke?= Date: Wed, 21 Feb 2024 18:07:27 +0100 Subject: [PATCH] RHI: fix Vulkan layout for PreserveDepthStencilContents depth textures Vulkan fails when we attach a depth texture to a render target with QRhiTextureRenderTarget::PreserveDepthStencilContents (we want to reuse the depth data from a depth pre-pass.) vkCreateRenderPass(): pCreateInfo->pAttachments[3] format is VK_FORMAT_D32_SFLOAT and loadOp is VK_ATTACHMENT_LOAD_OP_LOAD, but initialLayout is VK_IMAGE_LAYOUT_UNDEFINED. The Vulkan spec states: If format includes a color or depth component and loadOp is VK_ATTACHMENT_LOAD_OP_LOAD, then initialLayout must not be VK_IMAGE_LAYOUT_UNDEFINED (https://www.khronos.org/registry/vulkan/ specs/1.3-extensions/html/vkspec.html#VUID-VkAttachmentDescription- format-06699) To fix this, just do the same as color attachments: specify a VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL instead of VK_IMAGE_LAYOUT_UNDEFINED when the depth-stencil is preserved. [ChangeLog][RHI] QRhiTextureRenderTarget::PreserveDepthStencilContents now works properly on Vulkan Change-Id: I0577bc8021b3598ddfdcea4af98aaef46e8a4519 Reviewed-by: Laszlo Agocs (cherry picked from commit 9904686cf3e3fb59fa7839b2d16a6c78bb35bfa1) Reviewed-by: Qt Cherry-pick Bot --- src/gui/rhi/qrhivulkan.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/rhi/qrhivulkan.cpp b/src/gui/rhi/qrhivulkan.cpp index 242263a0800..3860e30d290 100644 --- a/src/gui/rhi/qrhivulkan.cpp +++ b/src/gui/rhi/qrhivulkan.cpp @@ -1445,7 +1445,7 @@ bool QRhiVulkan::createOffscreenRenderPass(QVkRenderPassDescriptor *rpD, attDesc.storeOp = storeOp; attDesc.stencilLoadOp = loadOp; attDesc.stencilStoreOp = storeOp; - attDesc.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; + attDesc.initialLayout = preserveDs ? VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL : VK_IMAGE_LAYOUT_UNDEFINED; attDesc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; rpD->attDescs.append(attDesc); }