Skip to content

Commit

Permalink
[d3d9] Templatize BindShader
Browse files Browse the repository at this point in the history
We know what shader we are going to bind whenever this is called so we know it constexprly
  • Loading branch information
misyltoad committed Dec 16, 2019
1 parent 78ce35e commit 172ff06
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
24 changes: 14 additions & 10 deletions src/d3d9/d3d9_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1915,8 +1915,12 @@ namespace dxvk {
break;

case D3DRS_SHADEMODE:
if (m_state.pixelShader)
BindShader(DxsoProgramType::PixelShader, GetCommonShader(m_state.pixelShader), GetPixelShaderPermutation());
if (m_state.pixelShader) {
BindShader<DxsoProgramType::PixelShader>(
GetCommonShader(m_state.pixelShader),
GetPixelShaderPermutation());
}

m_flags.set(D3D9DeviceFlag::DirtyFFPixelShader);
break;

Expand Down Expand Up @@ -2667,8 +2671,7 @@ namespace dxvk {
m_flags.clr(D3D9DeviceFlag::DirtyProgVertexShader);
m_flags.set(D3D9DeviceFlag::DirtyFFVertexShader);

BindShader(
DxsoProgramTypes::VertexShader,
BindShader<DxsoProgramTypes::VertexShader>(
GetCommonShader(shader),
GetVertexShaderPermutation());
}
Expand Down Expand Up @@ -2993,8 +2996,7 @@ namespace dxvk {
if (shader != nullptr) {
m_flags.set(D3D9DeviceFlag::DirtyFFPixelShader);

BindShader(
DxsoProgramTypes::PixelShader,
BindShader<DxsoProgramTypes::PixelShader>(
GetCommonShader(shader),
GetPixelShaderPermutation());
}
Expand Down Expand Up @@ -5363,7 +5365,10 @@ namespace dxvk {
if (likely(UseProgrammableVS())) {
if (unlikely(m_flags.test(D3D9DeviceFlag::DirtyProgVertexShader))) {
m_flags.set(D3D9DeviceFlag::DirtyInputLayout);
BindShader(DxsoProgramType::VertexShader, GetCommonShader(m_state.vertexShader), GetVertexShaderPermutation());

BindShader<DxsoProgramType::VertexShader>(
GetCommonShader(m_state.vertexShader),
GetVertexShaderPermutation());
}
UploadConstants<DxsoProgramTypes::VertexShader>();
}
Expand Down Expand Up @@ -5441,15 +5446,14 @@ namespace dxvk {
}


template <DxsoProgramType ShaderStage>
void D3D9DeviceEx::BindShader(
DxsoProgramType ShaderStage,
const D3D9CommonShader* pShaderModule,
D3D9ShaderPermutation Permutation) {
EmitCs([
cStage = GetShaderStage(ShaderStage),
cShader = pShaderModule->GetShader(Permutation)
] (DxvkContext* ctx) {
ctx->bindShader(cStage, cShader);
ctx->bindShader(GetShaderStage(ShaderStage), cShader);
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/d3d9/d3d9_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -805,8 +805,8 @@ namespace dxvk {

void PrepareDraw(D3DPRIMITIVETYPE PrimitiveType, bool up = false);

template <DxsoProgramType ShaderStage>
void BindShader(
DxsoProgramType ShaderStage,
const D3D9CommonShader* pShaderModule,
D3D9ShaderPermutation Permutation);

Expand Down

0 comments on commit 172ff06

Please sign in to comment.