2#include <UnCompute/Backend/BaseTypes.h>
3#include <UnCompute/Backend/IDeviceObject.h>
4#include <UnCompute/Memory/Ptr.h>
9 enum class CommandListState
19 inline const char* CommandListStateToString(CommandListState state)
24 case CommandListState::Initial:
return "CommandListState::Initial";
25 case CommandListState::Recording:
return "CommandListState::Recording";
26 case CommandListState::Executable:
return "CommandListState::Executable";
27 case CommandListState::Pending:
return "CommandListState::Pending";
28 case CommandListState::Invalid:
return "CommandListState::Invalid";
31 assert(
false &&
"CommandListState was unknown");
32 return "CommandListState::<Unknown>";
37 enum class CommandListFlags
40 OneTimeSubmit = UN_BIT(1)
43 UN_ENUM_OPERATORS(CommandListFlags);
48 const char*
Name =
nullptr;
50 CommandListFlags
Flags = CommandListFlags::None;
54 inline CommandListDesc(
const char* name, HardwareQueueKindFlags queueKindFlags,
55 CommandListFlags flags = CommandListFlags::None)
88 enum class AccessFlags
91 KernelRead = UN_BIT(1),
92 KernelWrite = UN_BIT(2),
93 TransferRead = UN_BIT(3),
94 TransferWrite = UN_BIT(4),
99 UN_ENUM_OPERATORS(AccessFlags);
115 HardwareQueueKindFlags sourceQueueKind = HardwareQueueKindFlags::None,
116 HardwareQueueKindFlags destQueueKind = HardwareQueueKindFlags::None)
139 : m_pCommandList(other.m_pCommandList)
141 other.m_pCommandList =
nullptr;
146 m_pCommandList = other.m_pCommandList;
147 other.m_pCommandList =
nullptr;
175 explicit operator bool();
184 virtual void End() = 0;
188 virtual void CmdDispatch(
IKernel* pKernel, Int32 x, Int32 y, Int32 z) = 0;
201 [[nodiscard]]
virtual CommandListState
GetState() = 0;
213 inline CommandListBuilder::CommandListBuilder(
ICommandList* pCommandList)
214 : m_pCommandList(pCommandList)
222 m_pCommandList->End();
223 m_pCommandList =
nullptr;
229 m_pCommandList->CmdMemoryBarrier(pBuffer, barrierDesc);
234 m_pCommandList->CmdCopy(pSource, pDestination, region);
239 m_pCommandList->CmdDispatch(pKernel, x, y, z);
242 inline CommandListBuilder::operator bool()
244 return m_pCommandList !=
nullptr;
247 inline CommandListBuilder::~CommandListBuilder()
254struct fmt::formatter<UN::CommandListState> : fmt::formatter<std::string_view>
256 template<
typename FormatContext>
257 auto format(
const UN::CommandListState& state, FormatContext& ctx)
const ->
decltype(ctx.out())
259 return fmt::format_to(ctx.out(),
"{}", UN::CommandListStateToString(state));
Command list builder, used for device command recording.
Definition: ICommandList.h:131
void Dispatch(IKernel *pKernel, Int32 x, Int32 y, Int32 z)
Dispatch a compute kernel to execute on the device.
Definition: ICommandList.h:237
void Copy(IBuffer *pSource, IBuffer *pDestination, const BufferCopyRegion ®ion)
Copy a region of the source buffer to the destination buffer.
Definition: ICommandList.h:232
void MemoryBarrier(IBuffer *pBuffer, const MemoryBarrierDesc &barrierDesc)
Insert a memory dependency.
Definition: ICommandList.h:227
void End()
Set the command list state to CommandListState::Executable.
Definition: ICommandList.h:218
An interface for backend-specific buffers that store the data on the device.
Definition: IBuffer.h:26
An interface for command lists that record commands to be executed by the backend.
Definition: ICommandList.h:180
virtual ResultCode Submit()=0
Submit the command list and set the state to CommandListState::Pending.
virtual void ResetState()=0
Set the command list state to CommandListState::Initial.
virtual CommandListBuilder Begin()=0
Set the command list state to CommandListState::Recording.
virtual IFence * GetFence()=0
Get the fence that is signaled after submit operation is complete.
virtual CommandListState GetState()=0
Get command list state.
Base interface for all compute backend objects.
Definition: IDeviceObject.h:30
An interface for fences - synchronization primitives that can be either signaled or reset.
Definition: IFence.h:31
An interface for compute kernel - a program running on the device.
Definition: IKernel.h:29
Region for buffer copy command.
Definition: ICommandList.h:65
UInt64 Size
Size of the copy region.
Definition: ICommandList.h:66
UInt32 DestOffset
Offset in the destination buffer.
Definition: ICommandList.h:68
UInt32 SourceOffset
Offset in the source buffer.
Definition: ICommandList.h:67
Command list descriptor.
Definition: ICommandList.h:47
const char * Name
Command list debug name.
Definition: ICommandList.h:48
HardwareQueueKindFlags QueueKindFlags
Command queue kind flags.
Definition: ICommandList.h:49
CommandListFlags Flags
Command list flags.
Definition: ICommandList.h:50
Memory barrier descriptor.
Definition: ICommandList.h:105
HardwareQueueKindFlags DestQueueKind
Destination command queue kind.
Definition: ICommandList.h:110
AccessFlags SourceAccess
Source access mask.
Definition: ICommandList.h:106
AccessFlags DestAccess
Destination access mask.
Definition: ICommandList.h:107
HardwareQueueKindFlags SourceQueueKind
Source command queue kind.
Definition: ICommandList.h:109