diff options
author | Robin Kertels <robin.kertels@gmail.com> | 2023-08-17 03:58:52 +0300 |
---|---|---|
committer | Joshie <joshua@froggi.es> | 2023-08-19 04:59:53 +0300 |
commit | bcaaac4ad7763986e2d7f80ae57500f036822bb9 (patch) | |
tree | ee03646cd4be6a2630029346e33e20e4ea23875d | |
parent | 1130512db5b696ae4e4491d11704ba12dd5a7060 (diff) |
[d3d9] Handle sampling from DS_READONLY properly
-rw-r--r-- | src/d3d9/d3d9_common_texture.h | 24 | ||||
-rw-r--r-- | src/d3d9/d3d9_device.cpp | 12 |
2 files changed, 17 insertions, 19 deletions
diff --git a/src/d3d9/d3d9_common_texture.h b/src/d3d9/d3d9_common_texture.h index 58cb854e..37b5bc3a 100644 --- a/src/d3d9/d3d9_common_texture.h +++ b/src/d3d9/d3d9_common_texture.h @@ -307,8 +307,8 @@ namespace dxvk { return util::computeMipLevelExtent(GetExtent(), MipLevel); } - bool MarkHazardous() { - return std::exchange(m_hazardous, true); + bool MarkTransitionedToHazardLayout() { + return std::exchange(m_transitionedToHazardLayout, true); } D3DRESOURCETYPE GetType() { @@ -340,7 +340,7 @@ namespace dxvk { } VkImageLayout DetermineRenderTargetLayout(VkImageLayout hazardLayout) const { - if (unlikely(m_hazardous)) + if (unlikely(m_transitionedToHazardLayout)) return hazardLayout; return m_image != nullptr && @@ -350,18 +350,16 @@ namespace dxvk { } VkImageLayout DetermineDepthStencilLayout(bool write, bool hazardous, VkImageLayout hazardLayout) const { - VkImageLayout layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; - - if (unlikely(hazardous)) { - layout = write - ? hazardLayout - : VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL; - } + if (unlikely(m_transitionedToHazardLayout)) + return hazardLayout; if (unlikely(m_image->info().tiling != VK_IMAGE_TILING_OPTIMAL)) - layout = VK_IMAGE_LAYOUT_GENERAL; + return VK_IMAGE_LAYOUT_GENERAL; + + if (unlikely(hazardous && !write)) + return VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL; - return layout; + return VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; } Rc<DxvkImageView> CreateView( @@ -512,7 +510,7 @@ namespace dxvk { int64_t m_size = 0; - bool m_hazardous = false; + bool m_transitionedToHazardLayout = false; D3D9ColorView m_sampleView; diff --git a/src/d3d9/d3d9_device.cpp b/src/d3d9/d3d9_device.cpp index 0d883c8d..7c14efa1 100644 --- a/src/d3d9/d3d9_device.cpp +++ b/src/d3d9/d3d9_device.cpp @@ -5595,8 +5595,7 @@ namespace dxvk { m_activeHazardsDS = m_activeHazardsDS & (~texMask); if (m_state.depthStencil != nullptr && - m_state.depthStencil->GetBaseTexture() != nullptr && - m_state.renderStates[D3DRS_ZWRITEENABLE]) { + m_state.depthStencil->GetBaseTexture() != nullptr) { for (uint32_t samplerIdx : bit::BitMask(masks.samplerMask)) { IDirect3DBaseTexture9* dsBase = m_state.depthStencil->GetBaseTexture(); IDirect3DBaseTexture9* texBase = m_state.textures[samplerIdx]; @@ -5643,16 +5642,17 @@ namespace dxvk { for (uint32_t samplerIdx : bit::BitMask(m_activeHazardsRT)) { // Guaranteed to not be nullptr... auto tex = GetCommonTexture(m_state.textures[samplerIdx]); - if (unlikely(!tex->MarkHazardous())) { + if (unlikely(!tex->MarkTransitionedToHazardLayout())) { TransitionImage(tex, m_hazardLayout); m_flags.set(D3D9DeviceFlag::DirtyFramebuffer); } } - if (m_activeHazardsDS != 0) { + bool zWriteEnabled = m_state.renderStates[D3DRS_ZWRITEENABLE]; + if (m_activeHazardsDS != 0 && zWriteEnabled) { // Guaranteed to not be nullptr... auto tex = m_state.depthStencil->GetCommonTexture(); - if (unlikely(!tex->MarkHazardous())) { + if (unlikely(!tex->MarkTransitionedToHazardLayout())) { TransitionImage(tex, m_hazardLayout); m_flags.set(D3D9DeviceFlag::DirtyFramebuffer); } @@ -5904,7 +5904,7 @@ namespace dxvk { if (m_hazardLayout == VK_IMAGE_LAYOUT_ATTACHMENT_FEEDBACK_LOOP_OPTIMAL_EXT) { if (m_activeHazardsRT != 0) feedbackLoopAspects |= VK_IMAGE_ASPECT_COLOR_BIT; - if (m_activeHazardsDS != 0) + if (m_activeHazardsDS != 0 && attachments.depth.layout != VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL) feedbackLoopAspects |= VK_IMAGE_ASPECT_DEPTH_BIT; } |