diff options
| author | degasus <wickmarkus@web.de> | 2013-10-13 14:14:32 +0200 |
|---|---|---|
| committer | degasus <wickmarkus@web.de> | 2013-10-13 14:14:32 +0200 |
| commit | 4dc1881f58f0b3c1276c5fde26fcabcdf114903f (patch) | |
| tree | 0f6d7b78dbacb983cf7c49a75bac437f618bf3e4 /Source/Core/VideoBackends | |
| parent | 0753ce5bdaf756b144ec6003e1df01388b9c3e8f (diff) | |
| parent | 2754c1132ee1f3e4cf1045bd50b77425cd308411 (diff) | |
Merge branch 'const_buffer_rework'
Diffstat (limited to 'Source/Core/VideoBackends')
| -rw-r--r-- | Source/Core/VideoBackends/D3D/Src/PixelShaderCache.cpp | 61 | ||||
| -rw-r--r-- | Source/Core/VideoBackends/D3D/Src/Render.h | 9 | ||||
| -rw-r--r-- | Source/Core/VideoBackends/D3D/Src/VertexShaderCache.cpp | 64 | ||||
| -rw-r--r-- | Source/Core/VideoBackends/OGL/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | Source/Core/VideoBackends/OGL/OGL.vcxproj | 4 | ||||
| -rw-r--r-- | Source/Core/VideoBackends/OGL/Src/PixelShaderCache.cpp | 104 | ||||
| -rw-r--r-- | Source/Core/VideoBackends/OGL/Src/ProgramShaderCache.cpp | 104 | ||||
| -rw-r--r-- | Source/Core/VideoBackends/OGL/Src/ProgramShaderCache.h | 9 | ||||
| -rw-r--r-- | Source/Core/VideoBackends/OGL/Src/Render.h | 9 | ||||
| -rw-r--r-- | Source/Core/VideoBackends/OGL/Src/TextureConverter.cpp | 2 | ||||
| -rw-r--r-- | Source/Core/VideoBackends/OGL/Src/VertexShaderCache.cpp | 130 |
11 files changed, 83 insertions, 415 deletions
diff --git a/Source/Core/VideoBackends/D3D/Src/PixelShaderCache.cpp b/Source/Core/VideoBackends/D3D/Src/PixelShaderCache.cpp index 56b61e05cd..04a1722d04 100644 --- a/Source/Core/VideoBackends/D3D/Src/PixelShaderCache.cpp +++ b/Source/Core/VideoBackends/D3D/Src/PixelShaderCache.cpp @@ -14,15 +14,12 @@ #include "Globals.h" #include "PixelShaderGen.h" #include "PixelShaderCache.h" +#include "PixelShaderManager.h" #include "ConfigManager.h" extern int frameCount; -// See comment near the bottom of this file. -float psconstants[C_PENVCONST_END*4]; -bool pscbufchanged = true; - namespace DX11 { @@ -339,15 +336,15 @@ ID3D11PixelShader* PixelShaderCache::GetClearProgram() ID3D11Buffer* &PixelShaderCache::GetConstantBuffer() { // TODO: divide the global variables of the generated shaders into about 5 constant buffers to speed this up - if (pscbufchanged) + if (PixelShaderManager::dirty) { D3D11_MAPPED_SUBRESOURCE map; D3D::context->Map(pscbuf, 0, D3D11_MAP_WRITE_DISCARD, 0, &map); - memcpy(map.pData, psconstants, sizeof(psconstants)); + memcpy(map.pData, &PixelShaderManager::constants, sizeof(PixelShaderConstants)); D3D::context->Unmap(pscbuf, 0); - pscbufchanged = false; + PixelShaderManager::dirty = false; - ADDSTAT(stats.thisFrame.bytesUniformStreamed, sizeof(psconstants)); + ADDSTAT(stats.thisFrame.bytesUniformStreamed, sizeof(PixelShaderConstants)); } return pscbuf; } @@ -364,7 +361,7 @@ public: void PixelShaderCache::Init() { - unsigned int cbsize = ((sizeof(psconstants))&(~0xf))+0x10; // must be a multiple of 16 + unsigned int cbsize = ((sizeof(PixelShaderConstants))&(~0xf))+0x10; // must be a multiple of 16 D3D11_BUFFER_DESC cbdesc = CD3D11_BUFFER_DESC(cbsize, D3D11_BIND_CONSTANT_BUFFER, D3D11_USAGE_DYNAMIC, D3D11_CPU_ACCESS_WRITE); D3D::device->CreateBuffer(&cbdesc, NULL, &pscbuf); CHECK(pscbuf!=NULL, "Create pixel shader constant buffer"); @@ -536,50 +533,4 @@ bool PixelShaderCache::InsertByteCode(const PixelShaderUid &uid, const void* byt return true; } -// 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); - pscbufchanged = true; -} - } // DX11 diff --git a/Source/Core/VideoBackends/D3D/Src/Render.h b/Source/Core/VideoBackends/D3D/Src/Render.h index 1fddfdb244..39b5b90d81 100644 --- a/Source/Core/VideoBackends/D3D/Src/Render.h +++ b/Source/Core/VideoBackends/D3D/Src/Render.h @@ -51,15 +51,6 @@ public: bool SaveScreenshot(const std::string &filename, const TargetRectangle &rc); 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..28a03b3bca 100644 --- a/Source/Core/VideoBackends/D3D/Src/VertexShaderCache.cpp +++ b/Source/Core/VideoBackends/D3D/Src/VertexShaderCache.cpp @@ -12,14 +12,10 @@ #include "D3DShader.h" #include "Globals.h" #include "VertexShaderCache.h" +#include "VertexShaderManager.h" #include "ConfigManager.h" -// See comment near the bottom of this file -static unsigned int vs_constant_offset_table[C_VENVCONST_END]; -float vsconstants[C_VENVCONST_END*4]; -bool vscbufchanged = true; - namespace DX11 { VertexShaderCache::VSCache VertexShaderCache::vshaders; @@ -44,15 +40,15 @@ ID3D11Buffer* vscbuf = NULL; ID3D11Buffer* &VertexShaderCache::GetConstantBuffer() { // TODO: divide the global variables of the generated shaders into about 5 constant buffers to speed this up - if (vscbufchanged) + if (VertexShaderManager::dirty) { D3D11_MAPPED_SUBRESOURCE map; D3D::context->Map(vscbuf, 0, D3D11_MAP_WRITE_DISCARD, 0, &map); - memcpy(map.pData, vsconstants, sizeof(vsconstants)); + memcpy(map.pData, &VertexShaderManager::constants, sizeof(VertexShaderConstants)); D3D::context->Unmap(vscbuf, 0); - vscbufchanged = false; + VertexShaderManager::dirty = false; - ADDSTAT(stats.thisFrame.bytesUniformStreamed, sizeof(vsconstants)); + ADDSTAT(stats.thisFrame.bytesUniformStreamed, sizeof(VertexShaderConstants)); } return vscbuf; } @@ -116,7 +112,7 @@ void VertexShaderCache::Init() { "COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 }, }; - unsigned int cbsize = ((sizeof(vsconstants))&(~0xf))+0x10; // must be a multiple of 16 + unsigned int cbsize = ((sizeof(VertexShaderConstants))&(~0xf))+0x10; // must be a multiple of 16 D3D11_BUFFER_DESC cbdesc = CD3D11_BUFFER_DESC(cbsize, D3D11_BIND_CONSTANT_BUFFER, D3D11_USAGE_DYNAMIC, D3D11_CPU_ACCESS_WRITE); HRESULT hr = D3D::device->CreateBuffer(&cbdesc, NULL, &vscbuf); CHECK(hr==S_OK, "Create vertex shader constant buffer (size=%u)", cbsize); @@ -141,19 +137,6 @@ void VertexShaderCache::Init() Clear(); - // these values are hardcoded, they depend on internal D3DCompile behavior - // TODO: Do this with D3DReflect or something instead - unsigned int k; - for (k = 0;k < 6;k++) vs_constant_offset_table[C_POSNORMALMATRIX+k] = 0+4*k; - for (k = 0;k < 4;k++) vs_constant_offset_table[C_PROJECTION+k] = 24+4*k; - for (k = 0;k < 4;k++) vs_constant_offset_table[C_MATERIALS+k] = 40+4*k; - for (k = 0;k < 40;k++) vs_constant_offset_table[C_LIGHTS+k] = 56+4*k; - for (k = 0;k < 24;k++) vs_constant_offset_table[C_TEXMATRICES+k] = 216+4*k; - for (k = 0;k < 64;k++) vs_constant_offset_table[C_TRANSFORMMATRICES+k] = 312+4*k; - for (k = 0;k < 32;k++) vs_constant_offset_table[C_NORMALMATRICES+k] = 568+4*k; - for (k = 0;k < 64;k++) vs_constant_offset_table[C_POSTTRANSFORMMATRICES+k] = 696+4*k; - vs_constant_offset_table[C_DEPTHPARAMS] = 952; - if (!File::Exists(File::GetUserPath(D_SHADERCACHE_IDX))) File::CreateDir(File::GetUserPath(D_SHADERCACHE_IDX).c_str()); @@ -277,39 +260,4 @@ bool VertexShaderCache::InsertByteCode(const VertexShaderUid &uid, D3DBlob* bcod return true; } -// 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; -} - -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); - vscbufchanged = true; -} - } // namespace DX11 diff --git a/Source/Core/VideoBackends/OGL/CMakeLists.txt b/Source/Core/VideoBackends/OGL/CMakeLists.txt index f3d7ce4e4f..3e1d2aaa60 100644 --- a/Source/Core/VideoBackends/OGL/CMakeLists.txt +++ b/Source/Core/VideoBackends/OGL/CMakeLists.txt @@ -3,7 +3,6 @@ set(SRCS Src/FramebufferManager.cpp Src/main.cpp Src/NativeVertexFormat.cpp Src/PerfQuery.cpp - Src/PixelShaderCache.cpp Src/PostProcessing.cpp Src/ProgramShaderCache.cpp Src/RasterFont.cpp @@ -12,7 +11,6 @@ set(SRCS Src/FramebufferManager.cpp Src/StreamBuffer.cpp Src/TextureCache.cpp Src/TextureConverter.cpp - Src/VertexShaderCache.cpp Src/VertexManager.cpp) set(LIBS videocommon diff --git a/Source/Core/VideoBackends/OGL/OGL.vcxproj b/Source/Core/VideoBackends/OGL/OGL.vcxproj index 69e23065c5..46113f53ce 100644 --- a/Source/Core/VideoBackends/OGL/OGL.vcxproj +++ b/Source/Core/VideoBackends/OGL/OGL.vcxproj @@ -151,7 +151,6 @@ <ClCompile Include="Src\main.cpp" /> <ClCompile Include="Src\NativeVertexFormat.cpp" /> <ClCompile Include="Src\PerfQuery.cpp" /> - <ClCompile Include="Src\PixelShaderCache.cpp" /> <ClCompile Include="Src\PostProcessing.cpp" /> <ClCompile Include="Src\ProgramShaderCache.cpp" /> <ClCompile Include="Src\RasterFont.cpp" /> @@ -169,7 +168,6 @@ <ClCompile Include="Src\TextureCache.cpp" /> <ClCompile Include="Src\TextureConverter.cpp" /> <ClCompile Include="Src\VertexManager.cpp" /> - <ClCompile Include="Src\VertexShaderCache.cpp" /> </ItemGroup> <ItemGroup> <ClInclude Include="Src\FramebufferManager.h" /> @@ -203,4 +201,4 @@ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <ImportGroup Label="ExtensionTargets"> </ImportGroup> -</Project>
\ No newline at end of file +</Project> diff --git a/Source/Core/VideoBackends/OGL/Src/PixelShaderCache.cpp b/Source/Core/VideoBackends/OGL/Src/PixelShaderCache.cpp deleted file mode 100644 index 3fac62bd73..0000000000 --- a/Source/Core/VideoBackends/OGL/Src/PixelShaderCache.cpp +++ /dev/null @@ -1,104 +0,0 @@ -// Copyright 2013 Dolphin Emulator Project -// Licensed under GPLv2 -// Refer to the license.txt file included. - -#include "Globals.h" - -#include "GLUtil.h" - -#include <cmath> - -#include "Statistics.h" -#include "VideoConfig.h" -#include "ImageWrite.h" -#include "Common.h" -#include "Render.h" -#include "VertexShaderGen.h" -#include "ProgramShaderCache.h" -#include "PixelShaderManager.h" -#include "OnScreenDisplay.h" -#include "StringUtil.h" -#include "FileUtil.h" -#include "Debugger.h" - -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) - { - ProgramShaderCache::SetMultiPSConstant4fv(const_number, f, count); - 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, count); - return; - } - } -} -} // namespace OGL diff --git a/Source/Core/VideoBackends/OGL/Src/ProgramShaderCache.cpp b/Source/Core/VideoBackends/OGL/Src/ProgramShaderCache.cpp index 94b9502d2f..51f41c063b 100644 --- a/Source/Core/VideoBackends/OGL/Src/ProgramShaderCache.cpp +++ b/Source/Core/VideoBackends/OGL/Src/ProgramShaderCache.cpp @@ -10,18 +10,16 @@ #include "Statistics.h" #include "ImageWrite.h" #include "Render.h" +#include "PixelShaderManager.h" +#include "VertexShaderManager.h" namespace OGL { static const u32 UBO_LENGTH = 32*1024*1024; -GLintptr ProgramShaderCache::s_vs_data_size; -GLintptr ProgramShaderCache::s_ps_data_size; -GLintptr ProgramShaderCache::s_vs_data_offset; -u8 *ProgramShaderCache::s_ubo_buffer; u32 ProgramShaderCache::s_ubo_buffer_size; -bool ProgramShaderCache::s_ubo_dirty; +s32 ProgramShaderCache::s_ubo_align; static StreamBuffer *s_buffer; static int num_failures = 0; @@ -36,6 +34,10 @@ UidChecker<VertexShaderUid,VertexShaderCode> ProgramShaderCache::vertex_uid_chec static char s_glsl_header[1024] = ""; + + +// Annoying sure, can be removed once we drop our UBO workaround + const char *UniformNames[NUM_UNIFORMS] = { // PIXEL SHADER UNIFORMS @@ -61,6 +63,33 @@ const char *UniformNames[NUM_UNIFORMS] = I_DEPTHPARAMS, }; +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 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 + void SHADER::SetProgramVariables() { // glsl shader must be bind to set samplers @@ -162,30 +191,43 @@ void SHADER::Bind() } } - -void ProgramShaderCache::SetMultiPSConstant4fv(unsigned int offset, const float *f, unsigned int count) -{ - s_ubo_dirty = true; - memcpy(s_ubo_buffer+(offset*4*sizeof(float)), f, count*4*sizeof(float)); -} - -void ProgramShaderCache::SetMultiVSConstant4fv(unsigned int offset, const float *f, unsigned int count) -{ - s_ubo_dirty = true; - memcpy(s_ubo_buffer+(offset*4*sizeof(float))+s_vs_data_offset, f, count*4*sizeof(float)); -} - void ProgramShaderCache::UploadConstants() { - if(s_ubo_dirty) { - s_buffer->Alloc(s_ubo_buffer_size); - size_t offset = s_buffer->Upload(s_ubo_buffer, s_ubo_buffer_size); - glBindBufferRange(GL_UNIFORM_BUFFER, 1, s_buffer->getBuffer(), offset, s_ps_data_size); - glBindBufferRange(GL_UNIFORM_BUFFER, 2, s_buffer->getBuffer(), offset + s_vs_data_offset, s_vs_data_size); - s_ubo_dirty = false; + if(g_ActiveConfig.backend_info.bSupportsGLSLUBO) + { + if(PixelShaderManager::dirty || VertexShaderManager::dirty) + { + s_buffer->Alloc(s_ubo_buffer_size); + + size_t offset = s_buffer->Upload((u8*)&PixelShaderManager::constants, ROUND_UP(sizeof(PixelShaderConstants), s_ubo_align)); + glBindBufferRange(GL_UNIFORM_BUFFER, 1, s_buffer->getBuffer(), offset, sizeof(PixelShaderConstants)); + offset = s_buffer->Upload((u8*)&VertexShaderManager::constants, ROUND_UP(sizeof(VertexShaderConstants), s_ubo_align)); + glBindBufferRange(GL_UNIFORM_BUFFER, 2, s_buffer->getBuffer(), offset, sizeof(VertexShaderConstants)); + + PixelShaderManager::dirty = false; + VertexShaderManager::dirty = false; + + ADDSTAT(stats.thisFrame.bytesUniformStreamed, s_ubo_buffer_size); + } + } + else + { + // UBO workaround + // this must be updated per shader switch, so also update it when it's not dirty + 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]); + } + 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]); + } ADDSTAT(stats.thisFrame.bytesUniformStreamed, s_ubo_buffer_size); } + } GLuint ProgramShaderCache::GetCurrentProgram(void) @@ -419,22 +461,14 @@ void ProgramShaderCache::Init(void) // then the UBO will fail. if (g_ActiveConfig.backend_info.bSupportsGLSLUBO) { - GLint Align; - glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, &Align); + glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, &s_ubo_align); - s_ps_data_size = C_PENVCONST_END * sizeof(float) * 4; - s_vs_data_size = C_VENVCONST_END * sizeof(float) * 4; - s_vs_data_offset = ROUND_UP(s_ps_data_size, Align); - s_ubo_buffer_size = ROUND_UP(s_ps_data_size, Align) + ROUND_UP(s_vs_data_size, Align); + s_ubo_buffer_size = ROUND_UP(sizeof(PixelShaderConstants), s_ubo_align) + ROUND_UP(sizeof(VertexShaderConstants), s_ubo_align); // We multiply by *4*4 because we need to get down to basic machine units. // So multiply by four to get how many floats we have from vec4s // Then once more to get bytes s_buffer = new StreamBuffer(GL_UNIFORM_BUFFER, UBO_LENGTH); - - s_ubo_buffer = new u8[s_ubo_buffer_size]; - memset(s_ubo_buffer, 0, s_ubo_buffer_size); - s_ubo_dirty = true; } // Read our shader cache, only if supported @@ -509,8 +543,6 @@ void ProgramShaderCache::Shutdown(void) { delete s_buffer; s_buffer = 0; - delete [] s_ubo_buffer; - s_ubo_buffer = 0; } } diff --git a/Source/Core/VideoBackends/OGL/Src/ProgramShaderCache.h b/Source/Core/VideoBackends/OGL/Src/ProgramShaderCache.h index 6c1350fe34..d0c792aaa0 100644 --- a/Source/Core/VideoBackends/OGL/Src/ProgramShaderCache.h +++ b/Source/Core/VideoBackends/OGL/Src/ProgramShaderCache.h @@ -87,9 +87,6 @@ public: static bool CompileShader(SHADER &shader, const char* vcode, const char* pcode); static GLuint CompileSingleShader(GLuint type, const char *code); - - static void SetMultiPSConstant4fv(unsigned int offset, const float *f, unsigned int count); - static void SetMultiVSConstant4fv(unsigned int offset, const float *f, unsigned int count); static void UploadConstants(); static void Init(void); @@ -110,12 +107,8 @@ private: static UidChecker<PixelShaderUid,PixelShaderCode> pixel_uid_checker; static UidChecker<VertexShaderUid,VertexShaderCode> vertex_uid_checker; - static GLintptr s_vs_data_size; - static GLintptr s_ps_data_size; - static GLintptr s_vs_data_offset; - static u8 *s_ubo_buffer; static u32 s_ubo_buffer_size; - static bool s_ubo_dirty; + static s32 s_ubo_align; }; } // namespace OGL diff --git a/Source/Core/VideoBackends/OGL/Src/Render.h b/Source/Core/VideoBackends/OGL/Src/Render.h index 4086ad3e87..8c6a8ca8f8 100644 --- a/Source/Core/VideoBackends/OGL/Src/Render.h +++ b/Source/Core/VideoBackends/OGL/Src/Render.h @@ -81,15 +81,6 @@ 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: void UpdateEFBCache(EFBAccessType type, u32 cacheRectIdx, const EFBRectangle& efbPixelRc, const TargetRectangle& targetPixelRc, const u32* data); }; 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/VideoBackends/OGL/Src/VertexShaderCache.cpp b/Source/Core/VideoBackends/OGL/Src/VertexShaderCache.cpp deleted file mode 100644 index 8e2c048f8d..0000000000 --- a/Source/Core/VideoBackends/OGL/Src/VertexShaderCache.cpp +++ /dev/null @@ -1,130 +0,0 @@ -// Copyright 2013 Dolphin Emulator Project -// Licensed under GPLv2 -// Refer to the license.txt file included. - -#include <math.h> - -#include "Globals.h" -#include "VideoConfig.h" -#include "Statistics.h" - -#include "GLUtil.h" - -#include "Render.h" -#include "VertexShaderGen.h" -#include "VertexShaderManager.h" -#include "ProgramShaderCache.h" -#include "VertexManager.h" -#include "VertexLoader.h" -#include "XFMemory.h" -#include "ImageWrite.h" -#include "FileUtil.h" -#include "Debugger.h" - -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) - { - ProgramShaderCache::SetMultiVSConstant4fv(const_number, f, 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, 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; - } - } -} - -} // namespace OGL |
