From 7797b9d753401871570d0993dff4e90ab0f1d126 Mon Sep 17 00:00:00 2001 From: Rodolfo Osvaldo Bogado Date: Sun, 10 Oct 2010 14:35:31 +0000 Subject: [PATCH] a little bugfix and a small optimization. this should fix issue 3313 but i can't test it git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@6267 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/Core/Common/Src/LinearDiskCache.cpp | 2 +- .../Core/VideoCommon/Src/PixelShaderGen.cpp | 40 ++++++++++++++++--- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/Source/Core/Common/Src/LinearDiskCache.cpp b/Source/Core/Common/Src/LinearDiskCache.cpp index f27b41e6e8..37dfb8a69a 100644 --- a/Source/Core/Common/Src/LinearDiskCache.cpp +++ b/Source/Core/Common/Src/LinearDiskCache.cpp @@ -22,7 +22,7 @@ static const char ID[4] = {'D', 'C', 'A', 'C'}; // Update this to the current SVN revision every time you change shader generation code. // We don't automatically get this from SVN_REV because that would mean regenerating the // shader cache for every revision, graphics-related or not, which is simply annoying. -const int version = 6223; +const int version = 6267; LinearDiskCache::LinearDiskCache() : file_(NULL), num_entries_(0) { diff --git a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp index 5a8050896a..e528c6a1b3 100644 --- a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp +++ b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp @@ -166,6 +166,7 @@ static void SampleTexture(char *&p, const char *destination, const char *texcoor // static void WriteAlphaCompare(char *&p, int num, int comp); static bool WriteAlphaTest(char *&p, API_TYPE ApiType); static void WriteFog(char *&p); +static int AlphaPreTest(); static const char *tevKSelTableC[] = // KCSEL { @@ -541,8 +542,27 @@ const char *GeneratePixelShaderCode(bool dstAlphaEnable, API_TYPE ApiType,u32 co } WRITE(p, " ) {\n"); - char* pmainstart = p; - + char* pmainstart = p; + int Pretest = AlphaPreTest(); + if (dstAlphaEnable && !DepthTextureEnable && Pretest >= 0) + { + if (!Pretest) + { + // alpha test will always fail, so restart the shader and just make it an empty function + WRITE(p, "ocol0 = 0;\n"); + if(DepthTextureEnable) + WRITE(p, "depth = 1.f;\n"); + WRITE(p, "discard;\n"); + if(ApiType != API_D3D11) + WRITE(p, "return;\n"); + } + else + { + WRITE(p, " ocol0 = "I_ALPHA"[0].aaaa;\n"); + } + WRITE(p, "}\n"); + return text; + } WRITE(p, " float4 c0 = "I_COLORS"[1], c1 = "I_COLORS"[2], c2 = "I_COLORS"[3], prev = float4(0.0f, 0.0f, 0.0f, 0.0f), textemp = float4(0.0f, 0.0f, 0.0f, 0.0f), rastemp = float4(0.0f, 0.0f, 0.0f, 0.0f), konsttemp = float4(0.0f, 0.0f, 0.0f, 0.0f);\n" " float3 comp16 = float3(1.0f, 255.0f, 0.0f), comp24 = float3(1.0f, 255.0f, 255.0f*255.0f);\n" @@ -970,7 +990,7 @@ static void WriteStage(char *&p, int n, API_TYPE ApiType) if (bCKonst || bAKonst ) { WRITE(p, "konsttemp = float4(%s, %s);\n", tevKSelTableC[kc], tevKSelTableA[ka]); - if(kc > 12 || ka > 15) + if(kc > 7 || ka > 7) { WRITE(p, "ckonsttemp = frac(4.0f + konsttemp * (255.0f/256.0f)) * (256.0f/255.0f);\n"); } @@ -1196,8 +1216,7 @@ static const char *tevAlphaFunclogicTable[] = " != ", // xor " == " // xnor }; - -static bool WriteAlphaTest(char *&p, API_TYPE ApiType) +static int AlphaPreTest() { u32 op = bpmem.alphaFunc.logic; u32 comp[2] = {bpmem.alphaFunc.comp0, bpmem.alphaFunc.comp1}; @@ -1227,8 +1246,19 @@ static bool WriteAlphaTest(char *&p, API_TYPE ApiType) break; default: PanicAlert("bad logic for alpha test? %08x", op); } + return -1; +} +static bool WriteAlphaTest(char *&p, API_TYPE ApiType) +{ + + int Pretest = AlphaPreTest(); + if(Pretest >= 0) + { + return Pretest; + } + // using discard then return works the same in cg and dx9 but not in dx11 WRITE(p, "if(!( ");