Skip to content

Commit cc6b526

Browse files
authored
Add smoothstep tests (#309)
This PR adds tests for the smoothstep function. Adds float16 and float32 test files. Fixes #171
1 parent ad02195 commit cc6b526

File tree

2 files changed

+458
-0
lines changed

2 files changed

+458
-0
lines changed
Lines changed: 235 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,235 @@
1+
#--- source.hlsl
2+
3+
StructuredBuffer<half2> Min2D : register(t0);
4+
StructuredBuffer<half4> Min3D : register(t1);
5+
StructuredBuffer<half4> Min4D : register(t2);
6+
StructuredBuffer<half2> Max2D : register(t3);
7+
StructuredBuffer<half4> Max3D : register(t4);
8+
StructuredBuffer<half4> Max4D : register(t5);
9+
StructuredBuffer<half2> X2D : register(t6);
10+
StructuredBuffer<half4> X3D : register(t7);
11+
StructuredBuffer<half4> X4D : register(t8);
12+
RWStructuredBuffer<half2> Result2D : register(u9);
13+
RWStructuredBuffer<half4> Result3D : register(u10);
14+
RWStructuredBuffer<half4> Result4D : register(u11);
15+
16+
[numthreads(1,1,1)]
17+
void main() {
18+
// 2D case
19+
half2 result2D = smoothstep(Min2D[0], Max2D[0], X2D[0]);
20+
Result2D[0] = result2D;
21+
half2 result2D_constant = smoothstep(half2(0.75, -0.5), half2(10.5, 24.5), half2(1.0, 23.0));
22+
Result2D[1] = result2D_constant;
23+
24+
// we should also test cases where x is below and above the min and max bounds
25+
// below case:
26+
half2 result2D_below_min = smoothstep(Min2D[1], Max2D[1], X2D[1]);
27+
Result2D[2] = result2D_below_min;
28+
// above case:
29+
half2 result2D_above_max = smoothstep(Min2D[2], Max2D[2], X2D[2]);
30+
Result2D[3] = result2D_above_max;
31+
32+
// 3D case, using half4 for alignment
33+
half4 result3D = half4(smoothstep(Min3D[0], Max3D[0], X3D[0]));
34+
Result3D[0] = result3D;
35+
half4 result3D_constant = half4(smoothstep(half3(0.75, -0.5, 1.0), half3(10.5, 24.5, 3.0), half3(1.0, 23.0, 3.0)), 0.0);
36+
Result3D[1] = result3D_constant;
37+
38+
// 4D case
39+
half4 result4D = smoothstep(Min4D[0], Max4D[0], X4D[0]);
40+
Result4D[0] = result4D;
41+
half4 result4D_constant = smoothstep(half4(0.75, -0.5, 1.0, -2.0), half4(10.5, 24.5, 3.0, -0.125), half4(1.0, 23.0, 2.5, -0.25));
42+
Result4D[1] = result4D_constant;
43+
}
44+
45+
//--- pipeline.yaml
46+
47+
---
48+
Shaders:
49+
- Stage: Compute
50+
Entry: main
51+
DispatchSize: [1, 1, 1]
52+
Buffers:
53+
54+
- Name: Min2D
55+
Format: Float16
56+
Stride: 4
57+
Data: [ 0x3a00, 0xb800, 0x3a00, 0xb800, 0x3a00, 0xb800, 0x0, 0x0 ]
58+
# 0.75, -0.5, 0.75, -0.5, 0.75, -0.5, 0.0, 0.0
59+
- Name: Min3D
60+
Format: Float16
61+
Stride: 8
62+
Data: [ 0x3a00, 0xb800, 0x3c00, 0x0]
63+
# 0.75, -0.5, 1.0, 0.0
64+
- Name: Min4D
65+
Format: Float16
66+
Stride: 8
67+
Data: [ 0x3a00, 0xb800, 0x3c00, 0xc000]
68+
# 0.75, -0.5, 1.0, -2.0
69+
- Name: Max2D
70+
Format: Float16
71+
Stride: 4
72+
Data: [ 0x4940, 0x4e20, 0x4940, 0x4e20, 0x4940, 0x4e20, 0x0, 0x0 ]
73+
# 10.5, 24.5, 10.5, 24.5, 10.5, 24.5, 0x0, 0x0
74+
- Name: Max3D
75+
Format: Float16
76+
Stride: 8
77+
Data: [ 0x4940, 0x4e20, 0x4200, 0x0 ]
78+
# 10.5, 24.5, 3.0, 0.0
79+
- Name: Max4D
80+
Format: Float16
81+
Stride: 8
82+
Data: [ 0x4940, 0x4e20, 0x4200, 0xb000 ]
83+
# 10.5, 24.5, 3.0, -0.125
84+
- Name: X2D
85+
Format: Float16
86+
Stride: 4
87+
Data: [ 0x3c00, 0x4dc0, 0xc580, 0xc580, 0x5004, 0x5004, 0x0, 0x0 ]
88+
# 1.0, 23.0, -5.5, -5.5, 32.125, 32.125, 0.0, 0.0
89+
- Name: X3D
90+
Format: Float16
91+
Stride: 8
92+
Data: [ 0x3c00, 0x4dc0, 0x4200, 0x0 ]
93+
# 1.0, 23.0, 3.0, 0.0
94+
- Name: X4D
95+
Format: Float16
96+
Stride: 8
97+
Data: [ 0x3c00, 0x4dc0, 0x4100, 0xb400 ]
98+
# 1.0, 23.0, 2.5, -0.25
99+
- Name: Result2D
100+
Format: Float16
101+
Stride: 4
102+
ZeroInitSize: 16
103+
- Name: ExpectedResult2D
104+
Format: Float16
105+
Stride: 4
106+
Data: [ 0x17F0, 0x3BEA, 0x17F0, 0x3BEA, 0x0, 0x0, 0x3C00, 0x3C00 ]
107+
# 0.0019378662, 0.9892578, 0.0019378662, 0.9892578, 0.0, 0.0, 1.0, 1.0
108+
- Name: Result3D
109+
Format: Float16
110+
Stride: 8
111+
ZeroInitSize: 16
112+
- Name: ExpectedResult3D
113+
Format: Float16
114+
Stride: 8
115+
Data: [ 0x17F0, 0x3BEA, 0x3C00, 0x0, 0x17F0, 0x3BEA, 0x3C00, 0x0]
116+
# 0.0019378662, 0.9892578, 1.0, 0.0, 0.0019378662, 0.9892578, 1.0, 0.0
117+
- Name: Result4D
118+
Format: Float16
119+
Stride: 8
120+
ZeroInitSize: 16
121+
- Name: ExpectedResult4D
122+
Format: Float16
123+
Stride: 8
124+
Data: [ 0x17F0, 0x3BEA, 0x3AC0, 0x3BE6, 0x17F0, 0x3BEA, 0x3AC0, 0x3BE6 ]
125+
# 0.0019378662, 0.9892578, 0.84375, 0.9873047, 0.0019378662, 0.9892578, 0.84375, 0.9873047
126+
Results:
127+
- Result: CheckResult2D
128+
Rule: BufferFloatULP
129+
ULPT: 2
130+
Actual: Result2D
131+
Expected: ExpectedResult2D
132+
- Result: CheckResult3D
133+
Rule: BufferFloatULP
134+
ULPT: 2
135+
Actual: Result3D
136+
Expected: ExpectedResult3D
137+
- Result: CheckResult4D
138+
Rule: BufferFloatULP
139+
ULPT: 2
140+
Actual: Result4D
141+
Expected: ExpectedResult4D
142+
143+
DescriptorSets:
144+
- Resources:
145+
- Name: Min2D
146+
Kind: StructuredBuffer
147+
DirectXBinding:
148+
Register: 0
149+
Space: 0
150+
VulkanBinding:
151+
Binding: 0
152+
- Name: Min3D
153+
Kind: StructuredBuffer
154+
DirectXBinding:
155+
Register: 1
156+
Space: 0
157+
VulkanBinding:
158+
Binding: 1
159+
- Name: Min4D
160+
Kind: StructuredBuffer
161+
DirectXBinding:
162+
Register: 2
163+
Space: 0
164+
VulkanBinding:
165+
Binding: 2
166+
- Name: Max2D
167+
Kind: StructuredBuffer
168+
DirectXBinding:
169+
Register: 3
170+
Space: 0
171+
VulkanBinding:
172+
Binding: 3
173+
- Name: Max3D
174+
Kind: StructuredBuffer
175+
DirectXBinding:
176+
Register: 4
177+
Space: 0
178+
VulkanBinding:
179+
Binding: 4
180+
- Name: Max4D
181+
Kind: StructuredBuffer
182+
DirectXBinding:
183+
Register: 5
184+
Space: 0
185+
VulkanBinding:
186+
Binding: 5
187+
- Name: X2D
188+
Kind: StructuredBuffer
189+
DirectXBinding:
190+
Register: 6
191+
Space: 0
192+
VulkanBinding:
193+
Binding: 6
194+
- Name: X3D
195+
Kind: StructuredBuffer
196+
DirectXBinding:
197+
Register: 7
198+
Space: 0
199+
VulkanBinding:
200+
Binding: 7
201+
- Name: X4D
202+
Kind: StructuredBuffer
203+
DirectXBinding:
204+
Register: 8
205+
Space: 0
206+
VulkanBinding:
207+
Binding: 8
208+
- Name: Result2D
209+
Kind: RWStructuredBuffer
210+
DirectXBinding:
211+
Register: 9
212+
Space: 0
213+
VulkanBinding:
214+
Binding: 9
215+
- Name: Result3D
216+
Kind: RWStructuredBuffer
217+
DirectXBinding:
218+
Register: 10
219+
Space: 0
220+
VulkanBinding:
221+
Binding: 10
222+
- Name: Result4D
223+
Kind: RWStructuredBuffer
224+
DirectXBinding:
225+
Register: 11
226+
Space: 0
227+
VulkanBinding:
228+
Binding: 11
229+
...
230+
#--- end
231+
# REQUIRES: Half
232+
233+
# RUN: split-file %s %t
234+
# RUN: %dxc_target -T cs_6_5 -enable-16bit-types -Fo %t.o %t/source.hlsl
235+
# RUN: %offloader %t/pipeline.yaml %t.o

0 commit comments

Comments
 (0)