From 4702de591eb69e815398b21c5b4321b1ac133552 Mon Sep 17 00:00:00 2001 From: NeoBrainX Date: Sun, 4 Sep 2011 02:10:07 +0200 Subject: [PATCH] Added safe pixel shader UIDs for debugging purposes. --- .../Core/VideoCommon/Src/PixelShaderGen.cpp | 54 ++++++++++++++++--- Source/Core/VideoCommon/Src/PixelShaderGen.h | 24 +++++---- Source/Core/VideoCommon/Src/VertexShaderGen.h | 2 +- 3 files changed, 63 insertions(+), 17 deletions(-) diff --git a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp index ff82438305..9913ea7c5a 100644 --- a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp +++ b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp @@ -164,7 +164,7 @@ void GetPixelShaderId(PIXELSHADERUID *uid, DSTALPHA_MODE dstAlphaMode) } u32* ptr = &uid->values[2]; - for (unsigned int i = 0; i < bpmem.genMode.numtevstages+1; ++i) + for (int i = 0; i < bpmem.genMode.numtevstages+1; ++i) { StageHash(i, ptr); ptr += 4; // max: ptr = &uid->values[66] @@ -315,6 +315,46 @@ void _GetPixelShaderId(PIXELSHADERUID *uid, DSTALPHA_MODE dstAlphaMode) } +void GetSafePixelShaderId(PIXELSHADERUIDSAFE *uid, DSTALPHA_MODE dstAlphaMode) +{ + u32* ptr = uid->values; + *ptr++ = dstAlphaMode; + *ptr++ = bpmem.genMode.hex; + *ptr++ = bpmem.ztex2.hex; + *ptr++ = bpmem.zcontrol.hex; + *ptr++ = bpmem.zmode.hex; + *ptr++ = g_ActiveConfig.bEnablePerPixelDepth; + *ptr++ = g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting; + *ptr++ = xfregs.numTexGen.hex; + + if (g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting) + { + // TODO: Include register states for lighting shader + } + + for (unsigned int i = 0; i < 8; ++i) + *ptr++ = xfregs.texMtxInfo[i].hex; + + for (unsigned int i = 0; i < 16; ++i) + *ptr++ = bpmem.tevind[i].hex; + + *ptr++ = bpmem.tevindref.hex; + + for (int i = 0; i < bpmem.genMode.numtevstages+1; ++i) + { + // TODO ... + StageHash(i, ptr); + ptr += 4; // max: ptr = &uid->values[66] + } + + *ptr++ = bpmem.fog.c_proj_fsel.hex; + + *ptr++ = bpmem.fogRange.Base.hex; + + _assert_((ptr - uid->values) == uid->GetNumValues()); +} + + // old tev->pixelshader notes // // color for this stage (alpha, color) is given by bpmem.tevorders[0].colorchan0 @@ -539,8 +579,8 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType char *p = text; WRITE(p, "//Pixel Shader for TEV stages\n"); - WRITE(p, "//%i TEV stages, %i texgens, %i IND stages\n", - numStages, numTexgen, bpmem.genMode.numindstages); + WRITE(p, "//%i TEV stages, %i texgens, XXX IND stages\n", + numStages, numTexgen/*, bpmem.genMode.numindstages*/); int nIndirectStagesUsed = 0; if (bpmem.genMode.numindstages > 0) @@ -876,7 +916,7 @@ static void WriteStage(char *&p, int n, API_TYPE ApiType) if (bHasIndStage) { - WRITE(p, "// indirect op\n", n); + WRITE(p, "// indirect op\n"); // perform the indirect op on the incoming regular coordinates using indtex%d as the offset coords if (bpmem.tevind[n].bs != ITBA_OFF) { @@ -1026,7 +1066,7 @@ static void WriteStage(char *&p, int n, API_TYPE ApiType) WRITE(p, "cc2 = frac(c2 * (255.0f/256.0f)) * (256.0f/255.0f);\n"); - WRITE(p, "// color combine\n", n); + WRITE(p, "// color combine\n"); if (cc.clamp) WRITE(p, "%s = saturate(", tevCOutputTable[cc.dest]); else @@ -1073,7 +1113,7 @@ static void WriteStage(char *&p, int n, API_TYPE ApiType) WRITE(p, ")"); WRITE(p,";\n"); - WRITE(p, "// alpha combine\n", n); + WRITE(p, "// alpha combine\n"); // combine the alpha channel if (ac.clamp) WRITE(p, "%s = saturate(", tevAOutputTable[ac.dest]); @@ -1119,7 +1159,7 @@ static void WriteStage(char *&p, int n, API_TYPE ApiType) if (ac.clamp) WRITE(p, ")"); WRITE(p, ";\n\n"); - WRITE(p, "// TEV done\n", n); + WRITE(p, "// TEV done\n"); } void SampleTexture(char *&p, const char *destination, const char *texcoords, const char *texswap, int texmap, API_TYPE ApiType) diff --git a/Source/Core/VideoCommon/Src/PixelShaderGen.h b/Source/Core/VideoCommon/Src/PixelShaderGen.h index 0ebdd0e42f..6ed39e7e74 100644 --- a/Source/Core/VideoCommon/Src/PixelShaderGen.h +++ b/Source/Core/VideoCommon/Src/PixelShaderGen.h @@ -45,36 +45,39 @@ #define C_PMATERIALS (C_PLIGHTS + 40) #define C_PENVCONST_END (C_PMATERIALS + 4) #define PIXELSHADERUID_MAX_VALUES 67 +#define PIXELSHADERUID_MAX_VALUES_SAFE 100 // DO NOT make anything in this class virtual. -class PIXELSHADERUID +template +class _PIXELSHADERUID { public: - u32 values[PIXELSHADERUID_MAX_VALUES]; + u32 values[safe ? PIXELSHADERUID_MAX_VALUES_SAFE : PIXELSHADERUID_MAX_VALUES]; u16 tevstages, indstages; - PIXELSHADERUID() + _PIXELSHADERUID() { - memset(values, 0, PIXELSHADERUID_MAX_VALUES * 4); + memset(values, 0, sizeof(values)); tevstages = indstages = 0; } - PIXELSHADERUID(const PIXELSHADERUID& r) + _PIXELSHADERUID(const _PIXELSHADERUID& r) { tevstages = r.tevstages; indstages = r.indstages; int N = GetNumValues(); - _assert_(N <= PIXELSHADERUID_MAX_VALUES); + _assert_(N <= GetNumValues()); for (int i = 0; i < N; ++i) values[i] = r.values[i]; } int GetNumValues() const { - return tevstages; + if (safe) return (sizeof(values) / sizeof(u32)); + else return tevstages; } - bool operator <(const PIXELSHADERUID& _Right) const + bool operator <(const _PIXELSHADERUID& _Right) const { if (values[0] < _Right.values[0]) return true; @@ -91,7 +94,7 @@ public: return false; } - bool operator ==(const PIXELSHADERUID& _Right) const + bool operator ==(const _PIXELSHADERUID& _Right) const { if (values[0] != _Right.values[0]) return false; @@ -104,6 +107,8 @@ public: return true; } }; +typedef _PIXELSHADERUID PIXELSHADERUID; +typedef _PIXELSHADERUID PIXELSHADERUIDSAFE; // Different ways to achieve rendering with destination alpha enum DSTALPHA_MODE @@ -115,6 +120,7 @@ enum DSTALPHA_MODE const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType, u32 components); void GetPixelShaderId(PIXELSHADERUID *uid, DSTALPHA_MODE dstAlphaMode); +void GetSafePixelShaderId(PIXELSHADERUIDSAFE *uid, DSTALPHA_MODE dstAlphaMode); extern PIXELSHADERUID last_pixel_shader_uid; diff --git a/Source/Core/VideoCommon/Src/VertexShaderGen.h b/Source/Core/VideoCommon/Src/VertexShaderGen.h index 50e9c5fc3b..1ab696acc2 100644 --- a/Source/Core/VideoCommon/Src/VertexShaderGen.h +++ b/Source/Core/VideoCommon/Src/VertexShaderGen.h @@ -57,7 +57,7 @@ public: _VERTEXSHADERUID() { - memset(values, 0, sizeof(values)); + memset(values, 0, sizeof(values)); } _VERTEXSHADERUID(const _VERTEXSHADERUID& r)