X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fglsl%2Foptimize.cpp;h=3cb10e862458903a0d07c2da1eec7465e3299ac5;hb=95312044b7b474af5671eb67f9df8debf96bf54c;hp=42e4a86ec7feb3466f7e0a119b4bf1a4feb28916;hpb=49e89e55692ecdbccd98b93578d29f89669a9fc0;p=libs%2Fgl.git diff --git a/source/glsl/optimize.cpp b/source/glsl/optimize.cpp index 42e4a86e..3cb10e86 100644 --- a/source/glsl/optimize.cpp +++ b/source/glsl/optimize.cpp @@ -717,6 +717,11 @@ void AggregateDismantler::visit(VariableDeclaration &var) } } +void AggregateDismantler::visit(FunctionDeclaration &func) +{ + func.body.visit(*this); +} + template T ConstantFolder::evaluate_logical(char oper, T left, T right) @@ -1255,23 +1260,15 @@ bool UnusedVariableRemover::apply(Stage &s) for(const auto &kvp: variables) { - if(kvp.second.output) + if(!kvp.second.referenced) + unused_nodes.insert(kvp.first); + else if(kvp.second.output) { /* The last visible assignments of output variables are used by the next stage or the API. */ for(AssignmentInfo *a: kvp.second.assignments) unused_nodes.erase(a->node); } - - if(!kvp.second.output && !kvp.second.referenced) - { - // Don't remove variables from inside interface blocks. - if(!kvp.second.interface_block) - unused_nodes.insert(kvp.first); - } - else if(kvp.second.interface_block) - // Interface blocks are kept if even one member is used. - unused_nodes.erase(kvp.second.interface_block); } NodeRemover().apply(s, unused_nodes); @@ -1327,7 +1324,7 @@ void UnusedVariableRemover::visit(VariableReference &var) { if(composite_reference) r_reference.declaration = var.declaration; - else + else if(var.declaration) referenced(var.declaration, var); } @@ -1335,7 +1332,7 @@ void UnusedVariableRemover::visit(InterfaceBlockReference &iface) { if(composite_reference) r_reference.declaration = iface.declaration; - else + else if(iface.declaration) referenced(iface.declaration, iface); } @@ -1387,6 +1384,7 @@ void UnusedVariableRemover::visit(BinaryExpression &binary) { SetFlag clear_assignment(assignment_target, false); SetFlag clear_composite(composite_reference, false); + SetForScope clear_reference(r_reference, Assignment::Target()); binary.right->visit(*this); } @@ -1488,14 +1486,14 @@ void UnusedVariableRemover::visit(VariableDeclaration &var) return; VariableInfo &var_info = variables[&var]; - var_info.interface_block = interface_block; /* Mark variables as output if they're used by the next stage or the graphics API. */ - if(interface_block) - var_info.output = (interface_block->interface=="out" && (interface_block->linked_block || !interface_block->block_name.compare(0, 3, "gl_"))); - else - var_info.output = (var.interface=="out" && (stage->type==Stage::FRAGMENT || var.linked_declaration || !var.name.compare(0, 3, "gl_"))); + var_info.output = (var.interface=="out" && (stage->type==Stage::FRAGMENT || var.linked_declaration || !var.name.compare(0, 3, "gl_"))); + + // Linked outputs are automatically referenced. + if(var_info.output && var.linked_declaration) + var_info.referenced = true; if(var.init_expression) {