Add initial support for GLSL ES 3.10.

GLSL ES 3.10 adds implicit support for the binding layout qualifier that we use.
Changes our GLSL version enums to bit values so we can check for both ES versions easily.
This commit is contained in:
Ryan Houdek 2014-03-30 13:58:05 -05:00
parent bad109402e
commit 3251d78f89
6 changed files with 49 additions and 13 deletions

View File

@ -2,6 +2,8 @@
// Licensed under GPLv2 // Licensed under GPLv2
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include <string>
#include "Common/MathUtil.h" #include "Common/MathUtil.h"
#include "VideoBackends/OGL/ProgramShaderCache.h" #include "VideoBackends/OGL/ProgramShaderCache.h"
@ -36,13 +38,33 @@ UidChecker<VertexShaderUid,VertexShaderCode> ProgramShaderCache::vertex_uid_chec
static char s_glsl_header[1024] = ""; 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() void SHADER::SetProgramVariables()
{ {
// glsl shader must be bind to set samplers // glsl shader must be bind to set samplers
Bind(); Bind();
// Bind UBO // Bind UBO
if (!g_ActiveConfig.backend_info.bSupportShadingLanguage420pack) if (!g_ActiveConfig.backend_info.bSupportsBindingLayout)
{ {
GLint PSBlock_id = glGetUniformBlockIndex(glprogid, "PSBlock"); GLint PSBlock_id = glGetUniformBlockIndex(glprogid, "PSBlock");
GLint VSBlock_id = glGetUniformBlockIndex(glprogid, "VSBlock"); GLint VSBlock_id = glGetUniformBlockIndex(glprogid, "VSBlock");
@ -455,7 +477,7 @@ void ProgramShaderCache::CreateHeader ( void )
"%s\n" // early-z "%s\n" // early-z
"%s\n" // 420pack "%s\n" // 420pack
// Precision defines for GLSLES3 // Precision defines for GLSL ES
"%s\n" "%s\n"
"%s\n" "%s\n"
@ -478,13 +500,13 @@ void ProgramShaderCache::CreateHeader ( void )
"%s\n" // replace textureSize as constant "%s\n" // replace textureSize as constant
"%s\n" // wipe out all centroid usages "%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<GLSL_140 ? "#extension GL_ARB_uniform_buffer_object : enable" : "" , 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.bSupportsEarlyZ ? "#extension GL_ARB_shader_image_load_store : enable" : ""
, g_ActiveConfig.backend_info.bSupportShadingLanguage420pack ? "#extension GL_ARB_shading_language_420pack : enable" : "" , (g_ActiveConfig.backend_info.bSupportsBindingLayout && v < GLSLES_310) ? "#extension GL_ARB_shading_language_420pack : enable" : ""
, v==GLSLES3 ? "precision highp float;" : "" , v>=GLSLES_300 ? "precision highp float;" : ""
, v==GLSLES3 ? "precision highp int;" : "" , v>=GLSLES_300 ? "precision highp int;" : ""
, DriverDetails::HasBug(DriverDetails::BUG_BROKENTEXTURESIZE) ? "#define textureSize(x, y) ivec2(1, 1)" : "" , DriverDetails::HasBug(DriverDetails::BUG_BROKENTEXTURESIZE) ? "#define textureSize(x, y) ivec2(1, 1)" : ""
, DriverDetails::HasBug(DriverDetails::BUG_BROKENCENTROID) ? "#define centroid" : "" , DriverDetails::HasBug(DriverDetails::BUG_BROKENCENTROID) ? "#define centroid" : ""

View File

@ -459,7 +459,10 @@ Renderer::Renderer()
g_Config.backend_info.bSupportsPrimitiveRestart = !DriverDetails::HasBug(DriverDetails::BUG_PRIMITIVERESTART) && g_Config.backend_info.bSupportsPrimitiveRestart = !DriverDetails::HasBug(DriverDetails::BUG_PRIMITIVERESTART) &&
((GLExtensions::Version() >= 310) || GLExtensions::Supports("GL_NV_primitive_restart")); ((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.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.bSupportsGLSLCache = GLExtensions::Supports("GL_ARB_get_program_binary");
g_ogl_config.bSupportsGLPinnedMemory = GLExtensions::Supports("GL_AMD_pinned_memory"); 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"); g_ogl_config.bSupportViewportFloat = GLExtensions::Supports("GL_ARB_viewport_array");
if (GLInterface->GetMode() == GLInterfaceMode::MODE_OPENGLES3) 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 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")) 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"))

View File

@ -11,8 +11,9 @@ void ClearEFBCache();
enum GLSL_VERSION { enum GLSL_VERSION {
GLSL_130, GLSL_130,
GLSL_140, GLSL_140,
GLSL_150, // and above GLSL_150, // and above
GLSLES3 GLSLES_300, // GLES 3.0
GLSLES_310, // GLES 3.1
}; };
// ogl-only config, so not in VideoConfig.h // ogl-only config, so not in VideoConfig.h

View File

@ -223,7 +223,7 @@ static inline void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_T
out.Write("\n"); out.Write("\n");
if (ApiType == API_OPENGL) 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_COLORS, "int4", I_COLORS"[4]");
DeclareUniform(out, ApiType, C_KCOLORS, "int4", I_KCOLORS"[4]"); DeclareUniform(out, ApiType, C_KCOLORS, "int4", I_KCOLORS"[4]");

View File

@ -83,7 +83,7 @@ static inline void GenerateVertexShader(T& out, u32 components, API_TYPE api_typ
// uniforms // uniforms
if (api_type == API_OPENGL) 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_POSNORMALMATRIX, "float4", I_POSNORMALMATRIX"[6]");
DeclareUniform(out, api_type, C_PROJECTION, "float4", I_PROJECTION"[4]"); DeclareUniform(out, api_type, C_PROJECTION, "float4", I_PROJECTION"[4]");

View File

@ -152,7 +152,7 @@ struct VideoConfig final
bool bSupportsSeparateAlphaFunction; bool bSupportsSeparateAlphaFunction;
bool bSupportsOversizedViewports; bool bSupportsOversizedViewports;
bool bSupportsEarlyZ; // 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 bool bSupportsBindingLayout; // Needed by ShaderGen, so must stay in VideoCommon
} backend_info; } backend_info;
// Utility // Utility