Skip to content

Commit 8e2d7d5

Browse files
authored
Add test for resources in structs with local variables/args and this access (#1098)
Add tests with resources in structs that are testing: - structure with a resource as a function argument and local variable - resource in a struct accessed from a struct method
1 parent 9379cf9 commit 8e2d7d5

2 files changed

Lines changed: 161 additions & 0 deletions

File tree

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#--- source.hlsl
2+
3+
// This test verifies handling of a simple resource in a struct
4+
// when used as a local argument.
5+
6+
struct A {
7+
RWBuffer<int> Buf;
8+
};
9+
10+
[[vk::binding(5)]]
11+
A a1 : register(u5);
12+
13+
A a2; // will bind to register u0
14+
15+
int foo(A LocalA, uint Index) {
16+
return LocalA.Buf[Index];
17+
}
18+
19+
int bar(A LocalA, uint Index) {
20+
A TmpA = LocalA;
21+
RWBuffer<int> LocalBuf = TmpA.Buf;
22+
return LocalBuf[Index];
23+
}
24+
25+
[numthreads(8, 1, 1)]
26+
void main(uint3 ID : SV_GroupThreadID) {
27+
a2.Buf[ID.x] = foo(a1, ID.x) + bar(a2, ID.x);
28+
}
29+
30+
//--- pipeline.yaml
31+
---
32+
Shaders:
33+
- Stage: Compute
34+
Entry: main
35+
DispatchSize: [1, 1, 1]
36+
Buffers:
37+
- Name: BufA1
38+
Format: Int32
39+
Data:
40+
[ 1, 2, 3, 4, 5, 6, 7, 8 ]
41+
42+
- Name: BufA2
43+
Format: Int32
44+
Data:
45+
[ 10, 20, 30, 40, 50, 60, 70, 80 ]
46+
47+
- Name: ExpectedBufA2
48+
Format: Int32
49+
Data:
50+
[ 11, 22, 33, 44, 55, 66, 77, 88 ]
51+
52+
Results:
53+
- Result: ExpectedResult
54+
Rule: BufferExact
55+
Actual: BufA2
56+
Expected: ExpectedBufA2
57+
58+
DescriptorSets:
59+
- Resources:
60+
- Name: BufA1
61+
Kind: RWBuffer
62+
DirectXBinding:
63+
Register: 5
64+
Space: 0
65+
VulkanBinding:
66+
Binding: 5
67+
- Name: BufA2
68+
Kind: RWBuffer
69+
DirectXBinding:
70+
Register: 0
71+
Space: 0
72+
VulkanBinding:
73+
Binding: 0
74+
...
75+
#--- end
76+
77+
# Unimplemented https://github.com/llvm/wg-hlsl/issues/367
78+
# XFAIL: Clang
79+
80+
# Unsupported on Metal - requires Vulkan feature robustBufferAccess
81+
# UNSUPPORTED: Metal
82+
83+
# RUN: split-file %s %t
84+
# RUN: %dxc_target -T cs_6_0 -Fo %t.o %t/source.hlsl
85+
# RUN: %offloader %t/pipeline.yaml %t.o
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#--- source.hlsl
2+
3+
// This test verifies handling of a simple resource in a struct
4+
// when used as a local argument.
5+
6+
struct A {
7+
RWBuffer<int> Buf;
8+
9+
int get(uint Index) {
10+
return this.Buf[Index];
11+
}
12+
};
13+
14+
[[vk::binding(5)]]
15+
A a1 : register(u5);
16+
17+
A a2; // will bind to register u0
18+
19+
[numthreads(8, 1, 1)]
20+
void main(uint3 ID : SV_GroupThreadID) {
21+
a2.Buf[ID.x] = a1.get(ID.x) + a2.get(ID.x);
22+
}
23+
24+
//--- pipeline.yaml
25+
---
26+
Shaders:
27+
- Stage: Compute
28+
Entry: main
29+
DispatchSize: [1, 1, 1]
30+
Buffers:
31+
- Name: BufA1
32+
Format: Int32
33+
Data:
34+
[ 1, 2, 3, 4, 5, 6, 7, 8 ]
35+
36+
- Name: BufA2
37+
Format: Int32
38+
Data:
39+
[ 10, 20, 30, 40, 50, 60, 70, 80 ]
40+
41+
- Name: ExpectedBufA2
42+
Format: Int32
43+
Data:
44+
[ 11, 22, 33, 44, 55, 66, 77, 88 ]
45+
46+
Results:
47+
- Result: ExpectedResult
48+
Rule: BufferExact
49+
Actual: BufA2
50+
Expected: ExpectedBufA2
51+
52+
DescriptorSets:
53+
- Resources:
54+
- Name: BufA1
55+
Kind: RWBuffer
56+
DirectXBinding:
57+
Register: 5
58+
Space: 0
59+
VulkanBinding:
60+
Binding: 5
61+
- Name: BufA2
62+
Kind: RWBuffer
63+
DirectXBinding:
64+
Register: 0
65+
Space: 0
66+
VulkanBinding:
67+
Binding: 0
68+
...
69+
#--- end
70+
71+
# Unimplemented https://github.com/llvm/wg-hlsl/issues/367
72+
# XFAIL: Clang
73+
74+
# RUN: split-file %s %t
75+
# RUN: %dxc_target -T cs_6_0 -Fo %t.o %t/source.hlsl
76+
# RUN: %offloader %t/pipeline.yaml %t.o

0 commit comments

Comments
 (0)