Skip to content

Commit 958565b

Browse files
authored
Add ByteAddressBuffer templated load/store tests (#504)
Closes #266. Adds tests for ByteAddressBuffer's templated load/store member functions. These test one 32-bit type (uint), bool, one 16-bit type (int16_t), one 64-bit type (int64_t), a struct with an array in it, a small struct, and a big struct. I didn't test every single type of scalar since we're mostly trying to test the various different shapes that could be used.
1 parent 184c0f0 commit 958565b

File tree

5 files changed

+321
-68
lines changed

5 files changed

+321
-68
lines changed

include/Support/Pipeline.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,11 @@ struct Resource {
199199
}
200200
}
201201

202-
uint32_t getElementSize() const { return BufferPtr->getElementSize(); }
202+
uint32_t getElementSize() const {
203+
// ByteAddressBuffers are treated as 4-byte elements to match their memory
204+
// format.
205+
return isByteAddressBuffer() ? 4 : BufferPtr->getElementSize();
206+
}
203207

204208
uint32_t size() const { return BufferPtr->size(); }
205209

lib/API/DX/Device.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,18 @@ static DXGI_FORMAT getRawDXFormat(const Resource &R) {
7878
return DXGI_FORMAT_UNKNOWN;
7979

8080
switch (R.BufferPtr->Format) {
81+
case DataFormat::Hex16:
82+
case DataFormat::UInt16:
83+
case DataFormat::Int16:
84+
case DataFormat::Float16:
8185
case DataFormat::Hex32:
8286
case DataFormat::UInt32:
8387
case DataFormat::Int32:
8488
case DataFormat::Float32:
89+
case DataFormat::Hex64:
90+
case DataFormat::UInt64:
91+
case DataFormat::Int64:
92+
case DataFormat::Float64:
8593
return DXGI_FORMAT_R32_TYPELESS;
8694
default:
8795
llvm_unreachable("Unsupported Resource format specified");
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#--- source.hlsl
2+
3+
// This test checks that we will get the expected values from invoking
4+
// various `Load` and `Store` methods on `[RW]ByteAddressBuffer`.
5+
6+
// The expected behaviour is to load the values in `In0` and `In1` at the given
7+
// byte-offset, add them, and store the result at the respective offset in
8+
// `Out`.
9+
10+
ByteAddressBuffer In0 : register(t0);
11+
ByteAddressBuffer In1 : register(t1);
12+
RWByteAddressBuffer Out : register(u2);
13+
14+
[numthreads(4,1,1)]
15+
void main() {
16+
int16_t U0 = In0.Load<int16_t>(0);
17+
int16_t V0 = In1.Load<int16_t>(0);
18+
Out.Store<int16_t>(0, U0 + V0);
19+
20+
int16_t2 U1 = In0.Load<int16_t2>(8);
21+
int16_t2 V1 = In1.Load<int16_t2>(8);
22+
Out.Store<int16_t2>(8, U1 + V1);
23+
24+
int16_t3 U2 = In0.Load<int16_t3>(16);
25+
int16_t3 V2 = In1.Load<int16_t3>(16);
26+
Out.Store<int16_t3>(16, U2 + V2);
27+
28+
int16_t4 U3 = In0.Load<int16_t4>(24);
29+
int16_t4 V3 = In1.Load<int16_t4>(24);
30+
Out.Store<int16_t4>(24, U3 + V3);
31+
}
32+
33+
//--- pipeline.yaml
34+
35+
---
36+
Shaders:
37+
- Stage: Compute
38+
Entry: main
39+
DispatchSize: [4, 1, 1]
40+
Buffers:
41+
- Name: In0
42+
Format: Int16
43+
Stride: 2
44+
Data: [ 1, 2, 3, 4, 5, 6, 7, 8,
45+
9, 10, 11, 12, 13, 14, 15, 16 ]
46+
- Name: In1
47+
Format: Hex16
48+
Stride: 2
49+
Data: [ 0x100, 0x200, 0x300, 0x400, 0x500, 0x600, 0x700, 0x800,
50+
0x900, 0xA00, 0xB00, 0xC00, 0xD00, 0xE00, 0xF00, 0x1000 ]
51+
- Name: Out
52+
Format: Hex16
53+
Stride: 2
54+
FillSize: 32
55+
- Name: ExpectedOut
56+
Format: Hex16
57+
Stride: 2
58+
Data: [ 0x101, 0x000, 0x000, 0x000, 0x505, 0x606, 0x000, 0x000,
59+
0x909, 0xA0A, 0xB0B, 0x000, 0xD0D, 0xE0E, 0xF0F, 0x1010 ]
60+
Results:
61+
- Result: Test0
62+
Rule: BufferExact
63+
Actual: Out
64+
Expected: ExpectedOut
65+
DescriptorSets:
66+
- Resources:
67+
- Name: In0
68+
Kind: ByteAddressBuffer
69+
DirectXBinding:
70+
Register: 0
71+
Space: 0
72+
VulkanBinding:
73+
Binding: 0
74+
- Name: In1
75+
Kind: ByteAddressBuffer
76+
DirectXBinding:
77+
Register: 1
78+
Space: 0
79+
VulkanBinding:
80+
Binding: 1
81+
- Name: Out
82+
Kind: RWByteAddressBuffer
83+
DirectXBinding:
84+
Register: 2
85+
Space: 0
86+
VulkanBinding:
87+
Binding: 2
88+
...
89+
#--- end
90+
91+
# Unimplemented https://github.com/llvm/llvm-project/issues/108058
92+
# XFAIL: Clang
93+
94+
# REQUIRES: Int16
95+
# RUN: split-file %s %t
96+
# RUN: %dxc_target -enable-16bit-types -T cs_6_5 -Fo %t.o %t/source.hlsl
97+
# RUN: %offloader %t/pipeline.yaml %t.o
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#--- source.hlsl
2+
3+
// This test checks that we will get the expected values from invoking
4+
// various `Load` and `Store` methods on `[RW]ByteAddressBuffer`.
5+
6+
// The expected behaviour is to load the values in `In0` and `In1` at the given
7+
// byte-offset, add them, and store the result at the respective offset in
8+
// `Out`.
9+
10+
ByteAddressBuffer In0 : register(t0);
11+
ByteAddressBuffer In1 : register(t1);
12+
RWByteAddressBuffer Out : register(u2);
13+
14+
[numthreads(4,1,1)]
15+
void main() {
16+
int64_t U0 = In0.Load<int64_t>(0);
17+
int64_t V0 = In1.Load<int64_t>(0);
18+
Out.Store<int64_t>(0, U0 + V0);
19+
20+
int64_t2 U1 = In0.Load<int64_t2>(32);
21+
int64_t2 V1 = In1.Load<int64_t2>(32);
22+
Out.Store<int64_t2>(32, U1 + V1);
23+
24+
int64_t3 U2 = In0.Load<int64_t3>(64);
25+
int64_t3 V2 = In1.Load<int64_t3>(64);
26+
Out.Store<int64_t3>(64, U2 + V2);
27+
28+
int64_t4 U3 = In0.Load<int64_t4>(96);
29+
int64_t4 V3 = In1.Load<int64_t4>(96);
30+
Out.Store<int64_t4>(96, U3 + V3);
31+
}
32+
33+
//--- pipeline.yaml
34+
35+
---
36+
Shaders:
37+
- Stage: Compute
38+
Entry: main
39+
DispatchSize: [4, 1, 1]
40+
Buffers:
41+
- Name: In0
42+
Format: Int64
43+
Stride: 8
44+
Data: [ 1, 2, 3, 4, 5, 6, 7, 8,
45+
9, 10, 11, 12, 13, 14, 15, 16 ]
46+
- Name: In1
47+
Format: Hex64
48+
Stride: 8
49+
Data: [ 0x100, 0x200, 0x300, 0x400, 0x500, 0x600, 0x700, 0x800,
50+
0x900, 0xA00, 0xB00, 0xC00, 0xD00, 0xE00, 0xF00, 0x1000 ]
51+
- Name: Out
52+
Format: Hex64
53+
Stride: 8
54+
FillSize: 128
55+
- Name: ExpectedOut
56+
Format: Hex64
57+
Stride: 8
58+
Data: [ 0x101, 0x000, 0x000, 0x000, 0x505, 0x606, 0x000, 0x000,
59+
0x909, 0xA0A, 0xB0B, 0x000, 0xD0D, 0xE0E, 0xF0F, 0x1010 ]
60+
Results:
61+
- Result: Test0
62+
Rule: BufferExact
63+
Actual: Out
64+
Expected: ExpectedOut
65+
DescriptorSets:
66+
- Resources:
67+
- Name: In0
68+
Kind: ByteAddressBuffer
69+
DirectXBinding:
70+
Register: 0
71+
Space: 0
72+
VulkanBinding:
73+
Binding: 0
74+
- Name: In1
75+
Kind: ByteAddressBuffer
76+
DirectXBinding:
77+
Register: 1
78+
Space: 0
79+
VulkanBinding:
80+
Binding: 1
81+
- Name: Out
82+
Kind: RWByteAddressBuffer
83+
DirectXBinding:
84+
Register: 2
85+
Space: 0
86+
VulkanBinding:
87+
Binding: 2
88+
...
89+
#--- end
90+
91+
# Unimplemented https://github.com/llvm/llvm-project/issues/108058
92+
# XFAIL: Clang
93+
94+
# REQUIRES: Int64
95+
# RUN: split-file %s %t
96+
# RUN: %dxc_target -T cs_6_5 -Fo %t.o %t/source.hlsl
97+
# RUN: %offloader %t/pipeline.yaml %t.o

0 commit comments

Comments
 (0)