[Piglit] [PATCH 5/8] arb_gpu_shader5: Add ldexp constant eval execution test.

Ian Romanick idr at freedesktop.org
Fri Aug 23 08:48:29 PDT 2013


On 08/23/2013 07:24 AM, Paul Berry wrote:
> On 22 August 2013 16:07, Matt Turner <mattst88 at gmail.com
> <mailto:mattst88 at gmail.com>> wrote:
>
>     ---
>       .../built-in-functions/const-ldexp.shader-test     | 62
>     ++++++++++++++++++++++
>       1 file changed, 62 insertions(+)
>       create mode 100644
>     tests/spec/arb_gpu_shader5/execution/built-in-functions/const-ldexp.shader-test
>
>     diff --git
>     a/tests/spec/arb_gpu_shader5/execution/built-in-functions/const-ldexp.shader-test
>     b/tests/spec/arb_gpu_shader5/execution/built-in-functions/const-ldexp.shader-test
>     new file mode 100644
>     index 0000000..5a6752c
>     --- /dev/null
>     +++
>     b/tests/spec/arb_gpu_shader5/execution/built-in-functions/const-ldexp.shader-test
>     @@ -0,0 +1,62 @@
>     +[require]
>     +GLSL >= 1.50
>     +GL_ARB_gpu_shader5
>     +
>     +[vertex shader]
>     +in vec4 vertex;
>     +
>     +void main() {
>     +       gl_Position = vertex;
>     +}
>     +
>     +[fragment shader]
>     +#extension GL_ARB_gpu_shader5 : enable
>     +
>     +void bad_constant_folding();
>
>
> Ah, I see what you did there.  By not declaring this function you ensure
> that there will be a link error if constants are folded incorrectly.
> Clever.
>
> Unfortunately, I don't think the GLSL spec makes any guarantee that
> there *won't* be a link error in the case where constants ase folded
> correctly.  A conformant implementation might, for instance, postpone
> optimization until after linking, so it would get a link error even if
> all the if tests correctly constant folded to "if (false)".

Correct.

> I'd recommend switching to the trick we do in the generated constant
> folding tests, which is to declare an array whose size is positive if
> the constant folding is done correctly, and negative if it is done
> incorrectly, e.g.:
>
> float[floatBitsToInt(vec4(0.0, -0.0, 0.5, -0.5)) !=
>        floatBitsToInt(ldexp(vec4(0.0, -0.0, 0.5, -0.5), ivec4(0)))
>        ? 1 : -1] array0;
> float[floatBitsToInt(vec4(0.49, 1.0, 25.0, 100.0)) !=
>        floatBitsToInt(ldexp(vec4(0.98, 0.5, 0.78125, 0.78125),
>                             ivec4(-1, 1, 5, 7)))
>        ? 1 : -1] array1;

Yes.  This is our usual idiom, so we should stick with it.

> etc.
>
> With that fixed, this patch is:
>
> Reviewed-by: Paul Berry <stereotype441 at gmail.com
> <mailto:stereotype441 at gmail.com>>
>
>     +
>     +out vec4 color;
>     +
>     +void main()
>     +{
>     +       /* Green if both pass. */
>     +       color = vec4(0.0, 1.0, 0.0, 1.0);
>     +
>     +       /* Compare the results after going through floatBitsToInt()
>     allows us
>     +        * to distinguish -0.0f from 0.0f.
>     +        */
>     +       if (floatBitsToInt(vec4(0.0, -0.0, 0.5, -0.5)) !=
>     +           floatBitsToInt(ldexp(vec4(0.0, -0.0, 0.5, -0.5),
>     ivec4(0)))) {
>     +               bad_constant_folding();
>     +       }
>     +       if (floatBitsToInt(vec4(0.49, 1.0, 25.0, 100.0)) !=
>     +           floatBitsToInt(ldexp(vec4(0.98, 0.5, 0.78125, 0.78125),
>     ivec4(-1, 1, 5, 7)))) {
>     +               bad_constant_folding();
>     +       }
>     +       if (floatBitsToInt(vec4(1.1754944e-38, -1.1754944e-38,
>     3.40282347e38, -3.40282347e38)) !=
>     +           floatBitsToInt(ldexp(vec4(0.5, -0.5, 0.999999940,
>     -0.999999940), ivec4(-125, -125, 128, 128)))) {
>     +               bad_constant_folding();
>     +       }
>     +       if (floatBitsToInt(vec4(0.5, -0.5, 0.999999940,
>     -0.999999940)) !=
>     +           floatBitsToInt(ldexp(vec4(1.1754944e-38, -1.1754944e-38,
>     3.40282347e38, -3.40282347e38), ivec4(125, 125, -128, -128)))) {
>     +               bad_constant_folding();
>     +       }
>     +       if (floatBitsToInt(vec4(0.0, -0.0, 0.0, -0.0)) !=
>     +           floatBitsToInt(ldexp(vec4(0.0, -0.0, 0.5, -0.5),
>     ivec4(-127)))) {
>     +               bad_constant_folding();
>     +       }
>     +       if (floatBitsToInt(vec4(0.0, -0.0, 0.0, -0.0)) !=
>     +           floatBitsToInt(ldexp(vec4(1.1754944e-38, -1.1754944e-38,
>     3.40282347e38, -3.40282347e38), ivec4(-1, -1, -255, -255)))) {
>     +               bad_constant_folding();
>     +       }
>     +}
>     +
>     +[vertex data]
>     +vertex/float/2
>     +-1.0 -1.0
>     + 1.0 -1.0
>     + 1.0  1.0
>     +-1.0  1.0
>     +
>     +[test]
>     +draw arrays GL_TRIANGLE_FAN 0 4
>     +probe all rgba 0.0 1.0 0.0 1.0
>     --
>     1.8.3.2
>
>     _______________________________________________
>     Piglit mailing list
>     Piglit at lists.freedesktop.org <mailto:Piglit at lists.freedesktop.org>
>     http://lists.freedesktop.org/mailman/listinfo/piglit
> _______________________________________________
> Piglit mailing list
> Piglit at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/piglit



More information about the Piglit mailing list