diff options
| author | NeoBrainX <NeoBrainX@googlemail.com> | 2012-09-02 20:00:15 +0200 |
|---|---|---|
| committer | NeoBrainX <NeoBrainX@gmail.com> | 2013-01-28 22:15:23 +0100 |
| commit | 0fdeb81038d9ef599d4741035245972c3d374be7 (patch) | |
| tree | 1d7b1bb7aa2659c6eab16704a14d6ffe75b8c6d5 /Source/Core/VideoCommon/Src/PixelShaderManager.cpp | |
| parent | 700cce9588fcd53b016161690f0d4c1fa5ccf3f3 (diff) | |
Add some code for generating a shader constant usage profile.
Diffstat (limited to 'Source/Core/VideoCommon/Src/PixelShaderManager.cpp')
| -rw-r--r-- | Source/Core/VideoCommon/Src/PixelShaderManager.cpp | 99 |
1 files changed, 66 insertions, 33 deletions
diff --git a/Source/Core/VideoCommon/Src/PixelShaderManager.cpp b/Source/Core/VideoCommon/Src/PixelShaderManager.cpp index eaaf99fbc8..ffec7d64cb 100644 --- a/Source/Core/VideoCommon/Src/PixelShaderManager.cpp +++ b/Source/Core/VideoCommon/Src/PixelShaderManager.cpp @@ -83,39 +83,58 @@ void PixelShaderManager::Shutdown() } -void PixelShaderManager::SetConstants() +void PixelShaderManager::SetConstants(u32 components) { - for (int i = 0; i < 2; ++i) + PixelShaderConstantProfile constant_profile(C_PENVCONST_END); + /// TODO: dst alpha/api/components type parameter... + GetPixelShaderConstantProfile(constant_profile, DSTALPHA_DUAL_SOURCE_BLEND, API_OPENGL, components); + + static int saved_updates = 0; + static int necessary_updates = 0; + + +#define IncStuff() { \ + saved_updates++; \ + printf("Saved a constant update at line %d! Saved %d against %d now!\n", __LINE__, saved_updates, necessary_updates); } + + for (int i = 0; i < 2; ++i) { - if (s_nColorsChanged[i]) + if (s_nColorsChanged[i]) { - int baseind = i ? C_KCOLORS : C_COLORS; - for (int j = 0; j < 4; ++j) + int baseind = i ? C_KCOLORS : C_COLORS; + for (int j = 0; j < 4; ++j) { - if (s_nColorsChanged[i] & (1 << j)) - SetPSConstant4fv(baseind+j, &lastRGBAfull[i][j][0]); - } - s_nColorsChanged[i] = 0; - } - } + if ((s_nColorsChanged[i] & (1 << j)) && constant_profile.ConstantIsUsed(baseind+j)) + { + SetPSConstant4fv(baseind+j, &lastRGBAfull[i][j][0]); + s_nColorsChanged[i] &= ~(1<<j); + ++necessary_updates; + } else if ((s_nColorsChanged[i] & (1 << j))) IncStuff(); + } + } + } if (s_nTexDimsChanged) { for (int i = 0; i < 8; ++i) { - if (s_nTexDimsChanged & (1<<i)) + if (s_nTexDimsChanged & (1<<i) && constant_profile.ConstantIsUsed(C_TEXDIMS+i)) + { + ++necessary_updates; SetPSTextureDims(i); + s_nTexDimsChanged &= ~(1<<i); + }else if (s_nTexDimsChanged & (1<<i)) IncStuff(); } - s_nTexDimsChanged = 0; } - if (s_bAlphaChanged) + if (s_bAlphaChanged && constant_profile.ConstantIsUsed(C_ALPHA)) { + ++necessary_updates; SetPSConstant4f(C_ALPHA, (lastAlpha&0xff)/255.0f, ((lastAlpha>>8)&0xff)/255.0f, 0, ((lastAlpha>>16)&0xff)/255.0f); s_bAlphaChanged = false; - } + } else if (s_bAlphaChanged) IncStuff(); - if (s_bZTextureTypeChanged) + if (s_bZTextureTypeChanged && constant_profile.ConstantIsUsed(C_ZBIAS)) { float ftemp[4]; switch (bpmem.ztex2.type) @@ -133,11 +152,12 @@ void PixelShaderManager::SetConstants() ftemp[0] = 16711680.0f/16777215.0f; ftemp[1] = 65280.0f/16777215.0f; ftemp[2] = 255.0f/16777215.0f; ftemp[3] = 0; break; } + ++necessary_updates; SetPSConstant4fv(C_ZBIAS, ftemp); s_bZTextureTypeChanged = false; - } + } else if (s_bZTextureTypeChanged) IncStuff(); - if (s_bZBiasChanged || s_bDepthRangeChanged) + if ((s_bZBiasChanged || s_bDepthRangeChanged) && constant_profile.ConstantIsUsed(C_ZBIAS+1)) { // reversed gxsetviewport(xorig, yorig, width, height, nearz, farz) // [0] = width/2 @@ -148,9 +168,10 @@ void PixelShaderManager::SetConstants() // [5] = 16777215 * farz //ERROR_LOG("pixel=%x,%x, bias=%x\n", bpmem.zcontrol.pixel_format, bpmem.ztex2.type, lastZBias); + ++necessary_updates; SetPSConstant4f(C_ZBIAS+1, xfregs.viewport.farZ / 16777216.0f, xfregs.viewport.zRange / 16777216.0f, 0, (float)(lastZBias)/16777215.0f); s_bZBiasChanged = s_bDepthRangeChanged = false; - } + }else if ((s_bZBiasChanged || s_bDepthRangeChanged)) IncStuff(); // indirect incoming texture scales if (s_nIndTexScaleChanged) @@ -158,7 +179,7 @@ void PixelShaderManager::SetConstants() // set as two sets of vec4s, each containing S and T of two ind stages. float f[8]; - if (s_nIndTexScaleChanged & 0x03) + if ((s_nIndTexScaleChanged & 0x03) && constant_profile.ConstantIsUsed(C_INDTEXSCALE)) { for (u32 i = 0; i < 2; ++i) { @@ -166,26 +187,30 @@ void PixelShaderManager::SetConstants() f[2 * i + 1] = bpmem.texscale[0].getScaleT(i & 1); PRIM_LOG("tex indscale%d: %f %f\n", i, f[2 * i], f[2 * i + 1]); } + ++necessary_updates; SetPSConstant4fv(C_INDTEXSCALE, f); + s_nIndTexScaleChanged &= ~0x03; } + else if ((s_nIndTexScaleChanged & 0x03)) IncStuff(); - if (s_nIndTexScaleChanged & 0x0c) { + if ((s_nIndTexScaleChanged & 0x0c) && constant_profile.ConstantIsUsed(C_INDTEXSCALE+1)) { for (u32 i = 2; i < 4; ++i) { f[2 * i] = bpmem.texscale[1].getScaleS(i & 1); f[2 * i + 1] = bpmem.texscale[1].getScaleT(i & 1); PRIM_LOG("tex indscale%d: %f %f\n", i, f[2 * i], f[2 * i + 1]); } + ++necessary_updates; SetPSConstant4fv(C_INDTEXSCALE+1, &f[4]); + s_nIndTexScaleChanged &= ~0x0c; } - - s_nIndTexScaleChanged = 0; + else if ((s_nIndTexScaleChanged & 0x0c)) IncStuff(); } if (s_nIndTexMtxChanged) { for (int i = 0; i < 3; ++i) { - if (s_nIndTexMtxChanged & (1 << i)) + if ((s_nIndTexMtxChanged & (1 << i)) && (constant_profile.ConstantIsUsed(C_INDTEXMTX+2*i) || constant_profile.ConstantIsUsed(C_INDTEXMTX+2*i+1))) { int scale = ((u32)bpmem.indmtx[i].col0.s0 << 0) | ((u32)bpmem.indmtx[i].col1.s1 << 2) | @@ -195,6 +220,8 @@ void PixelShaderManager::SetConstants() // xyz - static matrix // TODO w - dynamic matrix scale / 256...... somehow / 4 works better // rev 2972 - now using / 256.... verify that this works + ++necessary_updates; + ++necessary_updates; SetPSConstant4f(C_INDTEXMTX + 2 * i, bpmem.indmtx[i].col0.ma * fscale, bpmem.indmtx[i].col1.mc * fscale, @@ -210,19 +237,22 @@ void PixelShaderManager::SetConstants() i, 1024.0f*fscale, bpmem.indmtx[i].col0.ma * fscale, bpmem.indmtx[i].col1.mc * fscale, bpmem.indmtx[i].col2.me * fscale, bpmem.indmtx[i].col0.mb * fscale, bpmem.indmtx[i].col1.md * fscale, bpmem.indmtx[i].col2.mf * fscale); - } + + s_nIndTexMtxChanged &= ~(1 << i); + }else if ((s_nIndTexMtxChanged & (1 << i))) {IncStuff();IncStuff();} } - s_nIndTexMtxChanged = 0; } - if (s_bFogColorChanged) + if (s_bFogColorChanged && constant_profile.ConstantIsUsed(C_FOG)) { + ++necessary_updates; SetPSConstant4f(C_FOG, bpmem.fog.color.r / 255.0f, bpmem.fog.color.g / 255.0f, bpmem.fog.color.b / 255.0f, 0); s_bFogColorChanged = false; - } + }else if (s_bFogColorChanged) IncStuff(); - if (s_bFogParamChanged) + if (s_bFogParamChanged && constant_profile.ConstantIsUsed(C_FOG+1)) { + ++necessary_updates; if(!g_ActiveConfig.bDisableFog) { //downscale magnitude to 0.24 bits @@ -235,10 +265,11 @@ void PixelShaderManager::SetConstants() SetPSConstant4f(C_FOG + 1, 0.0, 1.0, 0.0, 1.0); s_bFogParamChanged = false; - } + }else if ( s_bFogParamChanged) IncStuff(); - if (s_bFogRangeAdjustChanged) + if (s_bFogRangeAdjustChanged && constant_profile.ConstantIsUsed(C_FOG+2)) { + ++necessary_updates; if(!g_ActiveConfig.bDisableFog && bpmem.fogRange.Base.Enabled == 1) { //bpmem.fogRange.Base.Center : center of the viewport in x axis. observation: bpmem.fogRange.Base.Center = realcenter + 342; @@ -257,8 +288,9 @@ void PixelShaderManager::SetConstants() SetPSConstant4f(C_FOG + 2, 0.0f, 1.0f, 1.0f, 0.0f); // Need to update these values for older hardware that fails to divide by zero in shaders. s_bFogRangeAdjustChanged = false; - } + }else if ( s_bFogRangeAdjustChanged) IncStuff(); + // TODO: use constant profile here! if (g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting) // config check added because the code in here was crashing for me inside SetPSConstant4f { if (nLightsChanged[0] >= 0) @@ -353,7 +385,8 @@ void PixelShaderManager::SetPSTextureDims(int texid) SetPSConstant4fv(C_TEXDIMS + texid, fdims); } -// This one is high in profiles (0.5%). TODO: Move conversion out, only store the raw color value +// This one is high in profiles (0.5%). +// TODO: Move conversion out, only store the raw color value // and update it when the shader constant is set, only. void PixelShaderManager::SetColorChanged(int type, int num, bool high) { |
