From 9e1ecec79fc91011cd2ff4cdd5b56b3f2f0e4d19 Mon Sep 17 00:00:00 2001 From: Robin Kertels Date: Wed, 3 Aug 2022 02:21:46 +0200 Subject: [PATCH] [d3d9] Disable fetch4 when binding an incompatible texture Fixes lighting in Spider-Man: Shattered Dimensions. --- src/d3d9/d3d9_device.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/d3d9/d3d9_device.cpp b/src/d3d9/d3d9_device.cpp index 5cc87d97d..8f9f964ff 100644 --- a/src/d3d9/d3d9_device.cpp +++ b/src/d3d9/d3d9_device.cpp @@ -3779,13 +3779,20 @@ namespace dxvk { m_dirtySamplerStates |= 1u << StateSampler; } - if (unlikely(m_fetch4Enabled & (1u << StateSampler) && !(m_fetch4 & (1u << StateSampler)))) { - bool textureSupportsFetch4 = newTexture->SupportsFetch4(); - if (textureSupportsFetch4 - && m_state.samplerStates[StateSampler][D3DSAMP_MAGFILTER] == D3DTEXF_POINT - && m_state.samplerStates[StateSampler][D3DSAMP_MINFILTER] == D3DTEXF_POINT) { + if (unlikely(m_fetch4Enabled & (1u << StateSampler))) { + const bool samplerFetch4 = (m_fetch4 & (1u << StateSampler)) != 0; + const bool pointFilter = m_state.samplerStates[StateSampler][D3DSAMP_MAGFILTER] == D3DTEXF_POINT + && m_state.samplerStates[StateSampler][D3DSAMP_MINFILTER] == D3DTEXF_POINT; + const bool textureSupportsFetch4 = newTexture->SupportsFetch4(); + + if (unlikely(textureSupportsFetch4 && pointFilter && !samplerFetch4)) { + // We're swapping a multi channel texture for a single channel texture => turn on fetch4 m_fetch4 |= 1u << StateSampler; m_dirtySamplerStates |= 1u << StateSampler; + } else if (unlikely(!textureSupportsFetch4 && samplerFetch4)) { + // We're swapping a single channel texture for a multi channel one => turn off fetch4 + m_fetch4 &= ~(1u << StateSampler); + m_dirtySamplerStates |= 1u << StateSampler; } } } else if (unlikely(m_fetch4 & (1u << StateSampler))) {