From 0c07531f8ec779edde9ebe765b3cd79a6960b838 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Thu, 4 Mar 2021 01:56:26 +0200 Subject: [PATCH] Fix function inlining in iteration init statement Also reword the other related comment to be more accurate. --- source/glsl/optimize.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/source/glsl/optimize.cpp b/source/glsl/optimize.cpp index a999a654..0af24e3e 100644 --- a/source/glsl/optimize.cpp +++ b/source/glsl/optimize.cpp @@ -289,11 +289,15 @@ void FunctionInliner::visit(Conditional &cond) void FunctionInliner::visit(Iteration &iter) { - SetForScope 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 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); } -- 2.45.2