3 #include <SDL3/SDL_gpu.h>
14 template <
typename T, SDL_GPUBufferUsageFlags U>
16 SDL_GPUDevice* device,
17 SDL_GPUCommandBuffer* commandBuffer,
21 Uint32 size = data.size() *
sizeof(T);
22 SDL_GPUTransferBufferCreateInfo info{
23 .usage = SDL_GPU_TRANSFERBUFFERUSAGE_UPLOAD, .size = size
25 auto transfer = SDL_CreateGPUTransferBuffer(device, &info);
28 SDL_GPUBufferCreateInfo vbInfo{.usage = U, .size = size};
29 auto dstBuffer = SDL_CreateGPUBuffer(device, &vbInfo);
32 auto mapping = (T*)SDL_MapGPUTransferBuffer(device, transfer,
false);
33 std::copy(data.begin(), data.end(), mapping);
34 SDL_UnmapGPUTransferBuffer(device, transfer);
37 SDL_GPUTransferBufferLocation src{.transfer_buffer = transfer};
38 SDL_GPUBufferRegion dst{.buffer = dstBuffer, .size = size};
39 auto pass = SDL_BeginGPUCopyPass(commandBuffer);
41 throw std::runtime_error(SDL_GetError());
43 SDL_UploadToGPUBuffer(pass, &src, &dst,
false);
44 SDL_EndGPUCopyPass(pass);
45 SDL_ReleaseGPUTransferBuffer(device, transfer);