[Piglit] [PATCH] Test that loop unrolling properly infers loop bounds.

Matt Turner mattst88 at gmail.com
Mon Jan 7 18:43:39 PST 2013


On Mon, Jan 7, 2013 at 6:22 PM, Paul Berry <stereotype441 at gmail.com> wrote:
> This patch introduces new vs and fs tests to provoke a bug in Mesa
> which caused loop bounds to be inferred incorrectly when the loop
> condition was expressed in an unusual way (e.g. "4 > i" instead of "i
> < 4").
> ---
>  .../execution/fs-loop-bounds-unrolled.shader_test  | 40 +++++++++++++++++++++
>  .../execution/vs-loop-bounds-unrolled.shader_test  | 41 ++++++++++++++++++++++
>  2 files changed, 81 insertions(+)
>  create mode 100644 tests/spec/glsl-1.10/execution/fs-loop-bounds-unrolled.shader_test
>  create mode 100644 tests/spec/glsl-1.10/execution/vs-loop-bounds-unrolled.shader_test
>
> diff --git a/tests/spec/glsl-1.10/execution/fs-loop-bounds-unrolled.shader_test b/tests/spec/glsl-1.10/execution/fs-loop-bounds-unrolled.shader_test
> new file mode 100644
> index 0000000..40fa6b7
> --- /dev/null
> +++ b/tests/spec/glsl-1.10/execution/fs-loop-bounds-unrolled.shader_test
> @@ -0,0 +1,40 @@
> +# This test verifies that loop unrolling properly interprets a variety
> +# of ways of specifying loop bounds.
> +
> +[vertex shader]
> +void main()
> +{
> +  gl_Position = gl_Vertex;
> +}
> +
> +[fragment shader]
> +void main()
> +{
> +  int sum;
> +  int i;
> +  bool failed = false;
> +
> +  sum = 0; for (i = 10; i < 14; i++) sum += i; if (sum != 46) failed = true;
> +  sum = 0; for (i = 10; i <= 13; i++) sum += i; if (sum != 46) failed = true;
> +  sum = 0; for (i = 10; 14 > i; i++) sum += i; if (sum != 46) failed = true;
> +  sum = 0; for (i = 10; 13 >= i; i++) sum += i; if (sum != 46) failed = true;
> +  sum = 0; for (i = 10; i != 14; i++) sum += i; if (sum != 46) failed = true;
> +  sum = 0; for (i = 10; 14 != i; i++) sum += i; if (sum != 46) failed = true;
> +  sum = 0; for (i = 10; i == 10; i++) sum += i; if (sum != 10) failed = true;
> +  sum = 0; for (i = 10; 10 == i; i++) sum += i; if (sum != 10) failed = true;
> +
> +  sum = 0; for (i = 13; i > 9; i--) sum += i; if (sum != 46) failed = true;
> +  sum = 0; for (i = 13; i >= 10; i--) sum += i; if (sum != 46) failed = true;
> +  sum = 0; for (i = 13; 9 < i; i--) sum += i; if (sum != 46) failed = true;
> +  sum = 0; for (i = 13; 10 <= i; i--) sum += i; if (sum != 46) failed = true;
> +  sum = 0; for (i = 13; i != 9; i--) sum += i; if (sum != 46) failed = true;
> +  sum = 0; for (i = 13; 9 != i; i--) sum += i; if (sum != 46) failed = true;
> +  sum = 0; for (i = 13; i == 13; i--) sum += i; if (sum != 13) failed = true;
> +  sum = 0; for (i = 13; 13 == i; i--) sum += i; if (sum != 13) failed = true;
> +
> +  gl_FragColor = failed ? vec4(1.0, 0.0, 0.0, 1.0) : vec4(0.0, 1.0, 0.0, 1.0);
> +}
> +
> +[test]
> +draw rect -1 -1 2 2
> +probe all rgba 0.0 1.0 0.0 1.0
> diff --git a/tests/spec/glsl-1.10/execution/vs-loop-bounds-unrolled.shader_test b/tests/spec/glsl-1.10/execution/vs-loop-bounds-unrolled.shader_test
> new file mode 100644
> index 0000000..c9d47f3
> --- /dev/null
> +++ b/tests/spec/glsl-1.10/execution/vs-loop-bounds-unrolled.shader_test
> @@ -0,0 +1,41 @@
> +# This test contains a variety of loops that are likely to be unrolled
> +# by the implementation, and verifies that they all execute correctly.
> +
> +[vertex shader]
> +void main()
> +{
> +  gl_Position = gl_Vertex;
> +  int sum;
> +  int i;
> +  bool failed = false;
> +
> +  sum = 0; for (i = 10; i < 14; i++) sum += i; if (sum != 46) failed = true;
> +  sum = 0; for (i = 10; i <= 13; i++) sum += i; if (sum != 46) failed = true;
> +  sum = 0; for (i = 10; 14 > i; i++) sum += i; if (sum != 46) failed = true;
> +  sum = 0; for (i = 10; 13 >= i; i++) sum += i; if (sum != 46) failed = true;
> +  sum = 0; for (i = 10; i != 14; i++) sum += i; if (sum != 46) failed = true;
> +  sum = 0; for (i = 10; 14 != i; i++) sum += i; if (sum != 46) failed = true;
> +  sum = 0; for (i = 10; i == 10; i++) sum += i; if (sum != 10) failed = true;
> +  sum = 0; for (i = 10; 10 == i; i++) sum += i; if (sum != 10) failed = true;
> +
> +  sum = 0; for (i = 13; i > 9; i--) sum += i; if (sum != 46) failed = true;
> +  sum = 0; for (i = 13; i >= 10; i--) sum += i; if (sum != 46) failed = true;
> +  sum = 0; for (i = 13; 9 < i; i--) sum += i; if (sum != 46) failed = true;
> +  sum = 0; for (i = 13; 10 <= i; i--) sum += i; if (sum != 46) failed = true;
> +  sum = 0; for (i = 13; i != 9; i--) sum += i; if (sum != 46) failed = true;
> +  sum = 0; for (i = 13; 9 != i; i--) sum += i; if (sum != 46) failed = true;
> +  sum = 0; for (i = 13; i == 13; i--) sum += i; if (sum != 13) failed = true;
> +  sum = 0; for (i = 13; 13 == i; i--) sum += i; if (sum != 13) failed = true;
> +
> +  gl_FrontColor = failed ? vec4(1.0, 0.0, 0.0, 1.0) : vec4(0.0, 1.0, 0.0, 1.0);
> +}
> +
> +[fragment shader]
> +void main()
> +{
> +  gl_FragColor = gl_Color;
> +}
> +
> +[test]
> +draw rect -1 -1 2 2
> +probe all rgba 0.0 1.0 0.0 1.0
> --
> 1.8.1

Reviewed-by: Matt Turner <mattst88 at gmail.com>


More information about the Piglit mailing list