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

Ian Romanick idr at freedesktop.org
Mon May 21 14:16:31 PDT 2012


On 05/19/2012 08:16 AM, Paul Berry wrote:
> 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.

Is there a bugzilla for this issue?  If so, it is better to refer to it 
than to refer to a date.

> +
> +[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;

If you require 1.20, you can assign the uniforms values in the shader. 
This would eliminate the need to add extra uses of the uniforms to 
prevent them from being eliminated.

#version 120
uniform int three = 3;
uniform float five = 5.0;

> +
> +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;z
> +
> +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



More information about the Piglit mailing list