GPU: shaders, pipelines & buffersSDL 3.2
SDL_CreateGPUBuffer
Creates a buffer in GPU memory for vertices, indices or shader data. It starts empty.
Signature
SDL_GPUBuffer * SDL_CreateGPUBuffer(SDL_GPUDevice *device, const SDL_GPUBufferCreateInfo *createinfo);
How it works
The create info has a usage (what the buffer is for) and a size in bytes. The CPU cannot write into a GPU buffer directly: fill it by copying from a transfer buffer in a copy pass (SDL_UploadToGPUBuffer).
Parameters
deviceSDL_GPUDevice *
The device.
createinfoconst SDL_GPUBufferCreateInfo *
usage flags and size in bytes.
Common values
- SDL_GPU_BUFFERUSAGE_VERTEX
- Vertex data (SDL_BindGPUVertexBuffers).
- SDL_GPU_BUFFERUSAGE_INDEX
- Indices (SDL_BindGPUIndexBuffer).
- SDL_GPU_BUFFERUSAGE_GRAPHICS_STORAGE_READ
- Read by shaders as a storage buffer.
- SDL_GPU_BUFFERUSAGE_INDIRECT
- Draw parameters written by the GPU (indirect draws).
Return value
The buffer, or NULL on failure.
Example
example.cpp
1SDL_GPUBufferCreateInfo bufInfo{};
2bufInfo.usage = SDL_GPU_BUFFERUSAGE_VERTEX;
3bufInfo.size = sizeof(vertices);
4SDL_GPUBuffer* vertexBuffer = SDL_CreateGPUBuffer(device, &bufInfo);