SDL_SetGPUAl...ramesInFlight(3)

πŸ’… SDL_SetGPUAllowedFramesInFlight πŸ’…

okay bestie, so this is a page from the SDL3 FUNCTIONS manual β€” it's SDL_SetGPUAllowedFramesInFlight from the SDL3 FUNCTIONS corner of the docs, and it's literally all about telling your GPU how many frames it's allowed to juggle at once. no cap.


✨ NAME ✨

SDL_SetGPUAllowedFramesInFlight β€” configures the maximum allowed number of frames in flight. like, the vibe ceiling for how many frames your GPU can have in the air at once πŸ¦‹


✨ SYNOPSIS ✨

#include <SDL3/SDL_gpu.h>

bool SDL_SetGPUAllowedFramesInFlight(
    SDL_GPUDevice *device,
    Uint32 allowed_frames_in_flight);

✨ DESCRIPTION ✨

okay so here's the tea πŸ«– β€” when the device gets created, the default value is 2. and what that means is: after you've submitted 2 frames for presentation, if the GPU hasn't finished working on the first frame yet, then SDL_AcquireGPUSwapchainTexture() will fill the swapchain texture pointer with NULL, and SDL_WaitAndAcquireGPUSwapchainTexture() will just… block. sitting there. waiting. πŸ™ˆ

the tradeoff is real and it's giving classic:

  • Higher values increase throughput β€” at the expense of visual latency.
  • Lower values decrease visual latency β€” at the expense of throughput.
⚠️ not me forgetting to mention: calling this function will stall and flush the command queue to prevent synchronization issues. so yeah, it's a whole thing.

the minimum value of allowed frames in flight is 1, and the maximum is 3. periodt. πŸ’…


✨ FUNCTION PARAMETERS ✨

  • device β€” a GPU context. your lil GPU situation πŸ’–
  • allowed_frames_in_flight β€” the maximum number of frames that can be pending on the GPU. the ceiling, the limit, the boundary πŸ‘‘

✨ RETURN VALUE ✨

returns true if it worked, false on error β€” and if it's erroring, go call SDL_GetError() for more information, she'll tell you what's up 😭


✨ AVAILABILITY ✨

this one is available since SDL 3.2.0. she's new-ish, she's fresh, she ate πŸ”₯


and that's the whole page bestie!! go forth and configure your frames in flight, you're the main character of your own render loop 🌈✨

mwah πŸ’‹ β€” with love from the Simple Directmedia Layer girlies, SDL 3.4.18 edition πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from