]> git.tdb.fi Git - libs/gl.git/commitdiff
Don't modify the target block's variable map from InlineContentInjector
authorMikko Rasa <tdb@tdb.fi>
Tue, 16 Mar 2021 09:38:55 +0000 (11:38 +0200)
committerMikko Rasa <tdb@tdb.fi>
Tue, 16 Mar 2021 09:54:12 +0000 (11:54 +0200)
This felt hacky, and also seemed wrong since the variable map contains
the original names of the variables, not new ones.  Instead avoid
inlining more than one function per pass into any given function.

source/glsl/optimize.cpp
source/glsl/optimize.h

index 7473fe2ca598ad996ee6c3263385f938986e80e2..6c49878b857603152d742383ab4fd1f611e6c1ac 100644 (file)
@@ -90,9 +90,6 @@ const string &InlineContentInjector::apply(Stage &stage, FunctionDeclaration &ta
                inlined.push_back(r_inlined_statement);
        }
 
-       // Insert the variables here to enable further inlinings to avoid conflicts.
-       tgt_blk.variables.insert(variable_map.begin(), variable_map.end());
-
        SetForScope<unsigned> set_remap(remap_names, 1);
        SetForScope<string> set_prefix(remap_prefix, target_func.name);
        variable_map.clear();
@@ -190,7 +187,8 @@ void InlineContentInjector::visit(Return &ret)
 
 FunctionInliner::FunctionInliner():
        current_function(0),
-       r_any_inlined(false)
+       r_any_inlined(false),
+       r_inlined_here(false)
 { }
 
 bool FunctionInliner::apply(Stage &s)
@@ -218,7 +216,7 @@ void FunctionInliner::visit(Block &block)
 {
        SetForScope<Block *> set_block(current_block, &block);
        SetForScope<NodeList<Statement>::iterator> save_insert_point(insert_point, block.body.begin());
-       for(NodeList<Statement>::iterator i=block.body.begin(); i!=block.body.end(); ++i)
+       for(NodeList<Statement>::iterator i=block.body.begin(); (!r_inlined_here && i!=block.body.end()); ++i)
        {
                insert_point = i;
                (*i)->visit(*this);
@@ -227,6 +225,9 @@ void FunctionInliner::visit(Block &block)
 
 void FunctionInliner::visit(FunctionCall &call)
 {
+       if(r_inlined_here)
+               return;
+
        for(NodeArray<Expression>::iterator i=call.arguments.begin(); i!=call.arguments.end(); ++i)
                visit(*i);
 
@@ -249,6 +250,7 @@ void FunctionInliner::visit(FunctionCall &call)
                /* Inlined variables need to be resolved before this function can be
                inlined further. */
                inlineable.erase(current_function);
+               r_inlined_here = true;
        }
 }
 
@@ -256,6 +258,7 @@ void FunctionInliner::visit(FunctionDeclaration &func)
 {
        SetForScope<FunctionDeclaration *> set_func(current_function, &func);
        TraversingVisitor::visit(func);
+       r_inlined_here = false;
 }
 
 void FunctionInliner::visit(Iteration &iter)
index 160388065b8fab22d492e3193f8eed9702f76acb..5091b008634b3d887df606844b326ccc3b353237 100644 (file)
@@ -75,6 +75,7 @@ private:
        NodeList<Statement>::iterator insert_point;
        RefPtr<Expression> r_inline_result;
        bool r_any_inlined;
+       bool r_inlined_here;
 
 public:
        FunctionInliner();