diff --git a/src/dxvk/dxvk_context.cpp b/src/dxvk/dxvk_context.cpp index 9977bb1a3..c73e308b2 100644 --- a/src/dxvk/dxvk_context.cpp +++ b/src/dxvk/dxvk_context.cpp @@ -5598,34 +5598,47 @@ namespace dxvk { VkFormat depthStencilFormat = VK_FORMAT_UNDEFINED; VkImageAspectFlags depthStencilAspects = 0; + VkImageAspectFlags depthStencilWritable = 0; auto& depthInfo = m_state.om.renderingInfo.depth; depthInfo = { VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO }; - if (framebufferInfo.getDepthTarget().view != nullptr) { - const auto& depthTarget = framebufferInfo.getDepthTarget(); + const auto& depthTarget = framebufferInfo.getDepthTarget(); + + if (depthTarget.view) { depthStencilFormat = depthTarget.view->info().format; depthStencilAspects = depthTarget.view->info().aspects; + depthStencilWritable = vk::getWritableAspectsForLayout(depthTarget.layout); + + if (!m_device->properties().khrMaintenance7.separateDepthStencilAttachmentAccess && depthStencilWritable) + depthStencilWritable = depthStencilAspects; + depthInfo.imageView = depthTarget.view->handle(); depthInfo.imageLayout = depthTarget.layout; depthInfo.loadOp = ops.depthOps.loadOpD; - depthInfo.storeOp = VK_ATTACHMENT_STORE_OP_STORE; + depthInfo.storeOp = (depthStencilWritable & VK_IMAGE_ASPECT_DEPTH_BIT) + ? VK_ATTACHMENT_STORE_OP_STORE : VK_ATTACHMENT_STORE_OP_NONE; - if (ops.depthOps.loadOpD == VK_ATTACHMENT_LOAD_OP_CLEAR) + if (ops.depthOps.loadOpD == VK_ATTACHMENT_LOAD_OP_CLEAR) { depthInfo.clearValue.depthStencil.depth = ops.depthOps.clearValue.depth; + depthInfo.storeOp = VK_ATTACHMENT_STORE_OP_STORE; + } renderingInheritance.rasterizationSamples = depthTarget.view->image()->info().sampleCount; } - + auto& stencilInfo = m_state.om.renderingInfo.stencil; stencilInfo = depthInfo; - if (framebufferInfo.getDepthTarget().view != nullptr) { + if (depthTarget.view) { stencilInfo.loadOp = ops.depthOps.loadOpS; - stencilInfo.storeOp = VK_ATTACHMENT_STORE_OP_STORE; + stencilInfo.storeOp = (depthStencilWritable & VK_IMAGE_ASPECT_STENCIL_BIT) + ? VK_ATTACHMENT_STORE_OP_STORE : VK_ATTACHMENT_STORE_OP_NONE; - if (ops.depthOps.loadOpS == VK_ATTACHMENT_LOAD_OP_CLEAR) + if (ops.depthOps.loadOpS == VK_ATTACHMENT_LOAD_OP_CLEAR) { stencilInfo.clearValue.depthStencil.stencil = ops.depthOps.clearValue.stencil; + stencilInfo.storeOp = VK_ATTACHMENT_STORE_OP_STORE; + } } auto& renderingInfo = m_state.om.renderingInfo.rendering;