]> git.tdb.fi Git - libs/gl.git/commitdiff
Only generate or link interfaces in the correct scope
authorMikko Rasa <tdb@tdb.fi>
Thu, 25 Feb 2021 19:15:08 +0000 (21:15 +0200)
committerMikko Rasa <tdb@tdb.fi>
Thu, 25 Feb 2021 19:15:08 +0000 (21:15 +0200)
source/glsl/generate.cpp
source/glsl/generate.h

index 48de1efc5992a4796411e5cadaf6618903c363e3..3ff04eb9890124f7098c015dafe1099d77d7d34e 100644 (file)
@@ -258,7 +258,8 @@ void FunctionResolver::visit(FunctionDeclaration &func)
 
 
 InterfaceGenerator::InterfaceGenerator():
-       stage(0)
+       stage(0),
+       function_scope(false)
 { }
 
 string InterfaceGenerator::get_out_prefix(Stage::Type type)
@@ -369,7 +370,9 @@ void InterfaceGenerator::visit(VariableDeclaration &var)
 {
        if(var.interface=="out")
        {
-               if(current_block!=&stage->content && generate_interface(var, "out", change_prefix(var.name, string())))
+               /* For out variables in function scope, generate a global interface and
+               replace the local declaration with an assignment. */
+               if(function_scope && generate_interface(var, "out", var.name))
                {
                        nodes_to_remove.insert(&var);
                        if(var.init_expression)
@@ -383,7 +386,9 @@ void InterfaceGenerator::visit(VariableDeclaration &var)
        }
        else if(var.interface=="in")
        {
-               if(!var.linked_declaration && stage->previous)
+               /* Try to link in variables in global scope with out variables from
+               previous stage */
+               if(current_block==&stage->content && !var.linked_declaration && stage->previous)
                {
                        const map<string, VariableDeclaration *> &prev_vars = stage->previous->content.variables;
                        map<string, VariableDeclaration *>::const_iterator i = prev_vars.find(var.name);
@@ -400,6 +405,7 @@ void InterfaceGenerator::visit(VariableDeclaration &var)
 
 void InterfaceGenerator::visit(FunctionDeclaration &func)
 {
+       SetFlag set_scope(function_scope, true);
        // Skip parameters because they're not useful here
        func.body.visit(*this);
 }
index f904021ad726fcf544f469c0787311bd056c9aea..72035b2c4869504199edda4df59e46958b41fed1 100644 (file)
@@ -84,6 +84,7 @@ private:
        Stage *stage;
        std::string in_prefix;
        std::string out_prefix;
+       bool function_scope;
        NodeList<Statement>::iterator iface_insert_point;
        NodeList<Statement>::iterator assignment_insert_point;
        std::set<Node *> nodes_to_remove;