5 [vertex shader passthrough]
9 #extension GL_EXT_gpu_shader4: require
11 /* Adapted from the nir_opt_algebraic pattern that causes the bug:
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))
21 * The problem was that this optimization triggered even on GPUs (e.g., Intel
22 * Sandybridge) that lack a BFREV instruction.
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);
35 out vec4 piglit_fragcolor;
37 uniform unsigned int value;
38 uniform unsigned int expected;
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);
48 uniform uint value 0x12345678
49 uniform uint expected 0x1e6a2c48
52 probe all rgba 0.0 1.0 0.0 1.0