Skip to content

Commit 59a0b7c

Browse files
committed
address Justin and Damyan
1 parent b58d924 commit 59a0b7c

File tree

4 files changed

+54
-41
lines changed

4 files changed

+54
-41
lines changed

include/Support/Pipeline.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ struct Resource {
143143
std::optional<VulkanBinding> VKBinding;
144144
Buffer *BufferPtr = nullptr;
145145
bool HasCounter;
146-
int TilesMapped = -1;
146+
std::optional<int> TilesMapped;
147147

148148
bool isRaw() const {
149149
switch (Kind) {

lib/API/DX/Device.cpp

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,6 @@ class DXDevice : public offloadtest::Device {
244244
ComPtr<ID3D12Resource> Upload;
245245
ComPtr<ID3D12Resource> Buffer;
246246
ComPtr<ID3D12Resource> Readback;
247-
// In unmapped cases, the Heap lifetime needs to be preserved
248247
ComPtr<ID3D12Heap> Heap;
249248
ResourceSet(ComPtr<ID3D12Resource> Upload, ComPtr<ID3D12Resource> Buffer,
250249
ComPtr<ID3D12Resource> Readback,
@@ -524,7 +523,7 @@ class DXDevice : public offloadtest::Device {
524523
addUploadEndBarrier(IS, Destination, R.isReadWrite());
525524
}
526525

527-
llvm::Expected<ResourceBundle> createUnmappedSRV(Resource &R,
526+
llvm::Expected<ResourceBundle> createReservedSRV(Resource &R,
528527
InvocationState &IS) {
529528
ResourceBundle Bundle;
530529
const uint32_t BufferSize = R.size();
@@ -537,8 +536,10 @@ class DXDevice : public offloadtest::Device {
537536
for (const auto &ResData : R.BufferPtr->Data) {
538537
llvm::outs() << "Creating SRV: { Size = " << BufferSize
539538
<< ", Register = t" << R.DXBinding.Register + RegOffset
540-
<< ", Space = " << R.DXBinding.Space
541-
<< ", TilesMapped = " << R.TilesMapped << " }\n";
539+
<< ", Space = " << R.DXBinding.Space;
540+
if (R.TilesMapped)
541+
llvm::outs() << ", TilesMapped = " << *R.TilesMapped;
542+
llvm::outs() << " }\n";
542543

543544
// Reserved SRV resource
544545
ComPtr<ID3D12Resource> Buffer;
@@ -563,7 +564,7 @@ class DXDevice : public offloadtest::Device {
563564
return Err;
564565

565566
// Tile mapping setup (optional if NumTiles > 0)
566-
UINT NumTiles = static_cast<UINT>(R.TilesMapped);
567+
UINT NumTiles = static_cast<UINT>(*R.TilesMapped);
567568
ComPtr<ID3D12Heap> Heap; // optional, only created if NumTiles > 0
568569

569570
if (NumTiles > 0) {
@@ -633,8 +634,8 @@ class DXDevice : public offloadtest::Device {
633634
return Bundle;
634635
}
635636

636-
llvm::Expected<ResourceBundle> createMappedSRV(Resource &R,
637-
InvocationState &IS) {
637+
llvm::Expected<ResourceBundle> createCommittedSRV(Resource &R,
638+
InvocationState &IS) {
638639
ResourceBundle Bundle;
639640

640641
const D3D12_HEAP_PROPERTIES HeapProp =
@@ -685,9 +686,9 @@ class DXDevice : public offloadtest::Device {
685686
}
686687

687688
llvm::Expected<ResourceBundle> createSRV(Resource &R, InvocationState &IS) {
688-
if (R.TilesMapped != -1)
689-
return createUnmappedSRV(R, IS);
690-
return createMappedSRV(R, IS);
689+
if (R.TilesMapped)
690+
return createReservedSRV(R, IS);
691+
return createCommittedSRV(R, IS);
691692
}
692693

693694
// returns the next available HeapIdx
@@ -712,7 +713,7 @@ class DXDevice : public offloadtest::Device {
712713
return HeapIdx;
713714
}
714715

715-
llvm::Expected<ResourceBundle> createUnmappedUAV(Resource &R,
716+
llvm::Expected<ResourceBundle> createReservedUAV(Resource &R,
716717
InvocationState &IS) {
717718
ResourceBundle Bundle;
718719
const uint32_t BufferSize = getUAVBufferSize(R);
@@ -740,8 +741,10 @@ class DXDevice : public offloadtest::Device {
740741
llvm::outs() << "Creating UAV: { Size = " << BufferSize
741742
<< ", Register = u" << R.DXBinding.Register + RegOffset
742743
<< ", Space = " << R.DXBinding.Space
743-
<< ", HasCounter = " << R.HasCounter
744-
<< ", TilesMapped = " << R.TilesMapped << " }\n";
744+
<< ", HasCounter = " << R.HasCounter;
745+
if (R.TilesMapped)
746+
llvm::outs() << ", TilesMapped = " << *R.TilesMapped;
747+
llvm::outs() << " }\n";
745748

746749
// Reserved UAV resource
747750
ComPtr<ID3D12Resource> Buffer;
@@ -776,7 +779,7 @@ class DXDevice : public offloadtest::Device {
776779
return Err;
777780

778781
// Tile mapping setup (optional if NumTiles > 0)
779-
UINT NumTiles = static_cast<UINT>(R.TilesMapped);
782+
UINT NumTiles = static_cast<UINT>(*R.TilesMapped);
780783
ComPtr<ID3D12Heap> Heap; // optional, only created if NumTiles > 0
781784

782785
if (NumTiles > 0) {
@@ -846,8 +849,8 @@ class DXDevice : public offloadtest::Device {
846849
return Bundle;
847850
}
848851

849-
llvm::Expected<ResourceBundle> createFullyMappedUAV(Resource &R,
850-
InvocationState &IS) {
852+
llvm::Expected<ResourceBundle> createCommittedUAV(Resource &R,
853+
InvocationState &IS) {
851854
ResourceBundle Bundle;
852855
const uint32_t BufferSize = getUAVBufferSize(R);
853856

@@ -924,9 +927,9 @@ class DXDevice : public offloadtest::Device {
924927
}
925928

926929
llvm::Expected<ResourceBundle> createUAV(Resource &R, InvocationState &IS) {
927-
if (R.TilesMapped != -1)
928-
return createUnmappedUAV(R, IS);
929-
return createFullyMappedUAV(R, IS);
930+
if (R.TilesMapped)
931+
return createReservedUAV(R, IS);
932+
return createCommittedUAV(R, IS);
930933
}
931934

932935
// returns the next available HeapIdx
@@ -943,8 +946,11 @@ class DXDevice : public offloadtest::Device {
943946
for (const ResourceSet &RS : ResBundle) {
944947
llvm::outs() << "UAV: HeapIdx = " << HeapIdx << " EltSize = " << EltSize
945948
<< " NumElts = " << NumElts
946-
<< " HasCounter = " << R.HasCounter
947-
<< " TilesMapped = " << R.TilesMapped << "\n";
949+
<< " HasCounter = " << R.HasCounter;
950+
if (R.TilesMapped)
951+
llvm::outs() << ", TilesMapped = " << *R.TilesMapped;
952+
llvm::outs() << " }\n";
953+
948954
D3D12_CPU_DESCRIPTOR_HANDLE UAVHandle = UAVHandleHeapStart;
949955
UAVHandle.ptr += HeapIdx * DescHandleIncSize;
950956
ID3D12Resource *CounterBuffer = R.HasCounter ? RS.Buffer.Get() : nullptr;
@@ -959,7 +965,7 @@ class DXDevice : public offloadtest::Device {
959965
return (Sz + 255u) & 0xFFFFFFFFFFFFFF00;
960966
}
961967

962-
llvm::Expected<ResourceBundle> createUnmappedCBV(Resource &R,
968+
llvm::Expected<ResourceBundle> createReservedCBV(Resource &R,
963969
InvocationState &IS) {
964970
ResourceBundle Bundle;
965971

@@ -983,8 +989,10 @@ class DXDevice : public offloadtest::Device {
983989
for (const auto &ResData : R.BufferPtr->Data) {
984990
llvm::outs() << "Creating CBV: { Size = " << BufferSize
985991
<< ", Register = b" << R.DXBinding.Register + RegOffset
986-
<< ", Space = " << R.DXBinding.Space
987-
<< ", TilesMapped = " << R.TilesMapped << " }\n";
992+
<< ", Space = " << R.DXBinding.Space;
993+
if (R.TilesMapped)
994+
llvm::outs() << ", TilesMapped = " << *R.TilesMapped;
995+
llvm::outs() << " }\n";
988996

989997
// Reserved CBV resource
990998
ComPtr<ID3D12Resource> Buffer;
@@ -1008,7 +1016,7 @@ class DXDevice : public offloadtest::Device {
10081016
return Err;
10091017

10101018
// Tile mapping setup (optional if NumTiles > 0)
1011-
UINT NumTiles = static_cast<UINT>(R.TilesMapped);
1019+
UINT NumTiles = static_cast<UINT>(*R.TilesMapped);
10121020
ComPtr<ID3D12Heap> Heap; // optional, only created if NumTiles > 0
10131021

10141022
if (NumTiles > 0) {
@@ -1078,8 +1086,8 @@ class DXDevice : public offloadtest::Device {
10781086
return Bundle;
10791087
}
10801088

1081-
llvm::Expected<ResourceBundle> createFullyMappedCBV(Resource &R,
1082-
InvocationState &IS) {
1089+
llvm::Expected<ResourceBundle> createCommittedCBV(Resource &R,
1090+
InvocationState &IS) {
10831091
ResourceBundle Bundle;
10841092

10851093
const size_t CBVSize = getCBVSize(R.size());
@@ -1147,9 +1155,9 @@ class DXDevice : public offloadtest::Device {
11471155
}
11481156

11491157
llvm::Expected<ResourceBundle> createCBV(Resource &R, InvocationState &IS) {
1150-
if (R.TilesMapped != -1)
1151-
return createUnmappedCBV(R, IS);
1152-
return createFullyMappedCBV(R, IS);
1158+
if (R.TilesMapped)
1159+
return createReservedCBV(R, IS);
1160+
return createCommittedCBV(R, IS);
11531161
}
11541162

11551163
// returns the next available HeapIdx

lib/API/VK/Device.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -776,8 +776,8 @@ class VKDevice : public offloadtest::Device {
776776
std::errc::invalid_argument,
777777
"No RenderTarget buffer specified for graphics pipeline.");
778778
Resource FrameBuffer = {
779-
ResourceKind::Texture2D, "RenderTarget", {}, {},
780-
P.Bindings.RTargetBufferPtr, false};
779+
ResourceKind::Texture2D, "RenderTarget", {}, {},
780+
P.Bindings.RTargetBufferPtr, false, std::nullopt};
781781
IS.FrameBufferResource.Size = P.Bindings.RTargetBufferPtr->size();
782782
IS.FrameBufferResource.BufferPtr = P.Bindings.RTargetBufferPtr;
783783
IS.FrameBufferResource.ImageLayout =
@@ -804,8 +804,8 @@ class VKDevice : public offloadtest::Device {
804804
std::errc::invalid_argument,
805805
"No Vertex buffer specified for graphics pipeline.");
806806
const Resource VertexBuffer = {
807-
ResourceKind::StructuredBuffer, "VertexBuffer", {}, {},
808-
P.Bindings.VertexBufferPtr, false};
807+
ResourceKind::StructuredBuffer, "VertexBuffer", {}, {},
808+
P.Bindings.VertexBufferPtr, false, std::nullopt};
809809
auto ExVHostBuf =
810810
createBuffer(IS, VK_BUFFER_USAGE_TRANSFER_SRC_BIT,
811811
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, VertexBuffer.size(),

test/Feature/HLSLLib/PartiallyMappedResources.test

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ StructuredBuffer<S> Y : register(t1);
1010
RWStructuredBuffer<int> Out : register(u2);
1111
RWStructuredBuffer<int> CAFM : register(u3);
1212

13-
1413
[numthreads(1,1,1)]
1514
void main() {
16-
// 32 S structs inside X or Y occupy 64KB of data. (32 * 512 ints * 4 bytes per int)
15+
// 32 S structs inside X or Y occupy 64KB of data.
16+
// (32 * 512 ints * 4 bytes per int)
1717
// So, any index into the buffer >= [32] will access a new "tile"
1818

1919
int idx = 0;
@@ -54,12 +54,12 @@ Buffers:
5454
Format: Int32
5555
Stride: 2048 # S is 512 ints, 512*4 = 2048.
5656
FillSize: 131072
57-
FillValue: 1
57+
FillValue: 9001
5858
- Name: Y
5959
Format: Int32
6060
Stride: 2048
6161
FillSize: 131072
62-
FillValue: 2
62+
FillValue: 9002
6363
- Name: Out
6464
Format: Int32
6565
Stride: 4
@@ -69,7 +69,7 @@ Buffers:
6969
Stride: 4
7070
# first 4 values are the actual data retrieved. For non-resident loads, 0 is expected.
7171
# last 4 values are the status. 1 is expected for resident memory, 0 for non-resident
72-
Data: [1, 0, 0, 0, 1, 0, 0, 0]
72+
Data: [9001, 0, 0, 0, 1, 0, 0, 0]
7373
- Name: CAFM
7474
Format: Int32
7575
Stride: 4
@@ -124,7 +124,12 @@ DescriptorSets:
124124
Binding: 3
125125
#--- end
126126

127-
# XFAIL: Clang
127+
# Unimplemented https://github.com/llvm/llvm-project/issues/138910
128+
# AND https://github.com/llvm/llvm-project/issues/99204
129+
# XFAIL: Clang
130+
131+
# Unimplemented https://github.com/llvm/llvm-project/issues/138910
132+
# AND https://github.com/llvm/llvm-project/issues/99204
128133
# XFAIL: Vulkan
129134

130135
# RUN: split-file %s %t

0 commit comments

Comments
 (0)