Skip to content

Commit 83622cc

Browse files
authored
Add tests for resource arrays (#308)
Add tests for arrays of resources to the offload test suite, including arrays declared locally or used as function arguments, multi-dimensional arrays, or subsets of multi-dimensional arrays. One test for global arrays was already added in #302 when support for resource arrays was added to the offload test suite. Closes llvm/wg-hlsl#292
1 parent 65732e3 commit 83622cc

File tree

7 files changed

+578
-0
lines changed

7 files changed

+578
-0
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#--- source.hlsl
2+
3+
// This test verified handling of resource arrays used as a local
4+
// variable and function argument.
5+
6+
RWBuffer<float> BufA : register(u0);
7+
RWBuffer<float> BufB : register(u1);
8+
RWBuffer<float> Out : register(u2);
9+
10+
float foo(RWBuffer<float> ArgArray[2], uint Index) {
11+
return ArgArray[0][Index] + ArgArray[1][Index] * 10;
12+
}
13+
14+
float bar(uint Index) {
15+
RWBuffer<float> LocalArray[2];
16+
LocalArray[0] = BufA;
17+
LocalArray[1] = BufB;
18+
return foo(LocalArray, Index);
19+
}
20+
21+
[numthreads(4,2,1)]
22+
void main(uint GI : SV_GroupIndex) {
23+
Out[GI] = bar(GI);
24+
}
25+
26+
//--- pipeline.yaml
27+
---
28+
Shaders:
29+
- Stage: Compute
30+
Entry: main
31+
DispatchSize: [1, 1, 1]
32+
Buffers:
33+
- Name: BufA
34+
Format: Float32
35+
Data: [ 0, 1, 2, 3, 4, 5, 6, 7 ]
36+
37+
- Name: BufB
38+
Format: Float32
39+
Data: [ 0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08 ]
40+
41+
- Name: BufOut
42+
Format: Float32
43+
ZeroInitSize: 32
44+
45+
- Name: ExpectedOut
46+
Format: Float32
47+
Data: [ 0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8 ]
48+
49+
Results:
50+
- Result: BufOut
51+
Rule: BufferFloatEpsilon
52+
Epsilon: 0.0001
53+
Actual: BufOut
54+
Expected: ExpectedOut
55+
56+
DescriptorSets:
57+
- Resources:
58+
- Name: BufA
59+
Kind: RWBuffer
60+
DirectXBinding:
61+
Register: 0
62+
Space: 0
63+
VulkanBinding:
64+
Binding: 0
65+
- Name: BufB
66+
Kind: RWBuffer
67+
DirectXBinding:
68+
Register: 1
69+
Space: 0
70+
VulkanBinding:
71+
Binding: 1
72+
- Name: BufOut
73+
Kind: RWBuffer
74+
DirectXBinding:
75+
Register: 2
76+
Space: 0
77+
VulkanBinding:
78+
Binding: 2
79+
...
80+
#--- end
81+
82+
# UNSUPPORTED: Clang
83+
84+
# Resource arrays are not yet supported on Metal
85+
# UNSUPPORTED: Metal
86+
87+
# RUN: split-file %s %t
88+
# RUN: %if !Vulkan %{ %dxc_target -T cs_6_0 -Fo %t.o %t/source.hlsl %}
89+
# RUN: %if Vulkan %{ %dxc_target -T cs_6_0 -fspv-target-env=vulkan1.3 -fvk-use-scalar-layout -Fo %t.o %t/source.hlsl %}
90+
# RUN: %offloader %t/pipeline.yaml %t.o
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#--- source.hlsl
2+
3+
// Another variation testing resource arrays used as a local variable and
4+
// function argument. In this case the function SomeFn modifies the array B,
5+
// which should be a local copy of array A that is defined in main function.
6+
// The test verifies that this modification of local array B does not affect
7+
// array A.
8+
9+
RWBuffer<int> X : register(u0);
10+
RWBuffer<int> Y : register(u1);
11+
12+
void SomeFn(RWBuffer<int> B[2], uint Idx, int Val0) {
13+
B[0] = Y;
14+
B[0][Idx] = Val0;
15+
}
16+
17+
[numthreads(4,1,1)]
18+
void main(uint GI : SV_GroupIndex) {
19+
RWBuffer<int> A[2] = {X, Y};
20+
SomeFn(A, GI, 1);
21+
A[0][GI] = 2;
22+
}
23+
24+
//--- pipeline.yaml
25+
---
26+
Shaders:
27+
- Stage: Compute
28+
Entry: main
29+
DispatchSize: [1, 1, 1]
30+
Buffers:
31+
- Name: BufX
32+
Format: Int32
33+
ZeroInitSize: 16
34+
35+
- Name: BufY
36+
Format: Int32
37+
ZeroInitSize: 16
38+
39+
- Name: ExpectedX
40+
Format: Int32
41+
Data: [ 2, 2, 2, 2 ]
42+
43+
- Name: ExpectedY
44+
Format: Int32
45+
Data: [ 1, 1, 1, 1 ]
46+
47+
Results:
48+
- Result: BufX
49+
Rule: BufferExact
50+
Actual: BufX
51+
Expected: ExpectedX
52+
53+
- Result: BufY
54+
Rule: BufferExact
55+
Actual: BufY
56+
Expected: ExpectedY
57+
58+
DescriptorSets:
59+
- Resources:
60+
- Name: BufX
61+
Kind: RWBuffer
62+
DirectXBinding:
63+
Register: 0
64+
Space: 0
65+
VulkanBinding:
66+
Binding: 0
67+
- Name: BufY
68+
Kind: RWBuffer
69+
DirectXBinding:
70+
Register: 1
71+
Space: 0
72+
VulkanBinding:
73+
Binding: 1
74+
...
75+
#--- end
76+
77+
# UNSUPPORTED: Clang
78+
79+
# DXC-DirectX has a bug here because it does not create a local copy
80+
# of a function argument if the type is resource or resource array.
81+
https://github.com/microsoft/DirectXShaderCompiler/issues/7678
82+
# XFAIL: DXC-DirectX
83+
84+
# Resource arrays are not yet supported on Metal
85+
# UNSUPPORTED: Metal
86+
87+
# RUN: split-file %s %t
88+
# RUN: %if !Vulkan %{ %dxc_target -T cs_6_0 -Fo %t.o %t/source.hlsl %}
89+
# RUN: %if Vulkan %{ %dxc_target -T cs_6_0 -fspv-target-env=vulkan1.3 -fvk-use-scalar-layout -Fo %t.o %t/source.hlsl %}
90+
# RUN: %offloader %t/pipeline.yaml %t.o
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#--- source.hlsl
2+
3+
// This test verified handling of global multi-dimensional resource arrays.
4+
5+
RWBuffer<int> In[2][3] : register(u0);
6+
RWBuffer<int> Out[2][3] : register(u6);
7+
8+
[numthreads(4,1,1)]
9+
void main(uint GI : SV_GroupIndex) {
10+
for (int i = 0; i < 2; i++) {
11+
for (int j = 0; j < 3; j++) {
12+
Out[i][j][GI] = In[i][j][GI] * 2;
13+
}
14+
}
15+
}
16+
17+
//--- pipeline.yaml
18+
---
19+
Shaders:
20+
- Stage: Compute
21+
Entry: main
22+
DispatchSize: [1, 1, 1]
23+
Buffers:
24+
- Name: BufIn
25+
Format: Int32
26+
ArraySize: 6
27+
Data:
28+
- [ 0, 1, 2, 3 ]
29+
- [ 1, 2, 3, 4 ]
30+
- [ 2, 3, 4, 5 ]
31+
- [ 3, 4, 5, 6 ]
32+
- [ 4, 5, 6, 7 ]
33+
- [ 5, 6, 7, 8 ]
34+
35+
- Name: BufOut
36+
Format: Int32
37+
ArraySize: 6
38+
ZeroInitSize: 16
39+
40+
- Name: ExpectedBufOut
41+
Format: Int32
42+
ArraySize: 6
43+
Data:
44+
- [ 0, 2, 4, 6 ]
45+
- [ 2, 4, 6, 8 ]
46+
- [ 4, 6, 8, 10 ]
47+
- [ 6, 8, 10, 12 ]
48+
- [ 8, 10, 12, 14 ]
49+
- [ 10, 12, 14, 16 ]
50+
51+
Results:
52+
- Result: BufOut
53+
Rule: BufferExact
54+
Actual: BufOut
55+
Expected: ExpectedBufOut
56+
57+
DescriptorSets:
58+
- Resources:
59+
- Name: BufIn
60+
Kind: RWBuffer
61+
DirectXBinding:
62+
Register: 0
63+
Space: 0
64+
- Name: BufOut
65+
Kind: RWBuffer
66+
DirectXBinding:
67+
Register: 6
68+
Space: 0
69+
...
70+
#--- end
71+
72+
# UNSUPPORTED: Clang
73+
74+
# Resource arrays are not yet supported on Metal
75+
# UNSUPPORTED: Metal
76+
77+
# Vulkan does not support multi-dimensional resource arrays
78+
# UNSUPPORTED: Vulkan
79+
80+
# RUN: split-file %s %t
81+
# RUN: %dxc_target -T cs_6_0 -Fo %t.o %t/source.hlsl
82+
# RUN: %offloader %t/pipeline.yaml %t.o
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#--- source.hlsl
2+
3+
// This test verified handling of multi-dimensional resource arrays
4+
// used as a local variable and function argument
5+
6+
RWBuffer<float> BufA : register(u0);
7+
RWBuffer<float> BufB : register(u1);
8+
RWBuffer<float> Out : register(u2);
9+
10+
float foo(RWBuffer<float> A[2][3], uint Index) {
11+
return A[0][0][Index] + (A[0][1][Index] + 1) * 10 + (A[0][2][Index] + 2) * 100 +
12+
A[1][0][Index] + (A[1][1][Index] + 0.1) / 10 + (A[1][2][Index] + 0.2) / 100;
13+
}
14+
15+
float bar(uint Index) {
16+
RWBuffer<float> LocalArray[2][3];
17+
for (int i = 0; i < 3; i++) {
18+
LocalArray[0][i] = BufA;
19+
LocalArray[1][i] = BufB;
20+
}
21+
return foo(LocalArray, Index);
22+
}
23+
24+
[numthreads(4,2,1)]
25+
void main(uint GI : SV_GroupIndex) {
26+
Out[GI] = bar(GI);
27+
}
28+
29+
//--- pipeline.yaml
30+
---
31+
Shaders:
32+
- Stage: Compute
33+
Entry: main
34+
DispatchSize: [1, 1, 1]
35+
Buffers:
36+
- Name: BufA
37+
Format: Float32
38+
Data: [ 0, 1, 2, 3, 4, 5, 6, 7 ]
39+
40+
- Name: BufB
41+
Format: Float32
42+
Data: [ 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7 ]
43+
44+
- Name: BufOut
45+
Format: Float32
46+
ZeroInitSize: 32
47+
48+
- Name: ExpectedOut
49+
Format: Float32
50+
Data: [ 210.012, 321.123, 432.234, 543.345, 654.456, 765.567,
51+
876.678, 987.789 ]
52+
Results:
53+
- Result: BufOut
54+
Rule: BufferFloatEpsilon
55+
Epsilon: 0.001
56+
Actual: BufOut
57+
Expected: ExpectedOut
58+
59+
DescriptorSets:
60+
- Resources:
61+
- Name: BufA
62+
Kind: RWBuffer
63+
DirectXBinding:
64+
Register: 0
65+
Space: 0
66+
- Name: BufB
67+
Kind: RWBuffer
68+
DirectXBinding:
69+
Register: 1
70+
Space: 0
71+
- Name: BufOut
72+
Kind: RWBuffer
73+
DirectXBinding:
74+
Register: 2
75+
Space: 0
76+
...
77+
#--- end
78+
79+
# UNSUPPORTED: Clang
80+
81+
# Vulkan does not support multi-dimensional resource arrays
82+
# UNSUPPORTED: Vulkan
83+
84+
# Resource arrays are not yet supported on Metal
85+
# UNSUPPORTED: Metal
86+
87+
# RUN: split-file %s %t
88+
# RUN: %if !Vulkan %{ %dxc_target -T cs_6_0 -Fo %t.o %t/source.hlsl %}
89+
# RUN: %if Vulkan %{ %dxc_target -T cs_6_0 -fspv-target-env=vulkan1.3 -fvk-use-scalar-layout -Fo %t.o %t/source.hlsl %}
90+
# RUN: %offloader %t/pipeline.yaml %t.o

0 commit comments

Comments
 (0)