Merge pull request #2364 from kayru/d3d_texture_bsf
D3D: StateManager::Apply no longer iterates through every texture and sampler slot
This commit is contained in:
commit
e0cfd934d2
|
@ -2,6 +2,7 @@
|
||||||
// Licensed under GPLv2
|
// Licensed under GPLv2
|
||||||
// Refer to the license.txt file included.
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#include "Common/BitSet.h"
|
||||||
#include "Common/Logging/Log.h"
|
#include "Common/Logging/Log.h"
|
||||||
|
|
||||||
#include "VideoBackends/D3D/D3DBase.h"
|
#include "VideoBackends/D3D/D3DBase.h"
|
||||||
|
@ -87,15 +88,18 @@ void StateManager::Apply()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const u32 dirtyTextures = DirtyFlag_Texture0 | DirtyFlag_Texture1 | DirtyFlag_Texture2 | DirtyFlag_Texture3
|
int textureMaskShift = LeastSignificantSetBit((u32)DirtyFlag_Texture0);
|
||||||
| DirtyFlag_Texture4 | DirtyFlag_Texture5 | DirtyFlag_Texture6 | DirtyFlag_Texture7;
|
int samplerMaskShift = LeastSignificantSetBit((u32)DirtyFlag_Sampler0);
|
||||||
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;
|
|
||||||
|
|
||||||
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] ||
|
if (m_current.pixelConstants[0] != m_pending.pixelConstants[0] ||
|
||||||
m_current.pixelConstants[1] != m_pending.pixelConstants[1])
|
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 ||
|
if (m_current.vertexBuffer != m_pending.vertexBuffer ||
|
||||||
m_current.vertexBufferStride != m_pending.vertexBufferStride ||
|
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
|
D3D::context->PSSetShaderResources(index, 1, &m_pending.textures[index]);
|
||||||
if (m_current.textures[i] != m_pending.textures[i])
|
m_current.textures[index] = m_pending.textures[index];
|
||||||
{
|
|
||||||
D3D::context->PSSetShaderResources(i, 1, &m_pending.textures[i]);
|
|
||||||
m_current.textures[i] = m_pending.textures[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_dirtyFlags & dirtySamplers)
|
dirtyTextures &= ~(1 << index);
|
||||||
{
|
|
||||||
for (int i = 0; i < 8; ++i)
|
|
||||||
{
|
|
||||||
// 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];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_dirtyFlags & dirtyShaders)
|
while (dirtySamplers)
|
||||||
|
{
|
||||||
|
int index = LeastSignificantSetBit(dirtySamplers);
|
||||||
|
if (m_current.samplers[index] != m_pending.samplers[index])
|
||||||
|
{
|
||||||
|
D3D::context->PSSetSamplers(index, 1, &m_pending.samplers[index]);
|
||||||
|
m_current.samplers[index] = m_pending.samplers[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
dirtySamplers &= ~(1 << index);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dirtyShaders)
|
||||||
{
|
{
|
||||||
if (m_current.pixelShader != m_pending.pixelShader)
|
if (m_current.pixelShader != m_pending.pixelShader)
|
||||||
{
|
{
|
||||||
|
@ -219,8 +221,7 @@ void StateManager::SetTextureByMask(u32 textureSlotMask, ID3D11ShaderResourceVie
|
||||||
{
|
{
|
||||||
while (textureSlotMask)
|
while (textureSlotMask)
|
||||||
{
|
{
|
||||||
unsigned long index;
|
int index = LeastSignificantSetBit(textureSlotMask);
|
||||||
_BitScanForward(&index, textureSlotMask);
|
|
||||||
SetTexture(index, srv);
|
SetTexture(index, srv);
|
||||||
textureSlotMask &= ~(1 << index);
|
textureSlotMask &= ~(1 << index);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue