-
Notifications
You must be signed in to change notification settings - Fork 6
/
eq_fp64.shader_test
133 lines (113 loc) · 3.18 KB
/
eq_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
# Check if 2 double are equals
# 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 true if the double-precision floating-point value `a' is equal to the
* corresponding value `b', and false otherwise. The comparison is performed
* according to the IEEE Standard for Floating-Point Arithmetic.
*/
bool
eq_fp64( uvec2 a, uvec2 b )
{
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;
}
return ( a.y == b.y ) &&
( ( a.x == b.x ) ||
( ( a.y == 0u ) && ( ( ( a.x | b.x )<<1) == 0u ) ) );
}
uniform uvec2 a;
uniform uvec2 b;
uniform bool expected;
void main()
{
/* Generate green if the expected value is producted, red
* otherwise.
*/
gl_FragColor = eq_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 1
draw rect -1 -1 2 2
probe all rgba 0.0 1.0 0.0 1.0
# Try -0.0 and +0.0
uniform uvec2 a 0x10000000 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 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 +Inf and +Inf
uniform uvec2 a 0x7FF00000 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 +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 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
# Try +Inf and NaN
uniform uvec2 a 0x7FF00000 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