]> git.tdb.fi Git - libs/gl.git/blobdiff - source/glsl/resolve.cpp
Use extended alignment in SPIR-V struct layout when necessary
[libs/gl.git] / source / glsl / resolve.cpp
index 406d7780e810181ffc8650e9c0ba8c20466d67aa..2f3192d77fa423a2f8fa3fb6587d283eec9da5a0 100644 (file)
@@ -28,7 +28,9 @@ bool TypeResolver::apply(Stage &s)
 
 TypeDeclaration *TypeResolver::get_or_create_array_type(TypeDeclaration &type)
 {
-       auto i = array_types.find(&type);
+       bool extended_alignment = iface_block;
+       auto key = make_pair(&type, extended_alignment);
+       auto i = array_types.find(key);
        if(i!=array_types.end())
                return i->second;
 
@@ -36,10 +38,11 @@ TypeDeclaration *TypeResolver::get_or_create_array_type(TypeDeclaration &type)
        array->source = INTERNAL_SOURCE;
        array->name = type.name+"[]";
        array->kind = BasicTypeDeclaration::ARRAY;
+       array->extended_alignment = extended_alignment;
        array->base = type.name;
        array->base_type = &type;
        stage->content.body.insert(type_insert_point, array);
-       array_types[&type] = array;
+       array_types[key] = array;
        return array;
 }
 
@@ -88,7 +91,7 @@ void TypeResolver::visit(BasicTypeDeclaration &type)
        if(type.kind==BasicTypeDeclaration::ALIAS && type.base_type)
                alias_map[&type] = type.base_type;
        else if(type.kind==BasicTypeDeclaration::ARRAY && type.base_type)
-               array_types[type.base_type] = &type;
+               array_types[make_pair(type.base_type, type.extended_alignment)] = &type;
 
        stage->types.insert(make_pair(type.name, &type));
 }
@@ -102,14 +105,20 @@ void TypeResolver::visit(ImageTypeDeclaration &type)
 void TypeResolver::visit(StructDeclaration &strct)
 {
        stage->types.insert(make_pair(strct.name, &strct));
+       SetForScope<InterfaceBlock *> set_iface(iface_block, strct.interface_block);
        TraversingVisitor::visit(strct);
 }
 
 void TypeResolver::visit(VariableDeclaration &var)
 {
        resolve_type(var.type_declaration, var.type, var.array);
-       if(iface_block && var.interface==iface_block->interface)
-               var.interface.clear();
+       if(iface_block)
+       {
+               if(var.interface==iface_block->interface)
+                       var.interface.clear();
+               if(StructDeclaration *strct = dynamic_cast<StructDeclaration *>(var.type_declaration))
+                       strct->extended_alignment = true;
+       }
 }
 
 void TypeResolver::visit(InterfaceBlock &iface)
@@ -123,6 +132,7 @@ void TypeResolver::visit(InterfaceBlock &iface)
                strct->source = INTERNAL_SOURCE;
                strct->name = format("_%s_%s", iface.interface, iface.block_name);
                strct->members.body.splice(strct->members.body.begin(), iface.members->body);
+               strct->extended_alignment = true;
                stage->content.body.insert(type_insert_point, strct);
                stage->types.insert(make_pair(strct->name, strct));