GPU: shaders, pipelines & buffersSDL 3.2

SDL_CreateGPUGraphicsPipeline

Builds a pipeline: shaders, vertex layout, primitive type, blending and target formats, fixed together.

Signature

SDL_GPUGraphicsPipeline * SDL_CreateGPUGraphicsPipeline(SDL_GPUDevice *device, const SDL_GPUGraphicsPipelineCreateInfo *createinfo);

How it works

Modern GPUs compile all drawing state into one object ahead of time, so switching between draws is fast. The create info holds the vertex_shader and fragment_shader, the vertex_input_state (how bytes in your buffer become shader inputs), the primitive_type (e.g. SDL_GPU_PRIMITIVETYPE_TRIANGLELIST), rasterizer, depth-stencil and multisample state, and target_info: the formats of the textures this pipeline will draw into.

The color target format must match the texture you draw into; for the window use SDL_GetGPUSwapchainTextureFormat(device, window). Create pipelines at load time; afterwards the shaders can be released.

Parameters

deviceSDL_GPUDevice *

The device.

createinfoconst SDL_GPUGraphicsPipelineCreateInfo *

Shaders, vertex input, primitive type, states and target formats.

Return value

The pipeline, or NULL on failure (shader/layout mismatch, unsupported state…).

Example

example.cpp
1SDL_GPUColorTargetDescription target{};
2target.format = SDL_GetGPUSwapchainTextureFormat(device, window);
3
4SDL_GPUGraphicsPipelineCreateInfo info{};
5info.vertex_shader   = vs;
6info.fragment_shader = fs;
7info.vertex_input_state = vertexInput;          // buffers + attributes
8info.primitive_type  = SDL_GPU_PRIMITIVETYPE_TRIANGLELIST;
9info.target_info.color_target_descriptions = ⌖
10info.target_info.num_color_targets         = 1;
11SDL_GPUGraphicsPipeline* pipeline = SDL_CreateGPUGraphicsPipeline(device, &info);
12SDL_ReleaseGPUShader(device, vs);   // baked into the pipeline now
13SDL_ReleaseGPUShader(device, fs);
Official SDL wiki