|
ObjectivelyGPU
Object oriented graphics framework for SDL3 and C
|
A recorded sequence of GPU commands for a single frame. More...
#include <CommandBuffer.h>
Public Member Functions | |
| bool | acquireSwapchainTexture (const CommandBuffer *self, SwapchainTexture *swapchain) |
| Acquires the next swapchain texture for rendering. | |
| ComputePass * | beginComputePass (CommandBuffer *self, const SDL_GPUStorageTextureReadWriteBinding *storageTextures, Uint32 numStorageTextures, const SDL_GPUStorageBufferReadWriteBinding *storageBuffers, Uint32 numStorageBuffers) |
| Begins a compute pass and returns a retained ComputePass. | |
| CopyPass * | beginCopyPass (CommandBuffer *self) |
| Begins a copy pass and returns a retained CopyPass. | |
| RenderPass * | beginRenderPass (CommandBuffer *self, const SDL_GPUColorTargetInfo *colorTargets, Uint32 numColorTargets, const SDL_GPUDepthStencilTargetInfo *depthStencil) |
| Begins a render pass and returns a retained RenderPass. | |
| RenderPass * | beginRenderPassWithFramebuffer (CommandBuffer *self, const Framebuffer *framebuffer, SDL_GPULoadOp loadOp, SDL_GPUStoreOp storeOp) |
Begins a render pass over all of framebuffer's color targets and its depth target (if any), using its own clear color(s) and clear depth when loadOp is SDL_GPU_LOADOP_CLEAR. | |
| void | blitTexture (const CommandBuffer *self, const SDL_GPUBlitInfo *info) |
| Blits a region of one texture to another. | |
| bool | cancel (CommandBuffer *self) |
| Cancels this command buffer without submitting it to the GPU. | |
| void | generateMipmaps (const CommandBuffer *self, SDL_GPUTexture *texture) |
| Records a mipmap generation command for the given texture. | |
| CommandBuffer * | initWithCommandBuffer (CommandBuffer *self, const RenderDevice *device, SDL_GPUCommandBuffer *commands) |
| void | insertDebugLabel (const CommandBuffer *self, const char *text) |
| Inserts an arbitrary debug label into the command stream. | |
| void | popDebugGroup (const CommandBuffer *self) |
| Ends the innermost active debug group. | |
| void | pushComputeUniformData (const CommandBuffer *self, Uint32 slot, const void *data, Uint32 length) |
| Pushes uniform data for the current compute shader. | |
| void | pushDebugGroup (const CommandBuffer *self, const char *name) |
| Begins a named debug group in the command stream. | |
| void | pushFragmentUniformData (const CommandBuffer *self, Uint32 slot, const void *data, Uint32 length) |
| Pushes uniform data for the current fragment shader. | |
| void | pushVertexUniformData (const CommandBuffer *self, Uint32 slot, const void *data, Uint32 length) |
| Pushes uniform data for the current vertex shader. | |
| void | pushUniformData (const CommandBuffer *self, Uint32 slot, const void *data, Uint32 length) |
Pushes the same uniform data to slot for both the current vertex and fragment shaders. | |
| bool | submit (CommandBuffer *self) |
| Submits this command buffer to the GPU for execution. | |
| Fence * | submitAndFence (CommandBuffer *self) |
| Submits this command buffer and returns a Fence for GPU completion. | |
| bool | waitAndAcquireSwapchainTexture (const CommandBuffer *self, SwapchainTexture *swapchain) |
| Blocks until a swapchain texture is available, then acquires it. | |
| Class * | _CommandBuffer (void) |
| The CommandBuffer archetype. | |
| CommandBuffer * | initWithCommandBuffer (CommandBuffer *self, const RenderDevice *device, *SDL_GPUCommandBuffer *commands) |
| Initializes this CommandBuffer wrapping the given SDL command buffer. | |
Data Fields | |
| Object | object |
| The superclass. | |
| SDL_GPUCommandBuffer * | commands |
| The underlying SDL command buffer. | |
| RenderDevice * | device |
| The RenderDevice that this CommandBuffer belongs to. | |
| ident | data |
| User data. | |
Protected Attributes | |
| CommandBufferInterface * | interface |
| The interface. | |
A recorded sequence of GPU commands for a single frame.
CommandBuffer is a lightweight wrapper around SDL_GPUCommandBuffer. Obtain one from RenderDevice::acquireCommandBuffer each frame. The three begin*Pass factory methods return the appropriate pass object; releasing the pass ends it, ready for the next pass or submission.
Submit or cancel the buffer with submit, submitAndFence, or cancel. Releasing a CommandBuffer without submitting or cancelling it is an error.
| Class * _CommandBuffer | ( | void | ) |
The CommandBuffer archetype.
| bool acquireSwapchainTexture | ( | const CommandBuffer * | self, |
| SwapchainTexture * | swapchain | ||
| ) |
Acquires the next swapchain texture for rendering.
Returns false (without asserting) when the window is minimised, too many frames are in flight, or the swapchain is temporarily unavailable; SDL reports those cases as success with a NULL texture, which MUST NOT be passed back into SDL, so they are reported here as failure and swapchain is zeroed. The caller should skip presenting for that frame.
| self | The CommandBuffer. |
| swapchain | Output structure populated with the texture and dimensions, or zeroed. |
| ComputePass * beginComputePass | ( | CommandBuffer * | self, |
| const SDL_GPUStorageTextureReadWriteBinding * | storageTextures, | ||
| Uint32 | numStorageTextures, | ||
| const SDL_GPUStorageBufferReadWriteBinding * | storageBuffers, | ||
| Uint32 | numStorageBuffers | ||
| ) |
Begins a compute pass and returns a retained ComputePass.
The returned ComputePass must be released when compute work is complete. Releasing it calls SDL_EndGPUComputePass automatically.
| self | The CommandBuffer. |
| storageTextures | Read-write storage texture bindings, or NULL. |
| numStorageTextures | Number of storage texture bindings. |
| storageBuffers | Read-write storage buffer bindings, or NULL. |
| numStorageBuffers | Number of storage buffer bindings. |
| CopyPass * beginCopyPass | ( | CommandBuffer * | self | ) |
Begins a copy pass and returns a retained CopyPass.
The returned CopyPass must be released when all transfers are complete. Releasing it calls SDL_EndGPUCopyPass automatically.
| self | The CommandBuffer. |
| RenderPass * beginRenderPass | ( | CommandBuffer * | self, |
| const SDL_GPUColorTargetInfo * | colorTargets, | ||
| Uint32 | numColorTargets, | ||
| const SDL_GPUDepthStencilTargetInfo * | depthStencil | ||
| ) |
Begins a render pass and returns a retained RenderPass.
The returned RenderPass must be released when all draw calls are recorded. Releasing it calls SDL_EndGPURenderPass automatically.
| self | The CommandBuffer. |
| colorTargets | Array of color target infos. |
| numColorTargets | Number of color targets. |
| depthStencil | Depth-stencil target info, or NULL. |
| RenderPass * beginRenderPassWithFramebuffer | ( | CommandBuffer * | self, |
| const Framebuffer * | framebuffer, | ||
| SDL_GPULoadOp | loadOp, | ||
| SDL_GPUStoreOp | storeOp | ||
| ) |
Begins a render pass over all of framebuffer's color targets and its depth target (if any), using its own clear color(s) and clear depth when loadOp is SDL_GPU_LOADOP_CLEAR.
Convenience for the common case of "render into this framebuffer" with a single load/store op shared by every target. For a mix of load ops across targets, per-target clear overrides, a query pool, or a subset of a framebuffer's targets (e.g. a depth-only pass), build the target infos yourself via Framebuffer::colorTargetInfo/depthTargetInfo and call beginRenderPass directly.
| self | The CommandBuffer. |
| framebuffer | The Framebuffer to render into. |
| loadOp | Load operation applied uniformly to every target. |
| storeOp | Store operation applied uniformly to every target. |
| void blitTexture | ( | const CommandBuffer * | self, |
| const SDL_GPUBlitInfo * | info | ||
| ) |
Blits a region of one texture to another.
| bool cancel | ( | CommandBuffer * | self | ) |
Cancels this command buffer without submitting it to the GPU.
Use this when swapchain acquisition fails or rendering must be skipped for a frame. The CommandBuffer must be released after cancel.
| self | The CommandBuffer. |
| void generateMipmaps | ( | const CommandBuffer * | self, |
| SDL_GPUTexture * | texture | ||
| ) |
Records a mipmap generation command for the given texture.
| CommandBuffer * initWithCommandBuffer | ( | CommandBuffer * | self, |
| const RenderDevice * | device, | ||
| *SDL_GPUCommandBuffer * | commands | ||
| ) |
Initializes this CommandBuffer wrapping the given SDL command buffer.
| self | The CommandBuffer. |
| device | The RenderDevice that created this CommandBuffer. |
| commands | The SDL command buffer to wrap. Must not be NULL. |
| CommandBuffer * initWithCommandBuffer | ( | CommandBuffer * | self, |
| const RenderDevice * | device, | ||
| SDL_GPUCommandBuffer * | commands | ||
| ) |
| void insertDebugLabel | ( | const CommandBuffer * | self, |
| const char * | text | ||
| ) |
Inserts an arbitrary debug label into the command stream.
| void popDebugGroup | ( | const CommandBuffer * | self | ) |
Ends the innermost active debug group.
| void pushComputeUniformData | ( | const CommandBuffer * | self, |
| Uint32 | slot, | ||
| const void * | data, | ||
| Uint32 | length | ||
| ) |
Pushes uniform data for the current compute shader.
| void pushDebugGroup | ( | const CommandBuffer * | self, |
| const char * | name | ||
| ) |
Begins a named debug group in the command stream.
| void pushFragmentUniformData | ( | const CommandBuffer * | self, |
| Uint32 | slot, | ||
| const void * | data, | ||
| Uint32 | length | ||
| ) |
Pushes uniform data for the current fragment shader.
| void pushUniformData | ( | const CommandBuffer * | self, |
| Uint32 | slot, | ||
| const void * | data, | ||
| Uint32 | length | ||
| ) |
Pushes the same uniform data to slot for both the current vertex and fragment shaders.
Convenience for the common case of a uniform block (e.g. globals, a material block) declared at the same binding in both stages. Equivalent to calling pushVertexUniformData and pushFragmentUniformData with the same arguments.
| self | The CommandBuffer. |
| slot | The uniform buffer slot, matching both shaders' declarations. |
| data | The uniform data to push. |
| length | The length of data in bytes. |
| void pushVertexUniformData | ( | const CommandBuffer * | self, |
| Uint32 | slot, | ||
| const void * | data, | ||
| Uint32 | length | ||
| ) |
Pushes uniform data for the current vertex shader.
| bool submit | ( | CommandBuffer * | self | ) |
Submits this command buffer to the GPU for execution.
All passes must be released before submitting. The CommandBuffer must be released after submission.
| self | The CommandBuffer. |
| Fence * submitAndFence | ( | CommandBuffer * | self | ) |
Submits this command buffer and returns a Fence for GPU completion.
The returned Fence is retained; release it when no longer needed.
| self | The CommandBuffer. |
NULL on error. | bool waitAndAcquireSwapchainTexture | ( | const CommandBuffer * | self, |
| SwapchainTexture * | swapchain | ||
| ) |
Blocks until a swapchain texture is available, then acquires it.
Prefer acquireSwapchainTexture unless you must guarantee a texture this frame (e.g. during resize). Blocking bounds how many frames may be in flight, but a drawable is still not guaranteed: as with acquireSwapchainTexture, an unavailable swapchain is reported as false with swapchain zeroed.
Call this as late in the frame as possible. The acquired drawable is held until this CommandBuffer is submitted, and holding it across a frame's CPU work starves the drawable pool.
| self | The CommandBuffer. |
| swapchain | Output structure populated with the texture and dimensions, or zeroed. |
| SDL_GPUCommandBuffer* CommandBuffer::commands |
The underlying SDL command buffer.
| ident CommandBuffer::data |
User data.
| RenderDevice* CommandBuffer::device |
The RenderDevice that this CommandBuffer belongs to.
|
protected |
The interface.
| Object CommandBuffer::object |
The superclass.