]> git.tdb.fi Git - libs/gl.git/commitdiff
Fix flattening of GLSL interface blocks
authorMikko Rasa <tdb@tdb.fi>
Mon, 8 Nov 2021 16:15:39 +0000 (18:15 +0200)
committerMikko Rasa <tdb@tdb.fi>
Mon, 8 Nov 2021 16:15:39 +0000 (18:15 +0200)
Anonymous interface blocks are treated as nameless variables since
dfcf8eb, so the member accesses need to be converted to plain variable
references when the block is flattened.

source/glsl/finalize.cpp
source/glsl/finalize.h

index 27c352098e0c0b0206616336f431e2c84de1942d..f005d87dcbf82749e33eb1ba8c55fdbece642b76 100644 (file)
@@ -336,6 +336,15 @@ void LegacyConverter::visit(Block &block)
        }
 }
 
+void LegacyConverter::visit(RefPtr<Expression> &expr)
+{
+       r_replaced_reference = 0;
+       expr->visit(*this);
+       if(r_replaced_reference)
+               expr = r_replaced_reference;
+       r_replaced_reference = 0;
+}
+
 bool LegacyConverter::check_version(const Version &feature_version) const
 {
        if(features.glsl_version<feature_version)
@@ -386,6 +395,23 @@ void LegacyConverter::visit(VariableReference &var)
        }
 }
 
+void LegacyConverter::visit(InterfaceBlockReference &iface)
+{
+       r_flattened_interface = nodes_to_remove.count(iface.declaration);
+}
+
+void LegacyConverter::visit(MemberAccess &memacc)
+{
+       r_flattened_interface = false;
+       visit(memacc.left);
+       if(r_flattened_interface)
+       {
+               VariableReference *var = new VariableReference;
+               var->name = memacc.member;
+               r_replaced_reference = var;
+       }
+}
+
 void LegacyConverter::visit(Assignment &assign)
 {
        TraversingVisitor::visit(assign);
@@ -635,6 +661,9 @@ void LegacyConverter::visit(InterfaceBlock &iface)
                        unsupported("ARB_uniform_buffer_object required for interface block instances");
                else if(iface.struct_declaration)
                {
+                       for(const RefPtr<Statement> &s: iface.struct_declaration->members.body)
+                               if(VariableDeclaration *var = dynamic_cast<VariableDeclaration *>(s.get()))
+                                       var->interface = iface.interface;
                        stage->content.body.splice(uniform_insert_point, iface.struct_declaration->members.body);
                        nodes_to_remove.insert(&iface);
                        nodes_to_remove.insert(iface.struct_declaration);
index 1fe5fa45a494b02988c90f37068ee4c34e760ca1..4f6ee4193bd869ba61ace5191cc1cd9382b14b4e 100644 (file)
@@ -86,6 +86,8 @@ private:
        VariableDeclaration *frag_out = 0;
        NodeList<Statement>::iterator uniform_insert_point;
        std::set<Node *> nodes_to_remove;
+       RefPtr<Expression> r_replaced_reference;
+       bool r_flattened_interface = false;
 
 public:
        virtual void apply(Stage &, const Features &);
@@ -94,11 +96,14 @@ private:
        void unsupported(const std::string &);
 
        virtual void visit(Block &);
+       virtual void visit(RefPtr<Expression> &);
        bool check_version(const Version &) const;
        bool check_extension(bool Features::*) const;
        bool supports_stage(Stage::Type) const;
        bool supports_unified_interface_syntax() const;
        virtual void visit(VariableReference &);
+       virtual void visit(InterfaceBlockReference &);
+       virtual void visit(MemberAccess &);
        virtual void visit(Assignment &);
        bool supports_unified_sampling_functions() const;
        virtual void visit(FunctionCall &);