-
Notifications
You must be signed in to change notification settings - Fork 5
/
lt_fp64.shader_test
172 lines (147 loc) · 4.2 KB
/
lt_fp64.shader_test
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# Check if double 'a' is less than 'b'
# IEEE 754 compliant
[require]
GLSL >= 1.30
[vertex shader]
#version 130
void main()
{
gl_Position = gl_Vertex;
}
[fragment shader]
#version 130
/* Returns the fraction bits of the double-precision floating-point value `a'.*/
uvec2
extractFloat64Frac( uvec2 a )
{
return uvec2( a.x & 0x000FFFFFu, a.y );
}
/* Returns the exponent bits of the double-precision floating-point value `a'.*/
uint
extractFloat64Exp( uvec2 a )
{
return (a.x>>20) & 0x7FFu;
}
/* Returns the sign bit of the double-precision floating-point value `a'.*/
uint
extractFloat64Sign( uvec2 a )
{
return (a.x>>31);
}
/* Returns true if the 64-bit value formed by concatenating `a0' and `a1' is less
* than the 64-bit value formed by concatenating `b0' and `b1'. Otherwise,
* returns false.
*/
bool
lt64( uint a0, uint a1, uint b0, uint b1 )
{
return ( a0 < b0 ) || ( ( a0 == b0 ) && ( a1 < b1 ) );
}
/* Returns true if the double-precision floating-point value `a' is less than
* the corresponding value `b', and false otherwise. The comparison is performed
* according to the IEEE Standard for Floating-Point Arithmetic.
*/
bool
lt_fp64( uvec2 a, uvec2 b )
{
uint aSign;
uint bSign;
uvec2 aFrac;
uvec2 bFrac;
bool isaNaN;
bool isbNaN;
aFrac = extractFloat64Frac( a );
bFrac = extractFloat64Frac( b );
isaNaN = ( extractFloat64Exp( a ) == 0x7FFu ) &&
( ( aFrac.x | aFrac.y ) != 0u );
isbNaN = ( extractFloat64Exp( b ) == 0x7FFu ) &&
( ( bFrac.x | bFrac.y ) != 0u );
if ( isaNaN || isbNaN ) {
return false;
}
aSign = extractFloat64Sign( a );
bSign = extractFloat64Sign( b );
if( aSign != bSign ) {
return ( aSign != 0u ) &&
( ( ( ( ( a.x | b.x )<<1 ) ) | a.y | b.y ) != 0u );
}
return ( aSign != 0u ) ? lt64( b.x, b.y, a.x, a.y )
: lt64( a.x, a.y, b.x, b.y );
}
uniform uvec2 a;
uniform uvec2 b;
uniform bool expected;
void main()
{
/* Generate green if the expected value is producted, red
* otherwise.
*/
gl_FragColor = lt_fp64(a,b) == expected
? vec4(0.0, 1.0, 0.0, 1.0)
: vec4(1.0, 0.0, 0.0, 1.0);
}
[test]
# A bunch of tests to run. The 'uniform' lines set the uniforms. The
# 'draw rect' line draws a rectangle that covers the whole window.
# The 'probe all' line verifies that every pixel contains the expected
# color.
# Try +0.0 and +0.0
uniform uvec2 a 0x00000000 0x00000000
uniform uvec2 b 0x00000000 0x00000000
uniform int expected 0
draw rect -1 -1 2 2
probe all rgba 0.0 1.0 0.0 1.0
# Try 0.1 and 0.0
uniform uvec2 a 0x3FB99999 0x9999999A
uniform uvec2 b 0x00000000 0x00000000
uniform int expected 0
draw rect -1 -1 2 2
probe all rgba 0.0 1.0 0.0 1.0
# Try 0.0 and 0.1
uniform uvec2 a 0x00000000 0x00000000
uniform uvec2 b 0x3FB99999 0x9999999A
uniform int expected 1
draw rect -1 -1 2 2
probe all rgba 0.0 1.0 0.0 1.0
# Try 1 bit set and 0.0
uniform uvec2 a 0x00000000 0x00000001
uniform uvec2 b 0x00000000 0x00000000
uniform int expected 0
draw rect -1 -1 2 2
probe all rgba 0.0 1.0 0.0 1.0
# Try 0.0 and 1 bit set
uniform uvec2 a 0x00000000 0x00000000
uniform uvec2 b 0x00000000 0x00000001
uniform int expected 1
draw rect -1 -1 2 2
probe all rgba 0.0 1.0 0.0 1.0
# Try 1 bit set and 1 bit set
uniform uvec2 a 0x00000000 0x00000001
uniform uvec2 b 0x00000000 0x00000001
uniform int expected 0
draw rect -1 -1 2 2
probe all rgba 0.0 1.0 0.0 1.0
# Try +Inf and +Inf
uniform uvec2 a 0x7FF00000 0x00000000
uniform uvec2 b 0x7FF00000 0x00000000
uniform int expected 0
draw rect -1 -1 2 2
probe all rgba 0.0 1.0 0.0 1.0
# Try +Inf and -Inf
uniform uvec2 a 0x7FF00000 0x00000000
uniform uvec2 b 0xFFF00000 0x00000000
uniform int expected 0
draw rect -1 -1 2 2
probe all rgba 0.0 1.0 0.0 1.0
# Try -Inf and +Inf
uniform uvec2 a 0xFFF00000 0x00000000
uniform uvec2 b 0x7FF00000 0x00000000
uniform int expected 1
draw rect -1 -1 2 2
probe all rgba 0.0 1.0 0.0 1.0
# Try 0 and NaN
uniform uvec2 a 0x00000000 0x00000000
uniform uvec2 b 0x7FF00000 0x00000001
uniform int expected 0
draw rect -1 -1 2 2
probe all rgba 0.0 1.0 0.0 1.0