diff --git a/Source/Core/VideoCommon/Src/VertexShaderGen.h b/Source/Core/VideoCommon/Src/VertexShaderGen.h index 667df311c2..9664e92359 100644 --- a/Source/Core/VideoCommon/Src/VertexShaderGen.h +++ b/Source/Core/VideoCommon/Src/VertexShaderGen.h @@ -42,6 +42,7 @@ #define I_POSTTRANSFORMMATRICES "cpostmtx" #define I_DEPTHPARAMS "cDepth" // farZ, zRange, scaled viewport width, scaled viewport height +//TODO: get rid of them, they aren't used at all #define C_POSNORMALMATRIX 0 #define C_PROJECTION (C_POSNORMALMATRIX + 6) #define C_MATERIALS (C_PROJECTION + 4) diff --git a/Source/Core/VideoCommon/Src/VertexShaderManager.cpp b/Source/Core/VideoCommon/Src/VertexShaderManager.cpp index 0698f7b472..e603e6e6c4 100644 --- a/Source/Core/VideoCommon/Src/VertexShaderManager.cpp +++ b/Source/Core/VideoCommon/Src/VertexShaderManager.cpp @@ -46,52 +46,6 @@ void UpdateViewportWithCorrection() UpdateViewport(s_viewportCorrection); } -inline void SetVSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4) -{ - float4* c = (float4*) &VertexShaderManager::constants; - c[const_number][0] = f1; - c[const_number][1] = f2; - c[const_number][2] = f3; - c[const_number][3] = f4; - VertexShaderManager::dirty = true; -} - -inline void SetVSConstant4fv(unsigned int const_number, const float *f) -{ - float4* c = (float4*) &VertexShaderManager::constants; - c[const_number][0] = f[0]; - c[const_number][1] = f[1]; - c[const_number][2] = f[2]; - c[const_number][3] = f[3]; - VertexShaderManager::dirty = true; -} - -inline void SetMultiVSConstant3fv(unsigned int const_number, unsigned int count, const float *f) -{ - float4* c = (float4*) &VertexShaderManager::constants; - for(u32 i=0; i> 24) & 0xFF) * NormalizationCoef, - ((color >> 16) & 0xFF) * NormalizationCoef, - ((color >> 8) & 0xFF) * NormalizationCoef, - ((color) & 0xFF) * NormalizationCoef); + constants.lights[5*i][0] = ((color >> 24) & 0xFF) / 255.0f; + constants.lights[5*i][1] = ((color >> 16) & 0xFF) / 255.0f; + constants.lights[5*i][2] = ((color >> 8) & 0xFF) / 255.0f; + constants.lights[5*i][3] = ((color) & 0xFF) / 255.0f; xfmemptr += 4; for (int j = 0; j < 4; ++j, xfmemptr += 3) @@ -278,35 +233,30 @@ void VertexShaderManager::SetConstants() fabs(xfmemptr[2]) < 0.00001f) { // dist attenuation, make sure not equal to 0!!! - SetVSConstant4f(C_LIGHTS+5*i+j+1, 0.00001f, xfmemptr[1], xfmemptr[2], 0); + constants.lights[5*i+j+1][0] = 0.00001f; } else - { - SetVSConstant4fv(C_LIGHTS+5*i+j+1, xfmemptr); - } + constants.lights[5*i+j+1][0] = xfmemptr[0]; + constants.lights[5*i+j+1][1] = xfmemptr[1]; + constants.lights[5*i+j+1][2] = xfmemptr[2]; } } + dirty = true; nLightsChanged[0] = nLightsChanged[1] = -1; } if (nMaterialsChanged) { - float GC_ALIGNED16(material[4]); - float NormalizationCoef = 1 / 255.0f; - for (int i = 0; i < 2; ++i) { if (nMaterialsChanged & (1 << i)) { u32 data = *(xfregs.ambColor + i); - - material[0] = ((data >> 24) & 0xFF) * NormalizationCoef; - material[1] = ((data >> 16) & 0xFF) * NormalizationCoef; - material[2] = ((data >> 8) & 0xFF) * NormalizationCoef; - material[3] = ( data & 0xFF) * NormalizationCoef; - - SetVSConstant4fv(C_MATERIALS + i, material); + constants.materials[i][0] = ((data >> 24) & 0xFF) / 255.0f; + constants.materials[i][1] = ((data >> 16) & 0xFF) / 255.0f; + constants.materials[i][2] = ((data >> 8) & 0xFF) / 255.0f; + constants.materials[i][3] = ( data & 0xFF) / 255.0f; } } @@ -315,15 +265,13 @@ void VertexShaderManager::SetConstants() if (nMaterialsChanged & (1 << (i + 2))) { u32 data = *(xfregs.matColor + i); - - material[0] = ((data >> 24) & 0xFF) * NormalizationCoef; - material[1] = ((data >> 16) & 0xFF) * NormalizationCoef; - material[2] = ((data >> 8) & 0xFF) * NormalizationCoef; - material[3] = ( data & 0xFF) * NormalizationCoef; - - SetVSConstant4fv(C_MATERIALS + i + 2, material); + constants.materials[i+2][0] = ((data >> 24) & 0xFF) / 255.0f; + constants.materials[i+2][1] = ((data >> 16) & 0xFF) / 255.0f; + constants.materials[i+2][2] = ((data >> 8) & 0xFF) / 255.0f; + constants.materials[i+2][3] = ( data & 0xFF) / 255.0f; } } + dirty = true; nMaterialsChanged = 0; } @@ -335,8 +283,11 @@ void VertexShaderManager::SetConstants() const float *pos = (const float *)xfmem + MatrixIndexA.PosNormalMtxIdx * 4; const float *norm = (const float *)xfmem + XFMEM_NORMALMATRICES + 3 * (MatrixIndexA.PosNormalMtxIdx & 31); - SetMultiVSConstant4fv(C_POSNORMALMATRIX, 3, pos); - SetMultiVSConstant3fv(C_POSNORMALMATRIX + 3, 3, norm); + memcpy(constants.posnormalmatrix, pos, 3*16); + memcpy(constants.posnormalmatrix[3], norm, 12); + memcpy(constants.posnormalmatrix[4], norm+3, 12); + memcpy(constants.posnormalmatrix[5], norm+6, 12); + dirty = true; } if (bTexMatricesChanged[0]) @@ -350,8 +301,9 @@ void VertexShaderManager::SetConstants() for (int i = 0; i < 4; ++i) { - SetMultiVSConstant4fv(C_TEXMATRICES + 3 * i, 3, fptrs[i]); + memcpy(constants.texmatrices[3*i], fptrs[i], 3*16); } + dirty = true; } if (bTexMatricesChanged[1]) @@ -364,18 +316,19 @@ void VertexShaderManager::SetConstants() for (int i = 0; i < 4; ++i) { - SetMultiVSConstant4fv(C_TEXMATRICES+3 * i + 12, 3, fptrs[i]); + memcpy(constants.texmatrices[3*i+12], fptrs[i], 3*16); } + dirty = true; } if (bViewportChanged) { bViewportChanged = false; - SetVSConstant4f(C_DEPTHPARAMS, - xfregs.viewport.farZ / 16777216.0f, - xfregs.viewport.zRange / 16777216.0f, - -1.f / (float)g_renderer->EFBToScaledX((int)ceil(2.0f * xfregs.viewport.wd)), - 1.f / (float)g_renderer->EFBToScaledY((int)ceil(-2.0f * xfregs.viewport.ht))); + constants.depthparams[0] = xfregs.viewport.farZ / 16777216.0f; + constants.depthparams[1] = xfregs.viewport.zRange / 16777216.0f; + constants.depthparams[2] = -1.f / g_renderer->EFBToScaledX(ceilf(2.0f * xfregs.viewport.wd)); + constants.depthparams[3] = 1.f / g_renderer->EFBToScaledY(ceilf(-2.0f * xfregs.viewport.ht)); + dirty = true; // This is so implementation-dependent that we can't have it here. UpdateViewport(s_viewportCorrection); bProjectionChanged = true; @@ -504,8 +457,7 @@ void VertexShaderManager::SetConstants() Matrix44::Set(mtxB, g_fProjectionMatrix); Matrix44::Multiply(mtxB, viewMtx, mtxA); // mtxA = projection x view Matrix44::Multiply(s_viewportCorrection, mtxA, mtxB); // mtxB = viewportCorrection x mtxA - - SetMultiVSConstant4fv(C_PROJECTION, 4, mtxB.data); + memcpy(constants.projection, mtxB.data, 4*16); } else { @@ -514,8 +466,9 @@ void VertexShaderManager::SetConstants() Matrix44 correctedMtx; Matrix44::Multiply(s_viewportCorrection, projMtx, correctedMtx); - SetMultiVSConstant4fv(C_PROJECTION, 4, correctedMtx.data); + memcpy(constants.projection, correctedMtx.data, 4*16); } + dirty = true; } }