From 437761843850ce32974fd4729d7b8d7d0405a04f Mon Sep 17 00:00:00 2001 From: degasus Date: Mon, 7 Oct 2013 16:02:24 +0200 Subject: [PATCH] VideoCommon: keep a copy of the const buffer in VideoCommon The upload in the backend isn't done, it's just pushed by the mostly removed SetMulti*SConstant4fv. Also no optimizations was done on VideoCommon side, but I can start now :-) Sorry for the hacky way, but I think this is a nice (working) snapshot for a much bigger change. --- .../D3D/Src/PixelShaderCache.cpp | 40 +------- Source/Core/VideoBackends/D3D/Src/Render.h | 6 -- .../D3D/Src/VertexShaderCache.cpp | 27 +----- .../OGL/Src/PixelShaderCache.cpp | 72 ++------------ Source/Core/VideoBackends/OGL/Src/Render.h | 6 -- .../OGL/Src/VertexShaderCache.cpp | 97 ++----------------- Source/Core/VideoCommon/Src/ConstantManager.h | 46 +++++++++ Source/Core/VideoCommon/Src/PixelShaderGen.h | 20 ++-- .../VideoCommon/Src/PixelShaderManager.cpp | 43 ++++++-- .../Core/VideoCommon/Src/PixelShaderManager.h | 6 ++ Source/Core/VideoCommon/Src/RenderBase.h | 7 -- .../Src/TextureConversionShader.cpp | 6 -- .../VideoCommon/Src/TextureConversionShader.h | 2 - Source/Core/VideoCommon/Src/VertexShaderGen.h | 18 ++-- .../VideoCommon/Src/VertexShaderManager.cpp | 50 +++++++++- .../VideoCommon/Src/VertexShaderManager.h | 4 + Source/Core/VideoCommon/Src/VideoCommon.h | 1 - 17 files changed, 172 insertions(+), 279 deletions(-) create mode 100644 Source/Core/VideoCommon/Src/ConstantManager.h diff --git a/Source/Core/VideoBackends/D3D/Src/PixelShaderCache.cpp b/Source/Core/VideoBackends/D3D/Src/PixelShaderCache.cpp index 56b61e05cd..8109d7fd20 100644 --- a/Source/Core/VideoBackends/D3D/Src/PixelShaderCache.cpp +++ b/Source/Core/VideoBackends/D3D/Src/PixelShaderCache.cpp @@ -538,47 +538,9 @@ bool PixelShaderCache::InsertByteCode(const PixelShaderUid &uid, const void* byt // These are "callbacks" from VideoCommon and thus must be outside namespace DX11. // This will have to be changed when we merge. - -// HACK to avoid some invasive VideoCommon changes -// these values are hardcoded, they depend on internal D3DCompile behavior; TODO: Solve this with D3DReflect or something -// offset given in floats, table index is float4 -static const unsigned int ps_constant_offset_table[] = { - 0, 4, 8, 12, // C_COLORS, 16 - 16, 20, 24, 28, // C_KCOLORS, 16 - 32, // C_ALPHA, 4 - 36, 40, 44, 48, 52, 56, 60, 64, // C_TEXDIMS, 32 - 68, 72, // C_ZBIAS, 8 - 76, 80, // C_INDTEXSCALE, 8 - 84, 88, 92, 96, 100, 104, // C_INDTEXMTX, 24 - 108, 112, 116, // C_FOG, 12 - 120, 124, 128, 132, 136, // C_PLIGHTS0, 20 - 140, 144, 148, 152, 156, // C_PLIGHTS1, 20 - 160, 164, 168, 172, 176, // C_PLIGHTS2, 20 - 180, 184, 188, 192, 196, // C_PLIGHTS3, 20 - 200, 204, 208, 212, 216, // C_PLIGHTS4, 20 - 220, 224, 228, 232, 236, // C_PLIGHTS5, 20 - 240, 244, 248, 252, 256, // C_PLIGHTS6, 20 - 260, 264, 268, 272, 276, // C_PLIGHTS7, 20 - 280, 284, 288, 292 // C_PMATERIALS, 16 -}; -void Renderer::SetPSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4) -{ - psconstants[ps_constant_offset_table[const_number] ] = f1; - psconstants[ps_constant_offset_table[const_number]+1] = f2; - psconstants[ps_constant_offset_table[const_number]+2] = f3; - psconstants[ps_constant_offset_table[const_number]+3] = f4; - pscbufchanged = true; -} - -void Renderer::SetPSConstant4fv(unsigned int const_number, const float* f) -{ - memcpy(&psconstants[ps_constant_offset_table[const_number]], f, sizeof(float)*4); - pscbufchanged = true; -} - void Renderer::SetMultiPSConstant4fv(unsigned int const_number, unsigned int count, const float* f) { - memcpy(&psconstants[ps_constant_offset_table[const_number]], f, sizeof(float)*4*count); + memcpy(psconstants, f, sizeof(float)*4*count); pscbufchanged = true; } diff --git a/Source/Core/VideoBackends/D3D/Src/Render.h b/Source/Core/VideoBackends/D3D/Src/Render.h index 1fddfdb244..c0090cd2f2 100644 --- a/Source/Core/VideoBackends/D3D/Src/Render.h +++ b/Source/Core/VideoBackends/D3D/Src/Render.h @@ -52,13 +52,7 @@ public: static bool CheckForResize(); - void SetPSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4); - void SetPSConstant4fv(unsigned int const_number, const float *f); void SetMultiPSConstant4fv(unsigned int const_number, unsigned int count, const float *f); - - void SetVSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4); - void SetVSConstant4fv(unsigned int const_number, const float *f); - void SetMultiVSConstant3fv(unsigned int const_number, unsigned int count, const float *f); void SetMultiVSConstant4fv(unsigned int const_number, unsigned int count, const float *f); }; diff --git a/Source/Core/VideoBackends/D3D/Src/VertexShaderCache.cpp b/Source/Core/VideoBackends/D3D/Src/VertexShaderCache.cpp index d9ea7e2a8c..6f3c4051b1 100644 --- a/Source/Core/VideoBackends/D3D/Src/VertexShaderCache.cpp +++ b/Source/Core/VideoBackends/D3D/Src/VertexShaderCache.cpp @@ -280,32 +280,7 @@ bool VertexShaderCache::InsertByteCode(const VertexShaderUid &uid, D3DBlob* bcod // These are "callbacks" from VideoCommon and thus must be outside namespace DX11. // This will have to be changed when we merge. -// maps the constant numbers to float indices in the constant buffer -void Renderer::SetVSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4) -{ - vsconstants[vs_constant_offset_table[const_number] ] = f1; - vsconstants[vs_constant_offset_table[const_number]+1] = f2; - vsconstants[vs_constant_offset_table[const_number]+2] = f3; - vsconstants[vs_constant_offset_table[const_number]+3] = f4; - vscbufchanged = true; -} - -void Renderer::SetVSConstant4fv(unsigned int const_number, const float* f) -{ - memcpy(&vsconstants[vs_constant_offset_table[const_number]], f, sizeof(float)*4); - vscbufchanged = true; -} - -void Renderer::SetMultiVSConstant3fv(unsigned int const_number, unsigned int count, const float* f) -{ - for (unsigned int i = 0; i < count; i++) - { - memcpy(&vsconstants[vs_constant_offset_table[const_number+i]], f+3*i, sizeof(float)*3); - vsconstants[vs_constant_offset_table[const_number+i]+3] = 0.f; - } - vscbufchanged = true; -} - +// TODO: fetch directly from VideoCommon void Renderer::SetMultiVSConstant4fv(unsigned int const_number, unsigned int count, const float* f) { memcpy(&vsconstants[vs_constant_offset_table[const_number]], f, sizeof(float)*4*count); diff --git a/Source/Core/VideoBackends/OGL/Src/PixelShaderCache.cpp b/Source/Core/VideoBackends/OGL/Src/PixelShaderCache.cpp index 3fac62bd73..0635003dfd 100644 --- a/Source/Core/VideoBackends/OGL/Src/PixelShaderCache.cpp +++ b/Source/Core/VideoBackends/OGL/Src/PixelShaderCache.cpp @@ -24,66 +24,7 @@ namespace OGL { -void SetPSConstant4fvByName(const char * name, unsigned int offset, const float *f, const unsigned int count = 1) -{ - ProgramShaderCache::PCacheEntry tmp = ProgramShaderCache::GetShaderProgram(); - for (int a = 0; a < NUM_UNIFORMS; ++a) - { - if (!strcmp(name, UniformNames[a])) - { - if (tmp.shader.UniformLocations[a] == -1) - return; - else if (tmp.shader.UniformSize[a] <= offset) - return; - else - { - unsigned int maxcount= tmp.shader.UniformSize[a]-offset; - glUniform4fv(tmp.shader.UniformLocations[a] + offset, std::min(count, maxcount), f); - return; - } - } - } -} - // Renderer functions -void Renderer::SetPSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4) -{ - float const f[4] = {f1, f2, f3, f4}; - - if (g_ActiveConfig.backend_info.bSupportsGLSLUBO) - { - ProgramShaderCache::SetMultiPSConstant4fv(const_number, f, 1); - return; - } - for (unsigned int a = 0; a < 10; ++a) - { - if (const_number >= PSVar_Loc[a].reg && const_number < (PSVar_Loc[a].reg + PSVar_Loc[a].size)) - { - unsigned int offset = const_number - PSVar_Loc[a].reg; - SetPSConstant4fvByName(PSVar_Loc[a].name, offset, f); - return; - } - } -} - -void Renderer::SetPSConstant4fv(unsigned int const_number, const float *f) -{ - if (g_ActiveConfig.backend_info.bSupportsGLSLUBO) - { - ProgramShaderCache::SetMultiPSConstant4fv(const_number, f, 1); - return; - } - for (unsigned int a = 0; a < 10; ++a) - { - if (const_number >= PSVar_Loc[a].reg && const_number < (PSVar_Loc[a].reg + PSVar_Loc[a].size)) - { - unsigned int offset = const_number - PSVar_Loc[a].reg; - SetPSConstant4fvByName(PSVar_Loc[a].name, offset, f); - return; - } - } -} - void Renderer::SetMultiPSConstant4fv(unsigned int const_number, unsigned int count, const float *f) { if (g_ActiveConfig.backend_info.bSupportsGLSLUBO) @@ -91,14 +32,15 @@ void Renderer::SetMultiPSConstant4fv(unsigned int const_number, unsigned int cou ProgramShaderCache::SetMultiPSConstant4fv(const_number, f, count); return; } + + ProgramShaderCache::PCacheEntry tmp = ProgramShaderCache::GetShaderProgram(); for (unsigned int a = 0; a < 10; ++a) { - if (const_number >= PSVar_Loc[a].reg && const_number < (PSVar_Loc[a].reg + PSVar_Loc[a].size)) - { - unsigned int offset = const_number - PSVar_Loc[a].reg; - SetPSConstant4fvByName(PSVar_Loc[a].name, offset, f, count); - return; - } + u32 offset = PSVar_Loc[a].reg - const_number; + if(offset >= count) return; + u32 size = std::min(tmp.shader.UniformSize[a], count-offset); + if(size > 0) + glUniform4fv(tmp.shader.UniformLocations[a], size, f + 4*offset); } } } // namespace OGL diff --git a/Source/Core/VideoBackends/OGL/Src/Render.h b/Source/Core/VideoBackends/OGL/Src/Render.h index 4086ad3e87..6216097e79 100644 --- a/Source/Core/VideoBackends/OGL/Src/Render.h +++ b/Source/Core/VideoBackends/OGL/Src/Render.h @@ -81,13 +81,7 @@ public: bool SaveScreenshot(const std::string &filename, const TargetRectangle &rc); - void SetPSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4); - void SetPSConstant4fv(unsigned int const_number, const float *f); void SetMultiPSConstant4fv(unsigned int const_number, unsigned int count, const float *f); - - void SetVSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4); - void SetVSConstant4fv(unsigned int const_number, const float *f); - void SetMultiVSConstant3fv(unsigned int const_number, unsigned int count, const float *f); void SetMultiVSConstant4fv(unsigned int const_number, unsigned int count, const float *f); private: diff --git a/Source/Core/VideoBackends/OGL/Src/VertexShaderCache.cpp b/Source/Core/VideoBackends/OGL/Src/VertexShaderCache.cpp index 8e2c048f8d..09f2368bad 100644 --- a/Source/Core/VideoBackends/OGL/Src/VertexShaderCache.cpp +++ b/Source/Core/VideoBackends/OGL/Src/VertexShaderCache.cpp @@ -24,65 +24,6 @@ namespace OGL { -void SetVSConstant4fvByName(const char * name, unsigned int offset, const float *f, const unsigned int count = 1) -{ - ProgramShaderCache::PCacheEntry tmp = ProgramShaderCache::GetShaderProgram(); - for (int a = 0; a < NUM_UNIFORMS; ++a) - { - if (!strcmp(name, UniformNames[a])) - { - if (tmp.shader.UniformLocations[a] == -1) - return; - else if (tmp.shader.UniformSize[a] <= offset) - return; - else - { - unsigned int maxcount= tmp.shader.UniformSize[a]-offset; - glUniform4fv(tmp.shader.UniformLocations[a] + offset, std::min(count, maxcount), f); - return; - } - } - } -} - -void Renderer::SetVSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4) -{ - float const buf[4] = {f1, f2, f3, f4}; - - if (g_ActiveConfig.backend_info.bSupportsGLSLUBO) - { - ProgramShaderCache::SetMultiVSConstant4fv(const_number, buf, 1); - return; - } - for (unsigned int a = 0; a < 9; ++a) - { - if (const_number >= VSVar_Loc[a].reg && const_number < ( VSVar_Loc[a].reg + VSVar_Loc[a].size)) - { - unsigned int offset = const_number - VSVar_Loc[a].reg; - SetVSConstant4fvByName(VSVar_Loc[a].name, offset, buf); - return; - } - } -} - -void Renderer::SetVSConstant4fv(unsigned int const_number, const float *f) -{ - if (g_ActiveConfig.backend_info.bSupportsGLSLUBO) - { - ProgramShaderCache::SetMultiVSConstant4fv(const_number, f, 1); - return; - } - for (unsigned int a = 0; a < 9; ++a) - { - if (const_number >= VSVar_Loc[a].reg && const_number < ( VSVar_Loc[a].reg + VSVar_Loc[a].size)) - { - unsigned int offset = const_number - VSVar_Loc[a].reg; - SetVSConstant4fvByName(VSVar_Loc[a].name, offset, f); - return; - } - } -} - void Renderer::SetMultiVSConstant4fv(unsigned int const_number, unsigned int count, const float *f) { if (g_ActiveConfig.backend_info.bSupportsGLSLUBO) @@ -90,40 +31,14 @@ void Renderer::SetMultiVSConstant4fv(unsigned int const_number, unsigned int cou ProgramShaderCache::SetMultiVSConstant4fv(const_number, f, count); return; } + ProgramShaderCache::PCacheEntry tmp = ProgramShaderCache::GetShaderProgram(); for (unsigned int a = 0; a < 9; ++a) { - if (const_number >= VSVar_Loc[a].reg && const_number < ( VSVar_Loc[a].reg + VSVar_Loc[a].size)) - { - unsigned int offset = const_number - VSVar_Loc[a].reg; - SetVSConstant4fvByName(VSVar_Loc[a].name, offset, f, count); - return; - } - } -} - -void Renderer::SetMultiVSConstant3fv(unsigned int const_number, unsigned int count, const float *f) -{ - float buf[4 * C_VENVCONST_END]; - for (unsigned int i = 0; i < count; i++) - { - buf[4*i ] = *f++; - buf[4*i+1] = *f++; - buf[4*i+2] = *f++; - buf[4*i+3] = 0.f; - } - if (g_ActiveConfig.backend_info.bSupportsGLSLUBO) - { - ProgramShaderCache::SetMultiVSConstant4fv(const_number, buf, count); - return; - } - for (unsigned int a = 0; a < 9; ++a) - { - if (const_number >= VSVar_Loc[a].reg && const_number < ( VSVar_Loc[a].reg + VSVar_Loc[a].size)) - { - unsigned int offset = const_number - VSVar_Loc[a].reg; - SetVSConstant4fvByName(VSVar_Loc[a].name, offset, buf, count); - return; - } + u32 offset = VSVar_Loc[a].reg - const_number; + if(offset >= count) return; + u32 size = std::min(tmp.shader.UniformSize[a+10], count-offset); + if(size > 0) + glUniform4fv(tmp.shader.UniformLocations[a+10], size, f + 4*offset); } } diff --git a/Source/Core/VideoCommon/Src/ConstantManager.h b/Source/Core/VideoCommon/Src/ConstantManager.h new file mode 100644 index 0000000000..f86d12e2db --- /dev/null +++ b/Source/Core/VideoCommon/Src/ConstantManager.h @@ -0,0 +1,46 @@ +// Copyright 2013 Dolphin Emulator Project +// Licensed under GPLv2 +// Refer to the license.txt file included. + +#ifndef _CONSTANTMANAGER_H +#define _CONSTANTMANAGER_H + +// all constant buffer attributes must be 16 bytes aligned, so this are the only allowed components: +typedef float float4[4]; +typedef u8 uchar16[16]; +typedef s8 schar16[16]; +typedef u16 ushort8[8]; +typedef s16 sshort8[8]; +typedef u32 uint4[4]; +typedef s32 sint4[4]; + +struct PixelShaderConstants +{ + float4 colors[4]; + float4 kcolors[4]; + float4 alpha; + float4 texdims[8]; + float4 zbias[2]; + float4 indtexscale[2]; + float4 indtexmts[6]; + float4 fog[3]; + + // For pixel lighting + float4 plights[40]; + float4 pmaterials[4]; +}; + +struct VertexShaderConstants +{ + float4 posnormalmatrix[6]; + float4 projection[4]; + float4 materials[4]; + float4 lights[40]; + float4 texmatrices[24]; + float4 transformmatrices[64]; + float4 normalmatrices[32]; + float4 posttransformmatrices[64]; + float4 depthparams; +}; + +#endif \ No newline at end of file diff --git a/Source/Core/VideoCommon/Src/PixelShaderGen.h b/Source/Core/VideoCommon/Src/PixelShaderGen.h index 5fbf28cd69..d9ce8c5874 100644 --- a/Source/Core/VideoCommon/Src/PixelShaderGen.h +++ b/Source/Core/VideoCommon/Src/PixelShaderGen.h @@ -44,16 +44,16 @@ enum DSTALPHA_MODE }; // Annoying sure, can be removed once we get up to GLSL ~1.3 -const s_svar PSVar_Loc[] = { {I_COLORS, C_COLORS, 4 }, - {I_KCOLORS, C_KCOLORS, 4 }, - {I_ALPHA, C_ALPHA, 1 }, - {I_TEXDIMS, C_TEXDIMS, 8 }, - {I_ZBIAS , C_ZBIAS, 2 }, - {I_INDTEXSCALE , C_INDTEXSCALE, 2 }, - {I_INDTEXMTX, C_INDTEXMTX, 6 }, - {I_FOG, C_FOG, 3 }, - {I_PLIGHTS, C_PLIGHTS, 40 }, - {I_PMATERIALS, C_PMATERIALS, 4 }, +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 }, }; #pragma pack(1) diff --git a/Source/Core/VideoCommon/Src/PixelShaderManager.cpp b/Source/Core/VideoCommon/Src/PixelShaderManager.cpp index aef4baa14c..3a13e287aa 100644 --- a/Source/Core/VideoCommon/Src/PixelShaderManager.cpp +++ b/Source/Core/VideoCommon/Src/PixelShaderManager.cpp @@ -29,19 +29,40 @@ static u32 lastTexDims[8]; // width | height << 16 | wrap_s << 28 | wrap_t << 30 static u32 lastZBias; static int nMaterialsChanged; +PixelShaderConstants PixelShaderManager::constants; +bool PixelShaderManager::dirty; + inline void SetPSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4) { - g_renderer->SetPSConstant4f(const_number, f1, f2, f3, f4); + float4* c = (float4*) &PixelShaderManager::constants; + c[const_number][0] = f1; + c[const_number][1] = f2; + c[const_number][2] = f3; + c[const_number][3] = f4; + PixelShaderManager::dirty = true; } inline void SetPSConstant4fv(unsigned int const_number, const float *f) { - g_renderer->SetPSConstant4fv(const_number, f); + float4* c = (float4*) &PixelShaderManager::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]; + PixelShaderManager::dirty = true; } inline void SetMultiPSConstant4fv(unsigned int const_number, unsigned int count, const float *f) { - g_renderer->SetMultiPSConstant4fv(const_number, count, f); + float4* c = (float4*) &PixelShaderManager::constants; + for(u32 i=0; iSetMultiPSConstant4fv(0, sizeof(constants)/16, (float*) &constants); + dirty = false; + } } void PixelShaderManager::SetPSTextureDims(int texid) @@ -495,7 +524,9 @@ void PixelShaderManager::DoState(PointerWrap &p) p.Do(lastAlpha); p.Do(lastTexDims); p.Do(lastZBias); - + p.Do(constants); + p.Do(dirty); + if (p.GetMode() == PointerWrap::MODE_READ) { Dirty(); diff --git a/Source/Core/VideoCommon/Src/PixelShaderManager.h b/Source/Core/VideoCommon/Src/PixelShaderManager.h index 7f63fb3f46..856b76d8d7 100644 --- a/Source/Core/VideoCommon/Src/PixelShaderManager.h +++ b/Source/Core/VideoCommon/Src/PixelShaderManager.h @@ -8,9 +8,12 @@ #include "BPMemory.h" #include "XFMemory.h" #include "PixelShaderGen.h" +#include "ConstantManager.h" class PointerWrap; + + // The non-API dependent parts. class PixelShaderManager { @@ -41,6 +44,9 @@ public: static void SetColorMatrix(const float* pmatrix); static void InvalidateXFRange(int start, int end); static void SetMaterialColorChanged(int index); + + static PixelShaderConstants constants; + static bool dirty; }; diff --git a/Source/Core/VideoCommon/Src/RenderBase.h b/Source/Core/VideoCommon/Src/RenderBase.h index 7d9f3f857c..08ed80343d 100644 --- a/Source/Core/VideoCommon/Src/RenderBase.h +++ b/Source/Core/VideoCommon/Src/RenderBase.h @@ -116,14 +116,7 @@ public: static void StorePixelFormat(unsigned int new_format) { prev_efb_format = new_format; } // TODO: doesn't belong here - virtual void SetPSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4) = 0; - virtual void SetPSConstant4fv(unsigned int const_number, const float *f) = 0; virtual void SetMultiPSConstant4fv(unsigned int const_number, unsigned int count, const float *f) = 0; - - // TODO: doesn't belong here - virtual void SetVSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4) = 0; - virtual void SetVSConstant4fv(unsigned int const_number, const float *f) = 0; - virtual void SetMultiVSConstant3fv(unsigned int const_number, unsigned int count, const float *f) = 0; virtual void SetMultiVSConstant4fv(unsigned int const_number, unsigned int count, const float *f) = 0; protected: diff --git a/Source/Core/VideoCommon/Src/TextureConversionShader.cpp b/Source/Core/VideoCommon/Src/TextureConversionShader.cpp index 7916e47c12..9b6c8762ff 100644 --- a/Source/Core/VideoCommon/Src/TextureConversionShader.cpp +++ b/Source/Core/VideoCommon/Src/TextureConversionShader.cpp @@ -867,10 +867,4 @@ const char *GenerateEncodingShader(u32 format,API_TYPE ApiType) return text; } -void SetShaderParameters(float width, float height, float offsetX, float offsetY, float widthStride, float heightStride,float buffW,float buffH) -{ - g_renderer->SetPSConstant4f(C_COLORMATRIX, widthStride, heightStride, buffW, buffH); - g_renderer->SetPSConstant4f(C_COLORMATRIX + 1, width, (height - 1), offsetX, offsetY); -} - } // namespace diff --git a/Source/Core/VideoCommon/Src/TextureConversionShader.h b/Source/Core/VideoCommon/Src/TextureConversionShader.h index aa42726b2c..843c5ef7ee 100644 --- a/Source/Core/VideoCommon/Src/TextureConversionShader.h +++ b/Source/Core/VideoCommon/Src/TextureConversionShader.h @@ -15,8 +15,6 @@ u16 GetEncodedSampleCount(u32 format); const char *GenerateEncodingShader(u32 format, API_TYPE ApiType = API_OPENGL); -void SetShaderParameters(float width, float height, float offsetX, float offsetY, float widthStride, float heightStride,float buffW = 0.0f,float buffH = 0.0f); - } #endif // _TEXTURECONVERSIONSHADER_H_ diff --git a/Source/Core/VideoCommon/Src/VertexShaderGen.h b/Source/Core/VideoCommon/Src/VertexShaderGen.h index 0ec703c07f..c5f32c741d 100644 --- a/Source/Core/VideoCommon/Src/VertexShaderGen.h +++ b/Source/Core/VideoCommon/Src/VertexShaderGen.h @@ -53,15 +53,15 @@ #define C_DEPTHPARAMS (C_POSTTRANSFORMMATRICES + 64) #define C_VENVCONST_END (C_DEPTHPARAMS + 1) -const s_svar VSVar_Loc[] = { {I_POSNORMALMATRIX, C_POSNORMALMATRIX, 6 }, - {I_PROJECTION , C_PROJECTION, 4 }, - {I_MATERIALS, C_MATERIALS, 4 }, - {I_LIGHTS, C_LIGHTS, 40 }, - {I_TEXMATRICES, C_TEXMATRICES, 24 }, - {I_TRANSFORMMATRICES , C_TRANSFORMMATRICES, 64 }, - {I_NORMALMATRICES , C_NORMALMATRICES, 32 }, - {I_POSTTRANSFORMMATRICES, C_POSTTRANSFORMMATRICES, 64 }, - {I_DEPTHPARAMS, C_DEPTHPARAMS, 1 }, +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 }, }; #pragma pack(1) diff --git a/Source/Core/VideoCommon/Src/VertexShaderManager.cpp b/Source/Core/VideoCommon/Src/VertexShaderManager.cpp index c07286d58f..016fb517e4 100644 --- a/Source/Core/VideoCommon/Src/VertexShaderManager.cpp +++ b/Source/Core/VideoCommon/Src/VertexShaderManager.cpp @@ -36,6 +36,9 @@ static Matrix33 s_viewInvRotationMatrix; static float s_fViewTranslationVector[3]; static float s_fViewRotation[2]; +VertexShaderConstants VertexShaderManager::constants; +bool VertexShaderManager::dirty; + void UpdateViewport(Matrix44& vpCorrection); void UpdateViewportWithCorrection() @@ -45,22 +48,48 @@ void UpdateViewportWithCorrection() inline void SetVSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4) { - g_renderer->SetVSConstant4f(const_number, f1, f2, f3, 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) { - g_renderer->SetVSConstant4fv(const_number, 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) { - g_renderer->SetMultiVSConstant3fv(const_number, count, f); + float4* c = (float4*) &VertexShaderManager::constants; + for(u32 i=0; iSetMultiVSConstant4fv(const_number, count, f); + float4* c = (float4*) &VertexShaderManager::constants; + for(u32 i=0; i= 0) { @@ -488,6 +520,12 @@ void VertexShaderManager::SetConstants() SetMultiVSConstant4fv(C_PROJECTION, 4, correctedMtx.data); } } + + if(dirty) + { + dirty = false; + g_renderer->SetMultiVSConstant4fv(0, sizeof(constants)/16, (float*) &constants); + } } void VertexShaderManager::InvalidateXFRange(int start, int end) @@ -669,6 +707,8 @@ void VertexShaderManager::DoState(PointerWrap &p) p.Do(s_viewInvRotationMatrix); p.Do(s_fViewTranslationVector); p.Do(s_fViewRotation); + p.Do(constants); + p.Do(dirty); if (p.GetMode() == PointerWrap::MODE_READ) { diff --git a/Source/Core/VideoCommon/Src/VertexShaderManager.h b/Source/Core/VideoCommon/Src/VertexShaderManager.h index b4c5d3907c..d681092902 100644 --- a/Source/Core/VideoCommon/Src/VertexShaderManager.h +++ b/Source/Core/VideoCommon/Src/VertexShaderManager.h @@ -6,6 +6,7 @@ #define _VERTEXSHADERMANAGER_H #include "VertexShaderGen.h" +#include "ConstantManager.h" class PointerWrap; @@ -35,6 +36,9 @@ public: static void TranslateView(float x, float y, float z = 0.0f); static void RotateView(float x, float y); static void ResetView(); + + static VertexShaderConstants constants; + static bool dirty; }; #endif // _VERTEXSHADERMANAGER_H diff --git a/Source/Core/VideoCommon/Src/VideoCommon.h b/Source/Core/VideoCommon/Src/VideoCommon.h index 175bd8a5b0..54a2504631 100644 --- a/Source/Core/VideoCommon/Src/VideoCommon.h +++ b/Source/Core/VideoCommon/Src/VideoCommon.h @@ -134,7 +134,6 @@ inline unsigned int GetPow2(unsigned int val) } struct s_svar { - const char *name; const unsigned int reg; const unsigned int size; };