From: Mikko Rasa Date: Mon, 5 Apr 2021 09:28:11 +0000 (+0300) Subject: Recognize matrix data order qualifiers and add one if missing X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=180698dbb41d312128c496721f1207c6688fe350;p=libs%2Fgl.git Recognize matrix data order qualifiers and add one if missing --- diff --git a/source/glsl/finalize.cpp b/source/glsl/finalize.cpp index 6e9a4780..94007b8f 100644 --- a/source/glsl/finalize.cpp +++ b/source/glsl/finalize.cpp @@ -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 &qualifiers = var.layout->qualifiers; for(vector::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(var.type_declaration); + while(basic && basic->kind==BasicTypeDeclaration::ARRAY) + basic = dynamic_cast(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; } } diff --git a/source/glsl/validate.cpp b/source/glsl/validate.cpp index d154388f..b313354d 100644 --- a/source/glsl/validate.cpp +++ b/source/glsl/validate.cpp @@ -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(variable->type_declaration); + while(basic && basic->kind==BasicTypeDeclaration::ARRAY) + basic = dynamic_cast(basic->base_type); + allowed = (basic && basic->kind==BasicTypeDeclaration::MATRIX); + err_descr = "non-matrix variable"; + } + } if(!allowed) {