Skip to content

Commit eb9f4f2

Browse files
Merge pull request o3de#17581 from jhmueller-huawei/multi-device-resources-dispatchitem-fence-fixes
Multi-device resources: DispatchItem and Fence fixes
2 parents d3517fd + 689360b commit eb9f4f2

File tree

3 files changed

+11
-64
lines changed

3 files changed

+11
-64
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,17 @@ namespace AZ::RHI
100100
return m_deviceDispatchItems.at(deviceIndex);
101101
}
102102

103+
//! Retrieve arguments specifing a dispatch type.
104+
const MultiDeviceDispatchArguments& GetArguments() const
105+
{
106+
return m_arguments;
107+
}
108+
103109
//! Arguments specific to a dispatch type.
104110
void SetArguments(const MultiDeviceDispatchArguments& arguments)
105111
{
112+
m_arguments = arguments;
113+
106114
for (auto& [deviceIndex, dispatchItem] : m_deviceDispatchItems)
107115
{
108116
dispatchItem.m_arguments = arguments.GetDeviceDispatchArguments(deviceIndex);
@@ -162,6 +170,8 @@ namespace AZ::RHI
162170
private:
163171
//! A DeviceMask denoting on which devices a device-specific DispatchItem should be generated
164172
MultiDevice::DeviceMask m_deviceMask{ MultiDevice::DefaultDevice };
173+
//! Caching the arguments for the corresponding getter.
174+
MultiDeviceDispatchArguments m_arguments;
165175
//! A map of all device-specific DispatchItem, indexed by the device index
166176
AZStd::unordered_map<int, DispatchItem> m_deviceDispatchItems;
167177
};

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

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,28 +29,18 @@ namespace AZ::RHI
2929
//! passes on the initial FenceState to each Fence
3030
ResultCode Init(MultiDevice::DeviceMask deviceMask, FenceState initialState);
3131

32-
//! Waits on m_waitThread and shuts down all device-specific fences.
32+
//! Shuts down all device-specific fences.
3333
void Shutdown() override final;
3434

3535
//! Signals the device-specific fences managed by this class
3636
RHI::ResultCode SignalOnCpu();
3737

38-
//! Waits (blocks) for all device-specific fences managed by this class
39-
RHI::ResultCode WaitOnCpu() const;
40-
4138
//! Resets the device-specific fences.
4239
RHI::ResultCode Reset();
4340

4441
using SignalCallback = AZStd::function<void()>;
4542

46-
//! Spawns a dedicated thread to wait on all device-specific fences. The provided callback
47-
//! is invoked when the fences complete.
48-
ResultCode WaitOnCpuAsync(SignalCallback callback);
49-
5043
protected:
5144
bool ValidateIsInitialized() const;
52-
53-
//! This can be used to asynchronously wait on all fences by calling WaitOnCpuAsync
54-
AZStd::thread m_waitThread;
5545
};
5646
} // namespace AZ::RHI

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

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,6 @@ namespace AZ::RHI
6969
{
7070
if (IsInitialized())
7171
{
72-
if (m_waitThread.joinable())
73-
{
74-
m_waitThread.join();
75-
}
76-
7772
IterateObjects<Fence>([]([[maybe_unused]] auto deviceIndex, auto deviceFence)
7873
{
7974
deviceFence->Shutdown();
@@ -96,54 +91,6 @@ namespace AZ::RHI
9691
});
9792
}
9893

99-
ResultCode MultiDeviceFence::WaitOnCpu() const
100-
{
101-
if (!ValidateIsInitialized())
102-
{
103-
return ResultCode::InvalidOperation;
104-
}
105-
106-
return IterateObjects<Fence>([]([[maybe_unused]] auto deviceIndex, auto deviceFence)
107-
{
108-
return deviceFence->WaitOnCpu();
109-
});
110-
}
111-
112-
ResultCode MultiDeviceFence::WaitOnCpuAsync(SignalCallback callback)
113-
{
114-
if (!ValidateIsInitialized())
115-
{
116-
return ResultCode::InvalidOperation;
117-
}
118-
119-
if (!callback)
120-
{
121-
AZ_Error("MultiDeviceFence", false, "Callback is null.");
122-
return ResultCode::InvalidOperation;
123-
}
124-
125-
if (m_waitThread.joinable())
126-
{
127-
m_waitThread.join();
128-
}
129-
130-
AZStd::thread_desc threadDesc{ "MultiDeviceFence WaitOnCpu Thread" };
131-
132-
m_waitThread = AZStd::thread(
133-
threadDesc,
134-
[this, callback]()
135-
{
136-
ResultCode resultCode = WaitOnCpu();
137-
if (resultCode != ResultCode::Success)
138-
{
139-
AZ_Error("MultiDeviceFence", false, "Failed to call WaitOnCpu in async thread.");
140-
}
141-
callback();
142-
});
143-
144-
return ResultCode::Success;
145-
}
146-
14794
ResultCode MultiDeviceFence::Reset()
14895
{
14996
if (!ValidateIsInitialized())

0 commit comments

Comments
 (0)