glsl-array-bounds: set out-of-bounds array index inside shader
[piglit.git] / tests / shaders / open-coded-bitfieldReverse-EXT_gpu_shader4.shader_test
blob902746d07df4748b5ec02a0010cc552a673336e1
1 [require]
2 GLSL >= 1.20
3 GL_EXT_gpu_shader4
5 [vertex shader passthrough]
7 [fragment shader]
8 #version 120
9 #extension GL_EXT_gpu_shader4: require
11 /* Adapted from the nir_opt_algebraic pattern that causes the bug:
12  *
13  *  step1 = ('ior', ('ishl', u, 16), ('ushr', u, 16))
14  *  step2 = ('ior', ('ishl', ('iand', step1, 0x00ff00ff), 8), ('ushr', ('iand', step1, 0xff00ff00), 8))
15  *  step3 = ('ior', ('ishl', ('iand', step2, 0x0f0f0f0f), 4), ('ushr', ('iand', step2, 0xf0f0f0f0), 4))
16  *  step4 = ('ior', ('ishl', ('iand', step3, 0x33333333), 2), ('ushr', ('iand', step3, 0xcccccccc), 2))
17  *  step5 = ('ior(many-comm-expr)', ('ishl', ('iand', step4, 0x55555555), 1), ('ushr', ('iand', step4, 0xaaaaaaaa), 1))
18  *
19  *  return step5
20  *
21  * The problem was that this optimization triggered even on GPUs (e.g., Intel
22  * Sandybridge) that lack a BFREV instruction.
23  */
24 unsigned int reverse(unsigned int u)
26     unsigned int step1 = (u << 16) | (u >> 16);
27     unsigned int step2 = ((step1 & 0x00ff00ffu) << 8) | ((step1 & 0xff00ff00u) >> 8);
28     unsigned int step3 = ((step2 & 0x0f0f0f0fu) << 4) | ((step2 & 0xf0f0f0f0u) >> 4);
29     unsigned int step4 = ((step3 & 0x33333333u) << 2) | ((step3 & 0xccccccccu) >> 2);
30     unsigned int step5 = ((step4 & 0x55555555u) << 1) | ((step4 & 0xaaaaaaaau) >> 1);
32     return step5;
35 out vec4 piglit_fragcolor;
37 uniform unsigned int value;
38 uniform unsigned int expected;
40 void main()
42     piglit_fragcolor = (reverse(value) != expected)
43         ? vec4(1.0, 0.0, 0.0, 1.0)
44         : vec4(0.0, 1.0, 0.0, 1.0);
47 [test]
48 uniform uint value    0x12345678
49 uniform uint expected 0x1e6a2c48
51 draw rect -1 -1 2 2
52 probe all rgba 0.0 1.0 0.0 1.0