Skip to content

Commit a2ba2d4

Browse files
Minor fixes based on PR feedback
1 parent 55f1b53 commit a2ba2d4

2 files changed

Lines changed: 40 additions & 26 deletions

File tree

lib/API/DX/Device.cpp

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,14 @@ static BufferUsage bufferUsageFromResourceKind(ResourceKind Kind) {
157157
case ResourceKind::ConstantBuffer:
158158
return BufferUsage::ConstantBuffer;
159159
break;
160-
default:
160+
case ResourceKind::Texture2D:
161+
case ResourceKind::RWTexture2D:
162+
case ResourceKind::Sampler:
163+
case ResourceKind::SampledTexture2D:
164+
case ResourceKind::AccelerationStructure:
161165
llvm_unreachable("Invalid case, ResourceKind is not a buffer.");
162166
}
167+
llvm_unreachable("All ResourceKind cases handled");
163168
}
164169

165170
static BufferShaderAccessType bufferShaderAccessTypeFromResourceKind(
@@ -186,10 +191,15 @@ static BufferShaderAccessType bufferShaderAccessTypeFromResourceKind(
186191
case ResourceKind::RWByteAddressBuffer:
187192
case ResourceKind::ConstantBuffer:
188193
return BufferShaderAccessType::Raw;
189-
default:
194+
case ResourceKind::Texture2D:
195+
case ResourceKind::RWTexture2D:
196+
case ResourceKind::Sampler:
197+
case ResourceKind::SampledTexture2D:
198+
case ResourceKind::AccelerationStructure:
190199
llvm_unreachable(
191200
"Invalid case, non-buffers should have been filtered out.");
192201
}
202+
llvm_unreachable("All ResourceKind cases handled");
193203
}
194204

195205
namespace {
@@ -596,28 +606,30 @@ class DXCommandBuffer : public offloadtest::CommandBuffer {
596606
D3D12_RESOURCE_STATES StateBefore,
597607
D3D12_RESOURCE_STATES StateAfter) {
598608

599-
for (size_t I = 0, N = PendingTransitions.size(); I < N; ++I) {
600-
auto &Trans = PendingTransitions[I];
601-
if (Trans.Transition.pResource == Resource) {
602-
assert(StateBefore == Trans.Transition.StateAfter);
603-
604-
if (StateAfter == Trans.Transition.StateBefore) {
605-
// We actually need the resource to be in the original state!
606-
// Remove the transition from the list of Pending Transitions.
607-
PendingTransitions.erase(PendingTransitions.begin() + I);
608-
609-
// NOTE: This could cause an execution barrier issue since legacy
610-
// barriers don't allow us to express execution barriers, cache
611-
// flushes, and layout transitions separately.
612-
// As a workaround we add a UAV barrier so an execution barrier and
613-
// cache flush is inserted.
614-
addPendingUAVBarrier();
615-
} else {
616-
Trans.Transition.StateAfter = StateAfter;
617-
}
609+
for (auto TransIt = PendingTransitions.begin(),
610+
End = PendingTransitions.end();
611+
TransIt != End; ++TransIt) {
612+
if (TransIt->Transition.pResource != Resource)
613+
continue;
614+
615+
assert(StateBefore == TransIt->Transition.StateAfter);
618616

619-
return;
617+
if (StateAfter == TransIt->Transition.StateBefore) {
618+
// We actually need the resource to be in the original state!
619+
// Remove the transition from the list of Pending Transitions.
620+
PendingTransitions.erase(TransIt);
621+
622+
// NOTE: This could cause an execution barrier issue since legacy
623+
// barriers don't allow us to express execution barriers, cache
624+
// flushes, and layout transitions separately.
625+
// As a workaround we add a UAV barrier so an execution barrier and
626+
// cache flush is inserted.
627+
addPendingUAVBarrier();
628+
} else {
629+
TransIt->Transition.StateAfter = StateAfter;
620630
}
631+
632+
return;
621633
}
622634

623635
PendingTransitions.push_back(CD3DX12_RESOURCE_BARRIER::Transition(
@@ -1895,7 +1907,7 @@ class DXDevice : public offloadtest::Device {
18951907
Tex->DSVHandle);
18961908
}
18971909

1898-
return std::move(Tex);
1910+
return Tex;
18991911
}
19001912

19011913
uint32_t getTextureUploadRowStrideInBytes(
@@ -2577,7 +2589,9 @@ class DXDevice : public offloadtest::Device {
25772589
std::errc::value_too_large,
25782590
"Root descriptor cannot refer to resource arrays.");
25792591

2580-
if (!RootDescIt->second.back().Buffer) {
2592+
const DXBuffer *BufferDX =
2593+
llvm::cast_if_present<DXBuffer>(RootDescIt->second.back().Buffer);
2594+
if (!BufferDX) {
25812595
return llvm::createStringError(
25822596
std::errc::value_too_large,
25832597
"Root descriptor can only refer to buffers.");
@@ -2586,7 +2600,7 @@ class DXDevice : public offloadtest::Device {
25862600
const auto &BufferDX =
25872601
llvm::cast<DXBuffer>(*RootDescIt->second.back().Buffer);
25882602
const D3D12_GPU_VIRTUAL_ADDRESS VirtualAddress =
2589-
BufferDX.Buffer->GetGPUVirtualAddress();
2603+
BufferDX->Buffer->GetGPUVirtualAddress();
25902604
switch (getDescriptorKind(RootDescIt->first->Kind)) {
25912605
case DescriptorKind::SRV:
25922606
IS.CB->CmdList->SetComputeRootShaderResourceView(RootParamIndex++,

lib/API/MTL/MTLDevice.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1477,7 +1477,7 @@ class MTLDevice : public offloadtest::Device {
14771477
for (const auto &Inst : R.first->TLASPtr->Instances)
14781478
Contributions.push_back(Inst.InstanceContributionToHitGroupIndex &
14791479
0xFFFFFFu);
1480-
const BufferCreateDesc Desc = DescBufferCreateDesc::uploadBuffer();
1480+
const BufferCreateDesc Desc = BufferCreateDesc::uploadBuffer();
14811481
auto ContribBufOrErr = createBufferWithData(
14821482
*IS.CB->Dev, "AS-Contributions", Desc, Contributions.data(),
14831483
InstCount * sizeof(uint32_t), nullptr, nullptr);

0 commit comments

Comments
 (0)