Skip to content

Commit 58a3f8b

Browse files
kmpengllvm-beanz
andauthored
Add max tests (#345)
Closes #148. Adds tests for `max` testing 16 bit int types, half, 32 bit types, 64 bit int types, and double. Most values for 16 bit int and 32 bit int pulled from [HLK tests](https://github.com/microsoft/DirectXShaderCompiler/blob/57177f77a4dc6996400ac97a0d618799c82374e8/tools/clang/unittests/HLSLExec/ShaderOpArithTable.xml#L3125). Didn't use HLK test inputs for half and float because they were mostly nan/inf/denorm values. No HLK tests for 64 bit int and double. Need to remove XFAIL after [#7691](microsoft/DirectXShaderCompiler#7691) is fixed. --------- Co-authored-by: Chris B <[email protected]>
1 parent 8749cdb commit 58a3f8b

File tree

5 files changed

+572
-0
lines changed

5 files changed

+572
-0
lines changed

test/Feature/HLSLLib/max.32.test

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
#--- source.hlsl
2+
StructuredBuffer<float4> X0 : register(t0);
3+
StructuredBuffer<float4> Y0 : register(t1);
4+
StructuredBuffer<int4> X1 : register(t2);
5+
StructuredBuffer<int4> Y1 : register(t3);
6+
StructuredBuffer<uint4> X2 : register(t4);
7+
StructuredBuffer<uint4> Y2 : register(t5);
8+
9+
RWStructuredBuffer<float4> Out0 : register(u6);
10+
RWStructuredBuffer<int4> Out1 : register(u7);
11+
RWStructuredBuffer<uint4> Out2 : register(u8);
12+
13+
14+
[numthreads(1,1,1)]
15+
void main() {
16+
// float
17+
Out0[0] = max(X0[0], Y0[0]);
18+
Out0[1] = float4(max(X0[1].xyz, Y0[1].xyz), max(X0[1].w, Y0[1].w));
19+
Out0[2] = float4(max(X0[2].xy, Y0[2].xy), max(X0[2].zw, Y0[2].zw));
20+
Out0[3] = max(half4(1.0, -1.0, 31408, -415), half4(-1.0, 1.0, 1.5, 129.5));
21+
22+
// int
23+
Out1[0] = max(X1[0], Y1[0]);
24+
Out1[1] = int4(max(X1[1].xyz, Y1[1].xyz), max(X1[1].w, Y1[1].w));
25+
Out1[2] = int4(max(X1[2].xy, Y1[2].xy), max(X1[2].zw, Y1[2].zw));
26+
Out1[3] = max(int4(-2147483648, -10, 10, 2147483647), int4(0, 10, 10, 0));
27+
28+
// uint
29+
Out2[0] = max(X2[0], Y2[0]);
30+
Out2[1] = uint4(max(X2[1].xyz, Y2[1].xyz), max(X2[1].w, Y2[1].w));
31+
Out2[2] = uint4(max(X2[2].xy, Y2[2].xy), max(X2[2].zw, Y2[2].zw));
32+
Out2[3] = max(uint4(0, 0, 10, 10000), uint4(0, 256, 4, 10001));
33+
}
34+
//--- pipeline.yaml
35+
36+
---
37+
Shaders:
38+
- Stage: Compute
39+
Entry: main
40+
DispatchSize: [1, 1, 1]
41+
Buffers:
42+
- Name: X0
43+
Format: Float32
44+
Stride: 16
45+
Data: [ 1.0, -1.0, 31408, -415, 3.14159, 42, -123.456, 0.0001, -10, 10.5, 3e+38, 0 ]
46+
- Name: Y0
47+
Format: Float32
48+
Stride: 16
49+
Data: [ -1.0, 1.0, 1.5, 129.5, 2.71828, 42, -654.321, 0.0002, 10, 10.5, 0, -3e+38 ]
50+
- Name: X1
51+
Format: Int32
52+
Stride: 16
53+
Data: [ -2147483648, -10, 0, 0, 10, 2147483647, 1000, 2500, 1, -1, 512, -2048 ]
54+
- Name: Y1
55+
Format: Int32
56+
Stride: 16
57+
Data: [ 0, 10, -10, 10, 10, 0, 1500, 2000, -1, 1, 511, -2047 ]
58+
- Name: X2
59+
Format: UInt32
60+
Stride: 16
61+
Data: [ 0, 0, 10, 10000, 2147483647, 4294967295, 1000, 2500, 1, 256, 512, 2048 ]
62+
- Name: Y2
63+
Format: UInt32
64+
Stride: 16
65+
Data: [ 0, 256, 4, 10001, 0, 4294967295, 1500, 2000, 0, 200, 511, 2047 ]
66+
- Name: Out0
67+
Format: Float32
68+
Stride: 16
69+
ZeroInitSize: 64
70+
- Name: ExpectedOut0
71+
Format: Float32
72+
Stride: 16
73+
Data: [ 1.0, 1.0, 31408, 129.5, 3.14159, 42, -123.456, 0.0002, 10, 10.5, 3e+38, 0, 1.0, 1.0, 31408, 129.5 ]
74+
- Name: Out1
75+
Format: Int32
76+
Stride: 16
77+
ZeroInitSize: 64
78+
- Name: ExpectedOut1
79+
Format: Int32
80+
Stride: 16
81+
Data: [ 0, 10, 0, 10, 10, 2147483647, 1500, 2500, 1, 1, 512, -2047, 0, 10, 10, 2147483647 ]
82+
- Name: Out2
83+
Format: UInt32
84+
Stride: 16
85+
ZeroInitSize: 64
86+
- Name: ExpectedOut2
87+
Format: UInt32
88+
Stride: 16
89+
Data: [ 0, 256, 10, 10001, 2147483647, 4294967295, 1500, 2500, 1, 256, 512, 2048, 0, 256, 10, 10001 ]
90+
Results:
91+
- Result: Test0
92+
Rule: BufferFloatEpsilon
93+
Epsilon: 0
94+
Actual: Out0
95+
Expected: ExpectedOut0
96+
- Result: Test1
97+
Rule: BufferExact
98+
Actual: Out1
99+
Expected: ExpectedOut1
100+
- Result: Test2
101+
Rule: BufferExact
102+
Actual: Out2
103+
Expected: ExpectedOut2
104+
DescriptorSets:
105+
- Resources:
106+
- Name: X0
107+
Kind: StructuredBuffer
108+
DirectXBinding:
109+
Register: 0
110+
Space: 0
111+
VulkanBinding:
112+
Binding: 0
113+
- Name: Y0
114+
Kind: StructuredBuffer
115+
DirectXBinding:
116+
Register: 1
117+
Space: 0
118+
VulkanBinding:
119+
Binding: 1
120+
- Name: X1
121+
Kind: StructuredBuffer
122+
DirectXBinding:
123+
Register: 2
124+
Space: 0
125+
VulkanBinding:
126+
Binding: 2
127+
- Name: Y1
128+
Kind: StructuredBuffer
129+
DirectXBinding:
130+
Register: 3
131+
Space: 0
132+
VulkanBinding:
133+
Binding: 3
134+
- Name: X2
135+
Kind: StructuredBuffer
136+
DirectXBinding:
137+
Register: 4
138+
Space: 0
139+
VulkanBinding:
140+
Binding: 4
141+
- Name: Y2
142+
Kind: StructuredBuffer
143+
DirectXBinding:
144+
Register: 5
145+
Space: 0
146+
VulkanBinding:
147+
Binding: 5
148+
- Name: Out0
149+
Kind: RWStructuredBuffer
150+
DirectXBinding:
151+
Register: 6
152+
Space: 0
153+
VulkanBinding:
154+
Binding: 6
155+
- Name: Out1
156+
Kind: RWStructuredBuffer
157+
DirectXBinding:
158+
Register: 7
159+
Space: 0
160+
VulkanBinding:
161+
Binding: 7
162+
- Name: Out2
163+
Kind: RWStructuredBuffer
164+
DirectXBinding:
165+
Register: 8
166+
Space: 0
167+
VulkanBinding:
168+
Binding: 8
169+
#--- end
170+
171+
172+
# RUN: split-file %s %t
173+
# RUN: %dxc_target -HV 202x -T cs_6_5 -Fo %t.o %t/source.hlsl
174+
# RUN: %offloader %t/pipeline.yaml %t.o

test/Feature/HLSLLib/max.fp16.test

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#--- source.hlsl
2+
StructuredBuffer<half4> X : register(t0);
3+
StructuredBuffer<half4> Y : register(t1);
4+
5+
RWStructuredBuffer<half4> Out : register(u2);
6+
7+
8+
[numthreads(1,1,1)]
9+
void main() {
10+
Out[0] = max(X[0], Y[0]);
11+
Out[1] = half4(max(X[1].xyz, Y[1].xyz), max(X[1].w, Y[1].w));
12+
Out[2] = half4(max(X[2].xy, Y[2].xy), max(X[2].zw, Y[2].zw));
13+
Out[3] = max(half4(1.0, -1.0, 31408, -415), half4(-1.0, 1.0, 1.5, 129.5));
14+
}
15+
//--- pipeline.yaml
16+
17+
---
18+
Shaders:
19+
- Stage: Compute
20+
Entry: main
21+
DispatchSize: [1, 1, 1]
22+
Buffers:
23+
- Name: X
24+
Format: Float16
25+
Stride: 8
26+
Data: [ 0x3c00, 0xbc00, 0x77ab, 0xde7c, 0x4248, 0x5140, 0xd7b7, 0x068e, 0xc900, 0x4940, 0x7bff, 0x0000 ]
27+
# 1.0, -1.0, 31408, -415, 3.14159, 42, -123.456, 0.0001, -10, 10.5, 65504, 0
28+
- Name: Y
29+
Format: Float16
30+
Stride: 8
31+
Data: [ 0xbc00, 0x3c00, 0x3e00, 0x580c, 0x4170, 0x5140, 0xe11d, 0x0a8e, 0x4900, 0x4940, 0x0000, 0xfbff ]
32+
# -1.0, 1.0, 1.5, 129.5, 2.71828, 42, -654.321, 0.0002, 10, 10.5, 0, -65504
33+
- Name: Out
34+
Format: Float16
35+
Stride: 8
36+
ZeroInitSize: 32
37+
- Name: ExpectedOut0
38+
Format: Float16
39+
Stride: 8
40+
Data: [ 0x3c00, 0x3c00, 0x77ab, 0x580c, 0x4248, 0x5140, 0xd7b7, 0x0a8e, 0x4900, 0x4940, 0x7bff, 0x0000, 0x3c00, 0x3c00, 0x77ab, 0x580c ]
41+
# 1.0, 1.0, 31408, 129.5, 3.14159, 42, -123.456, 0.0002, 10, 10.5, 65504, 0, 1.0, 1.0, 31408, 129.5
42+
Results:
43+
- Result: Test0
44+
Rule: BufferFloatEpsilon
45+
Epsilon: 0
46+
Actual: Out
47+
Expected: ExpectedOut0
48+
DescriptorSets:
49+
- Resources:
50+
- Name: X
51+
Kind: StructuredBuffer
52+
DirectXBinding:
53+
Register: 0
54+
Space: 0
55+
VulkanBinding:
56+
Binding: 0
57+
- Name: Y
58+
Kind: StructuredBuffer
59+
DirectXBinding:
60+
Register: 1
61+
Space: 0
62+
VulkanBinding:
63+
Binding: 1
64+
- Name: Out
65+
Kind: RWStructuredBuffer
66+
DirectXBinding:
67+
Register: 2
68+
Space: 0
69+
VulkanBinding:
70+
Binding: 2
71+
#--- end
72+
73+
# REQUIRES: Half
74+
# RUN: split-file %s %t
75+
# RUN: %dxc_target -enable-16bit-types -HV 202x -T cs_6_5 -Fo %t.o %t/source.hlsl
76+
# RUN: %offloader %t/pipeline.yaml %t.o

test/Feature/HLSLLib/max.fp64.test

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#--- source.hlsl
2+
StructuredBuffer<double4> X : register(t0);
3+
StructuredBuffer<double4> Y : register(t1);
4+
5+
RWStructuredBuffer<double4> Out : register(u2);
6+
7+
8+
[numthreads(1,1,1)]
9+
void main() {
10+
Out[0] = max(X[0], Y[0]);
11+
Out[1] = double4(max(X[1].xyz, Y[1].xyz), max(X[1].w, Y[1].w));
12+
Out[2] = double4(max(X[2].xy, Y[2].xy), max(X[2].zw, Y[2].zw));
13+
Out[3] = max(double4(1.0, -1.0, 31408, -415), double4(-1.0, 1.0, 1.5, 129.5));
14+
}
15+
//--- pipeline.yaml
16+
17+
---
18+
Shaders:
19+
- Stage: Compute
20+
Entry: main
21+
DispatchSize: [1, 1, 1]
22+
Buffers:
23+
- Name: X
24+
Format: Float64
25+
Stride: 32
26+
Data: [ 1.0, -1.0, 31408, -415, 3.14159, 42, -123.456, 0.0001, -10, 10.5, 1e+308, 0 ]
27+
- Name: Y
28+
Format: Float64
29+
Stride: 32
30+
Data: [ -1.0, 1.0, 1.5, 129.5, 2.71828, 42, -654.321, 0.0002, 10, 10.5, 0, -1e+308 ]
31+
- Name: Out
32+
Format: Float64
33+
Stride: 32
34+
ZeroInitSize: 128
35+
- Name: ExpectedOut0
36+
Format: Float64
37+
Stride: 32
38+
Data: [ 1.0, 1.0, 31408, 129.5, 3.14159, 42, -123.456, 0.0002, 10, 10.5, 1e+308, 0, 1.0, 1.0, 31408, 129.5 ]
39+
Results:
40+
- Result: Test0
41+
Rule: BufferFloatEpsilon
42+
Epsilon: 0
43+
Actual: Out
44+
Expected: ExpectedOut0
45+
DescriptorSets:
46+
- Resources:
47+
- Name: X
48+
Kind: StructuredBuffer
49+
DirectXBinding:
50+
Register: 0
51+
Space: 0
52+
VulkanBinding:
53+
Binding: 0
54+
- Name: Y
55+
Kind: StructuredBuffer
56+
DirectXBinding:
57+
Register: 1
58+
Space: 0
59+
VulkanBinding:
60+
Binding: 1
61+
- Name: Out
62+
Kind: RWStructuredBuffer
63+
DirectXBinding:
64+
Register: 2
65+
Space: 0
66+
VulkanBinding:
67+
Binding: 2
68+
#--- end
69+
70+
# REQUIRES: Double
71+
# RUN: split-file %s %t
72+
# RUN: %dxc_target -HV 202x -T cs_6_5 -Fo %t.o %t/source.hlsl
73+
# RUN: %offloader %t/pipeline.yaml %t.o

0 commit comments

Comments
 (0)