]> git.tdb.fi Git - libs/gl.git/commitdiff
Allow a push constant block to be specified, but flatten it for now
authorMikko Rasa <tdb@tdb.fi>
Mon, 8 Nov 2021 16:17:51 +0000 (18:17 +0200)
committerMikko Rasa <tdb@tdb.fi>
Mon, 8 Nov 2021 16:18:45 +0000 (18:18 +0200)
It's needed for Vulkan, but OpenGL does not have push constants.

source/glsl/finalize.cpp
source/glsl/validate.cpp

index f005d87dcbf82749e33eb1ba8c55fdbece642b76..2fff7549cab5b3c150feb3f7c223d314da324999 100644 (file)
@@ -221,15 +221,25 @@ void LocationAllocator::visit(InterfaceBlock &iface)
 
        if(iface.interface=="uniform")
        {
-               int bind_point = (iface.layout ? get_layout_value(*iface.layout, "binding") : -1);
+               bool push_constant = false;
+               if(iface.layout)
+               {
+                       auto i = find_member(iface.layout->qualifiers, string("push_constant"), &Layout::Qualifier::name);
+                       push_constant = (i!=iface.layout->qualifiers.end());
+               }
 
-               if(bind_point>=0)
+               if(!push_constant)
                {
-                       used_bindings[0].insert(bind_point);
-                       uniforms[iface.block_name].bind_point = bind_point;
+                       int bind_point = (iface.layout ? get_layout_value(*iface.layout, "binding") : -1);
+
+                       if(bind_point>=0)
+                       {
+                               used_bindings[0].insert(bind_point);
+                               uniforms[iface.block_name].bind_point = bind_point;
+                       }
+                       else
+                               unbound_blocks.push_back(&iface);
                }
-               else
-                       unbound_blocks.push_back(&iface);
        }
 }
 
@@ -636,6 +646,7 @@ bool LegacyConverter::supports_interface_block_location() const
 
 void LegacyConverter::visit(InterfaceBlock &iface)
 {
+       bool push_constant = false;
        if(iface.layout)
        {
                for(auto i=iface.layout->qualifiers.begin(); i!=iface.layout->qualifiers.end(); )
@@ -648,14 +659,18 @@ void LegacyConverter::visit(InterfaceBlock &iface)
                                i = iface.layout->qualifiers.erase(i);
                        }
                        else
+                       {
+                               if(i->name=="push_constant")
+                                       push_constant = true;
                                ++i;
+                       }
                }
 
                if(iface.layout->qualifiers.empty())
                        iface.layout = 0;
        }
 
-       if(!supports_interface_blocks(iface.interface) && iface.type_declaration)
+       if((!supports_interface_blocks(iface.interface) || push_constant) && iface.type_declaration)
        {
                if(!iface.instance_name.empty())
                        unsupported("ARB_uniform_buffer_object required for interface block instances");
index f12177db4a4236109f4060ffc72c13098f66093f..2da8345de4a7002e0020d98fe536443c72b8cba6 100644 (file)
@@ -49,6 +49,8 @@ const char *DeclarationValidator::describe_variable(ScopeType scope)
 
 void DeclarationValidator::visit(Layout &layout)
 {
+       bool push_constant = false;
+       bool binding = false;
        for(const Layout::Qualifier &q: layout.qualifiers)
        {
                bool allowed = false;
@@ -58,6 +60,8 @@ void DeclarationValidator::visit(Layout &layout)
                        allowed = (variable && scope==GLOBAL);
                else if(q.name=="binding" || q.name=="set")
                {
+                       binding = true;
+
                        if(q.name=="set")
                        {
                                error(layout, "Layout qualifier 'set' not allowed when targeting OpenGL");
@@ -141,6 +145,12 @@ void DeclarationValidator::visit(Layout &layout)
                                err_descr = "non-matrix variable";
                        }
                }
+               else if(q.name=="push_constant")
+               {
+                       push_constant = true;
+                       allowed = (iface_block && !variable && iface_block->interface=="uniform");
+                       value = false;
+               }
 
                if(!allowed)
                {
@@ -162,6 +172,9 @@ void DeclarationValidator::visit(Layout &layout)
                else if(!value && q.has_value)
                        error(layout, format("Layout qualifier '%s' does not allow a value", q.name));
        }
+
+       if(push_constant && binding)
+               error(layout, "Layout qualifier 'push_constant' not allowed together with 'binding' or 'set'");
 }
 
 void DeclarationValidator::visit(InterfaceLayout &layout)