From 63d582a6e7ab63e18503d1238101705a818f5ad0 Mon Sep 17 00:00:00 2001 From: Joshua Ashton Date: Fri, 5 Aug 2022 19:12:21 +0000 Subject: [PATCH] [d3d9] Use VK_IMAGE_LAYOUT_ATTACHMENT_FEEDBACK_LOOP_EXT for hazards if available --- src/d3d9/d3d9_common_texture.h | 12 +++++++----- src/d3d9/d3d9_device.cpp | 10 +++++++--- src/d3d9/d3d9_device.h | 2 ++ src/d3d9/d3d9_subresource.h | 8 ++++---- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/d3d9/d3d9_common_texture.h b/src/d3d9/d3d9_common_texture.h index c29a9243c..7d15ca954 100644 --- a/src/d3d9/d3d9_common_texture.h +++ b/src/d3d9/d3d9_common_texture.h @@ -343,20 +343,22 @@ namespace dxvk { return m_sampleView.Pick(srgb && IsSrgbCompatible()); } - VkImageLayout DetermineRenderTargetLayout() const { + VkImageLayout DetermineRenderTargetLayout(VkImageLayout hazardLayout) const { + if (unlikely(m_hazardous)) + return hazardLayout; + return m_image != nullptr && - m_image->info().tiling == VK_IMAGE_TILING_OPTIMAL && - !m_hazardous + m_image->info().tiling == VK_IMAGE_TILING_OPTIMAL ? VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL : VK_IMAGE_LAYOUT_GENERAL; } - VkImageLayout DetermineDepthStencilLayout(bool write, bool hazardous) const { + VkImageLayout DetermineDepthStencilLayout(bool write, bool hazardous, VkImageLayout hazardLayout) const { VkImageLayout layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; if (unlikely(hazardous)) { layout = write - ? VK_IMAGE_LAYOUT_GENERAL + ? hazardLayout : VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL; } diff --git a/src/d3d9/d3d9_device.cpp b/src/d3d9/d3d9_device.cpp index f629f5524..edae98ac1 100644 --- a/src/d3d9/d3d9_device.cpp +++ b/src/d3d9/d3d9_device.cpp @@ -115,6 +115,10 @@ namespace dxvk { m_availableMemory = DetermineInitialTextureMemory(); + m_hazardLayout = dxvkDevice->features().extAttachmentFeedbackLoopLayout.attachmentFeedbackLoopLayout + ? VK_IMAGE_LAYOUT_ATTACHMENT_FEEDBACK_LOOP_OPTIMAL_EXT + : VK_IMAGE_LAYOUT_GENERAL; + // Initially set all the dirty flags so we // always end up giving the backend *something* to work with. m_flags.set(D3D9DeviceFlag::DirtyFramebuffer); @@ -5241,7 +5245,7 @@ namespace dxvk { // Guaranteed to not be nullptr... auto tex = m_state.renderTargets[rtIdx]->GetCommonTexture(); if (unlikely(!tex->MarkHazardous())) { - TransitionImage(tex, VK_IMAGE_LAYOUT_GENERAL); + TransitionImage(tex, m_hazardLayout); m_flags.set(D3D9DeviceFlag::DirtyFramebuffer); } } @@ -5447,7 +5451,7 @@ namespace dxvk { attachments.color[i] = { m_state.renderTargets[i]->GetRenderTargetView(srgb), - m_state.renderTargets[i]->GetRenderTargetLayout() }; + m_state.renderTargets[i]->GetRenderTargetLayout(m_hazardLayout) }; } if (m_state.depthStencil != nullptr && @@ -5460,7 +5464,7 @@ namespace dxvk { if (likely(sampleCount == VK_SAMPLE_COUNT_FLAG_BITS_MAX_ENUM || sampleCount == dsImageInfo.sampleCount)) { attachments.depth = { m_state.depthStencil->GetDepthStencilView(), - m_state.depthStencil->GetDepthStencilLayout(depthWrite, m_activeHazardsDS != 0) }; + m_state.depthStencil->GetDepthStencilLayout(depthWrite, m_activeHazardsDS != 0, m_hazardLayout) }; } } diff --git a/src/d3d9/d3d9_device.h b/src/d3d9/d3d9_device.h index 0e1b5401b..78b16337e 100644 --- a/src/d3d9/d3d9_device.h +++ b/src/d3d9/d3d9_device.h @@ -1255,6 +1255,8 @@ namespace dxvk { bool m_amdATOC = false; bool m_nvATOC = false; bool m_ffZTest = false; + + VkImageLayout m_hazardLayout = VK_IMAGE_LAYOUT_GENERAL; float m_depthBiasScale = 0.0f; diff --git a/src/d3d9/d3d9_subresource.h b/src/d3d9/d3d9_subresource.h index 8d0475018..3431cec47 100644 --- a/src/d3d9/d3d9_subresource.h +++ b/src/d3d9/d3d9_subresource.h @@ -95,8 +95,8 @@ namespace dxvk { return view; } - inline VkImageLayout GetRenderTargetLayout() const { - return m_texture->DetermineRenderTargetLayout(); + inline VkImageLayout GetRenderTargetLayout(VkImageLayout hazardLayout) const { + return m_texture->DetermineRenderTargetLayout(hazardLayout); } inline const Rc& GetDepthStencilView() { @@ -108,8 +108,8 @@ namespace dxvk { return view; } - inline VkImageLayout GetDepthStencilLayout(bool write, bool hazardous) const { - return m_texture->DetermineDepthStencilLayout(write, hazardous); + inline VkImageLayout GetDepthStencilLayout(bool write, bool hazardous, VkImageLayout hazardLayout) const { + return m_texture->DetermineDepthStencilLayout(write, hazardous, hazardLayout); } inline bool IsNull() {