From cf7a4ab2cf97df56c10a612ce0197d22544cb265 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 8 Mar 2015 18:28:59 -0700 Subject: [PATCH] Avoid shader id data that doesn't change shader. This may reduce shader switches, or more likely at least total # of shaders, when alpha test settings are changed but alpha test is not enabled. --- GPU/Directx9/PixelShaderGeneratorDX9.cpp | 19 +++++++++---------- GPU/GLES/FragmentShaderGenerator.cpp | 19 +++++++++---------- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/GPU/Directx9/PixelShaderGeneratorDX9.cpp b/GPU/Directx9/PixelShaderGeneratorDX9.cpp index 1f22ccb915..7c54f12862 100644 --- a/GPU/Directx9/PixelShaderGeneratorDX9.cpp +++ b/GPU/Directx9/PixelShaderGeneratorDX9.cpp @@ -415,7 +415,6 @@ void ComputeFragmentShaderIDDX9(FragmentShaderIDDX9 *id) { bool lmode = gstate.isUsingSecondaryColor() && gstate.isLightingEnabled(); bool enableFog = gstate.isFogEnabled() && !gstate.isModeThrough(); bool enableAlphaTest = gstate.isAlphaTestEnabled() && !IsAlphaTestTriviallyTrue() && !g_Config.bDisableAlphaTest; - bool alphaTestAgainstZero = IsAlphaTestAgainstZero(); bool enableColorTest = gstate.isColorTestEnabled() && !IsColorTestTriviallyTrue(); bool enableColorDoubling = gstate.isColorDoublingEnabled(); bool doTextureProjection = gstate.getUVGenMode() == GE_TEXMAP_TEXTURE_MATRIX; @@ -447,28 +446,28 @@ void ComputeFragmentShaderIDDX9(FragmentShaderIDDX9 *id) { id0 |= (lmode & 1) << 11; #if !defined(DX9_USE_HW_ALPHA_TEST) if (enableAlphaTest) { - // 4 bits total. + // 5 bits total. id0 |= 1 << 12; id0 |= gstate.getAlphaTestFunction() << 13; + id0 |= (IsAlphaTestAgainstZero() & 1) << 16; } #endif if (enableColorTest) { // 3 bits total. - id0 |= 1 << 16; - id0 |= gstate.getColorTestFunction() << 17; + id0 |= 1 << 17; + id0 |= gstate.getColorTestFunction() << 18; } - id0 |= (enableFog & 1) << 19; - id0 |= (doTextureProjection & 1) << 20; - id0 |= (enableColorDoubling & 1) << 21; + id0 |= (enableFog & 1) << 20; + id0 |= (doTextureProjection & 1) << 21; + id0 |= (enableColorDoubling & 1) << 22; // 2 bits - id0 |= (stencilToAlpha) << 22; + id0 |= (stencilToAlpha) << 23; if (stencilToAlpha != REPLACE_ALPHA_NO) { // 4 bits - id0 |= ReplaceAlphaWithStencilType() << 24; + id0 |= ReplaceAlphaWithStencilType() << 25; } - id0 |= (alphaTestAgainstZero & 1) << 28; if (enableAlphaTest) gpuStats.numAlphaTestedDraws++; else diff --git a/GPU/GLES/FragmentShaderGenerator.cpp b/GPU/GLES/FragmentShaderGenerator.cpp index e7f171d079..2bb1896b3a 100644 --- a/GPU/GLES/FragmentShaderGenerator.cpp +++ b/GPU/GLES/FragmentShaderGenerator.cpp @@ -397,7 +397,6 @@ void ComputeFragmentShaderID(ShaderID *id) { bool lmode = gstate.isUsingSecondaryColor() && gstate.isLightingEnabled(); bool enableFog = gstate.isFogEnabled() && !gstate.isModeThrough(); bool enableAlphaTest = gstate.isAlphaTestEnabled() && !IsAlphaTestTriviallyTrue() && !g_Config.bDisableAlphaTest; - bool alphaTestAgainstZero = IsAlphaTestAgainstZero(); bool enableColorTest = gstate.isColorTestEnabled() && !IsColorTestTriviallyTrue(); bool enableColorDoubling = gstate.isColorDoublingEnabled() && gstate.isTextureMapEnabled(); bool doTextureProjection = gstate.getUVGenMode() == GE_TEXMAP_TEXTURE_MATRIX; @@ -430,28 +429,28 @@ void ComputeFragmentShaderID(ShaderID *id) { id0 |= (lmode & 1) << 11; #if !defined(DX9_USE_HW_ALPHA_TEST) if (enableAlphaTest) { - // 4 bits total. + // 5 bits total. id0 |= 1 << 12; id0 |= gstate.getAlphaTestFunction() << 13; + id0 |= (IsAlphaTestAgainstZero() & 1) << 16; } #endif if (enableColorTest) { // 3 bits total. - id0 |= 1 << 16; - id0 |= gstate.getColorTestFunction() << 17; + id0 |= 1 << 17; + id0 |= gstate.getColorTestFunction() << 18; } - id0 |= (enableFog & 1) << 19; - id0 |= (doTextureProjection & 1) << 20; - id0 |= (enableColorDoubling & 1) << 21; + id0 |= (enableFog & 1) << 20; + id0 |= (doTextureProjection & 1) << 21; + id0 |= (enableColorDoubling & 1) << 22; // 2 bits - id0 |= (stencilToAlpha) << 22; + id0 |= (stencilToAlpha) << 23; if (stencilToAlpha != REPLACE_ALPHA_NO) { // 4 bits - id0 |= ReplaceAlphaWithStencilType() << 24; + id0 |= ReplaceAlphaWithStencilType() << 25; } - id0 |= (alphaTestAgainstZero & 1) << 28; if (enableAlphaTest) gpuStats.numAlphaTestedDraws++; else