X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fglsl%2Foptimize.cpp;h=ea0f96f0e60920cba9dd23523e83c37a07133ffb;hb=0d5ff7918d50092d8cf2e1b8f7af1d7d29b6eb9b;hp=c9d3c33a543830f3618a6d2e337d92519026de6c;hpb=31f76e306f8e01884fa464ac6e09e8b48af5f79b;p=libs%2Fgl.git diff --git a/source/glsl/optimize.cpp b/source/glsl/optimize.cpp index c9d3c33a..ea0f96f0 100644 --- a/source/glsl/optimize.cpp +++ b/source/glsl/optimize.cpp @@ -114,9 +114,13 @@ string InlineContentInjector::apply(Stage &stage, FunctionDeclaration &target_fu source_func = call.declaration->definition; /* Populate referenced_names from the target function so we can rename - variables from the inlined function that would conflict. */ + variables from the inlined function that would conflict. Only consider + names which declared in blocks linearly related to the target block. */ pass = REFERENCED; - target_func.visit(*this); + tgt_blk.visit(*this); + for(const Block *b=&tgt_blk; b; b=b->parent) + for(const auto &kvp: b->variables) + referenced_names.insert(kvp.first); /* Inline and rename passes must be interleaved so used variable names are known when inlining the return statement. */ @@ -402,7 +406,7 @@ void ExpressionInliner::visit(Swizzle &swizzle) void ExpressionInliner::visit(UnaryExpression &unary) { - SetFlag set_write(access_write, access_write || unary.oper->token[1]=='+' || unary.oper->token[1]=='-'); + SetFlag set_write(access_write, (unary.oper->token[1]=='+' || unary.oper->token[1]=='-')); visit(unary.expression); r_trivial = false; } @@ -1053,10 +1057,11 @@ void ConstantFolder::visit(Iteration &iter) } -void ConstantConditionEliminator::apply(Stage &stage) +bool ConstantConditionEliminator::apply(Stage &stage) { stage.content.visit(*this); NodeRemover().apply(stage, nodes_to_remove); + return !nodes_to_remove.empty(); } ConstantConditionEliminator::ConstantStatus ConstantConditionEliminator::check_constant_condition(const Expression &expr)