Skip to content

Commit 724286d

Browse files
Fixes to MultiDeviceRayTracingTlas and MultiDeviceDrawPacket (o3de#17486)
Fixes to MDRT and MDDP Signed-off-by: Martin Winter <[email protected]> Signed-off-by: Joerg H. Mueller <[email protected]> Co-authored-by: Joerg H. Mueller <[email protected]>
1 parent a345dfb commit 724286d

File tree

5 files changed

+33
-25
lines changed

5 files changed

+33
-25
lines changed

Gems/Atom/RHI/Code/Include/Atom/RHI/MultiDeviceDrawItem.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@ namespace AZ::RHI
9090

9191
MultiDeviceDrawItem(MultiDevice::DeviceMask deviceMask, AZStd::unordered_map<int, DrawItem*>&& deviceDrawItemPtrs);
9292

93+
MultiDeviceDrawItem(const MultiDeviceDrawItem& other) = delete;
94+
MultiDeviceDrawItem(MultiDeviceDrawItem&& other) = default;
95+
96+
MultiDeviceDrawItem& operator=(const MultiDeviceDrawItem& other) = delete;
97+
MultiDeviceDrawItem& operator=(MultiDeviceDrawItem&& other) = default;
98+
9399
//! Returns the device-specific DrawItem for the given index
94100
const DrawItem& GetDeviceDrawItem(int deviceIndex) const
95101
{

Gems/Atom/RHI/Code/Include/Atom/RHI/MultiDeviceDrawPacketBuilder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace AZ::RHI
3030
MultiDeviceDrawRequest() = default;
3131

3232
//! Returns the device-specific DrawRequest for the given index
33-
DrawPacketBuilder::DrawRequest BuildDeviceDrawRequest(int deviceIndex);
33+
DrawPacketBuilder::DrawRequest GetDeviceDrawRequest(int deviceIndex);
3434

3535
//! The filter tag used to direct the draw item.
3636
DrawListTag m_listTag;

Gems/Atom/RHI/Code/Source/RHI/MultiDeviceDrawPacketBuilder.cpp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616

1717
namespace AZ::RHI
1818
{
19-
DrawPacketBuilder::DrawRequest MultiDeviceDrawPacketBuilder::MultiDeviceDrawRequest::BuildDeviceDrawRequest(int deviceIndex)
19+
DrawPacketBuilder::DrawRequest MultiDeviceDrawPacketBuilder::MultiDeviceDrawRequest::
20+
GetDeviceDrawRequest(int deviceIndex)
2021
{
2122
if (!m_deviceStreamBufferViews.contains(deviceIndex))
2223
{
@@ -28,14 +29,14 @@ namespace AZ::RHI
2829
}
2930
m_deviceStreamBufferViews.emplace(deviceIndex, AZStd::move(deviceStreamBufferView));
3031
}
31-
32-
return { m_listTag,
33-
m_stencilRef,
34-
m_deviceStreamBufferViews.at(deviceIndex),
35-
m_uniqueShaderResourceGroup ? m_uniqueShaderResourceGroup->GetDeviceShaderResourceGroup(deviceIndex).get() : nullptr,
36-
m_pipelineState ? m_pipelineState->GetDevicePipelineState(deviceIndex).get() : nullptr,
37-
m_sortKey,
38-
m_drawFilterMask };
32+
return DrawPacketBuilder::DrawRequest{
33+
m_listTag,
34+
m_stencilRef,
35+
m_deviceStreamBufferViews.at(deviceIndex),
36+
m_uniqueShaderResourceGroup ? m_uniqueShaderResourceGroup->GetDeviceShaderResourceGroup(deviceIndex).get() : nullptr,
37+
m_pipelineState ? m_pipelineState->GetDevicePipelineState(deviceIndex).get() : nullptr,
38+
m_sortKey,
39+
m_drawFilterMask };
3940
}
4041

4142
void MultiDeviceDrawPacketBuilder::Begin(IAllocator* allocator)
@@ -122,7 +123,7 @@ namespace AZ::RHI
122123
m_drawPacketInFlight->m_drawListMask.set(request.m_listTag.GetIndex());
123124
for (auto& [deviceIndex, deviceDrawPacketBuilder] : m_deviceDrawPacketBuilders)
124125
{
125-
deviceDrawPacketBuilder.AddDrawItem(request.BuildDeviceDrawRequest(deviceIndex));
126+
deviceDrawPacketBuilder.AddDrawItem(m_drawRequests.back().GetDeviceDrawRequest(deviceIndex));
126127
}
127128
}
128129
else
@@ -149,12 +150,12 @@ namespace AZ::RHI
149150
m_drawPacketInFlight->m_drawItems.reserve(m_drawRequests.size());
150151

151152
// Setup single-device DrawItems
152-
for (auto i{ 0 }; i < m_drawRequests.size(); ++i)
153+
for (auto drawItemIndex{ 0 }; drawItemIndex < m_drawRequests.size(); ++drawItemIndex)
153154
{
154155
AZStd::unordered_map<int, DrawItem*> deviceDrawItemPtrs;
155156
for (auto& [deviceIndex, deviceDrawPacketBuilder] : m_deviceDrawPacketBuilders)
156157
{
157-
deviceDrawItemPtrs.emplace(deviceIndex, m_drawPacketInFlight->m_deviceDrawPackets[deviceIndex]->GetDrawItem(0));
158+
deviceDrawItemPtrs.emplace(deviceIndex, m_drawPacketInFlight->m_deviceDrawPackets[deviceIndex]->GetDrawItem(drawItemIndex));
158159
}
159160
m_drawPacketInFlight->m_drawItems.emplace_back(MultiDeviceDrawItem{ m_deviceMask, AZStd::move(deviceDrawItemPtrs) });
160161
}
@@ -207,12 +208,12 @@ namespace AZ::RHI
207208
}
208209

209210
// Setup single-device DrawItems
210-
for (auto i{ 0 }; i < drawRequestCount; ++i)
211+
for (auto drawItemIndex{ 0 }; drawItemIndex < drawRequestCount; ++drawItemIndex)
211212
{
212213
AZStd::unordered_map<int, DrawItem*> deviceDrawItemPtrs;
213214
for (auto& [deviceIndex, deviceDrawPacketBuilder] : m_deviceDrawPacketBuilders)
214215
{
215-
deviceDrawItemPtrs.emplace(deviceIndex, m_drawPacketInFlight->m_deviceDrawPackets[deviceIndex]->GetDrawItem(0));
216+
deviceDrawItemPtrs.emplace(deviceIndex, m_drawPacketInFlight->m_deviceDrawPackets[deviceIndex]->GetDrawItem(drawItemIndex));
216217
}
217218
m_drawPacketInFlight->m_drawItems.emplace_back(MultiDeviceDrawItem{ m_deviceMask, AZStd::move(deviceDrawItemPtrs) });
218219
}

Gems/Atom/RHI/Code/Source/RHI/MultiDeviceRayTracingAccelerationStructure.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,6 @@ namespace AZ::RHI
7373

7474
RayTracingTlasDescriptor MultiDeviceRayTracingTlasDescriptor::GetDeviceRayTracingTlasDescriptor(int deviceIndex) const
7575
{
76-
AZ_Assert(m_mdInstancesBuffer, "No MultiDeviceBuffer available!\n");
77-
7876
RayTracingTlasDescriptor descriptor;
7977

8078
for (const auto& instance : m_mdInstances)
@@ -237,16 +235,19 @@ namespace AZ::RHI
237235

238236
MultiDeviceObject::Init(deviceMask);
239237

240-
ResultCode resultCode = IterateObjects<RayTracingTlas>(
241-
[this, &descriptor, &rayTracingBufferPools](int deviceIndex, auto deviceRayTracingTlas)
238+
ResultCode resultCode{ResultCode::Success};
239+
IterateDevices(
240+
[this, &descriptor, &rayTracingBufferPools, &resultCode](int deviceIndex)
242241
{
243242
auto device = RHISystemInterface::Get()->GetDevice(deviceIndex);
244-
this->m_deviceObjects[deviceIndex] = Factory::Get().CreateRayTracingTlas();
243+
auto deviceRayTracingTlas{Factory::Get().CreateRayTracingTlas()};
244+
this->m_deviceObjects[deviceIndex] = deviceRayTracingTlas;
245245

246246
auto deviceDescriptor{ descriptor->GetDeviceRayTracingTlasDescriptor(deviceIndex) };
247247

248-
return deviceRayTracingTlas->CreateBuffers(
248+
resultCode = deviceRayTracingTlas->CreateBuffers(
249249
*device, &deviceDescriptor, *rayTracingBufferPools.GetDeviceRayTracingBufferPools(deviceIndex).get());
250+
return resultCode == ResultCode::Success;
250251
});
251252

252253
if (resultCode != ResultCode::Success)
@@ -277,11 +278,11 @@ namespace AZ::RHI
277278
if (!tlasBuffer->m_deviceObjects[deviceIndex])
278279
{
279280
tlasBuffer = nullptr;
280-
return false;
281+
return ResultCode::Fail;
281282
}
282283

283284
tlasBuffer->SetDescriptor(tlasBuffer->GetDeviceBuffer(deviceIndex)->GetDescriptor());
284-
return true;
285+
return ResultCode::Success;
285286
});
286287

287288
return tlasBuffer;

Gems/Atom/RPI/Code/Source/RPI.Public/DynamicDraw/DynamicDrawContext.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ namespace AZ
546546
drawItem.m_stencilRef = m_stencilRef;
547547

548548
drawItemInfo.m_sortKey = m_sortKey++;
549-
m_cachedDrawItems.emplace_back(drawItemInfo);
549+
m_cachedDrawItems.emplace_back(AZStd::move(drawItemInfo));
550550
}
551551

552552
void DynamicDrawContext::DrawLinear(const void* vertexData, uint32_t vertexCount, Data::Instance<ShaderResourceGroup> drawSrg)
@@ -632,7 +632,7 @@ namespace AZ
632632
}
633633

634634
drawItemInfo.m_sortKey = m_sortKey++;
635-
m_cachedDrawItems.emplace_back(drawItemInfo);
635+
m_cachedDrawItems.emplace_back(AZStd::move(drawItemInfo));
636636
}
637637

638638
Data::Instance<ShaderResourceGroup> DynamicDrawContext::NewDrawSrg()

0 commit comments

Comments
 (0)