]> git.tdb.fi Git - libs/gl.git/commitdiff
Save possible outer reference when entering subscript
authorMikko Rasa <tdb@tdb.fi>
Sat, 16 Oct 2021 13:49:44 +0000 (16:49 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sat, 16 Oct 2021 16:03:01 +0000 (19:03 +0300)
Otherwise it gets corrupted and the outer variable may be incorrectly
removed if nothing else refers to it.

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

index 1e974c9f01f8eee6d3eea5faabc00b20759ffd37..08d9259942a6a5b3d27566baf0902179221f2555 100644 (file)
@@ -1384,6 +1384,7 @@ void UnusedVariableRemover::visit(BinaryExpression &binary)
                {
                        SetFlag clear_assignment(assignment_target, false);
                        SetFlag clear_composite(composite_reference, false);
+                       SetForScope<Assignment::Target> clear_reference(r_reference, Assignment::Target());
                        binary.right->visit(*this);
                }
 
diff --git a/tests/glsl/nested_member_access.glsl b/tests/glsl/nested_member_access.glsl
new file mode 100644 (file)
index 0000000..60b3a49
--- /dev/null
@@ -0,0 +1,46 @@
+uniform Lighting
+{
+       vec3 light_color[4];
+};
+uniform Params
+{
+       int light_index;
+};
+
+#pragma MSP stage(vertex)
+layout(location=0) in vec4 position;
+void main()
+{
+       gl_Position = position;
+}
+
+#pragma MSP stage(fragment)
+layout(location=0) out vec4 frag_color;
+void main()
+{
+       frag_color = vec4(light_color[light_index], 1.0);
+}
+
+/* Expected output: vertex
+layout(location=0) in vec4 position;
+void main()
+{
+       gl_Position = position;
+}
+*/
+
+/* Expected output: fragment
+layout(binding=5) uniform Lighting
+{
+       vec3 light_color[4];
+};
+layout(binding=80) uniform Params
+{
+       int light_index;
+};
+layout(location=0) out vec4 frag_color;
+void main()
+{
+       frag_color = vec4(light_color[light_index], 1.0);
+}
+*/