Skip to content

Commit

Permalink
Merge pull request #2364 from kayru/d3d_texture_bsf
Browse files Browse the repository at this point in the history
D3D: StateManager::Apply no longer iterates through every texture and sampler slot
  • Loading branch information
degasus committed May 3, 2015
2 parents a04ec46 + df5750e commit e0cfd93
Showing 1 changed file with 29 additions and 28 deletions.
57 changes: 29 additions & 28 deletions Source/Core/VideoBackends/D3D/D3DState.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -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])
Expand All @@ -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 ||
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit e0cfd93

Please sign in to comment.