]> git.tdb.fi Git - libs/gl.git/commitdiff
Recognize matrix data order qualifiers and add one if missing
authorMikko Rasa <tdb@tdb.fi>
Mon, 5 Apr 2021 09:28:11 +0000 (12:28 +0300)
committerMikko Rasa <tdb@tdb.fi>
Mon, 5 Apr 2021 09:28:11 +0000 (12:28 +0300)
source/glsl/finalize.cpp
source/glsl/validate.cpp

index 6e9a478012e0dad898065da952868d8bf03eff46..94007b8fc3eda25f24b91deff5425549de70ce15 100644 (file)
@@ -27,17 +27,21 @@ void StructOrganizer::visit(VariableDeclaration &var)
        if(offset>=0)
        {
                int *layout_offset = 0;
+               bool has_matrix_order = false;
                if(var.layout)
                {
                        vector<Layout::Qualifier> &qualifiers = var.layout->qualifiers;
                        for(vector<Layout::Qualifier>::iterator i=qualifiers.begin(); i!=qualifiers.end(); ++i)
+                       {
                                if(i->name=="offset" && i->has_value)
                                {
                                        layout_offset = &i->value;
                                        if(i->value>=offset)
                                                offset = i->value;
-                                       break;
                                }
+                               else if(i->name=="column_major" || i->name=="row_major")
+                                       has_matrix_order = true;
+                       }
                }
 
                MemoryRequirementsCalculator::Result mem_reqs = MemoryRequirementsCalculator().apply(var);
@@ -58,6 +62,19 @@ void StructOrganizer::visit(VariableDeclaration &var)
                        var.layout->qualifiers.push_back(qual);
                }
 
+               if(!has_matrix_order)
+               {
+                       const BasicTypeDeclaration *basic = dynamic_cast<const BasicTypeDeclaration *>(var.type_declaration);
+                       while(basic && basic->kind==BasicTypeDeclaration::ARRAY)
+                               basic = dynamic_cast<const BasicTypeDeclaration *>(basic->base_type);
+                       if(basic && basic->kind==BasicTypeDeclaration::MATRIX)
+                       {
+                               Layout::Qualifier qual;
+                               qual.name = "column_major";
+                               var.layout->qualifiers.push_back(qual);
+                       }
+               }
+
                offset += mem_reqs.size;
        }
 }
index d154388f98cd9eed44aa8d16c00e1e70d09f801c..b313354dc9c54d56688fe7d7b32b24f8328bcbfc 100644 (file)
@@ -141,6 +141,18 @@ void DeclarationValidator::visit(Layout &layout)
                        allowed = (iface_block && !variable && iface_block->interface=="uniform");
                        value = false;
                }
+               else if(i->name=="column_major" || i->name=="row_major")
+               {
+                       allowed = (variable && scope==INTERFACE_BLOCK);
+                       if(allowed)
+                       {
+                               BasicTypeDeclaration *basic = dynamic_cast<BasicTypeDeclaration *>(variable->type_declaration);
+                               while(basic && basic->kind==BasicTypeDeclaration::ARRAY)
+                                       basic = dynamic_cast<BasicTypeDeclaration *>(basic->base_type);
+                               allowed = (basic && basic->kind==BasicTypeDeclaration::MATRIX);
+                               err_descr = "non-matrix variable";
+                       }
+               }
 
                if(!allowed)
                {