From a9339ae8321e855b2c12d6f7a60fe956d8cd4ba5 Mon Sep 17 00:00:00 2001 From: Joshua Ashton Date: Fri, 20 Mar 2020 13:19:23 +0000 Subject: [PATCH] [d3d9] Fix depth hazard case for write + read Closes #1519 --- src/d3d9/d3d9_common_texture.h | 12 ++++++++---- src/d3d9/d3d9_device.cpp | 11 +++++++++-- src/d3d9/d3d9_subresource.h | 4 ++-- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/d3d9/d3d9_common_texture.h b/src/d3d9/d3d9_common_texture.h index 0bc47d51..7e13d0d9 100644 --- a/src/d3d9/d3d9_common_texture.h +++ b/src/d3d9/d3d9_common_texture.h @@ -324,10 +324,14 @@ namespace dxvk { : VK_IMAGE_LAYOUT_GENERAL; } - VkImageLayout DetermineDepthStencilLayout(bool hazardous) const { - VkImageLayout layout = hazardous - ? VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL - : VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; + VkImageLayout DetermineDepthStencilLayout(bool write, bool hazardous) const { + VkImageLayout layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; + + if (unlikely(hazardous)) { + layout = write + ? VK_IMAGE_LAYOUT_GENERAL + : VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL; + } if (unlikely(m_image->info().tiling != VK_IMAGE_TILING_OPTIMAL)) layout = VK_IMAGE_LAYOUT_GENERAL; diff --git a/src/d3d9/d3d9_device.cpp b/src/d3d9/d3d9_device.cpp index c79ed3c6..124dd274 100644 --- a/src/d3d9/d3d9_device.cpp +++ b/src/d3d9/d3d9_device.cpp @@ -1783,10 +1783,16 @@ namespace dxvk { m_flags.set(D3D9DeviceFlag::DirtyMultiSampleState); break; + case D3DRS_ZWRITEENABLE: + if (m_activeHazardsDS != 0) + m_flags.set(D3D9DeviceFlag::DirtyFramebuffer); + + m_flags.set(D3D9DeviceFlag::DirtyDepthStencilState); + break; + case D3DRS_ZENABLE: case D3DRS_ZFUNC: case D3DRS_TWOSIDEDSTENCILMODE: - case D3DRS_ZWRITEENABLE: case D3DRS_STENCILENABLE: case D3DRS_STENCILFAIL: case D3DRS_STENCILZFAIL: @@ -4962,11 +4968,12 @@ namespace dxvk { if (m_state.depthStencil != nullptr) { const DxvkImageCreateInfo& dsImageInfo = m_state.depthStencil->GetCommonTexture()->GetImage()->info(); + const bool depthWrite = m_state.renderStates[D3DRS_ZWRITEENABLE]; if (likely(sampleCount == VK_SAMPLE_COUNT_FLAG_BITS_MAX_ENUM || sampleCount == dsImageInfo.sampleCount)) { attachments.depth = { m_state.depthStencil->GetDepthStencilView(), - m_state.depthStencil->GetDepthStencilLayout(m_activeHazardsDS != 0) }; + m_state.depthStencil->GetDepthStencilLayout(depthWrite, m_activeHazardsDS != 0) }; } } diff --git a/src/d3d9/d3d9_subresource.h b/src/d3d9/d3d9_subresource.h index b8107094..c96d8243 100644 --- a/src/d3d9/d3d9_subresource.h +++ b/src/d3d9/d3d9_subresource.h @@ -99,8 +99,8 @@ namespace dxvk { return view; } - VkImageLayout GetDepthStencilLayout(bool hazardous) const { - return m_texture->DetermineDepthStencilLayout(hazardous); + VkImageLayout GetDepthStencilLayout(bool write, bool hazardous) const { + return m_texture->DetermineDepthStencilLayout(write, hazardous); } bool IsNull() {