diff options
| author | Ryan Houdek <Sonicadvance1@gmail.com> | 2011-12-09 17:30:05 -0600 |
|---|---|---|
| committer | Ryan Houdek <Sonicadvance1@gmail.com> | 2011-12-09 17:30:05 -0600 |
| commit | 8e5bb59cb692bae1bf4a94797a7c153e9bbd2d3d (patch) | |
| tree | 4c3f7bce56c03e85d49e97f497f30a7660654296 /Source/Plugins | |
| parent | 9119399547b44f9c9068fa52812a9e90ab367d8d (diff) | |
Add in UBOs, doesn't work yet. Still debugging here.
Diffstat (limited to 'Source/Plugins')
6 files changed, 98 insertions, 21 deletions
diff --git a/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.cpp b/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.cpp index f4f9a46e72..978357e18f 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.cpp @@ -82,8 +82,13 @@ void PixelShaderCache::Init() if (strstr((const char*)glGetString(GL_EXTENSIONS), "GL_ARB_shading_language_420pack") != NULL) g_Config.backend_info.bSupportsGLSLBinding = true; // This bit doesn't quite work yet, always set to false + // TODO: Probably just drop this entirely in favour of UBOS //if (strstr((const char*)glGetString(GL_EXTENSIONS), "GL_ARB_separate_shader_objects") != NULL) g_Config.backend_info.bSupportsGLSLLocation = false; + + if (strstr((const char*)glGetString(GL_EXTENSIONS), "GL_ARB_uniform_buffer_object") != NULL) + g_Config.backend_info.bSupportsGLSLUBO = true; + UpdateActiveConfig(); } else @@ -466,11 +471,11 @@ bool CompileGLSLPixelShader(FRAGMENTSHADER& ps, const char* pstrprogram) } void PixelShaderCache::SetPSSampler(const char * name, unsigned int Tex) { - if(g_ActiveConfig.backend_info.bSupportsGLSLBinding) + if (g_ActiveConfig.backend_info.bSupportsGLSLBinding) return; PROGRAMSHADER tmp = ProgramShaderCache::GetShaderProgram(); - for(int a = 0; a < NUM_UNIFORMS; ++a) - if(!strcmp(name, UniformNames[a])) + for (int a = 0; a < NUM_UNIFORMS; ++a) + if (!strcmp(name, UniformNames[a])) { if(tmp.UniformLocations[a] == -1) return; @@ -484,8 +489,8 @@ void PixelShaderCache::SetPSSampler(const char * name, unsigned int Tex) void SetPSConstant4fvByName(const char * name, unsigned int offset, const float *f, const unsigned int count = 1) { PROGRAMSHADER tmp = ProgramShaderCache::GetShaderProgram(); - for(int a = 0; a < NUM_UNIFORMS; ++a) - if(!strcmp(name, UniformNames[a])) + for (int a = 0; a < NUM_UNIFORMS; ++a) + if (!strcmp(name, UniformNames[a])) { if(tmp.UniformLocations[a] == -1) return; @@ -500,14 +505,19 @@ void SetGLSLPSConstant4f(unsigned int const_number, float f1, float f2, float f3 { float f[4] = { f1, f2, f3, f4 }; - if(g_ActiveConfig.backend_info.bSupportsGLSLLocation) + if (g_ActiveConfig.backend_info.bSupportsGLSLLocation) { glUniform4fv(const_number, 1, f); return; } - for( unsigned int a = 0; a < 10; ++a) + if (g_ActiveConfig.backend_info.bSupportsGLSLUBO) + { + ProgramShaderCache::SetUniformObjects(0, const_number, f); + 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)) + 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); @@ -518,14 +528,19 @@ void SetGLSLPSConstant4f(unsigned int const_number, float f1, float f2, float f3 void SetGLSLPSConstant4fv(unsigned int const_number, const float *f) { - if(g_ActiveConfig.backend_info.bSupportsGLSLLocation) + if (g_ActiveConfig.backend_info.bSupportsGLSLLocation) { glUniform4fv(const_number, 1, f); return; } - for( unsigned int a = 0; a < 10; ++a) + if (g_ActiveConfig.backend_info.bSupportsGLSLUBO) + { + ProgramShaderCache::SetUniformObjects(0, const_number, f); + 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)) + 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); @@ -536,14 +551,19 @@ void SetGLSLPSConstant4fv(unsigned int const_number, const float *f) void SetMultiGLSLPSConstant4fv(unsigned int const_number, unsigned int count, const float *f) { - if(g_ActiveConfig.backend_info.bSupportsGLSLLocation) + if (g_ActiveConfig.backend_info.bSupportsGLSLLocation) { glUniform4fv(const_number, count, f); return; } - for( unsigned int a = 0; a < 10; ++a) + if (g_ActiveConfig.backend_info.bSupportsGLSLUBO) + { + ProgramShaderCache::SetUniformObjects(0, 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)) + 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); diff --git a/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp b/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp index fc056aed63..776280103e 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp @@ -14,12 +14,15 @@ // Official SVN repository and contact information can be found at // http://code.google.com/p/dolphin-emu/ + #include "ProgramShaderCache.h" +#include <assert.h> namespace OGL { GLuint ProgramShaderCache::CurrentFShader = 0, ProgramShaderCache::CurrentVShader = 0, ProgramShaderCache::CurrentProgram = 0; ProgramShaderCache::PCache ProgramShaderCache::pshaders; + GLuint ProgramShaderCache::UBOBuffers[2]; std::pair<u64, u64> ProgramShaderCache::CurrentShaderProgram; const char *UniformNames[NUM_UNIFORMS] = { @@ -85,12 +88,14 @@ namespace OGL // Let's attach everything if(entry.program.vsid != 0) // attaching zero vertex shader makes it freak out glAttachShader(entry.program.glprogid, entry.program.vsid); + glAttachShader(entry.program.glprogid, entry.program.psid); + glLinkProgram(entry.program.glprogid); - //checkForGLError("linking program"); + glUseProgram(entry.program.glprogid); - //checkForGLError("using program"); + // We cache our uniform locations for now // Once we move up to a newer version of GLSL, ~1.30 // We can remove this @@ -122,18 +127,40 @@ namespace OGL CurrentShaderProgram = ShaderPair; CurrentProgram = entry.program.glprogid; } - + void ProgramShaderCache::SetUniformObjects(int Buffer, unsigned int offset, const float *f, unsigned int count) + { + assert(Buffer > 1); + glBindBuffer(GL_UNIFORM_BUFFER, UBOBuffers[Buffer]); + // glBufferSubData expects data in bytes, so multiply count by four + // Expects the offset in bytes as well, so multiply by *4 *4 since we are passing in a vec4 location + glBufferSubData(GL_UNIFORM_BUFFER, offset * 4 * 4, count * 4, (void*)&f[0]); + } GLuint ProgramShaderCache::GetCurrentProgram(void) { return CurrentProgram; } GLint ProgramShaderCache::GetAttr(int num) { return pshaders[CurrentShaderProgram].program.attrLoc[num]; } - PROGRAMSHADER ProgramShaderCache::GetShaderProgram() + PROGRAMSHADER ProgramShaderCache::GetShaderProgram(void) { return pshaders[CurrentShaderProgram].program; } - + void ProgramShaderCache::Init(void) + { + glGenBuffers(2, UBOBuffers); + glBindBuffer(GL_UNIFORM_BUFFER, UBOBuffers[0]); + // 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 + glBufferData(GL_UNIFORM_BUFFER, C_PENVCONST_END * 4 * 4, NULL, GL_DYNAMIC_DRAW); + // Now bind the buffer to the index point + // We know PS is 0 since we have it statically set in the shader + glBindBufferBase(GL_UNIFORM_BUFFER, 0, UBOBuffers[0]); + // Repeat for VS shader + glBindBuffer(GL_UNIFORM_BUFFER, UBOBuffers[1]); + glBufferData(GL_UNIFORM_BUFFER, C_VENVCONST_END * 4 * 4, NULL, GL_DYNAMIC_DRAW); + glBindBufferBase(GL_UNIFORM_BUFFER, 1, UBOBuffers[1]); + } void ProgramShaderCache::Shutdown(void) { PCache::iterator iter = pshaders.begin(); diff --git a/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.h b/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.h index 53abe440f5..a5ff097af6 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.h +++ b/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.h @@ -94,11 +94,17 @@ class ProgramShaderCache static PCache pshaders; static GLuint CurrentFShader, CurrentVShader, CurrentProgram; static std::pair<u64, u64> CurrentShaderProgram; + + // For UBOS + static GLuint UBOBuffers[2]; // PS is 0, VS is 1 public: - static PROGRAMSHADER GetShaderProgram(); + static PROGRAMSHADER GetShaderProgram(void); static GLint GetAttr(int num); static void SetBothShaders(GLuint PS, GLuint VS); static GLuint GetCurrentProgram(void); + static void SetUniformObjects(int Buffer, unsigned int offset, const float *f, unsigned int count = 1); + + static void Init(void); static void Shutdown(void); }; diff --git a/Source/Plugins/Plugin_VideoOGL/Src/VertexManager.cpp b/Source/Plugins/Plugin_VideoOGL/Src/VertexManager.cpp index e2723c0c98..fff8263569 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/VertexManager.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/VertexManager.cpp @@ -239,7 +239,8 @@ void VertexManager::vFlush() if(g_ActiveConfig.bUseGLSL) { ProgramShaderCache::SetBothShaders(ps->glprogid, 0); - PixelShaderManager::SetConstants(); // Need to set these again + if(!g_ActiveConfig.backend_info.bSupportsGLSLUBO) + PixelShaderManager::SetConstants(); // Need to set these again, if we don't support UBO if (g_nativeVertexFmt) g_nativeVertexFmt->SetupVertexPointers(); for (int i = 0; i < 8; i++) diff --git a/Source/Plugins/Plugin_VideoOGL/Src/VertexShaderCache.cpp b/Source/Plugins/Plugin_VideoOGL/Src/VertexShaderCache.cpp index 143340277e..dfa3293a46 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/VertexShaderCache.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/VertexShaderCache.cpp @@ -252,6 +252,11 @@ void SetGLSLVSConstant4f(unsigned int const_number, float f1, float f2, float f3 glUniform4fv(const_number, 1, buf); return; } + if (g_ActiveConfig.backend_info.bSupportsGLSLUBO) + { + ProgramShaderCache::SetUniformObjects(1, const_number, buf); + 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)) @@ -270,6 +275,11 @@ void SetGLSLVSConstant4fv(unsigned int const_number, const float *f) glUniform4fv(const_number, 1, f); return; } + if (g_ActiveConfig.backend_info.bSupportsGLSLUBO) + { + ProgramShaderCache::SetUniformObjects(1, const_number, f); + 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)) @@ -288,6 +298,11 @@ void SetMultiGLSLVSConstant4fv(unsigned int const_number, unsigned int count, co glUniform4fv(const_number, count, f); return; } + if (g_ActiveConfig.backend_info.bSupportsGLSLUBO) + { + ProgramShaderCache::SetUniformObjects(1, 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)) @@ -314,6 +329,11 @@ void SetMultiGLSLVSConstant3fv(unsigned int const_number, unsigned int count, co glUniform4fv(const_number, count, buf); return; } + if (g_ActiveConfig.backend_info.bSupportsGLSLUBO) + { + ProgramShaderCache::SetUniformObjects(1, 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)) diff --git a/Source/Plugins/Plugin_VideoOGL/Src/main.cpp b/Source/Plugins/Plugin_VideoOGL/Src/main.cpp index 0d1c3fc35a..c4e2a8f0ea 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/main.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/main.cpp @@ -83,6 +83,7 @@ Make AA apply instantly during gameplay if possible #include "PixelShaderManager.h" #include "VertexShaderCache.h" #include "VertexShaderManager.h" +#include "ProgramShaderCache.h" #include "CommandProcessor.h" #include "PixelEngine.h" #include "TextureConverter.h" @@ -199,6 +200,7 @@ void VideoBackend::Video_Prepare() VertexShaderManager::Init(); PixelShaderCache::Init(); PixelShaderManager::Init(); + ProgramShaderCache::Init(); PostProcessing::Init(); GL_REPORT_ERRORD(); VertexLoaderManager::Init(); @@ -226,6 +228,7 @@ void VideoBackend::Shutdown() // And need to be called from the video thread TextureConverter::Shutdown(); VertexLoaderManager::Shutdown(); + ProgramShaderCache::Shutdown(); VertexShaderCache::Shutdown(); VertexShaderManager::Shutdown(); PixelShaderManager::Shutdown(); |
