summaryrefslogtreecommitdiff
path: root/Source/Core
diff options
context:
space:
mode:
authorMarkus Wick <markus+github@selfnet.de>2015-05-03 21:39:33 +0200
committerMarkus Wick <markus+github@selfnet.de>2015-05-03 21:39:33 +0200
commite0cfd934d2d1c0bdedb91a4e030ecf11c9ca7694 (patch)
tree61a842132b38095b32d50abee4139720161d1d17 /Source/Core
parenta04ec46e40d893816dfb07394d073d8eda508527 (diff)
parentdf5750edfddef8939bb2f2034feeea43c8a3871e (diff)
Merge pull request #2364 from kayru/d3d_texture_bsf
D3D: StateManager::Apply no longer iterates through every texture and sampler slot
Diffstat (limited to 'Source/Core')
-rw-r--r--Source/Core/VideoBackends/D3D/D3DState.cpp57
1 files changed, 29 insertions, 28 deletions
diff --git a/Source/Core/VideoBackends/D3D/D3DState.cpp b/Source/Core/VideoBackends/D3D/D3DState.cpp
index 1f219fa2e2..7a6c34b9c4 100644
--- a/Source/Core/VideoBackends/D3D/D3DState.cpp
+++ b/Source/Core/VideoBackends/D3D/D3DState.cpp
@@ -2,6 +2,7 @@
// Licensed under GPLv2
// Refer to the license.txt file included.
+#include "Common/BitSet.h"
#include "Common/Logging/Log.h"
#include "VideoBackends/D3D/D3DBase.h"
@@ -87,15 +88,18 @@ void StateManager::Apply()
return;
}
- const u32 dirtyTextures = DirtyFlag_Texture0 | DirtyFlag_Texture1 | DirtyFlag_Texture2 | DirtyFlag_Texture3
- | DirtyFlag_Texture4 | DirtyFlag_Texture5 | DirtyFlag_Texture6 | DirtyFlag_Texture7;
- const u32 dirtySamplers = DirtyFlag_Sampler0 | DirtyFlag_Sampler1 | DirtyFlag_Sampler2 | DirtyFlag_Sampler3
- | DirtyFlag_Sampler4 | DirtyFlag_Sampler5 | DirtyFlag_Sampler6 | DirtyFlag_Sampler7;
- const u32 dirtyConstants = DirtyFlag_PixelConstants | DirtyFlag_VertexConstants | DirtyFlag_GeometryConstants;
- const u32 dirtyShaders = DirtyFlag_PixelShader | DirtyFlag_VertexShader | DirtyFlag_GeometryShader;
- const u32 dirtyBuffers = DirtyFlag_VertexBuffer | DirtyFlag_IndexBuffer;
+ int textureMaskShift = LeastSignificantSetBit((u32)DirtyFlag_Texture0);
+ int samplerMaskShift = LeastSignificantSetBit((u32)DirtyFlag_Sampler0);
- if (m_dirtyFlags & dirtyConstants)
+ u32 dirtyTextures = (m_dirtyFlags & (DirtyFlag_Texture0 | DirtyFlag_Texture1 | DirtyFlag_Texture2 | DirtyFlag_Texture3
+ | DirtyFlag_Texture4 | DirtyFlag_Texture5 | DirtyFlag_Texture6 | DirtyFlag_Texture7)) >> textureMaskShift;
+ u32 dirtySamplers = (m_dirtyFlags & (DirtyFlag_Sampler0 | DirtyFlag_Sampler1 | DirtyFlag_Sampler2 | DirtyFlag_Sampler3
+ | DirtyFlag_Sampler4 | DirtyFlag_Sampler5 | DirtyFlag_Sampler6 | DirtyFlag_Sampler7)) >> samplerMaskShift;
+ u32 dirtyConstants = m_dirtyFlags & (DirtyFlag_PixelConstants | DirtyFlag_VertexConstants | DirtyFlag_GeometryConstants);
+ u32 dirtyShaders = m_dirtyFlags & (DirtyFlag_PixelShader | DirtyFlag_VertexShader | DirtyFlag_GeometryShader);
+ u32 dirtyBuffers = m_dirtyFlags & (DirtyFlag_VertexBuffer | DirtyFlag_IndexBuffer);
+
+ if (dirtyConstants)
{
if (m_current.pixelConstants[0] != m_pending.pixelConstants[0] ||
m_current.pixelConstants[1] != m_pending.pixelConstants[1])
@@ -118,7 +122,7 @@ void StateManager::Apply()
}
}
- if (m_dirtyFlags & (dirtyBuffers|DirtyFlag_InputAssembler))
+ if (dirtyBuffers || (m_dirtyFlags & DirtyFlag_InputAssembler))
{
if (m_current.vertexBuffer != m_pending.vertexBuffer ||
m_current.vertexBufferStride != m_pending.vertexBufferStride ||
@@ -149,33 +153,31 @@ void StateManager::Apply()
}
}
- if (m_dirtyFlags & dirtyTextures)
+ while (dirtyTextures)
{
- for (int i = 0; i < 8; ++i)
+ int index = LeastSignificantSetBit(dirtyTextures);
+ if (m_current.textures[index] != m_pending.textures[index])
{
- // TODO: bit scan through dirty flags
- if (m_current.textures[i] != m_pending.textures[i])
- {
- D3D::context->PSSetShaderResources(i, 1, &m_pending.textures[i]);
- m_current.textures[i] = m_pending.textures[i];
- }
+ D3D::context->PSSetShaderResources(index, 1, &m_pending.textures[index]);
+ m_current.textures[index] = m_pending.textures[index];
}
+
+ dirtyTextures &= ~(1 << index);
}
- if (m_dirtyFlags & dirtySamplers)
+ while (dirtySamplers)
{
- for (int i = 0; i < 8; ++i)
+ int index = LeastSignificantSetBit(dirtySamplers);
+ if (m_current.samplers[index] != m_pending.samplers[index])
{
- // TODO: bit scan through dirty flags
- if (m_current.samplers[i] != m_pending.samplers[i])
- {
- D3D::context->PSSetSamplers(i, 1, &m_pending.samplers[i]);
- m_current.samplers[i] = m_pending.samplers[i];
- }
+ D3D::context->PSSetSamplers(index, 1, &m_pending.samplers[index]);
+ m_current.samplers[index] = m_pending.samplers[index];
}
+
+ dirtySamplers &= ~(1 << index);
}
- if (m_dirtyFlags & dirtyShaders)
+ if (dirtyShaders)
{
if (m_current.pixelShader != m_pending.pixelShader)
{
@@ -219,8 +221,7 @@ void StateManager::SetTextureByMask(u32 textureSlotMask, ID3D11ShaderResourceVie
{
while (textureSlotMask)
{
- unsigned long index;
- _BitScanForward(&index, textureSlotMask);
+ int index = LeastSignificantSetBit(textureSlotMask);
SetTexture(index, srv);
textureSlotMask &= ~(1 << index);
}