SDL_CreateGPUBuffer(3)

✨ NAME ✨

okay so bestie, we're doing SDL_CreateGPUBuffer today β€” it's a function from the SDL3 FUNCTIONS corner of the SDL3 manual, and it literally just creates a buffer object to be used in graphics or compute workflows. that's the whole vibe. πŸ’…


🌸 SYNOPSIS 🌸

#include <SDL3/SDL_gpu.h>

SDL_GPUBuffer * SDL_CreateGPUBuffer(
    SDL_GPUDevice *device,
    const SDL_GPUBufferCreateInfo *createinfo);

yes it's giving "two arguments and a dream". 🫢


πŸ’– DESCRIPTION πŸ’–

so like. the contents of this buffer are undefined until data is written to the buffer. not "empty", not "zeroed" β€” undefined. do not go reading it and expecting anything cute. πŸ™ˆ

also not all usage flag combos are valid, bestie. for example, a buffer cannot have both the VERTEX and INDEX flags. it's giving "pick a lane". βœ‹

if you use a STORAGE flag, the data in the buffer must respect std140 layout conventions. in practical terms that means you must ensure that vec3 and vec4 fields are 16-byte aligned. the alignment gods do not negotiate. 😭

and if you wanna actually understand the underlying concepts and memory management with the SDL GPU API, there's a blog post for that:

https://moonside.games/posts/sdl-gpu-concepts-cycling/

(it's a whole read, highly recommend, iykyk. πŸ“–)

there are optional properties you can hand over through props. these are the supported properties:

  • SDL_PROP_GPU_BUFFER_CREATE_NAME_STRING β€” a name that can be displayed in debugging tools. give ur buffer a little name tag, she deserves it πŸŽ€

πŸ¦‹ FUNCTION PARAMETERS πŸ¦‹

  • device β€” a GPU Context. (the whole GPU situation, basically πŸ‘‘)
  • createinfo β€” a struct describing the state of the buffer to create. (tell me everything about her. what she is. what she's for. ✨)

🌈 RETURN VALUE 🌈

returns a buffer object on success, or NULL on failure. and if it fails? call SDL_GetError() for more info, because she will tell you what went wrong, no cap. πŸ’€


⭐ AVAILABILITY ⭐

this function is available since SDL 3.2.0. so if ur on something older, sorry bestie, no buffer for you. πŸ™ˆ


πŸ‘‘ SEE ALSO πŸ‘‘

the whole friend group, obviously:

pspsps β€” don't forget SDL_ReleaseGPUBuffer(3) when ur done. memory doesn't clean itself up, and that's not the vibe we're going for. 🧚

Simple Directmedia Layer β€” SDL 3.4.18. mwah, that's the whole page, go forth and allocate responsibly πŸ’œπŸŒˆβœ¨

πŸ“¦ where this page comes from