Skip to content

Commit e8a5139

Browse files
authored
Add tests for resources in structs (#614)
This change adds tests for resource inside used-defined structs and classes. It includes 4 variants: - a single resource inside a struct - resource array inside a struct - array of structs that contain a resource - a class with a mix of UAV and SRV resources that also inherits a resource member from its base class Closes llvm/wg-hlsl#368
1 parent 3964ff7 commit e8a5139

File tree

4 files changed

+394
-0
lines changed

4 files changed

+394
-0
lines changed
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
#--- source.hlsl
2+
3+
// This test verifies handling of an array of structs with a resource.
4+
5+
struct A {
6+
RWBuffer<int> Buf;
7+
};
8+
9+
A d[8] : register(u10);
10+
A e[6];
11+
12+
RWBuffer<int> Out : register(u100);
13+
14+
[numthreads(4, 1, 1)]
15+
void main(uint3 ID : SV_GroupThreadID) {
16+
int x = d[2].Buf[ID.x];
17+
int y = d[7].Buf[ID.x];
18+
19+
e[0].Buf[ID.x] = x + y;
20+
e[1].Buf[ID.x] = x * y;
21+
}
22+
23+
//--- pipeline.yaml
24+
---
25+
Shaders:
26+
- Stage: Compute
27+
Entry: main
28+
DispatchSize: [1, 1, 1]
29+
Buffers:
30+
- Name: BufD2
31+
Format: Int32
32+
Data:
33+
[ 1, 2, 3, 4 ]
34+
35+
- Name: BufD7
36+
Format: Int32
37+
Data:
38+
[ 10, 20, 30, 40 ]
39+
40+
- Name: BufE1
41+
Format: Int32
42+
FillSize: 16
43+
44+
- Name: BufE3
45+
Format: Int32
46+
FillSize: 16
47+
48+
- Name: ExpectedBufE1
49+
Format: Int32
50+
Data:
51+
[ 11, 22, 33, 44 ]
52+
53+
- Name: ExpectedBufE3
54+
Format: Int32
55+
Data:
56+
[ 10, 40, 90, 160 ]
57+
58+
Results:
59+
- Result: ExpectedResult1
60+
Rule: BufferExact
61+
Actual: BufE1
62+
Expected: ExpectedBufE1
63+
64+
- Result: ExpectedResult2
65+
Rule: BufferExact
66+
Actual: BufE3
67+
Expected: ExpectedBufE3
68+
69+
DescriptorSets:
70+
- Resources:
71+
- Name: BufD2
72+
Kind: RWBuffer
73+
DirectXBinding:
74+
Register: 12
75+
Space: 0
76+
VulkanBinding:
77+
Binding: 12
78+
- Name: BufD7
79+
Kind: RWBuffer
80+
DirectXBinding:
81+
Register: 17
82+
Space: 0
83+
VulkanBinding:
84+
Binding: 17
85+
- Name: BufE1
86+
Kind: RWBuffer
87+
DirectXBinding:
88+
Register: 0
89+
Space: 0
90+
VulkanBinding:
91+
Binding: 0
92+
- Name: BufE3
93+
Kind: RWBuffer
94+
DirectXBinding:
95+
Register: 1
96+
Space: 0
97+
VulkanBinding:
98+
Binding: 1
99+
...
100+
#--- end
101+
102+
# Unimplemented https://github.com/llvm/wg-hlsl/issues/367
103+
# XFAIL: Clang
104+
105+
# RUN: split-file %s %t
106+
# RUN: %dxc_target -T cs_6_0 -Fo %t.o %t/source.hlsl
107+
# RUN: %offloader %t/pipeline.yaml %t.o
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
#--- source.hlsl
2+
3+
// This test verifies handling of a resource array in a struct.
4+
5+
class E {
6+
RWBuffer<int> UavBuf1;
7+
};
8+
9+
class F {
10+
StructuredBuffer<int> SrvBuf1;
11+
};
12+
13+
class G : F {
14+
E e;
15+
StructuredBuffer<int> SrvBuf2;
16+
RWBuffer<int> UavBuf2;
17+
uint n;
18+
};
19+
20+
RWStructuredBuffer<int4> Out : register(u0);
21+
22+
G g : register(u5) : register(t3);
23+
24+
[numthreads(4, 1, 1)]
25+
void main(uint3 ID : SV_GroupThreadID) {
26+
int x = g.e.UavBuf1[ID.x];
27+
int y = g.SrvBuf1[ID.x];
28+
int z = g.SrvBuf2[ID.x];
29+
int w = g.UavBuf2[ID.x];
30+
31+
Out[ID.x] = int4(x, y, z, w);
32+
}
33+
34+
//--- pipeline.yaml
35+
---
36+
Shaders:
37+
- Stage: Compute
38+
Entry: main
39+
DispatchSize: [1, 1, 1]
40+
Buffers:
41+
- Name: Buf_g_F_SrvBuf1
42+
Format: Int32
43+
Data:
44+
[ 1, 2, 3, 4 ]
45+
46+
- Name: Buf_g_SrvBuf2
47+
Format: Int32
48+
Data:
49+
[ 10, 20, 30, 40 ]
50+
51+
- Name: Buf_g_e_UavBuf1
52+
Format: Int32
53+
Data:
54+
[ 100, 200, 300, 400 ]
55+
56+
- Name: Buf_g_UavBuf2
57+
Format: Int32
58+
Data:
59+
[ 1000, 2000, 3000, 4000 ]
60+
61+
- Name: BufOut
62+
Format: Int32
63+
FillSize: 64
64+
65+
- Name: ExpectedBufOut
66+
Format: Int32
67+
Data:
68+
[ 100, 1, 10, 1000,
69+
200, 2, 20, 2000,
70+
300, 3, 30, 3000,
71+
400, 4, 40, 4000 ]
72+
73+
Results:
74+
- Result: ExpectedResult
75+
Rule: BufferExact
76+
Actual: BufOut
77+
Expected: ExpectedBufOut
78+
79+
DescriptorSets:
80+
- Resources:
81+
- Name: Buf_g_F_SrvBuf1
82+
Kind: StructuredBuffer
83+
DirectXBinding:
84+
Register: 3
85+
Space: 0
86+
VulkanBinding:
87+
Binding: 3
88+
- Name: Buf_g_SrvBuf2
89+
Kind: StructuredBuffer
90+
DirectXBinding:
91+
Register: 4
92+
Space: 0
93+
VulkanBinding:
94+
Binding: 4
95+
- Name: Buf_g_e_UavBuf1
96+
Kind: RWBuffer
97+
DirectXBinding:
98+
Register: 5
99+
Space: 0
100+
VulkanBinding:
101+
Binding: 5
102+
- Name: Buf_g_UavBuf2
103+
Kind: RWBuffer
104+
DirectXBinding:
105+
Register: 6
106+
Space: 0
107+
VulkanBinding:
108+
Binding: 6
109+
- Name: BufOut
110+
Kind: RWBuffer
111+
DirectXBinding:
112+
Register: 0
113+
Space: 0
114+
VulkanBinding:
115+
Binding: 0
116+
117+
...
118+
#--- end
119+
120+
# Unimplemented https://github.com/llvm/wg-hlsl/issues/367
121+
# XFAIL: Clang
122+
123+
# Bug https://github.com/llvm/offload-test-suite/issues/642
124+
# XFAIL: Metal
125+
126+
# Bug https://github.com/llvm/offload-test-suite/issues/643
127+
# XFAIL: Intel
128+
129+
# Vulkan does not support global structures with buffers or structures
130+
# containing both resources and non-resources.
131+
# UNSUPPORTED: Vulkan
132+
133+
# RUN: split-file %s %t
134+
# RUN: %dxc_target -T cs_6_0 -Fo %t.o %t/source.hlsl
135+
# RUN: %offloader %t/pipeline.yaml %t.o
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#--- source.hlsl
2+
3+
// This test verifies handling of a resource array in a struct.
4+
5+
struct B {
6+
RWBuffer<int> Bufs[2];
7+
};
8+
9+
[[vk::binding(3)]]
10+
B b1 : register(u3);
11+
B b2;
12+
13+
[numthreads(4,1,1)]
14+
void main(uint3 ID : SV_GroupThreadID) {
15+
int x = b1.Bufs[0][ID.x];
16+
int y = b1.Bufs[1][ID.x];
17+
18+
b2.Bufs[0][ID.x] = x + y;
19+
b2.Bufs[1][ID.x] = x * y;
20+
}
21+
22+
//--- pipeline.yaml
23+
---
24+
Shaders:
25+
- Stage: Compute
26+
Entry: main
27+
DispatchSize: [1, 1, 1]
28+
Buffers:
29+
- Name: BufB1
30+
Format: Int32
31+
ArraySize: 2
32+
Data:
33+
- [ 1, 2, 3, 4 ]
34+
- [ 10, 20, 30, 40 ]
35+
36+
- Name: BufB2
37+
Format: Int32
38+
ArraySize: 2
39+
FillSize: 16
40+
41+
- Name: ExpectedBufB2
42+
Format: Int32
43+
ArraySize: 2
44+
Data:
45+
- [ 11, 22, 33, 44 ]
46+
- [ 10, 40, 90, 160 ]
47+
48+
Results:
49+
- Result: ExpectedResult
50+
Rule: BufferExact
51+
Actual: BufB2
52+
Expected: ExpectedBufB2
53+
54+
DescriptorSets:
55+
- Resources:
56+
- Name: BufB1
57+
Kind: RWBuffer
58+
DirectXBinding:
59+
Register: 3
60+
Space: 0
61+
VulkanBinding:
62+
Binding: 3
63+
- Name: BufB2
64+
Kind: RWBuffer
65+
DirectXBinding:
66+
Register: 0
67+
Space: 0
68+
VulkanBinding:
69+
Binding: 0
70+
...
71+
#--- end
72+
73+
# Unimplemented https://github.com/llvm/wg-hlsl/issues/367
74+
# XFAIL: Clang
75+
76+
# Unimplemented https://github.com/llvm/offload-test-suite/issues/305
77+
# XFAIL: Metal
78+
79+
# RUN: split-file %s %t
80+
# RUN: %dxc_target -T cs_6_0 -Fo %t.o %t/source.hlsl
81+
# RUN: %offloader %t/pipeline.yaml %t.o
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#--- source.hlsl
2+
3+
// This test verifies handling of a simple resource in a struct.
4+
5+
struct A {
6+
RWBuffer<int> Buf;
7+
};
8+
9+
[[vk::binding(5)]]
10+
A a1 : register(u5);
11+
12+
A a2; // will bind to register u0
13+
14+
[numthreads(8, 1, 1)]
15+
void main(uint3 ID : SV_GroupThreadID) {
16+
a2.Buf[ID.x] += a1.Buf[ID.x];
17+
}
18+
19+
//--- pipeline.yaml
20+
---
21+
Shaders:
22+
- Stage: Compute
23+
Entry: main
24+
DispatchSize: [1, 1, 1]
25+
Buffers:
26+
- Name: BufA1
27+
Format: Int32
28+
Data:
29+
[ 1, 2, 3, 4, 5, 6, 7, 8 ]
30+
31+
- Name: BufA2
32+
Format: Int32
33+
Data:
34+
[ 10, 20, 30, 40, 50, 60, 70, 80 ]
35+
36+
- Name: ExpectedBufA2
37+
Format: Int32
38+
Data:
39+
[ 11, 22, 33, 44, 55, 66, 77, 88 ]
40+
41+
Results:
42+
- Result: ExpectedResult
43+
Rule: BufferExact
44+
Actual: BufA2
45+
Expected: ExpectedBufA2
46+
47+
DescriptorSets:
48+
- Resources:
49+
- Name: BufA1
50+
Kind: RWBuffer
51+
DirectXBinding:
52+
Register: 5
53+
Space: 0
54+
VulkanBinding:
55+
Binding: 5
56+
- Name: BufA2
57+
Kind: RWBuffer
58+
DirectXBinding:
59+
Register: 0
60+
Space: 0
61+
VulkanBinding:
62+
Binding: 0
63+
...
64+
#--- end
65+
66+
# Unimplemented https://github.com/llvm/wg-hlsl/issues/367
67+
# XFAIL: Clang
68+
69+
# RUN: split-file %s %t
70+
# RUN: %dxc_target -T cs_6_0 -Fo %t.o %t/source.hlsl
71+
# RUN: %offloader %t/pipeline.yaml %t.o

0 commit comments

Comments
 (0)