]> git.tdb.fi Git - libs/gl.git/commitdiff
Add default packing qualifiers to uniform and buffer blocks
authorMikko Rasa <tdb@tdb.fi>
Fri, 29 Dec 2023 07:55:18 +0000 (09:55 +0200)
committerMikko Rasa <tdb@tdb.fi>
Fri, 29 Dec 2023 07:55:18 +0000 (09:55 +0200)
The GLSL spec says they use shared packing by default, and it turns out
that on AMD graphics processors this results in large alignment event
for primitive types.  This threw off applications using storage buffers
since their contents are not reflected.

source/glsl/generate.cpp
source/glsl/generate.h

index c203c21a9f641cdef2986dcfb75333f692bc508d..4fb2d7f325a54bbd1ccd87a305285e12061aba02 100644 (file)
@@ -394,9 +394,9 @@ void InterfaceGenerator::visit(Passthrough &pass)
 
 void LayoutDefaulter::apply(Stage &stage)
 {
+       stage.content.visit(*this);
        if(stage.type==Stage::TESS_EVAL)
        {
-               stage.content.visit(*this);
                if((need_winding || need_spacing) && in_iface)
                {
                        if(need_winding)
@@ -423,6 +423,22 @@ void LayoutDefaulter::visit(InterfaceLayout &iface)
        }
 }
 
+void LayoutDefaulter::visit(VariableDeclaration &var)
+{
+       if(var.block_declaration && (var.interface=="uniform" || var.interface=="buffer"))
+       {
+               bool has_packing = false;
+               if(var.layout)
+               {
+                       for(auto i = var.layout->qualifiers.begin(); (!has_packing && i!=var.layout->qualifiers.end()); ++i)
+                               has_packing = (i->name=="std140" || i->name=="std430" || i->name=="shared" || i->name=="packed");
+               }
+
+               if(!has_packing)
+                       add_layout_qualifier(var.layout, Layout::Qualifier(var.interface=="buffer" ? "std430" : "std140"));
+       }
+}
+
 
 void ArraySizer::apply(Stage &stage)
 {
index fac9bc6a34cb8b06f6b8e10b0ec5390547714f4f..c5274bc35a86b4b686c9a1f4a1f07670156263da 100644 (file)
@@ -79,8 +79,9 @@ private:
 };
 
 /**
-Adds default global input and output layout qualifiers for stages which need
-them (currently tessellation evaluation).
+Adds default layout qualifiers when they haven't been specified already.  This
+includes packing qualifiers for uniform and buffer blocks and global input and
+output qualifiers for certain stages (currently tessellation evaluation).
 */
 class LayoutDefaulter: private TraversingVisitor
 {
@@ -94,6 +95,7 @@ public:
 
 private:
        void visit(InterfaceLayout &) override;
+       void visit(VariableDeclaration &) override;
 };
 
 /**