Record and submit commands using DkCmdBuf
masterCommand buffers (DkCmdBuf) are used to record command lists that are later submitted to a DkQueue.
Workflow
- Create a
DkCmdBufusingDkCmdBufMaker. - Provide backing memory via
dkCmdBufAddMemory. This memory must be aligned toDK_CMDMEM_ALIGNMENTand its size must be a multiple ofDK_CMDMEM_ALIGNMENT. It is recommended to useDkMemBlockFlags_GpuCached | DkMemBlockFlags_CpuUncached. - Record commands. If the buffer runs out of space, the
cbAddMemcallback in the maker can be used to dynamically add more memory. - Finalize the list with
dkCmdBufFinishList, which returns aDkCmdListhandle. - Submit the list to a queue using
dkQueueSubmitCommands. - Use
dkCmdBufClearto destroy all recorded command lists and reset the buffer.
Advanced Features
- Command List Reuse: Use
dkCmdBufCallListto insert a previously recordedDkCmdListinto the current buffer. This allows for efficient sub-command reuse. - Multithreading:
DkCmdBufobjects are externally synchronized. You should use one command buffer per worker thread and collect the resultingDkCmdListhandles in the main thread for submission.
Memory Requirements
Memory added via dkCmdBufAddMemory must have CPU-side cache disabled.
typedef void (*DkCmdBufAddMemFunc)(void* userData, DkCmdBuf cmdbuf, size_t minReqSize);
struct DkCmdBufMaker
{
DkDevice device;
void* userData;
DkCmdBufAddMemFunc cbAddMem;
};
void dkCmdBufMakerDefaults(DkCmdBufMaker* maker, DkDevice device);
DkCmdBuf dkCmdBufCreate(DkCmdBufMaker const* maker);
void dkCmdBufDestroy(DkCmdBuf obj);
void dkCmdBufAddMemory(DkCmdBuf obj, DkMemBlock mem, uint32_t offset, uint32_t size);
DkCmdList dkCmdBufFinishList(DkCmdBuf obj);
void dkCmdBufClear(DkCmdBuf obj);
void dkCmdBufCallList(DkCmdBuf obj, DkCmdList list);