diff --git a/Source/Core/VideoBackends/OGL/ProgramShaderCache.cpp b/Source/Core/VideoBackends/OGL/ProgramShaderCache.cpp index 90c73bf6ea..7cf40eed34 100644 --- a/Source/Core/VideoBackends/OGL/ProgramShaderCache.cpp +++ b/Source/Core/VideoBackends/OGL/ProgramShaderCache.cpp @@ -2,6 +2,8 @@ // Licensed under GPLv2 // Refer to the license.txt file included. +#include + #include "Common/MathUtil.h" #include "VideoBackends/OGL/ProgramShaderCache.h" @@ -36,13 +38,33 @@ UidChecker ProgramShaderCache::vertex_uid_chec static char s_glsl_header[1024] = ""; +std::string GetGLSLVersionString() +{ + GLSL_VERSION v = g_ogl_config.eSupportedGLSLVersion; + switch(v) + { + case GLSLES_300: + return "#version 300 es"; + case GLSLES_310: + return "#version 310 es"; + case GLSL_130: + return "#version 130"; + case GLSL_140: + return "#version 140"; + case GLSL_150: + return "#version 150"; + } + // Shouldn't ever hit this + return "#version ERROR"; +} + void SHADER::SetProgramVariables() { // glsl shader must be bind to set samplers Bind(); // Bind UBO - if (!g_ActiveConfig.backend_info.bSupportShadingLanguage420pack) + if (!g_ActiveConfig.backend_info.bSupportsBindingLayout) { GLint PSBlock_id = glGetUniformBlockIndex(glprogid, "PSBlock"); GLint VSBlock_id = glGetUniformBlockIndex(glprogid, "VSBlock"); @@ -455,7 +477,7 @@ void ProgramShaderCache::CreateHeader ( void ) "%s\n" // early-z "%s\n" // 420pack - // Precision defines for GLSLES3 + // Precision defines for GLSL ES "%s\n" "%s\n" @@ -478,13 +500,13 @@ void ProgramShaderCache::CreateHeader ( void ) "%s\n" // replace textureSize as constant "%s\n" // wipe out all centroid usages - , v==GLSLES3 ? "#version 300 es" : v==GLSL_130 ? "#version 130" : v==GLSL_140 ? "#version 140" : "#version 150" + , GetGLSLVersionString().c_str() , v=GLSLES_300 ? "precision highp float;" : "" + , v>=GLSLES_300 ? "precision highp int;" : "" , DriverDetails::HasBug(DriverDetails::BUG_BROKENTEXTURESIZE) ? "#define textureSize(x, y) ivec2(1, 1)" : "" , DriverDetails::HasBug(DriverDetails::BUG_BROKENCENTROID) ? "#define centroid" : "" diff --git a/Source/Core/VideoBackends/OGL/Render.cpp b/Source/Core/VideoBackends/OGL/Render.cpp index cfc48f980a..4ad70be08a 100644 --- a/Source/Core/VideoBackends/OGL/Render.cpp +++ b/Source/Core/VideoBackends/OGL/Render.cpp @@ -459,7 +459,10 @@ Renderer::Renderer() g_Config.backend_info.bSupportsPrimitiveRestart = !DriverDetails::HasBug(DriverDetails::BUG_PRIMITIVERESTART) && ((GLExtensions::Version() >= 310) || GLExtensions::Supports("GL_NV_primitive_restart")); g_Config.backend_info.bSupportsEarlyZ = GLExtensions::Supports("GL_ARB_shader_image_load_store"); - g_Config.backend_info.bSupportShadingLanguage420pack = GLExtensions::Supports("GL_ARB_shading_language_420pack"); + + // Desktop OpenGL supports the binding layout if it supports 420pack + // OpenGL ES 3.1 supports it implicitly without an extension + g_Config.backend_info.bSupportsBindingLayout = GLExtensions::Supports("GL_ARB_shading_language_420pack"); g_ogl_config.bSupportsGLSLCache = GLExtensions::Supports("GL_ARB_get_program_binary"); g_ogl_config.bSupportsGLPinnedMemory = GLExtensions::Supports("GL_AMD_pinned_memory"); @@ -472,7 +475,17 @@ Renderer::Renderer() g_ogl_config.bSupportViewportFloat = GLExtensions::Supports("GL_ARB_viewport_array"); if (GLInterface->GetMode() == GLInterfaceMode::MODE_OPENGLES3) - g_ogl_config.eSupportedGLSLVersion = GLSLES3; + { + if (strstr(g_ogl_config.glsl_version, "3.00")) + { + g_ogl_config.eSupportedGLSLVersion = GLSLES_300; + } + else + { + g_ogl_config.eSupportedGLSLVersion = GLSLES_310; + g_Config.backend_info.bSupportsBindingLayout = true; + } + } else { if (strstr(g_ogl_config.glsl_version, "1.00") || strstr(g_ogl_config.glsl_version, "1.10") || strstr(g_ogl_config.glsl_version, "1.20")) diff --git a/Source/Core/VideoBackends/OGL/Render.h b/Source/Core/VideoBackends/OGL/Render.h index fb822aa352..0ea0eaee0f 100644 --- a/Source/Core/VideoBackends/OGL/Render.h +++ b/Source/Core/VideoBackends/OGL/Render.h @@ -11,8 +11,9 @@ void ClearEFBCache(); enum GLSL_VERSION { GLSL_130, GLSL_140, - GLSL_150, // and above - GLSLES3 + GLSL_150, // and above + GLSLES_300, // GLES 3.0 + GLSLES_310, // GLES 3.1 }; // ogl-only config, so not in VideoConfig.h diff --git a/Source/Core/VideoCommon/PixelShaderGen.cpp b/Source/Core/VideoCommon/PixelShaderGen.cpp index 85d25b2cac..29e60df4e0 100644 --- a/Source/Core/VideoCommon/PixelShaderGen.cpp +++ b/Source/Core/VideoCommon/PixelShaderGen.cpp @@ -223,7 +223,7 @@ static inline void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_T out.Write("\n"); if (ApiType == API_OPENGL) - out.Write("layout(std140%s) uniform PSBlock {\n", g_ActiveConfig.backend_info.bSupportShadingLanguage420pack ? ", binding = 1" : ""); + out.Write("layout(std140%s) uniform PSBlock {\n", g_ActiveConfig.backend_info.bSupportsBindingLayout ? ", binding = 1" : ""); DeclareUniform(out, ApiType, C_COLORS, "int4", I_COLORS"[4]"); DeclareUniform(out, ApiType, C_KCOLORS, "int4", I_KCOLORS"[4]"); diff --git a/Source/Core/VideoCommon/VertexShaderGen.cpp b/Source/Core/VideoCommon/VertexShaderGen.cpp index 448b0deb04..c61beda283 100644 --- a/Source/Core/VideoCommon/VertexShaderGen.cpp +++ b/Source/Core/VideoCommon/VertexShaderGen.cpp @@ -83,7 +83,7 @@ static inline void GenerateVertexShader(T& out, u32 components, API_TYPE api_typ // uniforms if (api_type == API_OPENGL) - out.Write("layout(std140%s) uniform VSBlock {\n", g_ActiveConfig.backend_info.bSupportShadingLanguage420pack ? ", binding = 2" : ""); + out.Write("layout(std140%s) uniform VSBlock {\n", g_ActiveConfig.backend_info.bSupportsBindingLayout ? ", binding = 2" : ""); DeclareUniform(out, api_type, C_POSNORMALMATRIX, "float4", I_POSNORMALMATRIX"[6]"); DeclareUniform(out, api_type, C_PROJECTION, "float4", I_PROJECTION"[4]"); diff --git a/Source/Core/VideoCommon/VideoConfig.h b/Source/Core/VideoCommon/VideoConfig.h index 5d7ddbb0eb..8c858b722c 100644 --- a/Source/Core/VideoCommon/VideoConfig.h +++ b/Source/Core/VideoCommon/VideoConfig.h @@ -152,7 +152,7 @@ struct VideoConfig final bool bSupportsSeparateAlphaFunction; bool bSupportsOversizedViewports; bool bSupportsEarlyZ; // needed by PixelShaderGen, so must stay in VideoCommon - bool bSupportShadingLanguage420pack; // needed by ShaderGen, so must stay in VideoCommon + bool bSupportsBindingLayout; // Needed by ShaderGen, so must stay in VideoCommon } backend_info; // Utility