Questions regarding SDL_GPU buffers

So far I’ve been using OpenGL (4.5) and now considering switching to SDL_GPU, eventually. So far I watched some tutorials and looked at the documentation, and I do have some questions regarding buffers in SDL_GPU:

  • It looks like one cannot upload / download data without a transfer-buffer, and one can only map a transfer-buffer but not a GPU-buffer. Why is there always a need for a transfer-buffer when for example graphics on mobile use the same ram for CPU and video? Sounds to me like one could just map such buffer and write data to it directly (as long as not in use for something else).

  • Is the transfer-buffer guaranteed to be on host/CPU while the GPU-buffer on device/GPU or is it more like OpenGL where you give hints about usage and then the implementation decides (based on the hints and the actual usage and what not). Does SDL_GPUTransferBufferUsage has anything to do with that?

  • Why is there no function to map only a region of a buffer, only the entire buffer? Is it because the transfer-buffer is always in CPU-RAM and mapping does not actually copy anything from GPU-to-CPU so there is no gain in specifying some region only? Or is there some other reason?

OpenGL almost certainly uses transfer buffers as well, just behind the scenes.

  1. The thing to keep in mind about SDL_GPU is that it’s meant to be a subset of modern, low-level graphics APIs like DX12, Metal, and Vulkan. They require you to be more explicit about copying data to and from the GPU. Even on a shared memory system, uploading a texture still requires it to be tiled, etc.

  2. IDK if it’s spelled out specifically in the docs, but yes, the idea seems to be that the transfer buffer is on the host/CPU side.

  3. Yeah, it’s because the transfer buffer is on the host/CPU side. So if you want a specific region of a GPU buffer then just make your transfer buffer that size and specify the GPU buffer region when encoding your copy command.

Something to keep in mind with OpenGL vs modern APIs: while with OpenGL the expectation is typically that an OpenGL command is executed immediately (by CPU, GPU, or both), with modern APIs (including SDL_GPU) that’s out the window, and instead your application is mostly encoding commands into buffers that get executed later.

Thank you!, this answers my questions.