Skip to content

Commit 904291f

Browse files
authored
Add test for sign (#224)
Test for sign Test for NAN and denorm values separately from rest so we are more permissive of the allowed values. Closes #112
1 parent 203e685 commit 904291f

File tree

5 files changed

+588
-0
lines changed

5 files changed

+588
-0
lines changed

test/Feature/HLSLLib/sign.32.test

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
#--- source.hlsl
2+
3+
StructuredBuffer<int4> In1 : register(t0);
4+
StructuredBuffer<uint4> In2 : register(t1);
5+
StructuredBuffer<float4> In3 : register(t2);
6+
StructuredBuffer<float> In4 : register(t3);
7+
RWStructuredBuffer<int4> Out1 : register(u4);
8+
RWStructuredBuffer<int4> Out2 : register(u5);
9+
RWStructuredBuffer<int4> Out3 : register(u6);
10+
RWStructuredBuffer<uint> Out4 : register(u7);
11+
12+
[numthreads(1,1,1)]
13+
void main() {
14+
// int
15+
Out1[0] = sign(In1[0]);
16+
int4 Tmp = {sign(In1[0].xyz), sign(In1[0].w)};
17+
Out1[1] = Tmp;
18+
Out1[2].xy = sign(In1[0].xy);
19+
20+
// uint
21+
Out2[0] = sign(In2[0]);
22+
int4 Tmp2 = {sign(In2[0].xyz), sign(In2[0].w)};
23+
Out2[1] = Tmp2;
24+
Out2[2].xy = sign(In2[0].xy);
25+
26+
// float
27+
Out3[0] = sign(In3[0]);
28+
int4 Tmp3 = {sign(In3[1].xyz), sign(In3[1].w)};
29+
Out3[1] = Tmp3;
30+
Out3[2].xy = sign(In3[0].xy);
31+
32+
int X = sign(In4[0]); // testing nan
33+
Out4[0] = (X == 1 || X == 0 || X == -1);
34+
X = sign(In4[1]); // testing -nan
35+
Out4[1] = (X == 1 || X == 0 || X == -1);
36+
X = sign(In4[2]); // testing denorm
37+
Out4[2] = (X == 1 || X == 0);
38+
X = sign(In4[3]); // testing -denorm
39+
Out4[3] = (X == 0 || X == -1);
40+
}
41+
42+
//--- pipeline.yaml
43+
44+
---
45+
Shaders:
46+
- Stage: Compute
47+
Entry: main
48+
DispatchSize: [1, 1, 1]
49+
Buffers:
50+
- Name: In1
51+
Format: Int32
52+
Stride: 16
53+
Data: [-1, 0, -2147483648, 2147483647]
54+
- Name: In2
55+
Format: UInt32
56+
Stride: 16
57+
Data: [1, 0xffffffff, 0, 10]
58+
- Name: In3
59+
Format: Float32
60+
Stride: 16
61+
Data: [0, -0, -1.3, inf, -inf, -0.5, -0.05, 19]
62+
- Name: In4
63+
Format: Float32
64+
Stride: 4
65+
Data: [nan, -nan, 0x1.e7d42cp-127, -0x1.e7d42cp-127]
66+
- Name: Out1
67+
Format: Int32
68+
Stride: 16
69+
ZeroInitSize: 48
70+
- Name: ExpectedOut1 # The result we expect
71+
Format: Int32
72+
Stride: 16
73+
Data: [-1, 0, -1, 1, -1, 0, -1, 1, -1, 0, 0, 0] # Last two are filler
74+
- Name: Out2
75+
Format: Int32
76+
Stride: 16
77+
ZeroInitSize: 48
78+
- Name: ExpectedOut2 # The result we expect
79+
Format: Int32
80+
Stride: 16
81+
Data: [1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0] # Last two are filler
82+
- Name: Out3
83+
Format: Int32
84+
Stride: 16
85+
ZeroInitSize: 48
86+
- Name: ExpectedOut3 # The result we expect
87+
Format: Int32
88+
Stride: 16
89+
Data: [0, 0, -1, 1, -1, -1, -1, 1, 0, 0, 0, 0]
90+
- Name: Out4
91+
Format: UInt32
92+
Stride: 4
93+
ZeroInitSize: 16
94+
- Name: ExpectedOut4
95+
Format: UInt32
96+
Stride: 4
97+
Data: [1, 1, 1, 1]
98+
Results:
99+
- Result: Test1
100+
Rule: BufferExact
101+
Actual: Out1
102+
Expected: ExpectedOut1
103+
- Result: Test2
104+
Rule: BufferExact
105+
Actual: Out2
106+
Expected: ExpectedOut2
107+
- Result: Test3
108+
Rule: BufferExact
109+
Actual: Out3
110+
Expected: ExpectedOut3
111+
- Result: Test4
112+
Rule: BufferExact
113+
Actual: Out4
114+
Expected: ExpectedOut4
115+
DescriptorSets:
116+
- Resources:
117+
- Name: In1
118+
Kind: StructuredBuffer
119+
DirectXBinding:
120+
Register: 0
121+
Space: 0
122+
VulkanBinding:
123+
Binding: 0
124+
- Name: In2
125+
Kind: StructuredBuffer
126+
DirectXBinding:
127+
Register: 1
128+
Space: 0
129+
VulkanBinding:
130+
Binding: 1
131+
- Name: In3
132+
Kind: StructuredBuffer
133+
DirectXBinding:
134+
Register: 2
135+
Space: 0
136+
VulkanBinding:
137+
Binding: 2
138+
- Name: In4
139+
Kind: StructuredBuffer
140+
DirectXBinding:
141+
Register: 3
142+
Space: 0
143+
VulkanBinding:
144+
Binding: 3
145+
- Name: Out1
146+
Kind: RWStructuredBuffer
147+
DirectXBinding:
148+
Register: 4
149+
Space: 0
150+
VulkanBinding:
151+
Binding: 4
152+
- Name: Out2
153+
Kind: RWStructuredBuffer
154+
DirectXBinding:
155+
Register: 5
156+
Space: 0
157+
VulkanBinding:
158+
Binding: 5
159+
- Name: Out3
160+
Kind: RWStructuredBuffer
161+
DirectXBinding:
162+
Register: 6
163+
Space: 0
164+
VulkanBinding:
165+
Binding: 6
166+
- Name: Out4
167+
Kind: RWStructuredBuffer
168+
DirectXBinding:
169+
Register: 7
170+
Space: 0
171+
VulkanBinding:
172+
Binding: 7
173+
...
174+
#--- end
175+
176+
# https://github.com/microsoft/DirectXShaderCompiler/issues/7512
177+
# XFAIL: DXC-Vulkan
178+
179+
# RUN: split-file %s %t
180+
# RUN: %dxc_target -T cs_6_5 -Fo %t.o %t/source.hlsl
181+
# RUN: %offloader %t/pipeline.yaml %t.o

test/Feature/HLSLLib/sign.fp16.test

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
#--- source.hlsl
2+
3+
StructuredBuffer<half4> In1 : register(t0);
4+
StructuredBuffer<half> In2 : register(t1);
5+
RWStructuredBuffer<int4> Out1 : register(u2);
6+
RWStructuredBuffer<uint> Out2 : register(u3);
7+
8+
[numthreads(1,1,1)]
9+
void main() {
10+
Out1[0] = sign(In1[0]);
11+
int4 Tmp = {sign(In1[1].xyz), sign(In1[1].w)};
12+
Out1[1] = Tmp;
13+
Out1[2].xy = sign(In1[0].xy);
14+
15+
int X = sign(In2[0]); // testing nan
16+
Out2[0] = (X == 1 || X == 0 || X == -1);
17+
X = sign(In2[1]); // testing -nan
18+
Out2[1] = (X == 1 || X == 0 || X == -1);
19+
X = sign(In2[2]); // testing denorm
20+
Out2[2] = (X == 1 || X == 0);
21+
X = sign(In2[3]); // testing -denorm
22+
Out2[3] = (X == 0 || X == -1);
23+
}
24+
25+
//--- pipeline.yaml
26+
27+
---
28+
Shaders:
29+
- Stage: Compute
30+
Entry: main
31+
DispatchSize: [1, 1, 1]
32+
Buffers:
33+
- Name: In1
34+
Format: Float16
35+
Stride: 8
36+
Data: [0x0000, 0x8000, 0xbd33, 0x7c00, 0xfc00, 0xb800, 0xaa66, 0x4cc0]
37+
# 0, -0, -1.3, inf, -inf, -0.5, -0.05, 19
38+
- Name: In2 # special values where the result might differ based on platform or compiler
39+
Format: Float16
40+
Stride: 2
41+
Data: [0x7e00, 0xfe00, 0x0001, 0x8001] # nan, -nan, denorm, -denorm
42+
- Name: Out1
43+
Format: Int32
44+
Stride: 16
45+
ZeroInitSize: 48
46+
- Name: Out2
47+
Format: UInt32
48+
Stride: 4
49+
ZeroInitSize: 16
50+
- Name: ExpectedOut1 # The result we expect
51+
Format: Int32
52+
Stride: 16
53+
Data: [0, 0, -1, 1, -1, -1, -1, 1, 0, 0, 0, 0]
54+
- Name: ExpectedOut2
55+
Format: UInt32
56+
Stride: 4
57+
Data: [1, 1, 1, 1]
58+
Results:
59+
- Result: Test1
60+
Rule: BufferExact
61+
Actual: Out1
62+
Expected: ExpectedOut1
63+
- Result: Test2
64+
Rule: BufferExact
65+
Actual: Out2
66+
Expected: ExpectedOut2
67+
DescriptorSets:
68+
- Resources:
69+
- Name: In1
70+
Kind: StructuredBuffer
71+
DirectXBinding:
72+
Register: 0
73+
Space: 0
74+
VulkanBinding:
75+
Binding: 0
76+
- Name: In2
77+
Kind: StructuredBuffer
78+
DirectXBinding:
79+
Register: 1
80+
Space: 0
81+
VulkanBinding:
82+
Binding: 1
83+
- Name: Out1
84+
Kind: RWStructuredBuffer
85+
DirectXBinding:
86+
Register: 2
87+
Space: 0
88+
VulkanBinding:
89+
Binding: 2
90+
- Name: Out2
91+
Kind: RWStructuredBuffer
92+
DirectXBinding:
93+
Register: 3
94+
Space: 0
95+
VulkanBinding:
96+
Binding: 3
97+
...
98+
#--- end
99+
100+
# REQUIRES: Half
101+
# RUN: split-file %s %t
102+
# RUN: %dxc_target -enable-16bit-types -T cs_6_5 -Fo %t.o %t/source.hlsl
103+
# RUN: %offloader %t/pipeline.yaml %t.o

test/Feature/HLSLLib/sign.fp64.test

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#--- source.hlsl
2+
3+
StructuredBuffer<double4> In1 : register(t0);
4+
StructuredBuffer<double> In2 : register(t1);
5+
RWStructuredBuffer<int4> Out1 : register(u2);
6+
RWStructuredBuffer<uint> Out2 : register(u3);
7+
8+
[numthreads(1,1,1)]
9+
void main() {
10+
Out1[0] = sign(In1[0]);
11+
int4 Tmp = {sign(In1[1].xyz), sign(In1[1].w)};
12+
Out1[1] = Tmp;
13+
Out1[2].xy = sign(In1[2].xy);
14+
15+
int X = sign(In2[0]); // testing nan
16+
Out2[0] = (X == 1 || X == 0 || X == -1);
17+
X = sign(In2[1]); // testing -nan
18+
Out2[1] = (X == 1 || X == 0 || X == -1);
19+
X = sign(In2[2]); // testing denorm
20+
Out2[2] = (X == 1 || X == 0);
21+
X = sign(In2[3]); // testing -denorm
22+
Out2[3] = (X == 0 || X == -1);
23+
}
24+
25+
//--- pipeline.yaml
26+
27+
---
28+
Shaders:
29+
- Stage: Compute
30+
Entry: main
31+
DispatchSize: [1, 1, 1]
32+
Buffers:
33+
- Name: In1
34+
Format: Float64
35+
Stride: 32
36+
Data: [0, -0, -1.3, inf, -inf, -0.5, -0.05, 19]
37+
- Name: In2
38+
Format: Float64
39+
Stride: 8
40+
Data: [nan, -nan, 0x0.fffffffffffffp-1022, -0x0.fffffffffffffp-1022]
41+
- Name: Out1
42+
Format: Int32
43+
Stride: 16
44+
ZeroInitSize: 48
45+
- Name: ExpectedOut1 # The result we expect
46+
Format: Int32
47+
Stride: 16
48+
Data: [0, 0, -1, 1, -1, -1, -1, 1, 0, 0, 0, 0]
49+
- Name: Out2
50+
Format: UInt32
51+
Stride: 4
52+
ZeroInitSize: 16
53+
- Name: ExpectedOut2
54+
Format: UInt32
55+
Stride: 4
56+
Data: [1, 1, 1, 1]
57+
Results:
58+
- Result: Test1
59+
Rule: BufferExact
60+
Actual: Out1
61+
Expected: ExpectedOut1
62+
DescriptorSets:
63+
- Resources:
64+
- Name: In1
65+
Kind: StructuredBuffer
66+
DirectXBinding:
67+
Register: 0
68+
Space: 0
69+
VulkanBinding:
70+
Binding: 0
71+
- Name: In2
72+
Kind: StructuredBuffer
73+
DirectXBinding:
74+
Register: 1
75+
Space: 0
76+
VulkanBinding:
77+
Binding: 1
78+
- Name: Out1
79+
Kind: RWStructuredBuffer
80+
DirectXBinding:
81+
Register: 2
82+
Space: 0
83+
VulkanBinding:
84+
Binding: 2
85+
- Name: Out2
86+
Kind: RWStructuredBuffer
87+
DirectXBinding:
88+
Register: 3
89+
Space: 0
90+
VulkanBinding:
91+
Binding: 3
92+
...
93+
#--- end
94+
95+
# REQUIRES: Double
96+
# RUN: split-file %s %t
97+
# RUN: %dxc_target -T cs_6_5 -Fo %t.o %t/source.hlsl
98+
# RUN: %offloader %t/pipeline.yaml %t.o

0 commit comments

Comments
 (0)