SDL_CreateRenderer driver selection priority and fallback limits
0 reputation · 31 Mar 2023, 01:04 UTC
0 reputation · 31 Mar 2023, 01:04 UTC
When calling SDL_CreateRenderer with the driver index set to -1, SDL selects a renderer based on SDL_HINT_RENDER_DRIVER, the provided SDL_RendererFlags, and the drivers compiled into the library. While SDL_RENDERER_ACCELERATED and SDL_RENDERER_SOFTWARE allow for specific requirements, the internal priority list used for automatic selection is not explicitly defined in the public API.
On platforms where multiple hardware-accelerated drivers are available (such as OpenGL and Direct3D on Windows), the selection order may vary depending on the build configuration or platform version. Because SDL_GetRendererInfo only reports the final selection rather than the evaluation process, it is difficult to predict which driver will be chosen when no hint is provided.
SDL_RENDERER_ACCELERATED is requested but multiple drivers qualify, what determines the final selection?32775 reputation · 31 Mar 2023, 07:45 UTC
When SDL_CreateRenderer is called with a driver index of -1, SDL proceeds as follows:
SDL_HINT_RENDER_DRIVER. If it is set to a name that matches a compiled renderer, SDL attempts to create that renderer first.SDL_Init(SDL_VIDEO), trying each in the order they were added.SDL_RendererFlags (e.g., SDL_RENDERER_ACCELERATED requires a driver that reports the SDL_RENDERER_ACCELERATED flag). The first driver that both matches the flags and can successfully create a rendering context is chosen.SDL_RENDERER_SOFTWARE is allowed, the built‑in software fallback driver is used as the last resort.SDL_HINT_RENDER_DRIVER is consulted before any other logic.SDL_GetRendererInfo after creation.The registration order depends on how SDL was compiled. In typical official builds:
When SDL_RENDERER_ACCELERATED is requested, SDL skips drivers that only expose SDL_RENDERER_SOFTWARE; the first driver that reports the accelerated flag and can create a context wins. If none succeed and the software flag is also permitted, the software driver is chosen.
SDL_GetNumRenderDrivers() to get N.i = 0 … N‑1, invoke SDL_GetRenderDriverInfo(i, &info) and record info.name and info.flags.info.name values reflects the registration order SDL will use when the hint is unset.SDL_HINT_RENDER_DRIVER to each name in turn, call SDL_CreateRenderer(window, -1, desiredFlags), and observe which attempt succeeds.To give a definitive recommendation for your specific environment, please provide the output of the driver enumeration steps above (the list of driver names and their flags). Knowing which drivers are actually compiled into your SDL build determines whether the typical Direct3D‑first or OpenGL‑first order applies, and thus which driver will be selected when no hint is given.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.