Skip to content

Commit

Permalink
Updated definition of secondary command buffers.
Browse files Browse the repository at this point in the history
Secondary command buffers in Vulkan are limited compared to primary command buffers and implemented as bundles in D3D12 they are even more limited.
This new definition uses the least common denominator and restricts secondary command buffers in LLGL to a small set of commands.
They cannot start their own render pass and cannot use any of the copy or update commands (UpdateBuffer is not allowed while SetUniforms can still be used).

This will also require the D3D11 backend to implement a deferred command buffer similar to GL, except that only a subset of commands must be implemented.
Deferred and multi-submit primary command buffers can still benefit from D3D11's deferred command lists.
  • Loading branch information
LukasBanana committed May 29, 2024
1 parent cda7392 commit 347d0e4
Show file tree
Hide file tree
Showing 18 changed files with 132 additions and 74 deletions.
2 changes: 1 addition & 1 deletion include/LLGL-C/CommandBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

LLGL_C_EXPORT void llglBegin(LLGLCommandBuffer commandBuffer);
LLGL_C_EXPORT void llglEnd();
LLGL_C_EXPORT void llglExecute(LLGLCommandBuffer deferredCommandBuffer);
LLGL_C_EXPORT void llglExecute(LLGLCommandBuffer secondaryCommandBuffer);
LLGL_C_EXPORT void llglUpdateBuffer(LLGLBuffer dstBuffer, uint64_t dstOffset, const void* data, uint16_t dataSize);
LLGL_C_EXPORT void llglCopyBuffer(LLGLBuffer dstBuffer, uint64_t dstOffset, LLGLBuffer srcBuffer, uint64_t srcOffset, uint64_t size);
LLGL_C_EXPORT void llglCopyBufferFromTexture(LLGLBuffer dstBuffer, uint64_t dstOffset, LLGLTexture srcTexture, const LLGLTextureRegion* srcRegion, uint32_t rowStride, uint32_t layerStride);
Expand Down
2 changes: 1 addition & 1 deletion include/LLGL/Backend/CommandBuffer.Encoding.inl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ virtual void End(
) override final;

virtual void Execute(
LLGL::CommandBuffer& deferredCommandBuffer
LLGL::CommandBuffer& secondaryCommandBuffer
) override final;


Expand Down
6 changes: 3 additions & 3 deletions include/LLGL/CommandBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,16 @@ class LLGL_EXPORT CommandBuffer : public RenderSystemChild
virtual void End() = 0;

/**
\brief Executes the specified deferred command buffer.
\param[in] deferredCommandBuffer Specifies the deferred command buffer which is meant to be executed.
\brief Executes the specified secondary command buffer by inlining its commands into this command buffer.
\param[in] secondaryCommandBuffer Specifies the secondary command buffer which is meant to be inlined.
This command buffer must have been created with the CommandBufferFlags::Secondary flag.
\remarks This function can only be used by primary command buffers, i.e. command buffers that have \e not been created with the flag CommandBufferFlags::Secondary.
\remarks Once this command buffer is submitted for execution to one or more primary command buffers,
it <b>must not</b> be updated unless all of such primary command buffers are also updated before their next submission to the command queue.
\see CommandBufferFlags
\todo Incomplete for: D3D12, Vulkan, Metal.
*/
virtual void Execute(CommandBuffer& deferredCommandBuffer) = 0;
virtual void Execute(CommandBuffer& secondaryCommandBuffer) = 0;

/* ----- Blitting ----- */

Expand Down
10 changes: 9 additions & 1 deletion include/LLGL/CommandBufferFlags.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,17 @@ struct CommandBufferFlags
enum
{
/**
\brief Specifies that the encoded command buffer will be submitted as a secondary command buffer.
\brief Specifies that the command buffer will be submitted as a secondary command buffer which yields only a limited set of commands.
\remarks If this is specified, the command buffer must be submitted using the \c Execute function of a primary command buffer.
\remarks This cannot be used in combination with the \c ImmediateSubmit flag.
\remarks A secondary command buffer can only encode a limited set of commands and cannot start its own render pass.
If used for graphics commands, those commands will be inlined into the render pass of its primary command buffer when submitted via the \c Execute function.
Here is a list of commands that can be encoded with a secondary command buffer (\c Begin/\c End is implied):
- Setting vertex- and index buffers (CommandBuffer::SetVertexBuffer, CommandBuffer::SetVertexBufferArray, and CommandBuffer::SetIndexBuffer)
- Setting resources (CommandBuffer::SetResourceHeap and CommandBuffer::SetResource)
- Setting pipeline states (CommandBuffer::SetPipelineState, CommandBuffer::SetBlendFactor, CommandBuffer::SetStencilReference, and CommandBuffer::SetUniforms)
- Draw commands (CommandBuffer::Draw, CommandBuffer::DrawIndexed, CommandBuffer::DrawInstanced, CommandBuffer::DrawIndexedInstanced, CommandBuffer::DrawIndirect, and CommandBuffer::DrawIndexedIndirect)
- Compute commands (CommandBuffer::Dispatch, CommandBuffer::DispatchIndirect)
\see CommandBuffer::Execute
\see CommandBufferDescriptor::renderPass
*/
Expand Down
Loading

0 comments on commit 347d0e4

Please sign in to comment.