Skip to content

Commit b042c9d

Browse files
kmpengllvm-beanz
andauthored
Add min tests (#338)
Closes #163. Adds tests for `min` 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#L3083). 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 44c9a64 commit b042c9d

File tree

5 files changed

+574
-0
lines changed

5 files changed

+574
-0
lines changed

test/Feature/HLSLLib/min.32.test

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

test/Feature/HLSLLib/min.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] = min(X[0], Y[0]);
11+
Out[1] = half4(min(X[1].xyz, Y[1].xyz), min(X[1].w, Y[1].w));
12+
Out[2] = half4(min(X[2].xy, Y[2].xy), min(X[2].zw, Y[2].zw));
13+
Out[3] = min(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: ExpectedOut
38+
Format: Float16
39+
Stride: 8
40+
Data: [ 0xbc00, 0xbc00, 0x3e00, 0xde7c, 0x4170, 0x5140, 0xe11d, 0x068e, 0xc900, 0x4940, 0x0000, 0xfbff, 0xbc00, 0xbc00, 0x3e00, 0xde7c ]
41+
# -1.0, -1.0, 1.5, -415, 2.71828, 42, -654.321, 0.0001, -10, 10.5, 0, -65504, -1.0, -1.0, 1.5, -415
42+
Results:
43+
- Result: Test0
44+
Rule: BufferFloatEpsilon
45+
Epsilon: 0
46+
Actual: Out
47+
Expected: ExpectedOut
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 -Gis -HV 202x -T cs_6_5 -Fo %t.o %t/source.hlsl
76+
# RUN: %offloader %t/pipeline.yaml %t.o

test/Feature/HLSLLib/min.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] = min(X[0], Y[0]);
11+
Out[1] = double4(min(X[1].xyz, Y[1].xyz), min(X[1].w, Y[1].w));
12+
Out[2] = double4(min(X[2].xy, Y[2].xy), min(X[2].zw, Y[2].zw));
13+
Out[3] = min(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, 1.5, -415, 2.71828, 42, -654.321, 0.0001, -10, 10.5, 0, -1e+308, -1.0, -1.0, 1.5, -415 ]
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 -Gis -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)