From 0c18a8609025d29f91b69e5ffce742b497140f47 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Thu, 11 Feb 2021 03:13:24 +0100 Subject: [PATCH] [dxvk] Fix render target clears if attachments are not tightly packed We do actually need to use the color target indices here rather than the attachment index, since the repacking happens inside DxvkRenderPass. Clear values still need to be tightly packed. --- src/dxvk/dxvk_context.cpp | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/dxvk/dxvk_context.cpp b/src/dxvk/dxvk_context.cpp index 2c0ecbed5..afba7d113 100644 --- a/src/dxvk/dxvk_context.cpp +++ b/src/dxvk/dxvk_context.cpp @@ -1795,12 +1795,11 @@ namespace dxvk { ops, 1, &clearValue); this->renderPassUnbindFramebuffer(); } else if (m_flags.test(DxvkContextFlag::GpRenderPassBound)) { - // Clear the attachment in quesion. For color images, - // the attachment index for the current subpass is - // equal to the render pass attachment index. + uint32_t colorIndex = std::max(0, m_state.om.framebuffer->getColorAttachmentIndex(attachmentIndex)); + VkClearAttachment clearInfo; clearInfo.aspectMask = clearAspects; - clearInfo.colorAttachment = attachmentIndex; + clearInfo.colorAttachment = colorIndex; clearInfo.clearValue = clearValue; VkClearRect clearRect; @@ -1815,9 +1814,12 @@ namespace dxvk { } else { // Perform the clear when starting the render pass if (clearAspects & VK_IMAGE_ASPECT_COLOR_BIT) { - m_state.om.renderPassOps.colorOps[attachmentIndex].loadOp = colorOp.loadOp; - if (m_state.om.renderPassOps.colorOps[attachmentIndex].loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR && !is3D) - m_state.om.renderPassOps.colorOps[attachmentIndex].loadLayout = VK_IMAGE_LAYOUT_UNDEFINED; + uint32_t colorIndex = m_state.om.framebuffer->getColorAttachmentIndex(attachmentIndex); + + m_state.om.renderPassOps.colorOps[colorIndex].loadOp = colorOp.loadOp; + if (m_state.om.renderPassOps.colorOps[colorIndex].loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR && !is3D) + m_state.om.renderPassOps.colorOps[colorIndex].loadLayout = VK_IMAGE_LAYOUT_UNDEFINED; + m_state.om.clearValues[attachmentIndex].color = clearValue.color; } @@ -2720,11 +2722,11 @@ namespace dxvk { // Perform the actual clear operation VkClearAttachment clearInfo; clearInfo.aspectMask = aspect; - clearInfo.colorAttachment = attachmentIndex; + clearInfo.colorAttachment = 0; clearInfo.clearValue = value; - if (attachmentIndex < 0) - clearInfo.colorAttachment = 0; + if ((aspect & VK_IMAGE_ASPECT_COLOR_BIT) && (attachmentIndex >= 0)) + clearInfo.colorAttachment = m_state.om.framebuffer->getColorAttachmentIndex(attachmentIndex); VkClearRect clearRect; clearRect.rect.offset.x = offset.x;