From 5de7ac47919a0ecc09b078c55f094106a7564397 Mon Sep 17 00:00:00 2001 From: degasus Date: Tue, 8 Oct 2013 14:34:42 +0200 Subject: [PATCH] OGL: update ubo workaround --- .../OGL/Src/ProgramShaderCache.cpp | 52 +++++++++---------- .../OGL/Src/TextureConverter.cpp | 2 +- Source/Core/VideoCommon/Src/ConstantManager.h | 2 +- Source/Core/VideoCommon/Src/PixelShaderGen.h | 1 + .../VideoCommon/Src/PixelShaderManager.cpp | 16 +++--- 5 files changed, 35 insertions(+), 38 deletions(-) diff --git a/Source/Core/VideoBackends/OGL/Src/ProgramShaderCache.cpp b/Source/Core/VideoBackends/OGL/Src/ProgramShaderCache.cpp index 0904ef41eb..51f41c063b 100644 --- a/Source/Core/VideoBackends/OGL/Src/ProgramShaderCache.cpp +++ b/Source/Core/VideoBackends/OGL/Src/ProgramShaderCache.cpp @@ -63,34 +63,30 @@ const char *UniformNames[NUM_UNIFORMS] = I_DEPTHPARAMS, }; -struct s_svar -{ - const unsigned int reg; - const unsigned int size; +const static int PSVar_Loc[] = { + offsetof(PixelShaderConstants, colors)/16, + offsetof(PixelShaderConstants, kcolors)/16, + offsetof(PixelShaderConstants, alpha)/16, + offsetof(PixelShaderConstants, texdims)/16, + offsetof(PixelShaderConstants, zbias)/16, + offsetof(PixelShaderConstants, indtexscale)/16, + offsetof(PixelShaderConstants, indtexmtx)/16, + offsetof(PixelShaderConstants, fog)/16, + offsetof(PixelShaderConstants, plights)/16, + offsetof(PixelShaderConstants, pmaterials)/16, }; -const s_svar PSVar_Loc[] = { {C_COLORS, 4 }, - {C_KCOLORS, 4 }, - {C_ALPHA, 1 }, - {C_TEXDIMS, 8 }, - {C_ZBIAS, 2 }, - {C_INDTEXSCALE, 2 }, - {C_INDTEXMTX, 6 }, - {C_FOG, 3 }, - {C_PLIGHTS, 40 }, - {C_PMATERIALS, 4 }, - }; - -const s_svar VSVar_Loc[] = { {C_POSNORMALMATRIX, 6 }, - {C_PROJECTION, 4 }, - {C_MATERIALS, 4 }, - {C_LIGHTS, 40 }, - {C_TEXMATRICES, 24 }, - {C_TRANSFORMMATRICES, 64 }, - {C_NORMALMATRICES, 32 }, - {C_POSTTRANSFORMMATRICES, 64 }, - {C_DEPTHPARAMS, 1 }, - }; +const static int VSVar_Loc[] = { + offsetof(VertexShaderConstants, posnormalmatrix)/16, + offsetof(VertexShaderConstants, projection)/16, + offsetof(VertexShaderConstants, materials)/16, + offsetof(VertexShaderConstants, lights)/16, + offsetof(VertexShaderConstants, texmatrices)/16, + offsetof(VertexShaderConstants, transformmatrices)/16, + offsetof(VertexShaderConstants, normalmatrices)/16, + offsetof(VertexShaderConstants, posttransformmatrices)/16, + offsetof(VertexShaderConstants, depthparams)/16, +}; // End of UBO workaround @@ -221,12 +217,12 @@ void ProgramShaderCache::UploadConstants() for (unsigned int a = 0; a < 10; ++a) { if(last_entry->shader.UniformSize[a] > 0) - glUniform4fv(last_entry->shader.UniformLocations[a], last_entry->shader.UniformSize[a], (float*) &PixelShaderManager::constants + 4*PSVar_Loc[a].reg); + glUniform4fv(last_entry->shader.UniformLocations[a], last_entry->shader.UniformSize[a], (float*) &PixelShaderManager::constants + 4*PSVar_Loc[a]); } for (unsigned int a = 0; a < 9; ++a) { if(last_entry->shader.UniformSize[a+10] > 0) - glUniform4fv(last_entry->shader.UniformLocations[a+10], last_entry->shader.UniformSize[a+10], (float*) &VertexShaderManager::constants + 4*VSVar_Loc[a].reg); + glUniform4fv(last_entry->shader.UniformLocations[a+10], last_entry->shader.UniformSize[a+10], (float*) &VertexShaderManager::constants + 4*VSVar_Loc[a]); } ADDSTAT(stats.thisFrame.bytesUniformStreamed, s_ubo_buffer_size); diff --git a/Source/Core/VideoBackends/OGL/Src/TextureConverter.cpp b/Source/Core/VideoBackends/OGL/Src/TextureConverter.cpp index 693784054e..b2104af66a 100644 --- a/Source/Core/VideoBackends/OGL/Src/TextureConverter.cpp +++ b/Source/Core/VideoBackends/OGL/Src/TextureConverter.cpp @@ -324,7 +324,7 @@ int EncodeToRamFromTexture(u32 address,GLuint source_texture, bool bFromZBuffer, }; texconv_shader.Bind(); - glUniform4fv(texconv_shader.UniformLocations[C_COLORS], 2, params); + glUniform4fv(texconv_shader.UniformLocations[0], 2, params); TargetRectangle scaledSource; scaledSource.top = 0; diff --git a/Source/Core/VideoCommon/Src/ConstantManager.h b/Source/Core/VideoCommon/Src/ConstantManager.h index bd28ea8731..3c09c2007e 100644 --- a/Source/Core/VideoCommon/Src/ConstantManager.h +++ b/Source/Core/VideoCommon/Src/ConstantManager.h @@ -18,7 +18,7 @@ struct PixelShaderConstants float4 texdims[8]; float4 zbias[2]; float4 indtexscale[2]; - float4 indtexmts[6]; + float4 indtexmtx[6]; float4 fog[3]; // For pixel lighting diff --git a/Source/Core/VideoCommon/Src/PixelShaderGen.h b/Source/Core/VideoCommon/Src/PixelShaderGen.h index b73b17168c..983e304998 100644 --- a/Source/Core/VideoCommon/Src/PixelShaderGen.h +++ b/Source/Core/VideoCommon/Src/PixelShaderGen.h @@ -21,6 +21,7 @@ #define I_PLIGHTS "cPLights" #define I_PMATERIALS "cPmtrl" +// TODO: get rid of them as they aren't used #define C_COLORMATRIX 0 // 0 #define C_COLORS 0 // 0 #define C_KCOLORS (C_COLORS + 4) // 4 diff --git a/Source/Core/VideoCommon/Src/PixelShaderManager.cpp b/Source/Core/VideoCommon/Src/PixelShaderManager.cpp index 0f749a1d49..8afcb4429b 100644 --- a/Source/Core/VideoCommon/Src/PixelShaderManager.cpp +++ b/Source/Core/VideoCommon/Src/PixelShaderManager.cpp @@ -188,14 +188,14 @@ void PixelShaderManager::SetIndMatrixChanged(int matrixidx) // xyz - static matrix // TODO w - dynamic matrix scale / 256...... somehow / 4 works better // rev 2972 - now using / 256.... verify that this works - constants.indtexmts[2*matrixidx][0] = bpmem.indmtx[matrixidx].col0.ma * fscale; - constants.indtexmts[2*matrixidx][1] = bpmem.indmtx[matrixidx].col1.mc * fscale; - constants.indtexmts[2*matrixidx][2] = bpmem.indmtx[matrixidx].col2.me * fscale; - constants.indtexmts[2*matrixidx][3] = fscale * 4.0f; - constants.indtexmts[2*matrixidx+1][0] = bpmem.indmtx[matrixidx].col0.mb * fscale; - constants.indtexmts[2*matrixidx+1][1] = bpmem.indmtx[matrixidx].col1.md * fscale; - constants.indtexmts[2*matrixidx+1][2] = bpmem.indmtx[matrixidx].col2.mf * fscale; - constants.indtexmts[2*matrixidx+1][3] = fscale * 4.0f; + constants.indtexmtx[2*matrixidx][0] = bpmem.indmtx[matrixidx].col0.ma * fscale; + constants.indtexmtx[2*matrixidx][1] = bpmem.indmtx[matrixidx].col1.mc * fscale; + constants.indtexmtx[2*matrixidx][2] = bpmem.indmtx[matrixidx].col2.me * fscale; + constants.indtexmtx[2*matrixidx][3] = fscale * 4.0f; + constants.indtexmtx[2*matrixidx+1][0] = bpmem.indmtx[matrixidx].col0.mb * fscale; + constants.indtexmtx[2*matrixidx+1][1] = bpmem.indmtx[matrixidx].col1.md * fscale; + constants.indtexmtx[2*matrixidx+1][2] = bpmem.indmtx[matrixidx].col2.mf * fscale; + constants.indtexmtx[2*matrixidx+1][3] = fscale * 4.0f; dirty = true; PRIM_LOG("indmtx%d: scale=%f, mat=(%f %f %f; %f %f %f)\n",