Skip to content

Commit 6458811

Browse files
committed
change getElementSize, replace array test with struct array
1 parent 97cd8ae commit 6458811

File tree

3 files changed

+27
-21
lines changed

3 files changed

+27
-21
lines changed

include/Support/Pipeline.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,10 @@ struct Resource {
198198
}
199199
}
200200

201-
uint32_t getElementSize() const { return BufferPtr->getElementSize(); }
201+
uint32_t getElementSize() const {
202+
// ByteAddressBuffer uses DXGI_FORMAT_R32_TYPELESS which has 4-byte elements
203+
return isByteAddressBuffer() ? 4 : BufferPtr->getElementSize();
204+
}
202205

203206
uint32_t size() const { return BufferPtr->size(); }
204207

lib/API/DX/Device.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ static D3D12_RESOURCE_DESC getResourceDescription(const Resource &R) {
169169
}
170170

171171
static D3D12_SHADER_RESOURCE_VIEW_DESC getSRVDescription(const Resource &R) {
172-
const uint32_t EltSize = R.isByteAddressBuffer() ? 4 : R.getElementSize();
172+
const uint32_t EltSize = R.getElementSize();
173173
const uint32_t NumElts = R.size() / EltSize;
174174

175175
llvm::outs() << " EltSize = " << EltSize << " NumElts = " << NumElts
@@ -205,7 +205,7 @@ static D3D12_SHADER_RESOURCE_VIEW_DESC getSRVDescription(const Resource &R) {
205205
}
206206

207207
static D3D12_UNORDERED_ACCESS_VIEW_DESC getUAVDescription(const Resource &R) {
208-
const uint32_t EltSize = R.isByteAddressBuffer() ? 4 : R.getElementSize();
208+
const uint32_t EltSize = R.getElementSize();
209209
const uint32_t NumElts = R.size() / EltSize;
210210
const uint32_t CounterOffset = getUAVBufferCounterOffset(R);
211211

test/Feature/ByteAddressBuffer/ByteAddressBuffers.test

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@
77
// byte-offset, add them, and store the result at the respective offset in
88
// `Out`.
99

10-
struct S0 {
10+
struct ArrayStruct {
11+
int arr[4];
12+
};
13+
14+
struct SmallStruct {
1115
int a;
1216
uint b;
1317
};
1418

15-
struct S1 {
19+
struct LargeStruct {
1620
int4 a;
1721
int4 b;
1822
uint4 c;
@@ -59,25 +63,24 @@ void main() {
5963
bool4 V7 = In1.Load<bool4>(64);
6064
Out.Store<bool4>(112, U7 + V7);
6165

62-
// array
63-
int U8[4] = In0.Load<int[4]>(0);
64-
int V8[4] = In1.Load<int[4]>(0);
65-
int TempArray[4];
66+
// structs
67+
ArrayStruct U8 = In0.Load<ArrayStruct>(0);
68+
ArrayStruct V8 = In1.Load<ArrayStruct>(0);
69+
ArrayStruct TempStruct0;
6670
for(int I = 0; I < 4; I++) {
67-
TempArray[I] = U8[I] + V8[I];
71+
TempStruct0.arr[I] = U8.arr[I] + V8.arr[I];
6872
}
69-
Out.Store<int[4]>(128, TempArray);
73+
Out.Store<ArrayStruct>(128, TempStruct0);
7074

71-
// structs
72-
S0 U9 = In0.Load<S0>(0);
73-
S0 V9 = In1.Load<S0>(0);
74-
S0 TempStruct0 = {U9.a + V9.a, U9.b + V9.b};
75-
Out.Store<S0>(144, TempStruct0);
76-
77-
S1 U10 = In0.Load<S1>(0);
78-
S1 V10 = In1.Load<S1>(0);
79-
S1 TempStruct1 = {U10.a + V10.a, U10.b + V10.b, U10.c + V10.c, U10.d + V10.d};
80-
Out.Store<S1>(160, TempStruct1);
75+
SmallStruct U9 = In0.Load<SmallStruct>(0);
76+
SmallStruct V9 = In1.Load<SmallStruct>(0);
77+
SmallStruct TempStruct1 = {U9.a + V9.a, U9.b + V9.b};
78+
Out.Store<SmallStruct>(144, TempStruct1);
79+
80+
LargeStruct U10 = In0.Load<LargeStruct>(0);
81+
LargeStruct V10 = In1.Load<LargeStruct>(0);
82+
LargeStruct TempStruct2 = {U10.a + V10.a, U10.b + V10.b, U10.c + V10.c, U10.d + V10.d};
83+
Out.Store<LargeStruct>(160, TempStruct2);
8184
}
8285

8386
//--- pipeline.yaml

0 commit comments

Comments
 (0)