]> git.tdb.fi Git - libs/gl.git/blobdiff - source/glsl/optimize.cpp
Only set assign_to_subfield when in assignment target
[libs/gl.git] / source / glsl / optimize.cpp
index a999a654db84ac8ac072ef7fb817d5107643a584..137bd94343190f275eebbaa877dfa554b4785a50 100644 (file)
@@ -289,11 +289,15 @@ void FunctionInliner::visit(Conditional &cond)
 
 void FunctionInliner::visit(Iteration &iter)
 {
-       SetForScope<Block *> set_block(current_block, &iter.body);
+       /* Visit the initialization statement before entering the loop body so the
+       inlined statements get inserted outside. */
        if(iter.init_statement)
                iter.init_statement->visit(*this);
-       /* Skip the condition and loop expression parts because they're executed on
-       every iteration of the loop */
+
+       SetForScope<Block *> set_block(current_block, &iter.body);
+       /* Skip the condition and loop expression parts because they're not properly
+       inside the body block.  Inlining anything into them will require a more
+       comprehensive transformation. */
        iter.body.visit(*this);
 }
 
@@ -674,7 +678,8 @@ void UnusedVariableRemover::visit(InterfaceBlockReference &iface)
 
 void UnusedVariableRemover::visit(MemberAccess &memacc)
 {
-       r_assign_to_subfield = true;
+       if(assignment_target)
+               r_assign_to_subfield = true;
        TraversingVisitor::visit(memacc);
        unused_nodes.erase(memacc.declaration);
 }