]> git.tdb.fi Git - libs/gl.git/commitdiff
Avoid removing outputs which are referenced but not assigned
authorMikko Rasa <tdb@tdb.fi>
Tue, 9 Mar 2021 20:27:04 +0000 (22:27 +0200)
committerMikko Rasa <tdb@tdb.fi>
Tue, 9 Mar 2021 20:29:11 +0000 (22:29 +0200)
The values from such reads are undefined but the variables should be
kept nevertheless.

source/glsl/optimize.cpp
tests/glsl/referenced_but_unassigned_output.glsl [new file with mode: 0644]

index 7f60e67cc9c4ff58bfd46d452d407106b30d2315..500c841793315aa1f1decb29b611c824291b003f 100644 (file)
@@ -661,7 +661,7 @@ bool UnusedVariableRemover::apply(Stage &s)
                }
                if(output)
                {
-                       if(!i->second.assignments.empty() && i->second.interface_block)
+                       if((i->second.referenced || !i->second.assignments.empty()) && i->second.interface_block)
                                used_interface_blocks.insert(i->second.interface_block);
                        continue;
                }
diff --git a/tests/glsl/referenced_but_unassigned_output.glsl b/tests/glsl/referenced_but_unassigned_output.glsl
new file mode 100644 (file)
index 0000000..aabff08
--- /dev/null
@@ -0,0 +1,50 @@
+uniform mat4 projection;
+
+#pragma MSP stage(vertex)
+layout(location=0) in vec4 position;
+layout(location=1) in vec3 normal;
+out vec4 eye_vertex;
+out VertexOut
+{
+       vec4 color;
+};
+void main()
+{
+       gl_Position = projection*eye_vertex;
+       out float alpha = color.a;
+}
+
+#pragma MSP stage(fragment)
+layout(location=0) out vec4 frag_color;
+void main()
+{
+       frag_color = vec4(color.rgb, alpha);
+}
+
+/* Expected output: vertex
+uniform mat4 projection;
+out vec4 eye_vertex;
+out VertexOut
+{
+  vec4 color;
+};
+out float alpha;
+void main()
+{
+  gl_Position = projection*eye_vertex;
+  alpha = color.a;
+}
+*/
+
+/* Expected output: fragment
+layout(location=0) out vec4 frag_color;
+in VertexOut
+{
+  vec4 color;
+};
+in float alpha;
+void main()
+{
+  frag_color = vec4(color.rgb, alpha);
+}
+*/