From 3004026db848c5478a1905c7e76d80952e62da40 Mon Sep 17 00:00:00 2001 From: Robin Kertels Date: Tue, 29 Mar 2022 22:51:59 +0200 Subject: [PATCH] [d3d9] Only bind RT if we actually write to it The alternative render path for shadow maps in Dead Space relies on this. --- src/d3d9/d3d9_device.cpp | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/d3d9/d3d9_device.cpp b/src/d3d9/d3d9_device.cpp index d4140de5f..1ca50924a 100644 --- a/src/d3d9/d3d9_device.cpp +++ b/src/d3d9/d3d9_device.cpp @@ -1795,8 +1795,9 @@ namespace dxvk { return m_recorder->SetRenderState(State, Value); auto& states = m_state.renderStates; + DWORD old = states[State]; - bool changed = states[State] != Value; + bool changed = old != Value; if (likely(changed)) { const bool oldClipPlaneEnabled = IsClipPlaneEnabled(); @@ -1880,19 +1881,31 @@ namespace dxvk { break; case D3DRS_COLORWRITEENABLE: - UpdateActiveRTs(0); + if (likely(!old != !Value)) { + m_flags.set(D3D9DeviceFlag::DirtyFramebuffer); + UpdateActiveRTs(0); + } m_flags.set(D3D9DeviceFlag::DirtyBlendState); break; case D3DRS_COLORWRITEENABLE1: - UpdateActiveRTs(1); + if (likely(!old != !Value && m_state.renderTargets[1] != nullptr)) { + m_flags.set(D3D9DeviceFlag::DirtyFramebuffer); + UpdateActiveRTs(1); + } m_flags.set(D3D9DeviceFlag::DirtyBlendState); break; case D3DRS_COLORWRITEENABLE2: - UpdateActiveRTs(2); + if (likely(!old != !Value && m_state.renderTargets[2] != nullptr)) { + m_flags.set(D3D9DeviceFlag::DirtyFramebuffer); + UpdateActiveRTs(2); + } m_flags.set(D3D9DeviceFlag::DirtyBlendState); break; case D3DRS_COLORWRITEENABLE3: - UpdateActiveRTs(3); + if (likely(!old != !Value && m_state.renderTargets[3] != nullptr)) { + m_flags.set(D3D9DeviceFlag::DirtyFramebuffer); + UpdateActiveRTs(3); + } m_flags.set(D3D9DeviceFlag::DirtyBlendState); break; @@ -5555,6 +5568,9 @@ namespace dxvk { else if (unlikely(sampleCount != rtImageInfo.sampleCount)) continue; + if (!m_state.renderStates[ColorWriteIndex(i)]) + continue; + attachments.color[i] = { m_state.renderTargets[i]->GetRenderTargetView(srgb), m_state.renderTargets[i]->GetRenderTargetLayout() };