GPU: shaders, pipelines & buffersSDL 3.2

SDL_UploadToGPUBuffer

Records a copy from a transfer buffer into a GPU buffer.

Signature

void SDL_UploadToGPUBuffer(SDL_GPUCopyPass *copy_pass, const SDL_GPUTransferBufferLocation *source, const SDL_GPUBufferRegion *destination, bool cycle);

How it works

source is {transfer_buffer, offset}: where the bytes start in the staging buffer. destination is {buffer, offset, size}: where they go and how many. The copy itself happens on the GPU when the command buffer runs.

cycle works like in SDL_MapGPUTransferBuffer: true lets SDL use fresh memory for the destination if a previous frame is still reading it.

Parameters

copy_passSDL_GPUCopyPass *

The open copy pass.

sourceconst SDL_GPUTransferBufferLocation *

{transfer_buffer, offset}.

destinationconst SDL_GPUBufferRegion *

{buffer, offset, size}.

cyclebool

true to avoid waiting on a destination still in use.

Example

example.cpp
1SDL_GPUTransferBufferLocation src{staging, 0};
2SDL_GPUBufferRegion dst{vertexBuffer, 0, sizeof(vertices)};
3SDL_UploadToGPUBuffer(copy, &src, &dst, false);
Official SDL wiki