From: Mikko Rasa Date: Sun, 10 Oct 2021 12:37:07 +0000 (+0300) Subject: Remove output variables which are not referenced X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=209fc09bcf2947ca60ddf15b8903d0c3194c7d5d;p=libs%2Fgl.git Remove output variables which are not referenced --- diff --git a/source/glsl/optimize.cpp b/source/glsl/optimize.cpp index a8ff44a5..1e974c9f 100644 --- a/source/glsl/optimize.cpp +++ b/source/glsl/optimize.cpp @@ -1260,15 +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); } - else if(!kvp.second.referenced) - unused_nodes.insert(kvp.first); } NodeRemover().apply(s, unused_nodes); @@ -1490,6 +1490,10 @@ void UnusedVariableRemover::visit(VariableDeclaration &var) graphics API. */ 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) { var_info.initialized = true;