[Piglit] [PATCH] Reproduce a constant propagation bug in Mesa (indexing into vectors).

Jose Fonseca jfonseca at vmware.com
Sat May 19 13:05:09 PDT 2012


Good find and nice test IMO.

Jose

----- Original Message -----
> As of 5/19/12, Mesa's constant propagation optimization pass fails to
> properly account for the behaviour of array indexing applied to
> vectors.  If v is a vector and i is an integer, it assumes that
> 
> v[i] = ...;
> 
> kills the x component of v.  This is not necessarily the case--it
> might kill any component of v, depending on the value of i.
> ---
>  ...-vector-indexing-kills-all-channels.shader_test |   39
>  +++++++++++++++++++
>  ...-vector-indexing-kills-all-channels.shader_test |   41
>  ++++++++++++++++++++
>  2 files changed, 80 insertions(+), 0 deletions(-)
>  create mode 100644
>  tests/spec/glsl-1.10/execution/fs-vector-indexing-kills-all-channels.shader_test
>  create mode 100644
>  tests/spec/glsl-1.10/execution/vs-vector-indexing-kills-all-channels.shader_test
> 
> diff --git
> a/tests/spec/glsl-1.10/execution/fs-vector-indexing-kills-all-channels.shader_test
> b/tests/spec/glsl-1.10/execution/fs-vector-indexing-kills-all-channels.shader_test
> new file mode 100644
> index 0000000..b22405a
> --- /dev/null
> +++
> b/tests/spec/glsl-1.10/execution/fs-vector-indexing-kills-all-channels.shader_test
> @@ -0,0 +1,39 @@
> +# This test exercises a bug in mesa as of 5/19.12: constant
> +# propagation fails to detect that array indexing into a vector
> might
> +# kill any component of the vector.
> +
> +[vertex shader]
> +void main()
> +{
> +  gl_Position = gl_Vertex;
> +}
> +
> +[fragment shader]
> +#define RED vec4(1.0, 0.0, 0.0, 0.0)
> +#define GREEN vec4(0.0, 1.0, 0.0, 0.0)
> +
> +uniform int three;
> +uniform float five;
> +
> +void main()
> +{
> +  vec4 v = vec4(1.0, 2.0, 3.0, 4.0);
> +
> +  // If the bug is present, constant propagation will see a scalar
> on
> +  // the RHS, and incorrectly conclude that therefore only v.x is
> +  // killed.
> +  v[three] = five;
> +
> +  vec4 color = v.a == 5.0 ? GREEN : RED;
> +
> +  // If the bug is present, then index and new_value will be
> optimized
> +  // away, making shader_runner fail to assign uniforms.  To avoid
> +  // that, multiply color by (five - three - 1.0).
> +  gl_FragColor = color * (five - float(three) - 1.0);
> +}
> +
> +[test]
> +uniform int three 3
> +uniform float five 5.0
> +draw rect -1 -1 2 2
> +probe all rgba 0.0 1.0 0.0 0.0
> diff --git
> a/tests/spec/glsl-1.10/execution/vs-vector-indexing-kills-all-channels.shader_test
> b/tests/spec/glsl-1.10/execution/vs-vector-indexing-kills-all-channels.shader_test
> new file mode 100644
> index 0000000..6838f78
> --- /dev/null
> +++
> b/tests/spec/glsl-1.10/execution/vs-vector-indexing-kills-all-channels.shader_test
> @@ -0,0 +1,41 @@
> +# This test exercises a bug in mesa as of 5/19/12: constant
> +# propagation fails to detect that array indexing into a vector
> might
> +# kill any component of the vector.
> +
> +[vertex shader]
> +#define RED vec4(1.0, 0.0, 0.0, 0.0)
> +#define GREEN vec4(0.0, 1.0, 0.0, 0.0)
> +
> +uniform int three;
> +uniform float five;
> +
> +void main()
> +{
> +  gl_Position = gl_Vertex;
> +
> +  vec4 v = vec4(1.0, 2.0, 3.0, 4.0);
> +
> +  // If the bug is present, constant propagation will see a scalar
> on
> +  // the RHS, and incorrectly conclude that therefore only v.x is
> +  // killed.
> +  v[three] = five;
> +
> +  vec4 color = v.a == 5.0 ? GREEN : RED;
> +
> +  // If the bug is present, then index and new_value will be
> optimized
> +  // away, making shader_runner fail to assign uniforms.  To avoid
> +  // that, multiply color by (five - three - 1.0).
> +  gl_FrontColor = color * (five - float(three) - 1.0);
> +}
> +
> +[fragment shader]
> +void main()
> +{
> +  gl_FragColor = gl_Color;
> +}
> +
> +[test]
> +uniform int three 3
> +uniform float five 5.0
> +draw rect -1 -1 2 2
> +probe all rgba 0.0 1.0 0.0 0.0
> --
> 1.7.7.6
> 
> _______________________________________________
> Piglit mailing list
> Piglit at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/piglit
> 


More information about the Piglit mailing list