GPU: shaders, pipelines & buffersSDL 3.2

SDL_MapGPUTransferBuffer

Gives you a CPU pointer into a transfer buffer, so you can memcpy your data in.

Signature

void * SDL_MapGPUTransferBuffer(SDL_GPUDevice *device, SDL_GPUTransferBuffer *transfer_buffer, bool cycle);

How it works

Write your data, then SDL_UnmapGPUTransferBuffer BEFORE recording the copy. The memory belongs to the driver: never SDL_free it.

cycle matters when you reuse the same transfer buffer every frame. With true, if the GPU is still reading the previous contents, SDL hands you fresh memory instead of making you wait or overwriting data in use. For a one-shot upload pass false.

Parameters

deviceSDL_GPUDevice *

The device.

transfer_bufferSDL_GPUTransferBuffer *

The transfer buffer.

cyclebool

true to get fresh memory if the old contents may still be in use.

Return value

The mapped address, or NULL on failure.

Example

example.cpp
1void* mapped = SDL_MapGPUTransferBuffer(device, staging, false);
2SDL_memcpy(mapped, vertices, sizeof(vertices));
3SDL_UnmapGPUTransferBuffer(device, staging);
Official SDL wiki