1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
[require]
GLSL >= 1.50
GL_ARB_gpu_shader5
[vertex shader passthrough]
[fragment shader]
#extension GL_ARB_gpu_shader5 : enable
out vec4 color;
uniform bool test_signed;
uniform ivec4 iinsert;
uniform ivec4 ibase;
uniform ivec4 iresult;
uniform uvec4 uinsert;
uniform uvec4 ubase;
uniform uvec4 uresult;
uniform int offset, bits;
void main()
{
/* Green if both pass. */
color = vec4(0.0, 1.0, 0.0, 1.0);
if (test_signed && iresult != bitfieldInsert(ibase, iinsert, offset, bits))
/* Red if bitfieldInsert(ivec4, ...) fails. */
color = vec4(1.0, 0.0, 0.0, 1.0);
else if (!test_signed && uresult != bitfieldInsert(ubase, uinsert, offset, bits))
/* Blue if bitfieldInsert(uvec4, ...) fails. */
color = vec4(0.0, 0.0, 1.0, 1.0);
}
[test]
# Corner case: bits == 0 -> result == base
uniform int bits 0
uniform int offset 32
uniform int test_signed 1
uniform ivec4 iinsert 2147483647 15 7 3
uniform ivec4 ibase 42 56 72 97
uniform ivec4 iresult 42 56 72 97
draw rect -1 -1 2 2
probe all rgba 0.0 1.0 0.0 1.0
uniform int test_signed 0
uniform uvec4 uinsert 0xFFFFFFFF 15 7 3
uniform uvec4 ubase 42 56 72 97
uniform uvec4 uresult 42 56 72 97
draw rect -1 -1 2 2
probe all rgba 0.0 1.0 0.0 1.0
## Test overwriting set bits in <base>.
uniform int bits 4
uniform int offset 16
uniform int test_signed 1
uniform ivec4 iinsert 9 4 1 0
# 983055 is 0x000F000F
uniform ivec4 ibase 983055 983055 983055 983055
# 589839 is 0x0009000F.
# 262159 is 0x0004000F.
# 65551 is 0x0001000F.
uniform ivec4 iresult 589839 262159 65551 15
draw rect -1 -1 2 2
probe all rgba 0.0 1.0 0.0 1.0
uniform int test_signed 0
uniform uvec4 uinsert 0x9 0x4 0x1 0x0
uniform uvec4 ubase 0x000F000F 0x000F000F 0x000F000F 0x000F000F
uniform uvec4 uresult 0x0009000F 0x0004000F 0x0001000F 0x0000000F
draw rect -1 -1 2 2
probe all rgba 0.0 1.0 0.0 1.0
## Test various cases.
uniform int bits 4
uniform int offset 16
uniform int test_signed 1
uniform ivec4 iinsert 14 9 4 1
uniform ivec4 ibase 15 15 15 15
# 917519 is 0x000E000F.
# 589839 is 0x0009000F.
# 262159 is 0x0004000F.
# 65551 is 0x0001000F.
uniform ivec4 iresult 917519 589839 262159 65551
draw rect -1 -1 2 2
probe all rgba 0.0 1.0 0.0 1.0
uniform int test_signed 0
uniform uvec4 uinsert 0xE 0x9 0x4 0x1
uniform uvec4 ubase 0xF 0xF 0xF 0xF
uniform uvec4 uresult 0x000E000F 0x0009000F 0x0004000F 0x0001000F
draw rect -1 -1 2 2
probe all rgba 0.0 1.0 0.0 1.0
# Copy the whole integer
uniform int bits 32
uniform int offset 0
uniform int test_signed 1
uniform ivec4 iinsert 3203386110 3735928559 2343432205 3741239934
uniform ivec4 ibase 0 0 0 0
uniform ivec4 iresult 3203386110 3735928559 2343432205 3741239934
draw rect -1 -1 2 2
probe all rgba 0.0 1.0 0.0 1.0
uniform int test_signed 0
uniform uvec4 uinsert 0xBEEFCAFE 0xDEADBEEF 0x8BADF00D 0xDEFECA7E
uniform uvec4 ubase 0 0 0 0
uniform uvec4 uresult 0xBEEFCAFE 0xDEADBEEF 0x8BADF00D 0xDEFECA7E
draw rect -1 -1 2 2
probe all rgba 0.0 1.0 0.0 1.0
|