Skip to content

SDL_GPUDevice

A handle for low-level GPU operations via SDL GPU. Freed on GC.

claim_window(window) function

Claim an existing SDL_Window so this GPU device can render to it.

window: The SDL_Window to attach.

Returns: None

make_pipeline(pipelineDesc) function

Create a new graphics pipeline from a descriptor object specifying shaders, blend states, vertex format, etc.

pipelineDesc: An object containing pipeline fields (vertexShader, blend, etc.).

Returns: A SDL_GPUGraphicsPipeline handle.

compute_pipeline(desc) function

Create a compute pipeline from a descriptor (shader code, threadgroup sizes, etc.).

desc: An object with shader code, thread counts, etc.

Returns: SDL_GPUComputePipeline handle.

set_swapchain(composition, presentMode) function

Specify how the swapchain (final rendered image) is composed, e.g. 'sdr', 'hdr', and present mode like 'vsync' or 'immediate'.

composition: E.g. 'sdr', 'linear', or 'hdr'.

presentMode: E.g. 'vsync', 'immediate', 'mailbox'.

Returns: None

sort_sprite(a, b) function

A comparator function used for sorting sprite objects by layer, y, and texture. Usually used internally.

a: A sprite object.

b: Another sprite object.

Returns: <0, 0, or >0 for sort ordering.

make_sampler(samplerDesc) function

Create a sampler object specifying filtering, wrapping, anisotropy, etc.

samplerDesc: An object with min_filter, mag_filter, etc.

Returns: SDL_GPUSampler handle.

load_texture(surface, compressionLevel) function

Upload an SDL_Surface into a GPU texture, optionally compressing with DXT. Freed automatically.

surface: An SDL_Surface.

compressionLevel: 0=none, 1=DXT1 or DXT5, 2=high quality, etc.

Returns: SDL_GPUTexture

texture(desc) function

Create a GPU texture with the specified format usage.

desc: Object with {width, height, layers, type, format, usage, etc.}

Returns: SDL_GPUTexture

make_quad() function

Return a simple 2-triangle quad geometry covering [0,1]x[0,1]. Useful for post-processing passes.

Returns: A mesh {pos, uv, color, indices}.

driver() function

Return the name of the underlying GPU driver in use (e.g. 'OpenGL').

Returns: A string with driver name.

make_shader(desc) function

Compile raw shader code (vertex or fragment) in e.g. SPIR-V, MSL, or DXIL format.

desc: {code:ArrayBuffer, stage:'vertex'|'fragment', format:'spv'|..., entrypoint:'main', ...}

Returns: SDL_GPUShader object

acquire_cmd_buffer() function

Obtain a new command buffer for recording GPU commands. Must be submitted or canceled.

Returns: SDL_GPUCommandBuffer handle

upload(cmdBuffer, buffers, transferBuffer) function

Upload CPU data into a list of GPU buffers, optionally reusing or returning a transfer buffer. Typically you provide (cmdBuf, arrayOfTypedArrays, [transferBuffer]).

cmdBuffer: The command buffer in which to record copy commands.

buffers: An array of typed-array data to upload, each must have a 'gpu' property or so.

transferBuffer: Optional existing GPU transfer buffer to reuse.

Returns: The transfer buffer used or newly created.

wait_for_fences(fences, waitAll) function

Wait on an array of GPU fence objects, optionally requiring all or any.

fences: An array of SDL_GPUFence objects.

waitAll: Boolean, true to wait for all fences, false for any.

Returns: True if fences signaled, false on timeout or error.

query_fence(fence) function

Check if the given fence has been signaled yet. Non-blocking.

fence: SDL_GPUFence handle

Returns: True if signaled, false if still pending

shader_format() function

Return an array of supported GPU shader binary formats (like 'spv', 'dxbc', etc.).

Returns: Array of strings naming supported formats.

slice9(texture, dstRect, edges) function

Generate a 9-slice tiling geometry in one shot. For advanced usage with GPU pipeline.

texture: An SDL_GPUTexture

dstRect: The rectangle {x, y, w, h}

edges: {l, r, t, b} edge sizes

Returns: A mesh object

tile(texture, srcRect, dstRect, tileInfo) function

Generate geometry to tile a texture portion inside a dest rect. Often used for repeating backgrounds.

texture: The SDL_GPUTexture

srcRect: The portion to tile in pixels

dstRect: Where to fill

tileInfo: e.g. {repeat_x:true, repeat_y:true}

Returns: A mesh object