]> git.tdb.fi Git - libs/gl.git/commitdiff
Recognize unknown index as matching any index
authorMikko Rasa <tdb@tdb.fi>
Sat, 9 Oct 2021 16:46:27 +0000 (19:46 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sat, 9 Oct 2021 17:14:48 +0000 (20:14 +0300)
If an array is accessed with an unknown index, all assignments to the
array must be kept.

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

index 350e2eb746537be79ea9d9c1854f45a6b860b53a..768cfd5dc761659f504011780e3e0cbc74f90c0d 100644 (file)
@@ -1242,10 +1242,10 @@ void UnusedVariableRemover::referenced(const Assignment::Target &target, Node &n
                        {
                                Assignment::Target::ChainType type1 = static_cast<Assignment::Target::ChainType>(a->target.chain[j]&0xC0);
                                Assignment::Target::ChainType type2 = static_cast<Assignment::Target::ChainType>(target.chain[j]&0xC0);
+                               unsigned index1 = a->target.chain[j]&0x3F;
+                               unsigned index2 = target.chain[j]&0x3F;
                                if(type1==Assignment::Target::SWIZZLE || type2==Assignment::Target::SWIZZLE)
                                {
-                                       unsigned index1 = a->target.chain[j]&0x3F;
-                                       unsigned index2 = target.chain[j]&0x3F;
                                        if(type1==Assignment::Target::SWIZZLE && type2==Assignment::Target::SWIZZLE)
                                                covered = index1&index2;
                                        else if(type1==Assignment::Target::ARRAY && index1<4)
@@ -1256,7 +1256,7 @@ void UnusedVariableRemover::referenced(const Assignment::Target &target, Node &n
                                        covered as true */
                                }
                                else
-                                       covered = (a->target.chain[j]==target.chain[j]);
+                                       covered = (type1==type2 && (index1==index2 || index1==0x3F || index2==0x3F));
                        }
 
                        if(covered)
diff --git a/tests/glsl/array_element_assignment.glsl b/tests/glsl/array_element_assignment.glsl
new file mode 100644 (file)
index 0000000..eb98ddc
--- /dev/null
@@ -0,0 +1,26 @@
+#pragma MSP stage(vertex)
+void main()
+{
+       float a[3];
+       a[0] = 0.0;
+       a[1] = 1.0;
+       a[2] = 2.0;
+       float s = 0.0;
+       for(int i=0; i<3; ++i)
+               s += a[i];
+       gl_Position = vec4(s);
+}
+
+/* Expected output: vertex
+void main()
+{
+       float a[3];
+       a[0] = 0.0;
+       a[1] = 1.0;
+       a[2] = 2.0;
+       float s = 0.0;
+       for(int i = 0; i<3; ++i)
+               s += a[i];
+       gl_Position = vec4(s);
+}
+*/