gsdx-ogl-ES: require GL_EXT_shader_io_blocks + GLES3.1

Allow to use same shader interface for all API

Note: on the GL API it will require GL3.3 (see next commit)
This commit is contained in:
Gregory Hainaut 2014-09-30 21:56:36 +02:00
parent 1c501047f5
commit 594f6c33a2
11 changed files with 36 additions and 291 deletions

View File

@ -180,6 +180,9 @@ namespace GLLoader {
// Mandatory for FULL GL (but optional for GLES)
bool found_GL_ARB_shading_language_420pack = false; // GLES 3.1 ???
// Mandatory for opengl ES (allow to use GL code)
bool found_GL_EXT_shader_io_blocks = false;
// Mandatory
bool found_GL_ARB_texture_storage = false;
@ -268,10 +271,10 @@ namespace GLLoader {
int max_ext = 0;
glGetIntegerv(GL_NUM_EXTENSIONS, &max_ext);
#ifndef ENABLE_GLES
if (gl_GetStringi && max_ext) {
for (GLint i = 0; i < max_ext; i++) {
string ext((const char*)gl_GetStringi(GL_EXTENSIONS, i));
#ifndef ENABLE_GLES
// GL4.0
if (ext.compare("GL_ARB_gpu_shader5") == 0) found_GL_ARB_gpu_shader5 = true;
// GL4.1
@ -307,18 +310,18 @@ namespace GLLoader {
// GL4.5
if (ext.compare("GL_ARB_direct_state_access") == 0) found_GL_ARB_direct_state_access = true;
if (ext.compare("GL_ARB_clip_control") == 0) found_GL_ARB_clip_control = true;
#ifdef ENABLE_GLES
fprintf(stderr, "DEBUG ext: %s\n", ext.c_str());
#else // ENABLE_GLES
if (ext.compare("GL_EXT_shader_io_blocks") == 0) found_GL_EXT_shader_io_blocks = true;
#endif
//fprintf(stderr, "DEBUG ext: %s\n", ext.c_str());
}
}
#endif
bool status = true;
#ifndef ENABLE_GLES
fprintf(stderr, "\n");
#ifndef ENABLE_GLES
// GL4.0
status &= status_and_override(found_GL_ARB_gpu_shader5,"GL_ARB_gpu_shader5");
// GL4.1
@ -338,9 +341,11 @@ namespace GLLoader {
// GL4.5
status &= status_and_override(found_GL_ARB_clip_control, "GL_ARB_clip_control");
status &= status_and_override(found_GL_ARB_direct_state_access, "GL_ARB_direct_state_access");
#else // ENABLE_GLES
status &= status_and_override(found_GL_EXT_shader_io_blocks, "GL_EXT_shader_io_blocks");
#endif
fprintf(stderr, "\n");
#endif
return status;
}

View File

@ -420,6 +420,7 @@ namespace GLLoader {
extern bool intel_buggy_driver;
extern bool in_replayer;
// GL
extern bool found_GL_ARB_separate_shader_objects;
extern bool found_GL_ARB_shading_language_420pack;
extern bool found_GL_ARB_copy_image;
@ -434,4 +435,6 @@ namespace GLLoader {
extern bool found_GL_ARB_explicit_uniform_location;
extern bool found_GL_ARB_clip_control;
extern bool found_GL_ARB_direct_state_access;
// GLES
extern bool found_GL_EXT_shader_io_blocks;
}

View File

@ -171,9 +171,11 @@ bool GSDeviceOGL::Create(GSWnd* wnd)
// ****************************************************************
// Debug helper
// ****************************************************************
#ifndef ENABLE_GLES
#ifdef ENABLE_OGL_DEBUG
gl_DebugMessageCallback(DebugOutputToFile, NULL);
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB);
#endif
#endif
// ****************************************************************

View File

@ -355,7 +355,6 @@ std::string GSShaderOGL::GenGlslHeader(const std::string& entry, GLenum type, co
{
std::string header;
#ifndef ENABLE_GLES
if (GLLoader::found_only_gl30) {
header = "#version 130\n";
} else {
@ -370,8 +369,6 @@ std::string GSShaderOGL::GenGlslHeader(const std::string& entry, GLenum type, co
if (GLLoader::found_GL_ARB_separate_shader_objects) {
// Need GL version 410
header += "#extension GL_ARB_separate_shader_objects: require\n";
} else {
header += "#define DISABLE_SSO\n";
}
if (GLLoader::found_only_gl30) {
// Need version 330
@ -402,15 +399,13 @@ std::string GSShaderOGL::GenGlslHeader(const std::string& entry, GLenum type, co
header += "#extension GL_ARB_bindless_texture: require\n";
header += "#define ENABLE_BINDLESS_TEX\n";
}
if (GLLoader::found_GL_ARB_clip_control) {
header += "#define ZERO_TO_ONE_DEPTH\n";
}
#else
header = "#version 300 es\n";
#else // ENABLE_GLES
header = "#version 310 es\n";
header += "#extension GL_EXT_shader_io_blocks: require\n";
// Disable full GL features
header += "#define DISABLE_SSO\n";
header += "#define DISABLE_GL42\n";
header += "#define DISABLE_GL42_image\n";
#endif

View File

@ -9,13 +9,13 @@ struct vertex_basic
#ifdef VERTEX_SHADER
#if !pGL_ES && __VERSION__ > 140
out gl_PerVertex {
vec4 gl_Position;
float gl_PointSize;
#if !pGL_ES
float gl_ClipDistance[];
};
#endif
};
layout(location = 0) in vec2 POSITION;
layout(location = 1) in vec2 TEXCOORD0;
@ -28,8 +28,6 @@ layout(location = 1) in vec2 TEXCOORD0;
// smooth, the default, means to do perspective-correct interpolation.
//
// The centroid qualifier only matters when multisampling. If this qualifier is not present, then the value is interpolated to the pixel's center, anywhere in the pixel, or to one of the pixel's samples. This sample may lie outside of the actual primitive being rendered, since a primitive can cover only part of a pixel's area. The centroid qualifier is used to prevent this; the interpolation point must fall within both the pixel's area and the primitive's area.
#if !pGL_ES && __VERSION__ > 140
out SHADER
{
vec4 p;
@ -39,20 +37,6 @@ out SHADER
#define VSout_p (VSout.p)
#define VSout_t (VSout.t)
#else
#ifdef DISABLE_SSO
out vec4 SHADERp;
out vec2 SHADERt;
#else
layout(location = 0) out vec4 SHADERp;
layout(location = 1) out vec2 SHADERt;
#endif
#define VSout_p SHADERp
#define VSout_t SHADERt
#endif
void vs_main()
{
VSout_p = vec4(POSITION, 0.5f, 1.0f);
@ -64,8 +48,6 @@ void vs_main()
#ifdef FRAGMENT_SHADER
#if !pGL_ES && __VERSION__ > 140
in SHADER
{
vec4 p;
@ -75,20 +57,6 @@ in SHADER
#define PSin_p (PSin.p)
#define PSin_t (PSin.t)
#else
#ifdef DISABLE_SSO
in vec4 SHADERp;
in vec2 SHADERt;
#else
layout(location = 0) in vec4 SHADERp;
layout(location = 1) in vec2 SHADERt;
#endif
#define PSin_p SHADERp
#define PSin_t SHADERt
#endif
// Give a different name so I remember there is a special case!
#ifdef ps_main1
layout(location = 0) out uint SV_Target1;

View File

@ -34,13 +34,13 @@ static const char* convert_glsl =
"\n"
"#ifdef VERTEX_SHADER\n"
"\n"
"#if !pGL_ES && __VERSION__ > 140\n"
"out gl_PerVertex {\n"
" vec4 gl_Position;\n"
" float gl_PointSize;\n"
"#if !pGL_ES\n"
" float gl_ClipDistance[];\n"
"};\n"
"#endif\n"
"};\n"
"\n"
"layout(location = 0) in vec2 POSITION;\n"
"layout(location = 1) in vec2 TEXCOORD0;\n"
@ -53,8 +53,6 @@ static const char* convert_glsl =
"// smooth, the default, means to do perspective-correct interpolation.\n"
"//\n"
"// The centroid qualifier only matters when multisampling. If this qualifier is not present, then the value is interpolated to the pixel's center, anywhere in the pixel, or to one of the pixel's samples. This sample may lie outside of the actual primitive being rendered, since a primitive can cover only part of a pixel's area. The centroid qualifier is used to prevent this; the interpolation point must fall within both the pixel's area and the primitive's area.\n"
"#if !pGL_ES && __VERSION__ > 140\n"
"\n"
"out SHADER\n"
"{\n"
" vec4 p;\n"
@ -64,20 +62,6 @@ static const char* convert_glsl =
"#define VSout_p (VSout.p)\n"
"#define VSout_t (VSout.t)\n"
"\n"
"#else\n"
"\n"
"#ifdef DISABLE_SSO\n"
"out vec4 SHADERp;\n"
"out vec2 SHADERt;\n"
"#else\n"
"layout(location = 0) out vec4 SHADERp;\n"
"layout(location = 1) out vec2 SHADERt;\n"
"#endif\n"
"#define VSout_p SHADERp\n"
"#define VSout_t SHADERt\n"
"\n"
"#endif\n"
"\n"
"void vs_main()\n"
"{\n"
" VSout_p = vec4(POSITION, 0.5f, 1.0f);\n"
@ -89,8 +73,6 @@ static const char* convert_glsl =
"\n"
"#ifdef FRAGMENT_SHADER\n"
"\n"
"#if !pGL_ES && __VERSION__ > 140\n"
"\n"
"in SHADER\n"
"{\n"
" vec4 p;\n"
@ -100,20 +82,6 @@ static const char* convert_glsl =
"#define PSin_p (PSin.p)\n"
"#define PSin_t (PSin.t)\n"
"\n"
"#else\n"
"\n"
"#ifdef DISABLE_SSO\n"
"in vec4 SHADERp;\n"
"in vec2 SHADERt;\n"
"#else\n"
"layout(location = 0) in vec4 SHADERp;\n"
"layout(location = 1) in vec2 SHADERt;\n"
"#endif\n"
"#define PSin_p SHADERp\n"
"#define PSin_t SHADERt\n"
"\n"
"#endif\n"
"\n"
"// Give a different name so I remember there is a special case!\n"
"#ifdef ps_main1\n"
"layout(location = 0) out uint SV_Target1;\n"
@ -294,8 +262,6 @@ static const char* interlace_glsl =
" vec2 t;\n"
"};\n"
"\n"
"#if !pGL_ES && __VERSION__ > 140\n"
"\n"
"in SHADER\n"
"{\n"
" vec4 p;\n"
@ -305,20 +271,6 @@ static const char* interlace_glsl =
"#define PSin_p (PSin.p)\n"
"#define PSin_t (PSin.t)\n"
"\n"
"#else\n"
"\n"
"#ifdef DISABLE_SSO\n"
"in vec4 SHADERp;\n"
"in vec2 SHADERt;\n"
"#else\n"
"layout(location = 0) in vec4 SHADERp;\n"
"layout(location = 1) in vec2 SHADERt;\n"
"#endif\n"
"#define PSin_p SHADERp\n"
"#define PSin_t SHADERt\n"
"\n"
"#endif\n"
"\n"
"#ifdef FRAGMENT_SHADER\n"
"\n"
"layout(location = 0) out vec4 SV_Target0;\n"
@ -392,8 +344,6 @@ static const char* merge_glsl =
" vec2 t;\n"
"};\n"
"\n"
"#if !pGL_ES && __VERSION__ > 140\n"
"\n"
"in SHADER\n"
"{\n"
" vec4 p;\n"
@ -403,20 +353,6 @@ static const char* merge_glsl =
"#define PSin_p (PSin.p)\n"
"#define PSin_t (PSin.t)\n"
"\n"
"#else\n"
"\n"
"#ifdef DISABLE_SSO\n"
"in vec4 SHADERp;\n"
"in vec2 SHADERt;\n"
"#else\n"
"layout(location = 0) in vec4 SHADERp;\n"
"layout(location = 1) in vec2 SHADERt;\n"
"#endif\n"
"#define PSin_p SHADERp\n"
"#define PSin_t SHADERt\n"
"\n"
"#endif\n"
"\n"
"#ifdef FRAGMENT_SHADER\n"
"\n"
"layout(location = 0) out vec4 SV_Target0;\n"
@ -474,8 +410,6 @@ static const char* shadeboost_glsl =
"\n"
"#ifdef FRAGMENT_SHADER\n"
"\n"
"#if !pGL_ES && __VERSION__ > 140\n"
"\n"
"in SHADER\n"
"{\n"
" vec4 p;\n"
@ -485,20 +419,6 @@ static const char* shadeboost_glsl =
"#define PSin_p (PSin.p)\n"
"#define PSin_t (PSin.t)\n"
"\n"
"#else\n"
"\n"
"#ifdef DISABLE_SSO\n"
"in vec4 SHADERp;\n"
"in vec2 SHADERt;\n"
"#else\n"
"layout(location = 0) in vec4 SHADERp;\n"
"layout(location = 1) in vec2 SHADERt;\n"
"#endif\n"
"#define PSin_p SHADERp\n"
"#define PSin_t SHADERt\n"
"\n"
"#endif\n"
"\n"
"layout(location = 0) out vec4 SV_Target0;\n"
"\n"
"#ifdef DISABLE_GL42\n"
@ -615,8 +535,6 @@ static const char* tfx_glsl =
"layout(location = 5) in uvec2 i_uv;\n"
"layout(location = 6) in vec4 i_f;\n"
"\n"
"#if !pGL_ES && __VERSION__ > 140\n"
"\n"
"out SHADER\n"
"{\n"
" vec4 t;\n"
@ -628,30 +546,13 @@ static const char* tfx_glsl =
"#define VSout_c (VSout.c)\n"
"#define VSout_fc (VSout.fc)\n"
"\n"
"#else\n"
"\n"
"#ifdef DISABLE_SSO\n"
"out vec4 SHADERt;\n"
"out vec4 SHADERc;\n"
"flat out vec4 SHADERfc;\n"
"#else\n"
"layout(location = 0) out vec4 SHADERt;\n"
"layout(location = 1) out vec4 SHADERc;\n"
"flat layout(location = 2) out vec4 SHADERfc;\n"
"#endif\n"
"#define VSout_t SHADERt\n"
"#define VSout_c SHADERc\n"
"#define VSout_fc SHADERfc\n"
"\n"
"#endif\n"
"\n"
"#if !pGL_ES && __VERSION__ > 140\n"
"out gl_PerVertex {\n"
" invariant vec4 gl_Position;\n"
" float gl_PointSize;\n"
"#if !pGL_ES\n"
" float gl_ClipDistance[];\n"
"};\n"
"#endif\n"
"};\n"
"\n"
"#ifdef DISABLE_GL42\n"
"layout(std140) uniform cb20\n"
@ -772,14 +673,18 @@ static const char* tfx_glsl =
"in gl_PerVertex {\n"
" invariant vec4 gl_Position;\n"
" float gl_PointSize;\n"
"#if !pGL_ES\n"
" float gl_ClipDistance[];\n"
"#endif\n"
"} gl_in[];\n"
"//in int gl_PrimitiveIDIn;\n"
"\n"
"out gl_PerVertex {\n"
" vec4 gl_Position;\n"
" float gl_PointSize;\n"
"#if !pGL_ES\n"
" float gl_ClipDistance[];\n"
"#endif\n"
"};\n"
"//out int gl_PrimitiveID;\n"
"\n"
@ -866,8 +771,6 @@ static const char* tfx_glsl =
"\n"
"#ifdef FRAGMENT_SHADER\n"
"\n"
"#if !pGL_ES && __VERSION__ > 140\n"
"\n"
"in SHADER\n"
"{\n"
" vec4 t;\n"
@ -879,23 +782,6 @@ static const char* tfx_glsl =
"#define PSin_c (PSin.c)\n"
"#define PSin_fc (PSin.fc)\n"
"\n"
"#else\n"
"\n"
"#ifdef DISABLE_SSO\n"
"in vec4 SHADERt;\n"
"in vec4 SHADERc;\n"
"flat in vec4 SHADERfc;\n"
"#else\n"
"layout(location = 0) in vec4 SHADERt;\n"
"layout(location = 1) in vec4 SHADERc;\n"
"flat layout(location = 2) in vec4 SHADERfc;\n"
"#endif\n"
"#define PSin_t SHADERt\n"
"#define PSin_c SHADERc\n"
"#define PSin_fc SHADERfc\n"
"\n"
"#endif\n"
"\n"
"// Same buffer but 2 colors for dual source blending\n"
"#if pGL_ES\n"
"layout(location = 0) out vec4 SV_Target0;\n"
@ -1772,8 +1658,6 @@ static const char* old_fxaa_fx =
"#endif\n"
"#endif\n"
"\n"
"#if !pGL_ES && __VERSION__ > 140\n"
"\n"
"in SHADER\n"
"{\n"
" vec4 p;\n"
@ -1783,20 +1667,6 @@ static const char* old_fxaa_fx =
"#define PSin_p (PSin.p)\n"
"#define PSin_t (PSin.t)\n"
"\n"
"#else\n"
"\n"
"#ifdef DISABLE_SSO\n"
"in vec4 SHADERp;\n"
"in vec2 SHADERt;\n"
"#else\n"
"layout(location = 0) in vec4 SHADERp;\n"
"layout(location = 1) in vec2 SHADERt;\n"
"#endif\n"
"#define PSin_p SHADERp\n"
"#define PSin_t SHADERt\n"
"\n"
"#endif\n"
"\n"
"layout(location = 0) out vec4 SV_Target0;\n"
"\n"
"#endif\n"

View File

@ -6,8 +6,6 @@ struct vertex_basic
vec2 t;
};
#if !pGL_ES && __VERSION__ > 140
in SHADER
{
vec4 p;
@ -17,20 +15,6 @@ in SHADER
#define PSin_p (PSin.p)
#define PSin_t (PSin.t)
#else
#ifdef DISABLE_SSO
in vec4 SHADERp;
in vec2 SHADERt;
#else
layout(location = 0) in vec4 SHADERp;
layout(location = 1) in vec2 SHADERt;
#endif
#define PSin_p SHADERp
#define PSin_t SHADERt
#endif
#ifdef FRAGMENT_SHADER
layout(location = 0) out vec4 SV_Target0;

View File

@ -6,8 +6,6 @@ struct vertex_basic
vec2 t;
};
#if !pGL_ES && __VERSION__ > 140
in SHADER
{
vec4 p;
@ -17,20 +15,6 @@ in SHADER
#define PSin_p (PSin.p)
#define PSin_t (PSin.t)
#else
#ifdef DISABLE_SSO
in vec4 SHADERp;
in vec2 SHADERt;
#else
layout(location = 0) in vec4 SHADERp;
layout(location = 1) in vec2 SHADERt;
#endif
#define PSin_p SHADERp
#define PSin_t SHADERt
#endif
#ifdef FRAGMENT_SHADER
layout(location = 0) out vec4 SV_Target0;

View File

@ -91,8 +91,6 @@ layout(binding = 0) uniform sampler2D TextureSampler;
#endif
#endif
#if !pGL_ES && __VERSION__ > 140
in SHADER
{
vec4 p;
@ -102,20 +100,6 @@ in SHADER
#define PSin_p (PSin.p)
#define PSin_t (PSin.t)
#else
#ifdef DISABLE_SSO
in vec4 SHADERp;
in vec2 SHADERt;
#else
layout(location = 0) in vec4 SHADERp;
layout(location = 1) in vec2 SHADERt;
#endif
#define PSin_p SHADERp
#define PSin_t SHADERt
#endif
layout(location = 0) out vec4 SV_Target0;
#endif

View File

@ -14,8 +14,6 @@ struct vertex_basic
#ifdef FRAGMENT_SHADER
#if !pGL_ES && __VERSION__ > 140
in SHADER
{
vec4 p;
@ -25,20 +23,6 @@ in SHADER
#define PSin_p (PSin.p)
#define PSin_t (PSin.t)
#else
#ifdef DISABLE_SSO
in vec4 SHADERp;
in vec2 SHADERt;
#else
layout(location = 0) in vec4 SHADERp;
layout(location = 1) in vec2 SHADERt;
#endif
#define PSin_p SHADERp
#define PSin_t SHADERt
#endif
layout(location = 0) out vec4 SV_Target0;
#ifdef DISABLE_GL42

View File

@ -56,8 +56,6 @@ layout(location = 4) in uint i_z;
layout(location = 5) in uvec2 i_uv;
layout(location = 6) in vec4 i_f;
#if !pGL_ES && __VERSION__ > 140
out SHADER
{
vec4 t;
@ -69,30 +67,13 @@ out SHADER
#define VSout_c (VSout.c)
#define VSout_fc (VSout.fc)
#else
#ifdef DISABLE_SSO
out vec4 SHADERt;
out vec4 SHADERc;
flat out vec4 SHADERfc;
#else
layout(location = 0) out vec4 SHADERt;
layout(location = 1) out vec4 SHADERc;
flat layout(location = 2) out vec4 SHADERfc;
#endif
#define VSout_t SHADERt
#define VSout_c SHADERc
#define VSout_fc SHADERfc
#endif
#if !pGL_ES && __VERSION__ > 140
out gl_PerVertex {
invariant vec4 gl_Position;
float gl_PointSize;
#if !pGL_ES
float gl_ClipDistance[];
};
#endif
};
#ifdef DISABLE_GL42
layout(std140) uniform cb20
@ -213,14 +194,18 @@ void vs_main()
in gl_PerVertex {
invariant vec4 gl_Position;
float gl_PointSize;
#if !pGL_ES
float gl_ClipDistance[];
#endif
} gl_in[];
//in int gl_PrimitiveIDIn;
out gl_PerVertex {
vec4 gl_Position;
float gl_PointSize;
#if !pGL_ES
float gl_ClipDistance[];
#endif
};
//out int gl_PrimitiveID;
@ -307,8 +292,6 @@ void gs_main()
#ifdef FRAGMENT_SHADER
#if !pGL_ES && __VERSION__ > 140
in SHADER
{
vec4 t;
@ -320,23 +303,6 @@ in SHADER
#define PSin_c (PSin.c)
#define PSin_fc (PSin.fc)
#else
#ifdef DISABLE_SSO
in vec4 SHADERt;
in vec4 SHADERc;
flat in vec4 SHADERfc;
#else
layout(location = 0) in vec4 SHADERt;
layout(location = 1) in vec4 SHADERc;
flat layout(location = 2) in vec4 SHADERfc;
#endif
#define PSin_t SHADERt
#define PSin_c SHADERc
#define PSin_fc SHADERfc
#endif
// Same buffer but 2 colors for dual source blending
#if pGL_ES
layout(location = 0) out vec4 SV_Target0;