mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-21 05:09:34 -06:00
VideoBackends: rework d3d11 to specify samplers/bound textures using a bitset with a constant size, instead of hardcoding each individual enumeration value
This commit is contained in:
@ -28,12 +28,12 @@ StateManager::~StateManager() = default;
|
||||
|
||||
void StateManager::Apply()
|
||||
{
|
||||
if (!m_dirtyFlags)
|
||||
if (m_dirtyFlags.none())
|
||||
return;
|
||||
|
||||
// Framebuffer changes must occur before texture changes, otherwise the D3D runtime messes with
|
||||
// our bindings and sets them to null to prevent hazards.
|
||||
if (m_dirtyFlags & DirtyFlag_Framebuffer)
|
||||
if (m_dirtyFlags.test(DirtyFlag_Framebuffer))
|
||||
{
|
||||
if (g_ActiveConfig.backend_info.bSupportsBBox)
|
||||
{
|
||||
@ -56,11 +56,14 @@ void StateManager::Apply()
|
||||
m_current.use_integer_rtv = m_pending.use_integer_rtv;
|
||||
}
|
||||
|
||||
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);
|
||||
const bool dirtyConstants = m_dirtyFlags.test(DirtyFlag_PixelConstants) ||
|
||||
m_dirtyFlags.test(DirtyFlag_VertexConstants) ||
|
||||
m_dirtyFlags.test(DirtyFlag_GeometryConstants);
|
||||
const bool dirtyShaders = m_dirtyFlags.test(DirtyFlag_PixelShader) ||
|
||||
m_dirtyFlags.test(DirtyFlag_VertexShader) ||
|
||||
m_dirtyFlags.test(DirtyFlag_GeometryShader);
|
||||
const bool dirtyBuffers =
|
||||
m_dirtyFlags.test(DirtyFlag_VertexBuffer) || m_dirtyFlags.test(DirtyFlag_IndexBuffer);
|
||||
|
||||
if (dirtyConstants)
|
||||
{
|
||||
@ -87,7 +90,7 @@ void StateManager::Apply()
|
||||
}
|
||||
}
|
||||
|
||||
if (dirtyBuffers || (m_dirtyFlags & DirtyFlag_InputAssembler))
|
||||
if (dirtyBuffers || (m_dirtyFlags.test(DirtyFlag_InputAssembler)))
|
||||
{
|
||||
if (m_current.vertexBuffer != m_pending.vertexBuffer ||
|
||||
m_current.vertexBufferStride != m_pending.vertexBufferStride ||
|
||||
@ -140,17 +143,17 @@ void StateManager::Apply()
|
||||
}
|
||||
}
|
||||
|
||||
if (m_dirtyFlags & DirtyFlag_BlendState)
|
||||
if (m_dirtyFlags.test(DirtyFlag_BlendState))
|
||||
{
|
||||
D3D::context->OMSetBlendState(m_pending.blendState, nullptr, 0xFFFFFFFF);
|
||||
m_current.blendState = m_pending.blendState;
|
||||
}
|
||||
if (m_dirtyFlags & DirtyFlag_DepthState)
|
||||
if (m_dirtyFlags.test(DirtyFlag_DepthState))
|
||||
{
|
||||
D3D::context->OMSetDepthStencilState(m_pending.depthState, 0);
|
||||
m_current.depthState = m_pending.depthState;
|
||||
}
|
||||
if (m_dirtyFlags & DirtyFlag_RasterizerState)
|
||||
if (m_dirtyFlags.test(DirtyFlag_RasterizerState))
|
||||
{
|
||||
D3D::context->RSSetState(m_pending.rasterizerState);
|
||||
m_current.rasterizerState = m_pending.rasterizerState;
|
||||
@ -163,41 +166,32 @@ void StateManager::Apply()
|
||||
|
||||
void StateManager::ApplyTextures()
|
||||
{
|
||||
const int textureMaskShift = std::countr_zero((u32)DirtyFlag_Texture0);
|
||||
const int samplerMaskShift = std::countr_zero((u32)DirtyFlag_Sampler0);
|
||||
|
||||
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;
|
||||
while (dirtyTextures)
|
||||
for (u32 i = 0; i < VideoCommon::MAX_PIXEL_SHADER_SAMPLERS; i++)
|
||||
{
|
||||
const int index = std::countr_zero(dirtyTextures);
|
||||
if (m_current.textures[index] != m_pending.textures[index])
|
||||
const u32 flag = i;
|
||||
if (m_dirtyFlags.test(flag))
|
||||
{
|
||||
D3D::context->PSSetShaderResources(index, 1, &m_pending.textures[index]);
|
||||
m_current.textures[index] = m_pending.textures[index];
|
||||
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];
|
||||
}
|
||||
m_dirtyFlags.reset(flag);
|
||||
}
|
||||
|
||||
dirtyTextures &= ~(1 << index);
|
||||
}
|
||||
|
||||
while (dirtySamplers)
|
||||
for (u32 i = 0; i < VideoCommon::MAX_PIXEL_SHADER_SAMPLERS; i++)
|
||||
{
|
||||
const int index = std::countr_zero(dirtySamplers);
|
||||
if (m_current.samplers[index] != m_pending.samplers[index])
|
||||
const u32 flag = i + VideoCommon::MAX_PIXEL_SHADER_SAMPLERS;
|
||||
if (m_dirtyFlags.test(flag))
|
||||
{
|
||||
D3D::context->PSSetSamplers(index, 1, &m_pending.samplers[index]);
|
||||
m_current.samplers[index] = m_pending.samplers[index];
|
||||
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];
|
||||
}
|
||||
m_dirtyFlags.reset(flag);
|
||||
}
|
||||
|
||||
dirtySamplers &= ~(1 << index);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user