From 209fc09bcf2947ca60ddf15b8903d0c3194c7d5d Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 10 Oct 2021 15:37:07 +0300 Subject: [PATCH] Remove output variables which are not referenced --- 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 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; -- 2.43.0