From 5e48035e992d52c9862b2d2ef5ac1e92112cde90 Mon Sep 17 00:00:00 2001 From: Joshua Ashton Date: Wed, 11 Aug 2021 01:03:59 +0100 Subject: [PATCH] [d3d9] Only bind textures if they are used by the shader --- src/d3d9/d3d9_device.cpp | 11 ++++++----- src/d3d9/d3d9_device.h | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/d3d9/d3d9_device.cpp b/src/d3d9/d3d9_device.cpp index a344af5cb28..2a037118f41 100644 --- a/src/d3d9/d3d9_device.cpp +++ b/src/d3d9/d3d9_device.cpp @@ -5847,11 +5847,11 @@ namespace dxvk { } - void D3D9DeviceEx::UndirtyTextures() { - for (uint32_t tex = m_dirtyTextures; tex; tex &= tex - 1) + void D3D9DeviceEx::UndirtyTextures(uint32_t mask) { + for (uint32_t tex = mask; tex; tex &= tex - 1) BindTexture(bit::tzcnt(tex)); - m_dirtyTextures = 0; + m_dirtyTextures &= ~mask; } void D3D9DeviceEx::MarkTextureBindingDirty(IDirect3DBaseTexture9* texture) { @@ -5930,8 +5930,9 @@ namespace dxvk { if (activeDirtySamplers) UndirtySamplers(activeDirtySamplers); - if (m_dirtyTextures) - UndirtyTextures(); + const uint32_t activeDirtyTextures = m_dirtyTextures & usedSamplerMask; + if (activeDirtyTextures) + UndirtyTextures(activeDirtyTextures); if (m_flags.test(D3D9DeviceFlag::DirtyBlendState)) BindBlendState(); diff --git a/src/d3d9/d3d9_device.h b/src/d3d9/d3d9_device.h index 7dc5a386741..2c70c00f98a 100644 --- a/src/d3d9/d3d9_device.h +++ b/src/d3d9/d3d9_device.h @@ -837,7 +837,7 @@ namespace dxvk { void UndirtySamplers(uint32_t mask); - void UndirtyTextures(); + void UndirtyTextures(uint32_t mask); void MarkTextureBindingDirty(IDirect3DBaseTexture9* texture);