Skip to content

SDL_GPUCommandBuffer

A command buffer that accumulates rendering, copy, and compute operations. Freed after submission or GC.

render_pass(passDesc) function

Begin a render pass with color/depth attachments. Provide an object with 'color_targets' and optional 'depth_stencil'. Returns an SDL_GPURenderPass handle.

passDesc: {color_targets:[...], depth_stencil:...}

Returns: SDL_GPURenderPass

compute_pass(storageTextures, storageBuffers) function

Begin a compute pass reading/writing given arrays of textures and buffers.

storageTextures: array of read/write textures

storageBuffers: array of read/write buffers

Returns: SDL_GPUComputePass

swapchain_pass(clearColor) function

Begin a render pass that directly targets the swapchain (the window). Clears with the specified color.

clearColor: [r,g,b,a]

Returns: SDL_GPURenderPass

acquire_swapchain() function

Acquire the current swapchain texture from the window. Internal usage.

Returns: SDL_GPUTexture handle

bind_vertex_buffer(slot, buffer) function

Bind a GPU buffer as the vertex buffer at a given slot.

slot: Integer slot index.

buffer: The SDL_GPUBuffer.

Returns: None

bind_index_buffer(buffer, offset) function

Bind a GPU buffer as the index buffer (16-bit or 32-bit).

buffer: The SDL_GPUBuffer.

offset: Optional offset in bytes.

Returns: None

bind_fragment_sampler(slot, texture, sampler) function

Bind a texture+sampler pair to a particular fragment shader slot.

slot: Index of the sampler binding.

texture: The SDL_GPUTexture

sampler: The SDL_GPUSampler

Returns: None

push_vertex_uniform_data(slot, data) function

Push raw data to a vertex shader uniform block.

slot: The uniform buffer slot.

data: An ArrayBuffer with the data to upload.

Returns: None

push_fragment_uniform_data(slot, data) function

Push raw data to a fragment shader uniform block.

slot: The uniform buffer slot index.

data: An ArrayBuffer with uniform data.

Returns: None

push_compute_uniform_data(slot, data) function

Push raw data to a compute shader uniform buffer.

slot: The uniform buffer slot.

data: An ArrayBuffer with the data.

Returns: None

submit() function

Submit this command buffer to the GPU and return a fence for synchronization.

Returns: An SDL_GPUFence

cancel() function

Cancel (discard) this command buffer without submitting.

Returns: None

camera(cameraTransform, uniformSlot) function

Write a camera transform (projection/view) to a uniform slot for 3D or 2D usage.

cameraTransform: A camera object or transform with .pos, fov, etc.

uniformSlot: The integer uniform buffer slot to which data is pushed.

Returns: None

hud(sizeVec2, uniformSlot) function

Write an orthographic full-screen "HUD" matrix to a uniform slot. Typically used for 2D overlays.

sizeVec2: [width, height] of the viewport area.

uniformSlot: The integer uniform buffer slot.

Returns: None

push_debug_group(name) function

Push a named debug group marker onto the GPU command list (for debuggers/profilers).

name: The debug label string.

Returns: None

pop_debug_group() function

Pop the most recent debug group marker.

Returns: None

debug_label(label) function

Insert a one-off debug label at the current spot in the command list.

label: The debug label string

Returns: None

blit(blitDesc) function

Blit one GPU texture to another with optional flip mode, filter, and clear operations.

blitDesc: { src:{texture,mip_level, etc}, dst:{texture,...}, load_op, flip, filter, clear_color:[r,g,b,a] }

Returns: None