ui: more robust checks for EGL availability

SDL2 prefers GLX over EGL, however we require EGL to present VAAPI decoded frames to the screen, so we set a flag to force it over to EGL.

However some hardware (notably NVIDIA GPUs) do not provide EGL pathways. We must detect this and un-force EGL if so. However the un-forcing requires a little more work than expected. This code should work now.
This commit is contained in:
itsmattkc
2026-01-14 18:41:12 -08:00
parent fde6e0d3f2
commit 95b705a405
2 changed files with 47 additions and 10 deletions
+1 -1
View File
@@ -34,7 +34,7 @@ static char screenshot_buf[4096] = {0};
static const int VIDEO_STREAM_INDEX = 0;
static const int AUDIO_STREAM_INDEX = 1;
int vpi_egl_available = 1;
int vpi_egl_available = 0;
static int status_lbl;
static struct {
+46 -9
View File
@@ -579,6 +579,23 @@ int vui_sdl_event_thread(void *data)
return 0;
}
int vui_init_window(vui_context_t *ctx, vui_sdl_context_t *sdl_ctx, Uint32 window_flags)
{
sdl_ctx->window = SDL_CreateWindow("Vanilla", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, ctx->screen_width, ctx->screen_height, window_flags);
if (!sdl_ctx->window) {
vpilog("Failed to CreateWindow: %s\n", SDL_GetError());
return -1;
}
sdl_ctx->renderer = SDL_CreateRenderer(sdl_ctx->window, -1, SDL_RENDERER_ACCELERATED);
if (!sdl_ctx->renderer) {
vpilog("Failed to CreateRenderer: %s\n", SDL_GetError());
return -1;
}
return 0;
}
int vui_init_sdl(vui_context_t *ctx, int fullscreen)
{
// Enable Steam Deck gyroscopes even while Steam is open and in gaming mode
@@ -615,26 +632,46 @@ int vui_init_sdl(vui_context_t *ctx, int fullscreen)
SDL_ShowCursor(0);
}
sdl_ctx->window = SDL_CreateWindow("Vanilla", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, ctx->screen_width, ctx->screen_height, window_flags);
if (!sdl_ctx->window) {
vpilog("Failed to CreateWindow: %s\n", SDL_GetError());
return -1;
// Lookup ahead of time if we're on X11 + OpenGL (will be important for later check...)
const char *driver = SDL_GetVideoDriver(0);
if (!strcmp(driver, "x11") || !strcmp(driver, "wayland")) {
SDL_RendererInfo info;
SDL_GetRenderDriverInfo(0, &info);
if (!strcmp(info.name, "opengl") || !strcmp(info.name, "opengles")) {
// This saves a small amount of time on the EGL check below because
// SDL will fail on the earlier CreateWindow call rather than the
// later CreateRenderer call.
window_flags |= SDL_WINDOW_OPENGL;
vpi_egl_available = 1;
}
}
sdl_ctx->renderer = SDL_CreateRenderer(sdl_ctx->window, -1, SDL_RENDERER_ACCELERATED);
if (!sdl_ctx->renderer) {
if (vui_init_window(ctx, sdl_ctx, window_flags) != 0) {
// Re-attempt without EGL (X11/NVIDIA do not support this)
vpilog("Trying again without forcing EGL...\n");
SDL_SetHint(SDL_HINT_VIDEO_X11_FORCE_EGL, "0");
vpi_egl_available = 0;
sdl_ctx->renderer = SDL_CreateRenderer(sdl_ctx->window, -1, SDL_RENDERER_ACCELERATED);
if (!sdl_ctx->renderer) {
// Determine if we created a window, destroy it if so
if (sdl_ctx->window) {
SDL_DestroyWindow(sdl_ctx->window);
sdl_ctx->window = 0;
}
// SDL video subsystem must be reinitialized after changing hint
SDL_QuitSubSystem(SDL_INIT_VIDEO);
SDL_InitSubSystem(SDL_INIT_VIDEO);
if (vui_init_window(ctx, sdl_ctx, window_flags) != 0) {
// It's not because we forced EGL, so it's something else we're not prepared for
vpilog("Failed to CreateRenderer: %s\n", SDL_GetError());
return -1;
}
}
if (!vpi_egl_available) {
vpilog("EGL unavailable, VAAPI will be disabled\n");
}
// Open audio output device
SDL_AudioSpec desired = {0}, obtained;
desired.freq = 48000;