From f2a8fbb314aabb986e9f5711278272649a78b098 Mon Sep 17 00:00:00 2001 From: NeoBrainX Date: Fri, 29 Mar 2013 14:51:54 +0100 Subject: [PATCH] PixelShaderGen: Slightly reduce the number of redundant shader compilations. --- Source/Core/VideoCommon/Src/PixelShaderGen.cpp | 12 +++++++----- Source/Core/VideoCommon/Src/PixelShaderGen.h | 5 ++--- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp index d20e6ca755..6ee5a72994 100644 --- a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp +++ b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp @@ -289,7 +289,7 @@ void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType, u out.Write("//%i TEV stages, %i texgens, XXX IND stages\n", numStages, numTexgen/*, bpmem.genMode.numindstages*/); - SetUidField(components, components); +// SetUidField(components, components); // TODO: Enable once per pixel lighting is implemented again SetUidField(dstAlphaMode, dstAlphaMode); SetUidField(genMode.numindstages, bpmem.genMode.numindstages); @@ -620,8 +620,8 @@ void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType, u // Note: depth textures are disabled if early depth test is enabled SetUidField(ztex.op, bpmem.ztex2.op); - SetUidField(early_z, bpmem.zcontrol.early_ztest); // TODO: Should be per_pixel_depth instead... - SetUidField(ztestenable, bpmem.zmode.testenable); // TODO: Should be fog instead... + SetUidField(per_pixel_depth, per_pixel_depth); + SetUidField(fog.fsel, bpmem.fog.c_proj_fsel.fsel); // depth texture can safely be ignored if the result won't be written to the depth buffer (early_ztest) and isn't used for fog either bool skip_ztexture = !per_pixel_depth && !bpmem.fog.c_proj_fsel.fsel; @@ -632,12 +632,13 @@ void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType, u out.Write("zCoord = dot(" I_ZBIAS"[0].xyzw, textemp.xyzw) + " I_ZBIAS"[1].w %s;\n", (bpmem.ztex2.op == ZTEXTURE_ADD) ? "+ zCoord" : ""); - // scale to make result from frac correct + // U24 overflow emulation out.Write("zCoord = zCoord * (16777215.0f/16777216.0f);\n"); out.Write("zCoord = frac(zCoord);\n"); out.Write("zCoord = zCoord * (16777216.0f/16777215.0f);\n"); + // Note: depth texture output is only written to depth buffer if late depth test is used - // TODO: Should this be outside the ztex if-block? + // final depth value is used for fog calculation, though if (per_pixel_depth) out.Write("depth = zCoord;\n"); } @@ -1167,6 +1168,7 @@ static void WriteAlphaTest(T& out, API_TYPE ApiType, DSTALPHA_MODE dstAlphaMode, // when the alpha test fail. This is not a correct implementation because // even if the depth test fails the fragment could be alpha blended, but // we don't have a choice. + SetUidField(alpha_test.use_zcomploc_hack, bpmem.zcontrol.early_ztest && bpmem.zmode.updateenable); if (!(bpmem.zcontrol.early_ztest && bpmem.zmode.updateenable)) { out.Write("\t\tdiscard;\n"); diff --git a/Source/Core/VideoCommon/Src/PixelShaderGen.h b/Source/Core/VideoCommon/Src/PixelShaderGen.h index 4dc3e6c1e0..4f9cba0c37 100644 --- a/Source/Core/VideoCommon/Src/PixelShaderGen.h +++ b/Source/Core/VideoCommon/Src/PixelShaderGen.h @@ -163,6 +163,7 @@ struct pixel_shader_uid_data u32 comp1 : 3; u32 logic : 2; // TODO: ref??? + u32 use_zcomploc_hack : 1; } alpha_test; union { @@ -182,9 +183,7 @@ struct pixel_shader_uid_data u32 hex : 2; } ztex; - u32 early_z : 1; - u32 ztestenable : 1; - + u32 per_pixel_depth : 1; u32 bHasIndStage : 16; u32 xfregs_numTexGen_numTexGens : 4;