]> git.tdb.fi Git - libs/gl.git/commitdiff
Remove output variables which are not referenced
authorMikko Rasa <tdb@tdb.fi>
Sun, 10 Oct 2021 12:37:07 +0000 (15:37 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 10 Oct 2021 15:35:27 +0000 (18:35 +0300)
source/glsl/optimize.cpp

index a8ff44a50e44fa94b8eb3d799f3ec1d64eb22988..1e974c9f01f8eee6d3eea5faabc00b20759ffd37 100644 (file)
@@ -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;