From f5d4fe0bfe13937fa3736aa6b78974ceb6e190ad Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Sat, 3 Mar 2012 20:07:20 +0100 Subject: Fix some minor bugs pointed out by PVS Studio (thanks!) --- Source/Core/VideoCommon/Src/PixelShaderGen.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/VideoCommon/Src/PixelShaderGen.cpp') diff --git a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp index fe5827de05..3ef923dc3e 100644 --- a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp +++ b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp @@ -158,7 +158,7 @@ void GetPixelShaderId(PIXELSHADERUID *uid, DSTALPHA_MODE dstAlphaMode, u32 compo } u32* ptr = &uid->values[2]; - for (int i = 0; i < bpmem.genMode.numtevstages+1; ++i) + for (unsigned int i = 0; i < bpmem.genMode.numtevstages+1; ++i) { StageHash(i, ptr); ptr += 4; // max: ptr = &uid->values[66] -- cgit v1.2.3 From 006923e871e496a7c6c0fe9ba76da4ee939ce14e Mon Sep 17 00:00:00 2001 From: skidau Date: Thu, 22 Mar 2012 20:36:41 +1100 Subject: Disabled zcomploc while update_enable has been set in zmode. Fixes zcomploc in F-Zero GX. --- Source/Core/VideoCommon/Src/PixelShaderGen.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/VideoCommon/Src/PixelShaderGen.cpp') diff --git a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp index e4944c842c..ec4eb2c70b 100644 --- a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp +++ b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp @@ -1147,7 +1147,7 @@ static bool WriteAlphaTest(char *&p, API_TYPE ApiType,DSTALPHA_MODE dstAlphaMode WRITE(p, "ocol1 = 0;\n"); if (DepthTextureEnable) WRITE(p, "depth = 1.f;\n"); - if (!bpmem.zcontrol.zcomploc) + if (!(bpmem.zcontrol.zcomploc && bpmem.zmode.updateenable)) { WRITE(p, "discard;\n"); if (ApiType != API_D3D11) -- cgit v1.2.3 From 339ee98e6258024622ef509aafe25ff46ad19341 Mon Sep 17 00:00:00 2001 From: Pierre Bourdon Date: Thu, 22 Mar 2012 22:10:23 +0100 Subject: Add a comment before the zcomploc test explaining the implementation/hack --- Source/Core/VideoCommon/Src/PixelShaderGen.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'Source/Core/VideoCommon/Src/PixelShaderGen.cpp') diff --git a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp index 46ac264889..79afc45974 100644 --- a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp +++ b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp @@ -1198,6 +1198,16 @@ static bool WriteAlphaTest(char *&p, API_TYPE ApiType,DSTALPHA_MODE dstAlphaMode WRITE(p, "ocol1 = 0;\n"); if (DepthTextureEnable) WRITE(p, "depth = 1.f;\n"); + + // HAXX: zcomploc is a way to control whether depth test is done before + // or after texturing and alpha test. PC GPU have no way to support this + // feature properly as of 2012: depth buffer and depth test are not + // programmable and the depth test is always done after texturing. + // + // We implement "depth test before texturing" by discarding the fragment + // 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. if (!(bpmem.zcontrol.zcomploc && bpmem.zmode.updateenable)) { WRITE(p, "discard;\n"); -- cgit v1.2.3 From 41bcf657f89d912bb048247767c211f63eb13e94 Mon Sep 17 00:00:00 2001 From: skidau Date: Fri, 23 Mar 2012 23:20:19 +1100 Subject: Adjusted the DX9 offset of the Sampling address to more closely match what we are seeing in games. Fixes issue 5305. --- Source/Core/VideoCommon/Src/PixelShaderGen.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Source/Core/VideoCommon/Src/PixelShaderGen.cpp') diff --git a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp index 3ef923dc3e..da78c01741 100644 --- a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp +++ b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp @@ -1106,9 +1106,9 @@ void SampleTexture(char *&p, const char *destination, const char *texcoords, con WRITE(p, "%s=Tex%d.Sample(samp%d, %s.xy * "I_TEXDIMS"[%d].xy).%s;\n", destination, texmap,texmap, texcoords, texmap, texswap); else if (ApiType & API_D3D9) { - // D3D9 uses different pixel to texel mapping, so we need to offset our sampling address by half a pixel (assuming native and virtual texture dimensions match each other, otherwise some math is involved). + // D3D9 uses different pixel to texel mapping, so we need to offset our sampling address. // Read the MSDN article "Directly Mapping Texels to Pixels (Direct3D 9)" for further info. - WRITE(p, "%s=tex2D(samp%d, (%s.xy + 0.5f*"I_VTEXSCALE"[%d].%s) * "I_TEXDIMS"[%d].xy).%s;\n", destination, texmap, texcoords, texmap/2, (texmap&1)?"zw":"xy", texmap, texswap); + WRITE(p, "%s=tex2D(samp%d, (%s.xy + 0.0005f*"I_VTEXSCALE"[%d].%s) * "I_TEXDIMS"[%d].xy).%s;\n", destination, texmap, texcoords, texmap/2, (texmap&1)?"zw":"xy", texmap, texswap); } else WRITE(p, "%s=tex2D(samp%d, %s.xy * "I_TEXDIMS"[%d].xy).%s;\n", destination, texmap, texcoords, texmap, texswap); -- cgit v1.2.3 From fee98b426b5a0c4d78042a2db3b352c4fe79ef56 Mon Sep 17 00:00:00 2001 From: NeoBrainX Date: Sat, 24 Mar 2012 04:47:28 +0100 Subject: Revert r41bcf657f89d, r3a9fed0ba285, r9adc119e3c2f and re58692653afd (all of them are wrong). --- Source/Core/VideoCommon/Src/PixelShaderGen.cpp | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) (limited to 'Source/Core/VideoCommon/Src/PixelShaderGen.cpp') diff --git a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp index da78c01741..662c9c59a8 100644 --- a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp +++ b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp @@ -560,10 +560,6 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType WRITE(p, "uniform float4 "I_KCOLORS"[4] : register(c%d);\n", C_KCOLORS); WRITE(p, "uniform float4 "I_ALPHA"[1] : register(c%d);\n", C_ALPHA); WRITE(p, "uniform float4 "I_TEXDIMS"[8] : register(c%d);\n", C_TEXDIMS); - if (ApiType & API_D3D9) - { - WRITE(p, "uniform float4 "I_VTEXSCALE"[4] : register(c%d);\n", C_VTEXSCALE); - } WRITE(p, "uniform float4 "I_ZBIAS"[2] : register(c%d);\n", C_ZBIAS); WRITE(p, "uniform float4 "I_INDTEXSCALE"[2] : register(c%d);\n", C_INDTEXSCALE); WRITE(p, "uniform float4 "I_INDTEXMTX"[6] : register(c%d);\n", C_INDTEXMTX); @@ -1103,15 +1099,9 @@ static void WriteStage(char *&p, int n, API_TYPE ApiType) void SampleTexture(char *&p, const char *destination, const char *texcoords, const char *texswap, int texmap, API_TYPE ApiType) { if (ApiType == API_D3D11) - WRITE(p, "%s=Tex%d.Sample(samp%d, %s.xy * "I_TEXDIMS"[%d].xy).%s;\n", destination, texmap,texmap, texcoords, texmap, texswap); - else if (ApiType & API_D3D9) - { - // D3D9 uses different pixel to texel mapping, so we need to offset our sampling address. - // Read the MSDN article "Directly Mapping Texels to Pixels (Direct3D 9)" for further info. - WRITE(p, "%s=tex2D(samp%d, (%s.xy + 0.0005f*"I_VTEXSCALE"[%d].%s) * "I_TEXDIMS"[%d].xy).%s;\n", destination, texmap, texcoords, texmap/2, (texmap&1)?"zw":"xy", texmap, texswap); - } + WRITE(p, "%s=Tex%d.Sample(samp%d,%s.xy * "I_TEXDIMS"[%d].xy).%s;\n", destination, texmap,texmap, texcoords, texmap, texswap); else - WRITE(p, "%s=tex2D(samp%d, %s.xy * "I_TEXDIMS"[%d].xy).%s;\n", destination, texmap, texcoords, texmap, texswap); + WRITE(p, "%s=tex2D(samp%d,%s.xy * "I_TEXDIMS"[%d].xy).%s;\n", destination, texmap, texcoords, texmap, texswap); } static const char *tevAlphaFuncsTable[] = -- cgit v1.2.3 From 9ed83765e69f81ae1799e8e8ff8cfada2f53e9a2 Mon Sep 17 00:00:00 2001 From: rodolfoosvaldobogado Date: Sun, 25 Mar 2012 00:01:47 -0300 Subject: long time no commits :) a little code cleaning to avoid duplicated execution of AlphaPreTest and a little correction to some comments from the previous commits. this change must behave exactly like last revision, if something is broken please let me know --- Source/Core/VideoCommon/Src/PixelShaderGen.cpp | 134 ++++++++++++------------- 1 file changed, 63 insertions(+), 71 deletions(-) (limited to 'Source/Core/VideoCommon/Src/PixelShaderGen.cpp') diff --git a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp index 89032c67ea..76964f248c 100644 --- a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp +++ b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp @@ -299,7 +299,7 @@ void ValidatePixelShaderIDs(API_TYPE api, PIXELSHADERUIDSAFE old_id, const std:: static void WriteStage(char *&p, int n, API_TYPE ApiType); static void SampleTexture(char *&p, const char *destination, const char *texcoords, const char *texswap, int texmap, API_TYPE ApiType); // static void WriteAlphaCompare(char *&p, int num, int comp); -static bool WriteAlphaTest(char *&p, API_TYPE ApiType,DSTALPHA_MODE dstAlphaMode); +static void WriteAlphaTest(char *&p, API_TYPE ApiType,DSTALPHA_MODE dstAlphaMode); static void WriteFog(char *&p); static const char *tevKSelTableC[] = // KCSEL @@ -619,22 +619,29 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType char* pmainstart = p; int Pretest = AlphaPreTest(); - if (dstAlphaMode == DSTALPHA_ALPHA_PASS && !DepthTextureEnable && Pretest >= 0) + if(Pretest >= 0 && !DepthTextureEnable) { if (!Pretest) { - // alpha test will always fail, so restart the shader and just make it an empty function + // 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"); + if(dstAlphaMode == DSTALPHA_DUAL_SOURCE_BLEND) + WRITE(p, "ocol1 = 0;\n"); WRITE(p, "discard;\n"); if(ApiType != API_D3D11) WRITE(p, "return;\n"); } - else + else if (dstAlphaMode == DSTALPHA_ALPHA_PASS) { WRITE(p, " ocol0 = "I_ALPHA"[0].aaaa;\n"); } - WRITE(p, "}\n"); - return text; + if(!Pretest || dstAlphaMode == DSTALPHA_ALPHA_PASS) + { + 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" @@ -723,65 +730,53 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType // emulation of unsigned 8 overflow when casting WRITE(p, "prev = frac(4.0f + prev * (255.0f/256.0f)) * (256.0f/255.0f);\n"); - // TODO: Why are we doing a second alpha pretest here? - if (!WriteAlphaTest(p, ApiType, dstAlphaMode)) + if(Pretest == -1) { - // alpha test will always fail, so restart the shader and just make it an empty function - p = pmainstart; - WRITE(p, "ocol0 = 0;\n"); - if(DepthTextureEnable) - WRITE(p, "depth = 1.f;\n"); - if(dstAlphaMode == DSTALPHA_DUAL_SOURCE_BLEND) - WRITE(p, "ocol1 = 0;\n"); - WRITE(p, "discard;\n"); - if(ApiType != API_D3D11) - WRITE(p, "return;\n"); + WriteAlphaTest(p, ApiType, dstAlphaMode); } - else - { - if((bpmem.fog.c_proj_fsel.fsel != 0) || DepthTextureEnable) - { - // the screen space depth value = far z + (clip z / clip w) * z range - WRITE(p, "float zCoord = "I_ZBIAS"[1].x + (clipPos.z / clipPos.w) * "I_ZBIAS"[1].y;\n"); - } + if((bpmem.fog.c_proj_fsel.fsel != 0) || DepthTextureEnable) + { + // the screen space depth value = far z + (clip z / clip w) * z range + WRITE(p, "float zCoord = "I_ZBIAS"[1].x + (clipPos.z / clipPos.w) * "I_ZBIAS"[1].y;\n"); + } - if (DepthTextureEnable) + if (DepthTextureEnable) + { + // use the texture input of the last texture stage (textemp), hopefully this has been read and is in correct format... + if (bpmem.ztex2.op != ZTEXTURE_DISABLE && !bpmem.zcontrol.zcomploc && bpmem.zmode.testenable && bpmem.zmode.updateenable) { - // use the texture input of the last texture stage (textemp), hopefully this has been read and is in correct format... - if (bpmem.ztex2.op != ZTEXTURE_DISABLE && !bpmem.zcontrol.zcomploc && bpmem.zmode.testenable && bpmem.zmode.updateenable) - { - if (bpmem.ztex2.op == ZTEXTURE_ADD) - WRITE(p, "zCoord = dot("I_ZBIAS"[0].xyzw, textemp.xyzw) + "I_ZBIAS"[1].w + zCoord;\n"); - else - WRITE(p, "zCoord = dot("I_ZBIAS"[0].xyzw, textemp.xyzw) + "I_ZBIAS"[1].w;\n"); - - // scale to make result from frac correct - WRITE(p, "zCoord = zCoord * (16777215.0f/16777216.0f);\n"); - WRITE(p, "zCoord = frac(zCoord);\n"); - WRITE(p, "zCoord = zCoord * (16777216.0f/16777215.0f);\n"); - } - WRITE(p, "depth = zCoord;\n"); - } + if (bpmem.ztex2.op == ZTEXTURE_ADD) + WRITE(p, "zCoord = dot("I_ZBIAS"[0].xyzw, textemp.xyzw) + "I_ZBIAS"[1].w + zCoord;\n"); + else + WRITE(p, "zCoord = dot("I_ZBIAS"[0].xyzw, textemp.xyzw) + "I_ZBIAS"[1].w;\n"); - if (dstAlphaMode == DSTALPHA_ALPHA_PASS) - WRITE(p, " ocol0 = float4(prev.rgb, "I_ALPHA"[0].a);\n"); - else - { - WriteFog(p); - WRITE(p, " ocol0 = prev;\n"); + // scale to make result from frac correct + WRITE(p, "zCoord = zCoord * (16777215.0f/16777216.0f);\n"); + WRITE(p, "zCoord = frac(zCoord);\n"); + WRITE(p, "zCoord = zCoord * (16777216.0f/16777215.0f);\n"); } + WRITE(p, "depth = zCoord;\n"); + } - // On D3D11, use dual-source color blending to perform dst alpha in a - // single pass - if (dstAlphaMode == DSTALPHA_DUAL_SOURCE_BLEND) - { - // Colors will be blended against the alpha from ocol1... - WRITE(p, " ocol1 = ocol0;\n"); - // ...and the alpha from ocol0 will be written to the framebuffer. - WRITE(p, " ocol0.a = "I_ALPHA"[0].a;\n"); - } + if (dstAlphaMode == DSTALPHA_ALPHA_PASS) + WRITE(p, " ocol0 = float4(prev.rgb, "I_ALPHA"[0].a);\n"); + else + { + WriteFog(p); + WRITE(p, " ocol0 = prev;\n"); } + + // On D3D11, use dual-source color blending to perform dst alpha in a + // single pass + if (dstAlphaMode == DSTALPHA_DUAL_SOURCE_BLEND) + { + // Colors will be blended against the alpha from ocol1... + WRITE(p, " ocol1 = ocol0;\n"); + // ...and the alpha from ocol0 will be written to the framebuffer. + WRITE(p, " ocol0.a = "I_ALPHA"[0].a;\n"); + } + WRITE(p, "}\n"); if (text[sizeof(text) - 1] != 0x7C) PanicAlert("PixelShader generator - buffer too small, canary has been eaten!"); @@ -1157,19 +1152,13 @@ static int AlphaPreTest() } -static bool WriteAlphaTest(char *&p, API_TYPE ApiType,DSTALPHA_MODE dstAlphaMode) +static void WriteAlphaTest(char *&p, API_TYPE ApiType,DSTALPHA_MODE dstAlphaMode) { static const char *alphaRef[2] = { I_ALPHA"[0].r", I_ALPHA"[0].g" - }; - - int Pretest = AlphaPreTest(); - if(Pretest >= 0) - { - return Pretest != 0; - } + }; // using discard then return works the same in cg and dx9 but not in dx11 WRITE(p, "if(!( "); @@ -1190,14 +1179,17 @@ static bool WriteAlphaTest(char *&p, API_TYPE ApiType,DSTALPHA_MODE dstAlphaMode WRITE(p, "depth = 1.f;\n"); // HAXX: zcomploc is a way to control whether depth test is done before - // or after texturing and alpha test. PC GPU have no way to support this - // feature properly as of 2012: depth buffer and depth test are not - // programmable and the depth test is always done after texturing. - // + // or after texturing and alpha test. PC GPU does depth test before texturing ONLY if depth value is + // not updated during shader execution. // We implement "depth test before texturing" by discarding the fragment // 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. + // even if the depth test fails the fragment could be alpha blended. + // this implemnetation is a trick to keep speed. + // the correct, but slow, way to implement a correct zComploc is : + // 1 - if zcomplock is enebled make a first pass, with color channel write disabled updating only + // depth channel. + // 2 - in the next pass disable depth chanel update, but proccess the color data normally + // this way is the only CORRECT way to emulate perfectly the zcomplock behaviour if (!(bpmem.zcontrol.zcomploc && bpmem.zmode.updateenable)) { WRITE(p, "discard;\n"); @@ -1206,7 +1198,7 @@ static bool WriteAlphaTest(char *&p, API_TYPE ApiType,DSTALPHA_MODE dstAlphaMode } WRITE(p, "}\n"); - return true; + } static const char *tevFogFuncsTable[] = -- cgit v1.2.3 From 450dcc9d2cd874f6ab40d4a339afc29f55751319 Mon Sep 17 00:00:00 2001 From: rodolfoosvaldobogado Date: Tue, 27 Mar 2012 15:44:58 -0300 Subject: As requested, this is my implementation of zcomploc using a multi-pass algorithm. My apologize to the others devs for committing in the main branch but is the only way to get this tested as soon as possible. please test for regressions, speed and for other issues fixed, as a example, the black color in water splash in super mario galaxy are fixed with this rev. please as soon as yo find a bug let me know. --- Source/Core/VideoCommon/Src/PixelShaderGen.cpp | 46 +++++++++++++++----------- 1 file changed, 26 insertions(+), 20 deletions(-) (limited to 'Source/Core/VideoCommon/Src/PixelShaderGen.cpp') diff --git a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp index 76964f248c..7d8a3734da 100644 --- a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp +++ b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp @@ -109,7 +109,7 @@ void GetPixelShaderId(PIXELSHADERUID *uid, DSTALPHA_MODE dstAlphaMode, u32 compo uid->values[0] |= bpmem.genMode.numtexgens << 4; // 4 uid->values[0] |= dstAlphaMode << 8; // 2 - bool DepthTextureEnable = (bpmem.ztex2.op != ZTEXTURE_DISABLE && !bpmem.zcontrol.zcomploc && bpmem.zmode.testenable && bpmem.zmode.updateenable) || g_ActiveConfig.bEnablePerPixelDepth; + bool DepthTextureEnable = (bpmem.ztex2.op != ZTEXTURE_DISABLE && !bpmem.zcontrol.zcomploc && bpmem.zmode.testenable) || g_ActiveConfig.bEnablePerPixelDepth; uid->values[0] |= DepthTextureEnable << 10; // 1 @@ -121,7 +121,7 @@ void GetPixelShaderId(PIXELSHADERUID *uid, DSTALPHA_MODE dstAlphaMode, u32 compo uid->values[0] |= alphaPreTest << 16; // 2 - if (alphaPreTest == 1 || (alphaPreTest && !DepthTextureEnable && dstAlphaMode == DSTALPHA_ALPHA_PASS)) + if (alphaPreTest == 1 || (alphaPreTest == 2 && !DepthTextureEnable && dstAlphaMode == DSTALPHA_ALPHA_PASS) || dstAlphaMode == DSTALPHA_ZCOMPLOC) { // Courtesy of PreAlphaTest, we're done already ;) // NOTE: The comment header of generated shaders depends on the value of bpmem.genmode.numindstages.. shouldnt really bother about that though. @@ -177,6 +177,8 @@ void GetPixelShaderId(PIXELSHADERUID *uid, DSTALPHA_MODE dstAlphaMode, u32 compo ptr[0] |= bpmem.zcontrol.zcomploc << 13; // 1 ptr[0] |= bpmem.zmode.testenable << 14; // 1 ptr[0] |= bpmem.zmode.updateenable << 15; // 1 + ptr[0] |= g_ActiveConfig.bAcurateZcomploc << 16; // 1 + } } @@ -184,8 +186,8 @@ void GetPixelShaderId(PIXELSHADERUID *uid, DSTALPHA_MODE dstAlphaMode, u32 compo { if (bpmem.fog.c_proj_fsel.fsel != 0) { - ptr[0] |= bpmem.fog.c_proj_fsel.proj << 16; // 1 - ptr[0] |= bpmem.fogRange.Base.Enabled << 17; // 1 + ptr[0] |= bpmem.fog.c_proj_fsel.proj << 17; // 1 + ptr[0] |= bpmem.fogRange.Base.Enabled << 18; // 1 } } @@ -523,7 +525,7 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType nIndirectStagesUsed |= 1 << bpmem.tevind[i].bt; } } - DepthTextureEnable = (bpmem.ztex2.op != ZTEXTURE_DISABLE && !bpmem.zcontrol.zcomploc && bpmem.zmode.testenable && bpmem.zmode.updateenable) || g_ActiveConfig.bEnablePerPixelDepth ; + DepthTextureEnable = (bpmem.ztex2.op != ZTEXTURE_DISABLE && !bpmem.zcontrol.zcomploc && bpmem.zmode.testenable) || g_ActiveConfig.bEnablePerPixelDepth ; // Declare samplers if(ApiType != API_D3D11) @@ -619,9 +621,9 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType char* pmainstart = p; int Pretest = AlphaPreTest(); - if(Pretest >= 0 && !DepthTextureEnable) + if(Pretest >= 0 || dstAlphaMode == DSTALPHA_ZCOMPLOC) { - if (!Pretest) + if (!Pretest || dstAlphaMode == DSTALPHA_ZCOMPLOC) { // alpha test will always fail, so restart the shader and just make it an empty function WRITE(p, "ocol0 = 0;\n"); @@ -629,15 +631,18 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType WRITE(p, "depth = 1.f;\n"); if(dstAlphaMode == DSTALPHA_DUAL_SOURCE_BLEND) WRITE(p, "ocol1 = 0;\n"); - WRITE(p, "discard;\n"); - if(ApiType != API_D3D11) - WRITE(p, "return;\n"); + if(dstAlphaMode != DSTALPHA_ZCOMPLOC) + { + WRITE(p, "discard;\n"); + if(ApiType != API_D3D11) + WRITE(p, "return;\n"); + } } - else if (dstAlphaMode == DSTALPHA_ALPHA_PASS) + else if (dstAlphaMode == DSTALPHA_ALPHA_PASS && !DepthTextureEnable) { WRITE(p, " ocol0 = "I_ALPHA"[0].aaaa;\n"); } - if(!Pretest || dstAlphaMode == DSTALPHA_ALPHA_PASS) + if(!Pretest || (dstAlphaMode == DSTALPHA_ALPHA_PASS && !DepthTextureEnable) || dstAlphaMode == DSTALPHA_ZCOMPLOC) { WRITE(p, "}\n"); return text; @@ -744,7 +749,7 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType if (DepthTextureEnable) { // use the texture input of the last texture stage (textemp), hopefully this has been read and is in correct format... - if (bpmem.ztex2.op != ZTEXTURE_DISABLE && !bpmem.zcontrol.zcomploc && bpmem.zmode.testenable && bpmem.zmode.updateenable) + if (bpmem.ztex2.op != ZTEXTURE_DISABLE && !bpmem.zcontrol.zcomploc && bpmem.zmode.testenable) { if (bpmem.ztex2.op == ZTEXTURE_ADD) WRITE(p, "zCoord = dot("I_ZBIAS"[0].xyzw, textemp.xyzw) + "I_ZBIAS"[1].w + zCoord;\n"); @@ -1180,17 +1185,18 @@ static void WriteAlphaTest(char *&p, API_TYPE ApiType,DSTALPHA_MODE dstAlphaMode // HAXX: zcomploc is a way to control whether depth test is done before // or after texturing and alpha test. PC GPU does depth test before texturing ONLY if depth value is - // not updated during shader execution. + // not updated during shader execution. but GC hardware acts different: + // if zcomlock is enabled, depth value is updated even if alpha test fails // We implement "depth test before texturing" by discarding the fragment // when the alpha test fail. This is not a correct implementation because - // even if the depth test fails the fragment could be alpha blended. - // this implemnetation is a trick to keep speed. - // the correct, but slow, way to implement a correct zComploc is : + // even if the depth test fails the fragment could be alpha blended. + // the more correct, but slow, way is: // 1 - if zcomplock is enebled make a first pass, with color channel write disabled updating only // depth channel. - // 2 - in the next pass disable depth chanel update, but proccess the color data normally - // this way is the only CORRECT way to emulate perfectly the zcomplock behaviour - if (!(bpmem.zcontrol.zcomploc && bpmem.zmode.updateenable)) + // 2 - in the next pass disable depth chanel update, but proccess the color data normally an update only the pixels + // updated by the depth pass + + if (!(bpmem.zcontrol.zcomploc && bpmem.zmode.updateenable) || g_ActiveConfig.bAcurateZcomploc) { WRITE(p, "discard;\n"); if (ApiType != API_D3D11) -- cgit v1.2.3 From 402006a83a89bc0f790934096e915f0e8c23f808 Mon Sep 17 00:00:00 2001 From: rodolfoosvaldobogado Date: Thu, 29 Mar 2012 18:26:58 -0300 Subject: more fixes to zcomplock and opengl implementation --- Source/Core/VideoCommon/Src/PixelShaderGen.cpp | 38 ++++++++++++-------------- 1 file changed, 18 insertions(+), 20 deletions(-) (limited to 'Source/Core/VideoCommon/Src/PixelShaderGen.cpp') diff --git a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp index 7d8a3734da..5340b84f1a 100644 --- a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp +++ b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp @@ -177,7 +177,7 @@ void GetPixelShaderId(PIXELSHADERUID *uid, DSTALPHA_MODE dstAlphaMode, u32 compo ptr[0] |= bpmem.zcontrol.zcomploc << 13; // 1 ptr[0] |= bpmem.zmode.testenable << 14; // 1 ptr[0] |= bpmem.zmode.updateenable << 15; // 1 - ptr[0] |= g_ActiveConfig.bAcurateZcomploc << 16; // 1 + ptr[0] |= g_ActiveConfig.bEnableFastZcomploc << 16; // 1 } } @@ -212,7 +212,8 @@ void GetSafePixelShaderId(PIXELSHADERUIDSAFE *uid, DSTALPHA_MODE dstAlphaMode, u *ptr++ = bpmem.zmode.hex; // 4 *ptr++ = g_ActiveConfig.bEnablePerPixelDepth; // 5 *ptr++ = g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting; // 6 - *ptr++ = xfregs.numTexGen.hex; // 7 + *ptr++ = g_ActiveConfig.bEnableFastZcomploc ; // 7 + *ptr++ = xfregs.numTexGen.hex; // 8 if (g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting) { @@ -224,28 +225,28 @@ void GetSafePixelShaderId(PIXELSHADERUIDSAFE *uid, DSTALPHA_MODE dstAlphaMode, u } for (unsigned int i = 0; i < 8; ++i) - *ptr++ = xfregs.texMtxInfo[i].hex; // 8-15 + *ptr++ = xfregs.texMtxInfo[i].hex; // 9-16 for (unsigned int i = 0; i < 16; ++i) - *ptr++ = bpmem.tevind[i].hex; // 16-31 + *ptr++ = bpmem.tevind[i].hex; // 17-32 - *ptr++ = bpmem.tevindref.hex; // 32 + *ptr++ = bpmem.tevindref.hex; // 33 for (int i = 0; i < bpmem.genMode.numtevstages+1; ++i) // up to 16 times { - *ptr++ = bpmem.combiners[i].colorC.hex; // 33+5*i - *ptr++ = bpmem.combiners[i].alphaC.hex; // 34+5*i - *ptr++ = bpmem.tevind[i].hex; // 35+5*i - *ptr++ = bpmem.tevksel[i/2].hex; // 36+5*i - *ptr++ = bpmem.tevorders[i/2].hex; // 37+5*i + *ptr++ = bpmem.combiners[i].colorC.hex; // 34+5*i + *ptr++ = bpmem.combiners[i].alphaC.hex; // 35+5*i + *ptr++ = bpmem.tevind[i].hex; // 36+5*i + *ptr++ = bpmem.tevksel[i/2].hex; // 37+5*i + *ptr++ = bpmem.tevorders[i/2].hex; // 38+5*i } - ptr = &uid->values[113]; + ptr = &uid->values[114]; - *ptr++ = bpmem.alphaFunc.hex; // 113 + *ptr++ = bpmem.alphaFunc.hex; // 114 - *ptr++ = bpmem.fog.c_proj_fsel.hex; // 114 - *ptr++ = bpmem.fogRange.Base.hex; // 115 + *ptr++ = bpmem.fog.c_proj_fsel.hex; // 115 + *ptr++ = bpmem.fogRange.Base.hex; // 116 _assert_((ptr - uid->values) == uid->GetNumValues()); } @@ -1191,12 +1192,9 @@ static void WriteAlphaTest(char *&p, 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. // the more correct, but slow, way is: - // 1 - if zcomplock is enebled make a first pass, with color channel write disabled updating only - // depth channel. - // 2 - in the next pass disable depth chanel update, but proccess the color data normally an update only the pixels - // updated by the depth pass - - if (!(bpmem.zcontrol.zcomploc && bpmem.zmode.updateenable) || g_ActiveConfig.bAcurateZcomploc) + // 1 - if zcomplock is enabled make a last pass, with color channel write disabled updating only + // depth channel. + if (!(g_ActiveConfig.bEnableFastZcomploc && bpmem.zcontrol.zcomploc && bpmem.zmode.updateenable)) { WRITE(p, "discard;\n"); if (ApiType != API_D3D11) -- cgit v1.2.3 From 460610ea0e0d5083e261ed9d137048f2a5fc7e59 Mon Sep 17 00:00:00 2001 From: NeoBrainX Date: Fri, 30 Mar 2012 01:56:24 +0200 Subject: Revert Rodolfo's recent zcomploc commits until they actually work correctly. This reverts commit 402006a83a89bc0f790934096e915f0e8c23f808. This reverts commit 48d8d71391fc2cc40d85732680eb6421164bf87c. This reverts commit 450dcc9d2cd874f6ab40d4a339afc29f55751319. --- Source/Core/VideoCommon/Src/PixelShaderGen.cpp | 74 ++++++++++++-------------- 1 file changed, 35 insertions(+), 39 deletions(-) (limited to 'Source/Core/VideoCommon/Src/PixelShaderGen.cpp') diff --git a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp index 5340b84f1a..76964f248c 100644 --- a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp +++ b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp @@ -109,7 +109,7 @@ void GetPixelShaderId(PIXELSHADERUID *uid, DSTALPHA_MODE dstAlphaMode, u32 compo uid->values[0] |= bpmem.genMode.numtexgens << 4; // 4 uid->values[0] |= dstAlphaMode << 8; // 2 - bool DepthTextureEnable = (bpmem.ztex2.op != ZTEXTURE_DISABLE && !bpmem.zcontrol.zcomploc && bpmem.zmode.testenable) || g_ActiveConfig.bEnablePerPixelDepth; + bool DepthTextureEnable = (bpmem.ztex2.op != ZTEXTURE_DISABLE && !bpmem.zcontrol.zcomploc && bpmem.zmode.testenable && bpmem.zmode.updateenable) || g_ActiveConfig.bEnablePerPixelDepth; uid->values[0] |= DepthTextureEnable << 10; // 1 @@ -121,7 +121,7 @@ void GetPixelShaderId(PIXELSHADERUID *uid, DSTALPHA_MODE dstAlphaMode, u32 compo uid->values[0] |= alphaPreTest << 16; // 2 - if (alphaPreTest == 1 || (alphaPreTest == 2 && !DepthTextureEnable && dstAlphaMode == DSTALPHA_ALPHA_PASS) || dstAlphaMode == DSTALPHA_ZCOMPLOC) + if (alphaPreTest == 1 || (alphaPreTest && !DepthTextureEnable && dstAlphaMode == DSTALPHA_ALPHA_PASS)) { // Courtesy of PreAlphaTest, we're done already ;) // NOTE: The comment header of generated shaders depends on the value of bpmem.genmode.numindstages.. shouldnt really bother about that though. @@ -177,8 +177,6 @@ void GetPixelShaderId(PIXELSHADERUID *uid, DSTALPHA_MODE dstAlphaMode, u32 compo ptr[0] |= bpmem.zcontrol.zcomploc << 13; // 1 ptr[0] |= bpmem.zmode.testenable << 14; // 1 ptr[0] |= bpmem.zmode.updateenable << 15; // 1 - ptr[0] |= g_ActiveConfig.bEnableFastZcomploc << 16; // 1 - } } @@ -186,8 +184,8 @@ void GetPixelShaderId(PIXELSHADERUID *uid, DSTALPHA_MODE dstAlphaMode, u32 compo { if (bpmem.fog.c_proj_fsel.fsel != 0) { - ptr[0] |= bpmem.fog.c_proj_fsel.proj << 17; // 1 - ptr[0] |= bpmem.fogRange.Base.Enabled << 18; // 1 + ptr[0] |= bpmem.fog.c_proj_fsel.proj << 16; // 1 + ptr[0] |= bpmem.fogRange.Base.Enabled << 17; // 1 } } @@ -212,8 +210,7 @@ void GetSafePixelShaderId(PIXELSHADERUIDSAFE *uid, DSTALPHA_MODE dstAlphaMode, u *ptr++ = bpmem.zmode.hex; // 4 *ptr++ = g_ActiveConfig.bEnablePerPixelDepth; // 5 *ptr++ = g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting; // 6 - *ptr++ = g_ActiveConfig.bEnableFastZcomploc ; // 7 - *ptr++ = xfregs.numTexGen.hex; // 8 + *ptr++ = xfregs.numTexGen.hex; // 7 if (g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting) { @@ -225,28 +222,28 @@ void GetSafePixelShaderId(PIXELSHADERUIDSAFE *uid, DSTALPHA_MODE dstAlphaMode, u } for (unsigned int i = 0; i < 8; ++i) - *ptr++ = xfregs.texMtxInfo[i].hex; // 9-16 + *ptr++ = xfregs.texMtxInfo[i].hex; // 8-15 for (unsigned int i = 0; i < 16; ++i) - *ptr++ = bpmem.tevind[i].hex; // 17-32 + *ptr++ = bpmem.tevind[i].hex; // 16-31 - *ptr++ = bpmem.tevindref.hex; // 33 + *ptr++ = bpmem.tevindref.hex; // 32 for (int i = 0; i < bpmem.genMode.numtevstages+1; ++i) // up to 16 times { - *ptr++ = bpmem.combiners[i].colorC.hex; // 34+5*i - *ptr++ = bpmem.combiners[i].alphaC.hex; // 35+5*i - *ptr++ = bpmem.tevind[i].hex; // 36+5*i - *ptr++ = bpmem.tevksel[i/2].hex; // 37+5*i - *ptr++ = bpmem.tevorders[i/2].hex; // 38+5*i + *ptr++ = bpmem.combiners[i].colorC.hex; // 33+5*i + *ptr++ = bpmem.combiners[i].alphaC.hex; // 34+5*i + *ptr++ = bpmem.tevind[i].hex; // 35+5*i + *ptr++ = bpmem.tevksel[i/2].hex; // 36+5*i + *ptr++ = bpmem.tevorders[i/2].hex; // 37+5*i } - ptr = &uid->values[114]; + ptr = &uid->values[113]; - *ptr++ = bpmem.alphaFunc.hex; // 114 + *ptr++ = bpmem.alphaFunc.hex; // 113 - *ptr++ = bpmem.fog.c_proj_fsel.hex; // 115 - *ptr++ = bpmem.fogRange.Base.hex; // 116 + *ptr++ = bpmem.fog.c_proj_fsel.hex; // 114 + *ptr++ = bpmem.fogRange.Base.hex; // 115 _assert_((ptr - uid->values) == uid->GetNumValues()); } @@ -526,7 +523,7 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType nIndirectStagesUsed |= 1 << bpmem.tevind[i].bt; } } - DepthTextureEnable = (bpmem.ztex2.op != ZTEXTURE_DISABLE && !bpmem.zcontrol.zcomploc && bpmem.zmode.testenable) || g_ActiveConfig.bEnablePerPixelDepth ; + DepthTextureEnable = (bpmem.ztex2.op != ZTEXTURE_DISABLE && !bpmem.zcontrol.zcomploc && bpmem.zmode.testenable && bpmem.zmode.updateenable) || g_ActiveConfig.bEnablePerPixelDepth ; // Declare samplers if(ApiType != API_D3D11) @@ -622,9 +619,9 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType char* pmainstart = p; int Pretest = AlphaPreTest(); - if(Pretest >= 0 || dstAlphaMode == DSTALPHA_ZCOMPLOC) + if(Pretest >= 0 && !DepthTextureEnable) { - if (!Pretest || dstAlphaMode == DSTALPHA_ZCOMPLOC) + if (!Pretest) { // alpha test will always fail, so restart the shader and just make it an empty function WRITE(p, "ocol0 = 0;\n"); @@ -632,18 +629,15 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType WRITE(p, "depth = 1.f;\n"); if(dstAlphaMode == DSTALPHA_DUAL_SOURCE_BLEND) WRITE(p, "ocol1 = 0;\n"); - if(dstAlphaMode != DSTALPHA_ZCOMPLOC) - { - WRITE(p, "discard;\n"); - if(ApiType != API_D3D11) - WRITE(p, "return;\n"); - } + WRITE(p, "discard;\n"); + if(ApiType != API_D3D11) + WRITE(p, "return;\n"); } - else if (dstAlphaMode == DSTALPHA_ALPHA_PASS && !DepthTextureEnable) + else if (dstAlphaMode == DSTALPHA_ALPHA_PASS) { WRITE(p, " ocol0 = "I_ALPHA"[0].aaaa;\n"); } - if(!Pretest || (dstAlphaMode == DSTALPHA_ALPHA_PASS && !DepthTextureEnable) || dstAlphaMode == DSTALPHA_ZCOMPLOC) + if(!Pretest || dstAlphaMode == DSTALPHA_ALPHA_PASS) { WRITE(p, "}\n"); return text; @@ -750,7 +744,7 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType if (DepthTextureEnable) { // use the texture input of the last texture stage (textemp), hopefully this has been read and is in correct format... - if (bpmem.ztex2.op != ZTEXTURE_DISABLE && !bpmem.zcontrol.zcomploc && bpmem.zmode.testenable) + if (bpmem.ztex2.op != ZTEXTURE_DISABLE && !bpmem.zcontrol.zcomploc && bpmem.zmode.testenable && bpmem.zmode.updateenable) { if (bpmem.ztex2.op == ZTEXTURE_ADD) WRITE(p, "zCoord = dot("I_ZBIAS"[0].xyzw, textemp.xyzw) + "I_ZBIAS"[1].w + zCoord;\n"); @@ -1186,15 +1180,17 @@ static void WriteAlphaTest(char *&p, API_TYPE ApiType,DSTALPHA_MODE dstAlphaMode // HAXX: zcomploc is a way to control whether depth test is done before // or after texturing and alpha test. PC GPU does depth test before texturing ONLY if depth value is - // not updated during shader execution. but GC hardware acts different: - // if zcomlock is enabled, depth value is updated even if alpha test fails + // not updated during shader execution. // We implement "depth test before texturing" by discarding the fragment // when the alpha test fail. This is not a correct implementation because - // even if the depth test fails the fragment could be alpha blended. - // the more correct, but slow, way is: - // 1 - if zcomplock is enabled make a last pass, with color channel write disabled updating only - // depth channel. - if (!(g_ActiveConfig.bEnableFastZcomploc && bpmem.zcontrol.zcomploc && bpmem.zmode.updateenable)) + // even if the depth test fails the fragment could be alpha blended. + // this implemnetation is a trick to keep speed. + // the correct, but slow, way to implement a correct zComploc is : + // 1 - if zcomplock is enebled make a first pass, with color channel write disabled updating only + // depth channel. + // 2 - in the next pass disable depth chanel update, but proccess the color data normally + // this way is the only CORRECT way to emulate perfectly the zcomplock behaviour + if (!(bpmem.zcontrol.zcomploc && bpmem.zmode.updateenable)) { WRITE(p, "discard;\n"); if (ApiType != API_D3D11) -- cgit v1.2.3 From 722480cb2e864ea7dd03427e509470ec09ce6f40 Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Sat, 7 Apr 2012 14:45:12 -0500 Subject: Fix compilation with g++ 4.7 and some warnings. Fixes issue 5347. --- Source/Core/VideoCommon/Src/PixelShaderGen.cpp | 64 +++++++++++++------------- 1 file changed, 32 insertions(+), 32 deletions(-) (limited to 'Source/Core/VideoCommon/Src/PixelShaderGen.cpp') diff --git a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp index 76964f248c..7500997fef 100644 --- a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp +++ b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp @@ -556,22 +556,22 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType WRITE(p, "\n"); - WRITE(p, "uniform float4 "I_COLORS"[4] : register(c%d);\n", C_COLORS); - WRITE(p, "uniform float4 "I_KCOLORS"[4] : register(c%d);\n", C_KCOLORS); - WRITE(p, "uniform float4 "I_ALPHA"[1] : register(c%d);\n", C_ALPHA); - WRITE(p, "uniform float4 "I_TEXDIMS"[8] : register(c%d);\n", C_TEXDIMS); - WRITE(p, "uniform float4 "I_ZBIAS"[2] : register(c%d);\n", C_ZBIAS); - WRITE(p, "uniform float4 "I_INDTEXSCALE"[2] : register(c%d);\n", C_INDTEXSCALE); - WRITE(p, "uniform float4 "I_INDTEXMTX"[6] : register(c%d);\n", C_INDTEXMTX); - WRITE(p, "uniform float4 "I_FOG"[3] : register(c%d);\n", C_FOG); + WRITE(p, "uniform float4 " I_COLORS"[4] : register(c%d);\n", C_COLORS); + WRITE(p, "uniform float4 " I_KCOLORS"[4] : register(c%d);\n", C_KCOLORS); + WRITE(p, "uniform float4 " I_ALPHA"[1] : register(c%d);\n", C_ALPHA); + WRITE(p, "uniform float4 " I_TEXDIMS"[8] : register(c%d);\n", C_TEXDIMS); + WRITE(p, "uniform float4 " I_ZBIAS"[2] : register(c%d);\n", C_ZBIAS); + WRITE(p, "uniform float4 " I_INDTEXSCALE"[2] : register(c%d);\n", C_INDTEXSCALE); + WRITE(p, "uniform float4 " I_INDTEXMTX"[6] : register(c%d);\n", C_INDTEXMTX); + WRITE(p, "uniform float4 " I_FOG"[3] : register(c%d);\n", C_FOG); if(g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting) { WRITE(p,"typedef struct { float4 col; float4 cosatt; float4 distatt; float4 pos; float4 dir; } Light;\n"); - WRITE(p,"typedef struct { Light lights[8]; } s_"I_PLIGHTS";\n"); - WRITE(p, "uniform s_"I_PLIGHTS" "I_PLIGHTS" : register(c%d);\n", C_PLIGHTS); - WRITE(p, "typedef struct { float4 C0, C1, C2, C3; } s_"I_PMATERIALS";\n"); - WRITE(p, "uniform s_"I_PMATERIALS" "I_PMATERIALS" : register(c%d);\n", C_PMATERIALS); + WRITE(p,"typedef struct { Light lights[8]; } s_" I_PLIGHTS";\n"); + WRITE(p, "uniform s_" I_PLIGHTS" " I_PLIGHTS" : register(c%d);\n", C_PLIGHTS); + WRITE(p, "typedef struct { float4 C0, C1, C2, C3; } s_" I_PMATERIALS";\n"); + WRITE(p, "uniform s_" I_PMATERIALS" " I_PMATERIALS" : register(c%d);\n", C_PMATERIALS); } WRITE(p, "void main(\n"); @@ -635,7 +635,7 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType } else if (dstAlphaMode == DSTALPHA_ALPHA_PASS) { - WRITE(p, " ocol0 = "I_ALPHA"[0].aaaa;\n"); + WRITE(p, " ocol0 = " I_ALPHA"[0].aaaa;\n"); } if(!Pretest || dstAlphaMode == DSTALPHA_ALPHA_PASS) { @@ -644,7 +644,7 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType } } - 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" + 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" " float4 alphabump=float4(0.0f,0.0f,0.0f,0.0f);\n" " float3 tevcoord=float3(0.0f, 0.0f, 0.0f);\n" @@ -695,7 +695,7 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType WRITE(p, " uv%d.xy = uv%d.xy / uv%d.z;\n", i, i, i); } - WRITE(p, "uv%d.xy = uv%d.xy * "I_TEXDIMS"[%d].zw;\n", i, i, i); + WRITE(p, "uv%d.xy = uv%d.xy * " I_TEXDIMS"[%d].zw;\n", i, i, i); } } @@ -707,7 +707,7 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType int texcoord = bpmem.tevindref.getTexCoord(i); if (texcoord < numTexgen) - WRITE(p, "tempcoord = uv%d.xy * "I_INDTEXSCALE"[%d].%s;\n", texcoord, i/2, (i&1)?"zw":"xy"); + WRITE(p, "tempcoord = uv%d.xy * " I_INDTEXSCALE"[%d].%s;\n", texcoord, i/2, (i&1)?"zw":"xy"); else WRITE(p, "tempcoord = float2(0.0f, 0.0f);\n"); @@ -738,7 +738,7 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType if((bpmem.fog.c_proj_fsel.fsel != 0) || DepthTextureEnable) { // the screen space depth value = far z + (clip z / clip w) * z range - WRITE(p, "float zCoord = "I_ZBIAS"[1].x + (clipPos.z / clipPos.w) * "I_ZBIAS"[1].y;\n"); + WRITE(p, "float zCoord = " I_ZBIAS"[1].x + (clipPos.z / clipPos.w) * " I_ZBIAS"[1].y;\n"); } if (DepthTextureEnable) @@ -747,9 +747,9 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType if (bpmem.ztex2.op != ZTEXTURE_DISABLE && !bpmem.zcontrol.zcomploc && bpmem.zmode.testenable && bpmem.zmode.updateenable) { if (bpmem.ztex2.op == ZTEXTURE_ADD) - WRITE(p, "zCoord = dot("I_ZBIAS"[0].xyzw, textemp.xyzw) + "I_ZBIAS"[1].w + zCoord;\n"); + WRITE(p, "zCoord = dot(" I_ZBIAS"[0].xyzw, textemp.xyzw) + " I_ZBIAS"[1].w + zCoord;\n"); else - WRITE(p, "zCoord = dot("I_ZBIAS"[0].xyzw, textemp.xyzw) + "I_ZBIAS"[1].w;\n"); + WRITE(p, "zCoord = dot(" I_ZBIAS"[0].xyzw, textemp.xyzw) + " I_ZBIAS"[1].w;\n"); // scale to make result from frac correct WRITE(p, "zCoord = zCoord * (16777215.0f/16777216.0f);\n"); @@ -760,7 +760,7 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType } if (dstAlphaMode == DSTALPHA_ALPHA_PASS) - WRITE(p, " ocol0 = float4(prev.rgb, "I_ALPHA"[0].a);\n"); + WRITE(p, " ocol0 = float4(prev.rgb, " I_ALPHA"[0].a);\n"); else { WriteFog(p); @@ -774,7 +774,7 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType // Colors will be blended against the alpha from ocol1... WRITE(p, " ocol1 = ocol0;\n"); // ...and the alpha from ocol0 will be written to the framebuffer. - WRITE(p, " ocol0.a = "I_ALPHA"[0].a;\n"); + WRITE(p, " ocol0.a = " I_ALPHA"[0].a;\n"); } WRITE(p, "}\n"); @@ -867,20 +867,20 @@ static void WriteStage(char *&p, int n, API_TYPE ApiType) if (bpmem.tevind[n].mid <= 3) { int mtxidx = 2*(bpmem.tevind[n].mid-1); - WRITE(p, "float2 indtevtrans%d = float2(dot("I_INDTEXMTX"[%d].xyz, indtevcrd%d), dot("I_INDTEXMTX"[%d].xyz, indtevcrd%d));\n", + WRITE(p, "float2 indtevtrans%d = float2(dot(" I_INDTEXMTX"[%d].xyz, indtevcrd%d), dot(" I_INDTEXMTX"[%d].xyz, indtevcrd%d));\n", n, mtxidx, n, mtxidx+1, n); } else if (bpmem.tevind[n].mid <= 7 && bHasTexCoord) { // s matrix _assert_(bpmem.tevind[n].mid >= 5); int mtxidx = 2*(bpmem.tevind[n].mid-5); - WRITE(p, "float2 indtevtrans%d = "I_INDTEXMTX"[%d].ww * uv%d.xy * indtevcrd%d.xx;\n", n, mtxidx, texcoord, n); + WRITE(p, "float2 indtevtrans%d = " I_INDTEXMTX"[%d].ww * uv%d.xy * indtevcrd%d.xx;\n", n, mtxidx, texcoord, n); } else if (bpmem.tevind[n].mid <= 11 && bHasTexCoord) { // t matrix _assert_(bpmem.tevind[n].mid >= 9); int mtxidx = 2*(bpmem.tevind[n].mid-9); - WRITE(p, "float2 indtevtrans%d = "I_INDTEXMTX"[%d].ww * uv%d.xy * indtevcrd%d.yy;\n", n, mtxidx, texcoord, n); + WRITE(p, "float2 indtevtrans%d = " I_INDTEXMTX"[%d].ww * uv%d.xy * indtevcrd%d.yy;\n", n, mtxidx, texcoord, n); } else WRITE(p, "float2 indtevtrans%d = 0;\n", n); @@ -1094,9 +1094,9 @@ static void WriteStage(char *&p, int n, API_TYPE ApiType) void SampleTexture(char *&p, const char *destination, const char *texcoords, const char *texswap, int texmap, API_TYPE ApiType) { if (ApiType == API_D3D11) - WRITE(p, "%s=Tex%d.Sample(samp%d,%s.xy * "I_TEXDIMS"[%d].xy).%s;\n", destination, texmap,texmap, texcoords, texmap, texswap); + WRITE(p, "%s=Tex%d.Sample(samp%d,%s.xy * " I_TEXDIMS"[%d].xy).%s;\n", destination, texmap,texmap, texcoords, texmap, texswap); else - WRITE(p, "%s=tex2D(samp%d,%s.xy * "I_TEXDIMS"[%d].xy).%s;\n", destination, texmap, texcoords, texmap, texswap); + WRITE(p, "%s=tex2D(samp%d,%s.xy * " I_TEXDIMS"[%d].xy).%s;\n", destination, texmap, texcoords, texmap, texswap); } static const char *tevAlphaFuncsTable[] = @@ -1221,13 +1221,13 @@ static void WriteFog(char *&p) { // perspective // ze = A/(B - (Zs >> B_SHF) - WRITE (p, " float ze = "I_FOG"[1].x / ("I_FOG"[1].y - (zCoord / "I_FOG"[1].w));\n"); + WRITE (p, " float ze = " I_FOG"[1].x / (" I_FOG"[1].y - (zCoord / " I_FOG"[1].w));\n"); } else { // orthographic // ze = a*Zs (here, no B_SHF) - WRITE (p, " float ze = "I_FOG"[1].x * zCoord;\n"); + WRITE (p, " float ze = " I_FOG"[1].x * zCoord;\n"); } // x_adjust = sqrt((x-center)^2 + k^2)/k @@ -1235,12 +1235,12 @@ static void WriteFog(char *&p) //this is complitly teorical as the real hard seems to use a table intead of calculate the values. if(bpmem.fogRange.Base.Enabled) { - WRITE (p, " float x_adjust = (2.0f * (clipPos.x / "I_FOG"[2].y)) - 1.0f - "I_FOG"[2].x;\n"); - WRITE (p, " x_adjust = sqrt(x_adjust * x_adjust + "I_FOG"[2].z * "I_FOG"[2].z) / "I_FOG"[2].z;\n"); + WRITE (p, " float x_adjust = (2.0f * (clipPos.x / " I_FOG"[2].y)) - 1.0f - " I_FOG"[2].x;\n"); + WRITE (p, " x_adjust = sqrt(x_adjust * x_adjust + " I_FOG"[2].z * " I_FOG"[2].z) / " I_FOG"[2].z;\n"); WRITE (p, " ze *= x_adjust;\n"); } - WRITE (p, " float fog = saturate(ze - "I_FOG"[1].z);\n"); + WRITE (p, " float fog = saturate(ze - " I_FOG"[1].z);\n"); if(bpmem.fog.c_proj_fsel.fsel > 3) { @@ -1252,7 +1252,7 @@ static void WriteFog(char *&p) WARN_LOG(VIDEO, "Unknown Fog Type! %08x", bpmem.fog.c_proj_fsel.fsel); } - WRITE(p, " prev.rgb = lerp(prev.rgb,"I_FOG"[0].rgb,fog);\n"); + WRITE(p, " prev.rgb = lerp(prev.rgb," I_FOG"[0].rgb,fog);\n"); } -- cgit v1.2.3