]> git.tdb.fi Git - libs/gl.git/commitdiff
Improve compatibility checks of location qualifiers in various contexts
authorMikko Rasa <tdb@tdb.fi>
Sat, 3 Apr 2021 10:20:34 +0000 (13:20 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sat, 3 Apr 2021 16:40:26 +0000 (19:40 +0300)
extensions/arb_enhanced_layouts.glext [new file with mode: 0644]
extensions/arb_explicit_uniform_location.glext [new file with mode: 0644]
extensions/arb_separate_shader_objects.glext [new file with mode: 0644]
source/glsl/features.cpp
source/glsl/features.h
source/glsl/finalize.cpp
source/glsl/finalize.h
source/glsl/output.cpp

diff --git a/extensions/arb_enhanced_layouts.glext b/extensions/arb_enhanced_layouts.glext
new file mode 100644 (file)
index 0000000..8274244
--- /dev/null
@@ -0,0 +1 @@
+extension ARB_enhanced_layouts
diff --git a/extensions/arb_explicit_uniform_location.glext b/extensions/arb_explicit_uniform_location.glext
new file mode 100644 (file)
index 0000000..20b8685
--- /dev/null
@@ -0,0 +1 @@
+extension ARB_explicit_uniform_location
diff --git a/extensions/arb_separate_shader_objects.glext b/extensions/arb_separate_shader_objects.glext
new file mode 100644 (file)
index 0000000..af01a01
--- /dev/null
@@ -0,0 +1,3 @@
+extension ARB_separate_shader_objects
+# Also defined in ARB_geometry_shader4
+ignore glProgramParameteri
index dab230d339c517f2a4f4bd5a3ecf895b07c08c10..1c19c0b0fa73294298b5303c3bb7c2c41c0c3544 100644 (file)
@@ -1,5 +1,8 @@
+#include <msp/gl/extensions/arb_enhanced_layouts.h>
 #include <msp/gl/extensions/arb_explicit_attrib_location.h>
+#include <msp/gl/extensions/arb_explicit_uniform_location.h>
 #include <msp/gl/extensions/arb_gpu_shader5.h>
+#include <msp/gl/extensions/arb_separate_shader_objects.h>
 #include <msp/gl/extensions/arb_uniform_buffer_object.h>
 #include <msp/gl/extensions/ext_gpu_shader4.h>
 #include <msp/gl/extensions/ext_texture_array.h>
@@ -11,8 +14,11 @@ namespace SL {
 
 Features::Features():
        gl_api(OPENGL),
+       arb_enhanced_layouts(false),
        arb_explicit_attrib_location(false),
+       arb_explicit_uniform_location(false),
        arb_gpu_shader5(false),
+       arb_separate_shader_objects(false),
        arb_uniform_buffer_object(false),
        ext_gpu_shader4(false),
        ext_texture_array(false),
@@ -24,9 +30,11 @@ Features Features::from_context()
        Features features;
        features.gl_api = get_gl_api();
        features.glsl_version = get_glsl_version();
+       features.arb_enhanced_layouts = ARB_enhanced_layouts;
        features.arb_explicit_attrib_location = ARB_explicit_attrib_location;
+       features.arb_explicit_uniform_location = ARB_explicit_uniform_location;
        features.arb_gpu_shader5 = ARB_gpu_shader5;
-       //features.arb_texture_cube_map_array = ARB_texture_cube_map_array;
+       features.arb_separate_shader_objects = ARB_separate_shader_objects;
        features.arb_uniform_buffer_object = ARB_uniform_buffer_object;
        features.ext_gpu_shader4 = EXT_gpu_shader4;
        features.ext_texture_array = EXT_texture_array;
@@ -38,8 +46,11 @@ Features Features::all()
        Features features;
        features.gl_api = OPENGL;
        features.glsl_version = Version(4, 60);
+       features.arb_enhanced_layouts = true;
        features.arb_explicit_attrib_location = true;
+       features.arb_explicit_uniform_location = true;
        features.arb_gpu_shader5 = true;
+       features.arb_separate_shader_objects = true;
        features.arb_uniform_buffer_object = true;
        features.ext_gpu_shader4 = true;
        features.ext_texture_array = true;
index b65a61e2fc8c0690a2e380ca690755c09b47bcba..c18efe05088e9c53b8d89ad7e3e2266e705a6980 100644 (file)
@@ -11,8 +11,11 @@ struct Features
 {
        GLApi gl_api;
        Version glsl_version;
+       bool arb_enhanced_layouts;
        bool arb_explicit_attrib_location;
+       bool arb_explicit_uniform_location;
        bool arb_gpu_shader5;
+       bool arb_separate_shader_objects;
        bool arb_uniform_buffer_object;
        bool ext_gpu_shader4;
        bool ext_texture_array;
index 030cb432a4a0c835b2485773ffa8b92fb36b705d..0adb2960b1da3784a4554d9a97b447b12163481d 100644 (file)
@@ -234,6 +234,16 @@ bool LegacyConverter::supports_interface_layouts() const
                return false;
 }
 
+bool LegacyConverter::supports_stage_interface_layouts() const
+{
+       if(features.gl_api==OPENGL_ES2)
+               return check_version(Version(3, 10));
+       else if(check_version(Version(4, 10)))
+               return true;
+       else
+               return check_extension(&Features::arb_separate_shader_objects);
+}
+
 bool LegacyConverter::supports_centroid_sampling() const
 {
        if(features.gl_api==OPENGL_ES2)
@@ -254,25 +264,53 @@ bool LegacyConverter::supports_sample_sampling() const
                return check_extension(&Features::arb_gpu_shader5);
 }
 
+bool LegacyConverter::supports_uniform_location() const
+{
+       if(features.gl_api==OPENGL_ES2)
+               return check_version(Version(3, 10));
+       else if(check_version(Version(4, 30)))
+               return true;
+       else
+               return check_extension(&Features::arb_explicit_uniform_location);
+}
+
 void LegacyConverter::visit(VariableDeclaration &var)
 {
        if(var.layout)
        {
                for(vector<Layout::Qualifier>::const_iterator i=var.layout->qualifiers.begin(); i!=var.layout->qualifiers.end(); )
                {
-                       if(i->name=="location" && !supports_interface_layouts())
+                       if(i->name=="location")
                        {
-                               if(stage->type==Stage::VERTEX && var.interface=="in")
-                                       stage->locations[var.name] = i->value;
-                               else if(stage->type==Stage::FRAGMENT && var.interface=="out")
+                               bool supported = true;
+                               bool external = false;
+                               if(var.interface=="in")
                                {
-                                       if(check_extension(&Features::ext_gpu_shader4))
-                                               stage->locations[var.name] = i->value;
-                                       else if(i->value!=0)
-                                               unsupported("EXT_gpu_shader4 required for multiple fragment shader outputs");
+                                       external = (stage->type==Stage::VERTEX);
+                                       supported = (external ? supports_interface_layouts() : supports_stage_interface_layouts());
                                }
+                               else if(var.interface=="out")
+                               {
+                                       external = (stage->type==Stage::FRAGMENT);
+                                       supported = (external ? supports_interface_layouts() : supports_stage_interface_layouts());
+                                       if(external && !supported && !check_extension(&Features::ext_gpu_shader4))
+                                       {
+                                               external = false;
+                                               if(i->value!=0)
+                                                       unsupported("EXT_gpu_shader4 required for multiple fragment shader outputs");
+                                       }
+                               }
+                               else if(var.interface=="uniform")
+                                       supported = supports_uniform_location();
 
-                               i = var.layout->qualifiers.erase(i);
+                               if(!supported)
+                               {
+                                       if(external)
+                                               stage->locations[var.name] = i->value;
+                                       i = var.layout->qualifiers.erase(i);
+                               }
+                               else
+                                       ++i;
                        }
                        else
                                ++i;
@@ -322,8 +360,32 @@ bool LegacyConverter::supports_interface_blocks(const string &iface) const
                return false;
 }
 
+bool LegacyConverter::supports_interface_block_location() const
+{
+       if(features.gl_api==OPENGL_ES2)
+               return check_version(Version(3, 20));
+       else if(check_version(Version(4, 40)))
+               return true;
+       else
+               return check_extension(&Features::arb_enhanced_layouts);
+}
+
 void LegacyConverter::visit(InterfaceBlock &iface)
 {
+       if(iface.layout)
+       {
+               for(vector<Layout::Qualifier>::const_iterator i=iface.layout->qualifiers.begin(); i!=iface.layout->qualifiers.end(); )
+               {
+                       if(i->name=="location" && !supports_interface_block_location())
+                               i = iface.layout->qualifiers.erase(i);
+                       else
+                               ++i;
+               }
+
+               if(iface.layout->qualifiers.empty())
+                       iface.layout = 0;
+       }
+
        if(!supports_interface_blocks(iface.interface) && iface.type_declaration)
        {
                if(!iface.instance_name.empty())
index e0904b2e40eab2272accfd1cf4c8e6d4972ac4fd..357351b476bd071500847c5653e044025a82c082 100644 (file)
@@ -58,10 +58,13 @@ private:
        bool supports_unified_sampling_functions() const;
        virtual void visit(FunctionCall &);
        bool supports_interface_layouts() const;
+       bool supports_stage_interface_layouts() const;
        bool supports_centroid_sampling() const;
        bool supports_sample_sampling() const;
+       bool supports_uniform_location() const;
        virtual void visit(VariableDeclaration &);
        bool supports_interface_blocks(const std::string &) const;
+       bool supports_interface_block_location() const;
        virtual void visit(InterfaceBlock &);
 };
 
index b86cdd0a0ad4f75082d49146c05ae892e5684b16..1d82cae6a9ed95f20debbcf500a6a242c929c54a 100644 (file)
@@ -32,10 +32,16 @@ const string &Formatter::apply(Stage &s)
                formatted += '\n';
        }
 
+       if(s.required_features.arb_enhanced_layouts)
+               append("#extension GL_ARB_enhanced_layouts: require\n");
        if(s.required_features.arb_explicit_attrib_location)
                append("#extension GL_ARB_explicit_attrib_location: require\n");
+       if(s.required_features.arb_explicit_uniform_location)
+               append("#extension GL_ARB_explicit_uniform_location: require\n");
        if(s.required_features.arb_gpu_shader5)
                append("#extension GL_ARB_gpu_shader5: require\n");
+       if(s.required_features.arb_separate_shader_objects)
+               append("#extension GL_ARB_separate_shader_objects: require\n");
        if(s.required_features.arb_uniform_buffer_object)
                append("#extension GL_ARB_uniform_buffer_object: require\n");
        if(s.required_features.ext_gpu_shader4)