GPU: shaders, pipelines & buffersSDL 3.2
SDL_CreateGPUTransferBuffer
Creates a staging buffer the CPU CAN write into, used to move data to (or from) the GPU.
Signature
SDL_GPUTransferBuffer * SDL_CreateGPUTransferBuffer(SDL_GPUDevice *device, const SDL_GPUTransferBufferCreateInfo *createinfo);
How it works
Uploading takes two hops. Fastest GPU memory is not visible to the CPU, so you write into a transfer buffer (mapped memory the CPU can see), then a copy pass moves the bytes into the real buffer or texture.
usage is SDL_GPU_TRANSFERBUFFERUSAGE_UPLOAD (CPU → GPU) or _DOWNLOAD (GPU → CPU, e.g. reading a screenshot back). size is in bytes.
Parameters
deviceSDL_GPUDevice *
The device.
createinfoconst SDL_GPUTransferBufferCreateInfo *
usage (UPLOAD or DOWNLOAD) and size in bytes.
Return value
The transfer buffer, or NULL on failure.
Example
example.cpp
1SDL_GPUTransferBufferCreateInfo tbInfo{};
2tbInfo.usage = SDL_GPU_TRANSFERBUFFERUSAGE_UPLOAD;
3tbInfo.size = sizeof(vertices);
4SDL_GPUTransferBuffer* staging = SDL_CreateGPUTransferBuffer(device, &tbInfo);