Skip to content

Commit a60d95f

Browse files
authored
Add distance tests (#270)
This PR adds tests for the `distance` function. Adds float16 and float32 test files. Fixes #175
1 parent b9c1acb commit a60d95f

File tree

2 files changed

+250
-0
lines changed

2 files changed

+250
-0
lines changed

test/Feature/HLSLLib/distance.16.test

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
#--- source.hlsl
2+
3+
// This test tests four different distance scenarios
4+
// One in 1D, 2D, 3D, and 4D
5+
6+
StructuredBuffer<half4> X : register(t0);
7+
StructuredBuffer<half4> Y : register(t1);
8+
9+
RWStructuredBuffer<half> Result : register(u2);
10+
11+
[numthreads(1,1,1)]
12+
void main() {
13+
// distance ({1.125}, {2.375}) = 1.25
14+
half R0 = distance(X[0].x, Y[0].x);
15+
Result[0] = R0;
16+
half R0_constant = distance(half(1.125), half(2.375));
17+
Result[1] = R0_constant;
18+
19+
// distance({1.125, 2.5}, {2.375, 5.25}) = 3.02076
20+
half R1 = distance(X[0].xy, Y[0].xy);
21+
Result[2] = R1;
22+
half R1_constant = distance(half2(1.125, 2.5), half2(2.375, 5.25));
23+
Result[3] = R1_constant;
24+
25+
// distance({1.125, 2.5, 4.75}, {2.375, 5.25, 8.375}) = 4.71865
26+
half R2 = distance(X[0].xyz, Y[0].xyz);
27+
Result[4] = R2;
28+
half R2_constant = distance(half3(1.125, 2.5, 4.75), half3(2.375, 5.25, 8.375));
29+
Result[5] = R2_constant;
30+
31+
// distance({1.125, 2.5, 4.75, 6.625}, {2.375, 5.25, 8.375, 5.30}) = 4.90115
32+
half R3 = distance(X[0], Y[0]);
33+
Result[6] = R3;
34+
half R3_constant = distance(half4(1.125, 2.5, 4.75, 6.625), half4(2.375, 5.25, 8.375, 5.30));
35+
Result[7] = R3_constant;
36+
37+
// distance ({-7.29}, {-12.29}) = 5.0
38+
half R4 = distance(X[1].x, Y[1].x);
39+
Result[8] = R4;
40+
half R4_constant = distance(half(-7.29), half(-12.29));
41+
Result[9] = R4_constant;
42+
43+
// distance({-7.29, 137.14}, {-12.29, -4.0}) = 141.2303
44+
half R5 = distance(X[1].xy, Y[1].xy);
45+
Result[10] = R5;
46+
half R5_constant = distance(half2(-7.29, 137.14), half2(-12.29, -4.0));
47+
Result[11] = R5_constant;
48+
49+
// distance({-7.29, 137.14, 1.1}, {-12.29, -4.0, -2.1}) = 141.2406
50+
half R6 = distance(X[1].xyz, Y[1].xyz);
51+
Result[12] = R6;
52+
half R6_constant = distance(half3(-7.29, 137.14, 1.1), half3(-12.29, -4.0, -2.1));
53+
Result[13] = R6_constant;
54+
55+
// distance({-7.29, 137.14, 1.1, -3.5}, {-12.29, -4.0, -2.1, -2.5}) = 141.2445
56+
half R7 = distance(X[1], Y[1]);
57+
Result[14] = R7;
58+
half R7_constant = distance(half4(-7.29, 137.14, 11.1, -30.5), half4(-12.29, -4.0, -2.1, -2.5));
59+
Result[15] = R7_constant;
60+
}
61+
62+
//--- pipeline.yaml
63+
64+
---
65+
Shaders:
66+
- Stage: Compute
67+
Entry: main
68+
DispatchSize: [1, 1, 1]
69+
Buffers:
70+
- Name: X
71+
Format: Float16
72+
Stride: 8
73+
Data: [ 0x3c80, 0x4100, 0x44c0, 0x46a0, 0xc74a, 0x5849, 0x498d, 0xcfa0 ]
74+
# 1.125, 2.5, 4.75, 6.625, -7.29, 137.14, 11.1, -30.5
75+
- Name: Y
76+
Format: Float16
77+
Stride: 8
78+
Data: [ 0x40c0, 0x4540, 0x4830, 0x454d, 0xca25, 0xc400, 0xc033, 0xc100 ]
79+
# 2.375, 5.25, 8.375, 5.30, -12.29, -4.0, -2.1, -2.5
80+
- Name: Result
81+
Format: Float16
82+
Stride: 2
83+
ZeroInitSize: 32
84+
- Name: ExpectedResult
85+
Format: Float16
86+
Stride: 2
87+
Data: [ 0x3d00, 0x3d00, 0x420b, 0x420b, 0x44b8, 0x44b8, 0x44e7, 0x44e7, 0x4500, 0x4500, 0x586a, 0x586a, 0x586f, 0x586f, 0x5885, 0x5885 ]
88+
# 1.25, 1.25, 3.02076, 3.02076, 4.71865, 4.71865, 4.90115, 4.90115, 5.0, 5.0, 141.229, 141.229, 141.844, 141.844, 144.581, 144.581
89+
Results:
90+
- Result: CheckResult
91+
Rule: BufferFloatULP
92+
ULPT: 5
93+
Actual: Result
94+
Expected: ExpectedResult
95+
DescriptorSets:
96+
- Resources:
97+
- Name: X
98+
Kind: StructuredBuffer
99+
DirectXBinding:
100+
Register: 0
101+
Space: 0
102+
VulkanBinding:
103+
Binding: 0
104+
- Name: Y
105+
Kind: StructuredBuffer
106+
DirectXBinding:
107+
Register: 1
108+
Space: 0
109+
VulkanBinding:
110+
Binding: 1
111+
- Name: Result
112+
Kind: RWStructuredBuffer
113+
DirectXBinding:
114+
Register: 2
115+
Space: 0
116+
VulkanBinding:
117+
Binding: 2
118+
...
119+
#--- end
120+
121+
# UNSUPPORTED: Clang-Vulkan
122+
# Clang-Vulkan is unsupported because of two validation errors
123+
# This issue tracks its resolution: https://github.com/llvm/offload-test-suite/issues/285
124+
# REQUIRES: Half
125+
# RUN: split-file %s %t
126+
# RUN: %dxc_target -enable-16bit-types -T cs_6_5 -Fo %t.o %t/source.hlsl
127+
# RUN: %offloader %t/pipeline.yaml %t.o

test/Feature/HLSLLib/distance.32.test

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
#--- source.hlsl
2+
3+
// This test tests eight different distance scenarios
4+
// Two in 1D, 2D, 3D, and 4D
5+
6+
StructuredBuffer<float4> X : register(t0);
7+
StructuredBuffer<float4> Y : register(t1);
8+
9+
RWStructuredBuffer<float> Result : register(u2);
10+
11+
[numthreads(1,1,1)]
12+
void main() {
13+
// distance ({1.125}, {2.375}) = 1.25
14+
float R0 = distance(X[0].x, Y[0].x);
15+
Result[0] = R0;
16+
float R0_constant = distance(1.125, 2.375);
17+
Result[1] = R0_constant;
18+
19+
// distance({1.125, 2.5}, {2.375, 5.25}) = 3.02076
20+
float R1 = distance(X[0].xy, Y[0].xy);
21+
Result[2] = R1;
22+
float R1_constant = distance(float2(1.125, 2.5), float2(2.375, 5.25));
23+
Result[3] = R1_constant;
24+
25+
// distance({1.125, 2.5, 4.75}, {2.375, 5.25, 8.375}) = 4.71865
26+
float R2 = distance(X[0].xyz, Y[0].xyz);
27+
Result[4] = R2;
28+
float R2_constant = distance(float3(1.125, 2.5, 4.75), float3(2.375, 5.25, 8.375));
29+
Result[5] = R2_constant;
30+
31+
// distance({1.125, 2.5, 4.75, 6.625}, {2.375, 5.25, 8.375, 5.30}) = 4.90115
32+
float R3 = distance(X[0], Y[0]);
33+
Result[6] = R3;
34+
float R3_constant = distance(float4(1.125, 2.5, 4.75, 6.625), float4(2.375, 5.25, 8.375, 5.30));
35+
Result[7] = R3_constant;
36+
37+
// distance ({-7.29}, {-12.29}) = 5.0
38+
float R4 = distance(X[1].x, Y[1].x);
39+
Result[8] = R4;
40+
float R4_constant = distance(-7.29, -12.29);
41+
Result[9] = R4_constant;
42+
43+
// distance({-7.29, 137.14}, {-12.29, -4.0}) = 141.2303
44+
float R5 = distance(X[1].xy, Y[1].xy);
45+
Result[10] = R5;
46+
float R5_constant = distance(float2(-7.29, 137.14), float2(-12.29, -4.0));
47+
Result[11] = R5_constant;
48+
49+
// distance({-7.29, 137.14, 11.1}, {-12.29, -4.0, -2.1}) = 141.745
50+
float R6 = distance(X[1].xyz, Y[1].xyz);
51+
Result[12] = R6;
52+
float R6_constant = distance(float3(-7.29, 137.14, 11.1), float3(-12.29, -4.0, -2.1));
53+
Result[13] = R6_constant;
54+
55+
// distance({-7.29, 137.14, 11.1, -30.5}, {-12.29, -4.0, -2.1, -2.5}) = 141.2445
56+
float R7 = distance(X[1], Y[1]);
57+
Result[14] = R7;
58+
float R7_constant = distance(float4(-7.29, 137.14, 11.1, -30.5), float4(-12.29, -4.0, -2.1, -2.5));
59+
Result[15] = R7_constant;
60+
}
61+
62+
//--- pipeline.yaml
63+
64+
---
65+
Shaders:
66+
- Stage: Compute
67+
Entry: main
68+
DispatchSize: [1, 1, 1]
69+
Buffers:
70+
- Name: X
71+
Format: Float32
72+
Stride: 16
73+
Data: [ 1.125, 2.5, 4.75, 6.625, -7.29, 137.14, 11.1, -30.5 ]
74+
- Name: Y
75+
Format: Float32
76+
Stride: 16
77+
Data: [ 2.375, 5.25, 8.375, 5.30, -12.29, -4.0, -2.1, -2.5 ]
78+
- Name: Result
79+
Format: Float32
80+
Stride: 4
81+
ZeroInitSize: 64
82+
- Name: ExpectedResult
83+
Format: Float32
84+
Stride: 4
85+
Data: [ 1.25, 1.25, 3.02076, 3.02076, 4.71865, 4.71865, 4.90115, 4.90115, 5.0, 5.0, 141.229, 141.229, 141.844, 141.844, 144.581, 144.581 ]
86+
Results:
87+
- Result: CheckResult
88+
Rule: BufferFloatEpsilon
89+
Epsilon: .0008
90+
Actual: Result
91+
Expected: ExpectedResult
92+
DescriptorSets:
93+
- Resources:
94+
- Name: X
95+
Kind: StructuredBuffer
96+
DirectXBinding:
97+
Register: 0
98+
Space: 0
99+
VulkanBinding:
100+
Binding: 0
101+
- Name: Y
102+
Kind: StructuredBuffer
103+
DirectXBinding:
104+
Register: 1
105+
Space: 0
106+
VulkanBinding:
107+
Binding: 1
108+
- Name: Result
109+
Kind: RWStructuredBuffer
110+
DirectXBinding:
111+
Register: 2
112+
Space: 0
113+
VulkanBinding:
114+
Binding: 2
115+
...
116+
#--- end
117+
118+
# UNSUPPORTED: Clang-Vulkan
119+
# Clang-Vulkan is unsupported because of two validation errors
120+
# This issue tracks its resolution: https://github.com/llvm/offload-test-suite/issues/285
121+
# RUN: split-file %s %t
122+
# RUN: %dxc_target -T cs_6_5 -Fo %t.o %t/source.hlsl
123+
# RUN: %offloader %t/pipeline.yaml %t.o

0 commit comments

Comments
 (0)