From 254cd8bd06bf9bd12bfd712fbce5f16d9e520677 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Mon, 15 Oct 2018 16:35:40 +0200 Subject: [PATCH] [dxvk] Optimize image descriptor updates Avoids unnecessary atomic operations when rendering to a framebuffer with a depth attachment. --- src/dxvk/dxvk_context.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/dxvk/dxvk_context.cpp b/src/dxvk/dxvk_context.cpp index 1e6bfc47..86b74fa7 100644 --- a/src/dxvk/dxvk_context.cpp +++ b/src/dxvk/dxvk_context.cpp @@ -2536,10 +2536,19 @@ namespace dxvk { const DxvkPipelineLayout* layout) { bool updatePipelineState = false; - DxvkAttachment depthAttachment; + // If the depth attachment is also bound as a shader + // resource, we have to use the appropriate layout + VkImage depthImage = VK_NULL_HANDLE; + VkImageLayout depthLayout = VK_IMAGE_LAYOUT_UNDEFINED; - if (bindPoint == VK_PIPELINE_BIND_POINT_GRAPHICS && m_state.om.framebuffer != nullptr) - depthAttachment = m_state.om.framebuffer->getDepthTarget(); + if (bindPoint == VK_PIPELINE_BIND_POINT_GRAPHICS && m_state.om.framebuffer != nullptr) { + const auto& depthAttachment = m_state.om.framebuffer->getDepthTarget(); + + if (depthAttachment.view != nullptr) { + depthImage = depthAttachment.view->imageHandle(); + depthLayout = depthAttachment.layout; + } + } for (uint32_t i = 0; i < layout->bindingCount(); i++) { const auto& binding = layout->binding(i); @@ -2569,9 +2578,8 @@ namespace dxvk { m_descInfos[i].image.imageView = res.imageView->handle(binding.view); m_descInfos[i].image.imageLayout = res.imageView->imageInfo().layout; - if (depthAttachment.view != nullptr - && depthAttachment.view->image() == res.imageView->image()) - m_descInfos[i].image.imageLayout = depthAttachment.layout; + if (res.imageView->imageHandle() == depthImage) + m_descInfos[i].image.imageLayout = depthLayout; m_cmd->trackResource(res.imageView); m_cmd->trackResource(res.imageView->image());