Skip to content

Commit

Permalink
[d3d9] Optimize UpdateAnyColorWrites for 0th case
Browse files Browse the repository at this point in the history
This is the most common
  • Loading branch information
misyltoad committed May 24, 2023
1 parent cafd104 commit b5c18a0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
25 changes: 14 additions & 11 deletions src/d3d9/d3d9_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1981,22 +1981,22 @@ namespace dxvk {

case D3DRS_COLORWRITEENABLE:
if (likely(!old != !Value))
UpdateAnyColorWrites(0, !!Value);
UpdateAnyColorWrites<0>(!!Value);
m_flags.set(D3D9DeviceFlag::DirtyBlendState);
break;
case D3DRS_COLORWRITEENABLE1:
if (likely(!old != !Value))
UpdateAnyColorWrites(1, !!Value);
UpdateAnyColorWrites<1>(!!Value);
m_flags.set(D3D9DeviceFlag::DirtyBlendState);
break;
case D3DRS_COLORWRITEENABLE2:
if (likely(!old != !Value))
UpdateAnyColorWrites(2, !!Value);
UpdateAnyColorWrites<2>(!!Value);
m_flags.set(D3D9DeviceFlag::DirtyBlendState);
break;
case D3DRS_COLORWRITEENABLE3:
if (likely(!old != !Value))
UpdateAnyColorWrites(3, !!Value);
UpdateAnyColorWrites<3>(!!Value);
m_flags.set(D3D9DeviceFlag::DirtyBlendState);
break;

Expand Down Expand Up @@ -5361,18 +5361,19 @@ namespace dxvk {
UpdateActiveHazardsRT(bit);
}


inline void D3D9DeviceEx::UpdateAnyColorWrites(uint32_t index, bool has) {
const uint32_t bit = 1 << index;
template <uint32_t Index>
inline void D3D9DeviceEx::UpdateAnyColorWrites(bool has) {
const uint32_t bit = 1 << Index;

m_anyColorWrites &= ~bit;

if (has)
m_anyColorWrites |= bit;

if (m_boundRTs & bit) {
// The 0th RT is always bound.
if (Index == 0 || m_boundRTs & bit) {
m_flags.set(D3D9DeviceFlag::DirtyFramebuffer);
UpdateActiveRTs(index);
UpdateActiveRTs(Index);
}
}

Expand Down Expand Up @@ -7385,8 +7386,10 @@ namespace dxvk {
UpdatePixelBoolSpec(0u);
UpdateCommonSamplerSpec(0u, 0u, 0u);

for (uint32_t i = 0; i < caps::MaxSimultaneousRenderTargets; i++)
UpdateAnyColorWrites(i, true);
UpdateAnyColorWrites<0>(true);
UpdateAnyColorWrites<1>(true);
UpdateAnyColorWrites<2>(true);
UpdateAnyColorWrites<3>(true);
}


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

void UpdateActiveRTs(uint32_t index);

void UpdateAnyColorWrites(uint32_t index, bool has);
template <uint32_t Index>
void UpdateAnyColorWrites(bool has);

void UpdateActiveTextures(uint32_t index, DWORD combinedUsage);

Expand Down

0 comments on commit b5c18a0

Please sign in to comment.