Skip to content

Commit

Permalink
OpenGL: use shader 420pack if available to staticly bind ubo location
Browse files Browse the repository at this point in the history
Bindung locations after compiling a shader stalls the driver. So if we manage not to bind anything after compilation, the lag would be reduced much.
  • Loading branch information
degasus committed Jan 5, 2014
1 parent 4fff5ac commit c42f274
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 4 deletions.
5 changes: 3 additions & 2 deletions Source/Core/VideoBackends/OGL/ProgramShaderCache.cpp
Expand Up @@ -96,7 +96,7 @@ void SHADER::SetProgramVariables()
Bind();

// Bind UBO
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO && !g_ActiveConfig.backend_info.bSupportShadingLanguage420pack)
{
GLint PSBlock_id = glGetUniformBlockIndex(glprogid, "PSBlock");
GLint VSBlock_id = glGetUniformBlockIndex(glprogid, "VSBlock");
Expand Down Expand Up @@ -135,7 +135,6 @@ void SHADER::SetProgramVariables()
}
}


// Bind Texture Sampler
for (int a = 0; a <= 9; ++a)
{
Expand Down Expand Up @@ -569,6 +568,7 @@ void ProgramShaderCache::CreateHeader ( void )
"%s\n"
"%s\n" // ubo
"%s\n" // early-z
"%s\n" // 420pack

// Precision defines for GLSLES3
"%s\n"
Expand Down Expand Up @@ -597,6 +597,7 @@ void ProgramShaderCache::CreateHeader ( void )
, v==GLSLES3 ? "#version 300 es" : v==GLSL_130 ? "#version 130" : v==GLSL_140 ? "#version 140" : "#version 150"
, g_ActiveConfig.backend_info.bSupportsGLSLUBO && v<GLSL_140 ? "#extension GL_ARB_uniform_buffer_object : enable" : ""
, g_ActiveConfig.backend_info.bSupportsEarlyZ ? "#extension GL_ARB_shader_image_load_store : enable" : ""
, g_ActiveConfig.backend_info.bSupportShadingLanguage420pack ? "#extension GL_ARB_shading_language_420pack : enable" : ""

, v==GLSLES3 ? "precision highp float;" : ""

Expand Down
2 changes: 2 additions & 0 deletions Source/Core/VideoBackends/OGL/Render.cpp
Expand Up @@ -371,6 +371,7 @@ Renderer::Renderer()
g_Config.backend_info.bSupportsGLSLUBO = !DriverDetails::HasBug(DriverDetails::BUG_ANNIHILATEDUBOS);
g_Config.backend_info.bSupportsPrimitiveRestart = true;
g_Config.backend_info.bSupportsEarlyZ = false;
g_Config.backend_info.bSupportShadingLanguage420pack = false;

g_ogl_config.bSupportsGLSLCache = true;
g_ogl_config.bSupportsGLPinnedMemory = false;
Expand Down Expand Up @@ -482,6 +483,7 @@ Renderer::Renderer()
g_Config.backend_info.bSupportsPrimitiveRestart = !DriverDetails::HasBug(DriverDetails::BUG_PRIMITIVERESTART) &&
(TO_BOOL(GLEW_VERSION_3_1) || TO_BOOL(GLEW_NV_primitive_restart));
g_Config.backend_info.bSupportsEarlyZ = TO_BOOL(GLEW_ARB_shader_image_load_store);
g_Config.backend_info.bSupportShadingLanguage420pack = TO_BOOL(GLEW_ARB_shading_language_420pack);

g_ogl_config.bSupportsGLSLCache = TO_BOOL(GLEW_ARB_get_program_binary);
g_ogl_config.bSupportsGLPinnedMemory = TO_BOOL(GLEW_AMD_pinned_memory);
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/VideoCommon/PixelShaderGen.cpp
Expand Up @@ -284,7 +284,7 @@ static inline void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_T
out.Write("\n");

if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
out.Write("layout(std140) uniform PSBlock {\n");
out.Write("layout(std140%s) uniform PSBlock {\n", g_ActiveConfig.backend_info.bSupportShadingLanguage420pack ? ", binding = 1" : "");

DeclareUniform(out, ApiType, g_ActiveConfig.backend_info.bSupportsGLSLUBO, C_COLORS, "float4", I_COLORS"[4]");
DeclareUniform(out, ApiType, g_ActiveConfig.backend_info.bSupportsGLSLUBO, C_KCOLORS, "float4", I_KCOLORS"[4]");
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/VideoCommon/VertexShaderGen.cpp
Expand Up @@ -84,7 +84,7 @@ static inline void GenerateVertexShader(T& out, u32 components, API_TYPE api_typ

// uniforms
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
out.Write("layout(std140) uniform VSBlock {\n");
out.Write("layout(std140%s) uniform VSBlock {\n", g_ActiveConfig.backend_info.bSupportShadingLanguage420pack ? ", binding = 2" : "");

DeclareUniform(out, api_type, g_ActiveConfig.backend_info.bSupportsGLSLUBO, C_POSNORMALMATRIX, "float4", I_POSNORMALMATRIX"[6]");
DeclareUniform(out, api_type, g_ActiveConfig.backend_info.bSupportsGLSLUBO, C_PROJECTION, "float4", I_PROJECTION"[4]");
Expand Down
1 change: 1 addition & 0 deletions Source/Core/VideoCommon/VideoConfig.h
Expand Up @@ -155,6 +155,7 @@ struct VideoConfig
bool bSupportsOversizedViewports;
bool bSupportsGLSLUBO; // needed by PixelShaderGen, so must stay in VideoCommon
bool bSupportsEarlyZ; // needed by PixelShaderGen, so must stay in VideoCommon
bool bSupportShadingLanguage420pack; // needed by ShaderGen, so must stay in VideoCommon
} backend_info;

// Utility
Expand Down

0 comments on commit c42f274

Please sign in to comment.