From: Mikko Rasa Date: Sat, 9 Oct 2021 16:46:27 +0000 (+0300) Subject: Recognize unknown index as matching any index X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=e2ed3de4cbbc682ff490a3b0b760b8a45260f611;p=libs%2Fgl.git Recognize unknown index as matching any index If an array is accessed with an unknown index, all assignments to the array must be kept. --- diff --git a/source/glsl/optimize.cpp b/source/glsl/optimize.cpp index 350e2eb7..768cfd5d 100644 --- a/source/glsl/optimize.cpp +++ b/source/glsl/optimize.cpp @@ -1242,10 +1242,10 @@ void UnusedVariableRemover::referenced(const Assignment::Target &target, Node &n { Assignment::Target::ChainType type1 = static_cast(a->target.chain[j]&0xC0); Assignment::Target::ChainType type2 = static_cast(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 index 00000000..eb98ddc4 --- /dev/null +++ b/tests/glsl/array_element_assignment.glsl @@ -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); +} +*/