Skip to content

Commit d0cdcaf

Browse files
committed
add distance tests
1 parent 81e73ae commit d0cdcaf

File tree

2 files changed

+166
-0
lines changed

2 files changed

+166
-0
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#--- source.hlsl
2+
3+
StructuredBuffer<float4> X : register(t0);
4+
StructuredBuffer<float4> Y : register(t1);
5+
6+
RWStructuredBuffer<float> Result : register(u2);
7+
8+
[numthreads(1,1,1)]
9+
void main() {
10+
// distance ({0.0}, {3.0}) = 3.0
11+
float R0 = distance(X[0].x, Y[0].x);
12+
Result[0] = R0;
13+
// distance({0.0, 0.0}, {3.0, 4.0}) = 5.0
14+
float R1 = distance(X[0].xy, Y[0].xy);
15+
Result[1] = R1;
16+
// distance({0.0, 0.0, 0.0}, {3.0, 4.0, 12.0}) = 13.0
17+
float R2 = distance(X[0].xyz, Y[0].xyz);
18+
Result[2] = R2;
19+
// distance({0.0, 0.0, 0.0, 0.0}, {3.0, 4.0, 12.0, 84.0}) = 85.0
20+
float R3 = distance(X[0].xyzw, Y[0].xyzw);
21+
Result[3] = R3;
22+
}
23+
24+
//--- pipeline.yaml
25+
26+
---
27+
Shaders:
28+
- Stage: Compute
29+
Entry: main
30+
DispatchSize: [1, 1, 1]
31+
Buffers:
32+
- Name: X
33+
Format: Float32
34+
Stride: 16
35+
Data: [ 0.0, 0.0, 0.0, 0.0 ]
36+
- Name: Y
37+
Format: Float32
38+
Stride: 16
39+
Data: [ 3.0, 4.0, 12.0, 84.0 ]
40+
- Name: Result
41+
Format: Float32
42+
Stride: 4
43+
ZeroInitSize: 16
44+
- Name: ExpectedResult
45+
Format: Float32
46+
Stride: 4
47+
Data: [ 3.0, 5.0, 13.0, 85.0 ]
48+
Results:
49+
- Result: CheckResult
50+
Rule: BufferExact
51+
Actual: Result
52+
Expected: ExpectedResult
53+
DescriptorSets:
54+
- Resources:
55+
- Name: X
56+
Kind: StructuredBuffer
57+
DirectXBinding:
58+
Register: 0
59+
Space: 0
60+
VulkanBinding:
61+
Binding: 0
62+
- Name: Y
63+
Kind: StructuredBuffer
64+
DirectXBinding:
65+
Register: 1
66+
Space: 0
67+
VulkanBinding:
68+
Binding: 1
69+
- Name: Result
70+
Kind: RWStructuredBuffer
71+
DirectXBinding:
72+
Register: 2
73+
Space: 0
74+
VulkanBinding:
75+
Binding: 2
76+
...
77+
#--- end
78+
79+
# UNSUPPORTED: Clang-Vulkan
80+
# RUN: split-file %s %t
81+
# RUN: %dxc_target -T cs_6_5 -Fo %t.o %t/source.hlsl
82+
# RUN: %offloader %t/pipeline.yaml %t.o
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#--- source.hlsl
2+
3+
StructuredBuffer<half4> X : register(t0);
4+
StructuredBuffer<half4> Y : register(t1);
5+
6+
RWStructuredBuffer<half> Result : register(u2);
7+
8+
[numthreads(1,1,1)]
9+
void main() {
10+
// distance ({0.0}, {3.0}) = 3.0
11+
half R0 = distance(X[0].x, Y[0].x);
12+
Result[0] = R0;
13+
// distance({0.0, 0.0}, {3.0, 4.0}) = 5.0
14+
half R1 = distance(X[0].xy, Y[0].xy);
15+
Result[1] = R1;
16+
// distance({0.0, 0.0, 0.0}, {3.0, 4.0, 12.0}) = 13.0
17+
half R2 = distance(X[0].xyz, Y[0].xyz);
18+
Result[2] = R2;
19+
// distance({0.0, 0.0, 0.0, 0.0}, {3.0, 4.0, 12.0, 84.0}) = 85.0
20+
half R3 = distance(X[0].xyzw, Y[0].xyzw);
21+
Result[3] = R3;
22+
}
23+
24+
//--- pipeline.yaml
25+
26+
---
27+
Shaders:
28+
- Stage: Compute
29+
Entry: main
30+
DispatchSize: [1, 1, 1]
31+
Buffers:
32+
- Name: X
33+
Format: Float16
34+
Stride: 8
35+
Data: [ 0x0000, 0x0000, 0x0000, 0x0000 ]
36+
- Name: Y
37+
Format: Float16
38+
Stride: 8
39+
Data: [ 0x4200, 0x4400, 0x4a00, 0x5540 ]
40+
- Name: Result
41+
Format: Float16
42+
Stride: 2
43+
ZeroInitSize: 8
44+
- Name: ExpectedResult
45+
Format: Float16
46+
Stride: 2
47+
Data: [ 0x4200, 0x4500, 0x4a80, 0x5550 ]
48+
Results:
49+
- Result: CheckResult
50+
Rule: BufferFloatEpsilon
51+
Epsilon: 0.1
52+
Actual: Result
53+
Expected: ExpectedResult
54+
DescriptorSets:
55+
- Resources:
56+
- Name: X
57+
Kind: StructuredBuffer
58+
DirectXBinding:
59+
Register: 0
60+
Space: 0
61+
VulkanBinding:
62+
Binding: 0
63+
- Name: Y
64+
Kind: StructuredBuffer
65+
DirectXBinding:
66+
Register: 1
67+
Space: 0
68+
VulkanBinding:
69+
Binding: 1
70+
- Name: Result
71+
Kind: RWStructuredBuffer
72+
DirectXBinding:
73+
Register: 2
74+
Space: 0
75+
VulkanBinding:
76+
Binding: 2
77+
...
78+
#--- end
79+
80+
# UNSUPPORTED: Clang-Vulkan
81+
# REQUIRES: Half
82+
# RUN: split-file %s %t
83+
# RUN: %dxc_target -enable-16bit-types -T cs_6_5 -Fo %t.o %t/source.hlsl
84+
# RUN: %offloader %t/pipeline.yaml %t.o

0 commit comments

Comments
 (0)