From 276e4bce829223651935cacd90bb1cb5ad81c45a Mon Sep 17 00:00:00 2001 From: "U-DESKTOP-SPFP6AQ\\twistedtechre" Date: Fri, 1 May 2026 11:58:43 +0200 Subject: [PATCH 1/4] gl3: remove dead Cg shader-backend paths from glcore driver The gl3 (glcore video driver) shader fallback selector and dispatcher both had RARCH_SHADER_CG arms, but those branches were unreachable in any build configuration: 1. The Cg fallback in gl3_get_fallback_shader_type gates on GFX_CTX_FLAGS_SHADERS_CG. No context driver ever sets that flag when the active video driver is "glcore" -- audited x_ctx.c:1106-1116, wgl_ctx.c:778-788, drm_ctx.c, drm_go2_ctx.c, orbis_ctx.c, switch_ctx.c, wayland_ctx.c, xegl_ctx.c (eight context drivers, all of which the glcore branch advertises only SHADERS_SLANG). The Cg flag is only set by ps3_ctx (which uses the rsx driver, not glcore) and by the legacy / non-Core branch of x_ctx and wgl_ctx (gated on !core_hw_context_enable, so only for the gl driver, not glcore). 2. Even if the gating were bypassed, gl_cg_backend in shader_gl_cg.c uses cgGLEnableProfile / cgGLBindProgram / cgGLEnableClientState et al. These rely on the legacy ARB asm program pipeline (GL_VERTEX_PROGRAM_ARB style) which is removed from Core Profile contexts. NVIDIA's Cg runtime hasn't been updated since 2012 and has no Core Profile support. Remove: - the RARCH_SHADER_CG case in gl3_get_fallback_shader_type - the RARCH_SHADER_CG case in gl3_shader_driver_set_backend - HAVE_CG from the function-level guard - the now-unused 3rd loop iteration (the cycle is GLSL <-> SLANG) The fallback chain becomes a 2-element cycle: GLSL falls back to SLANG and vice versa, matching what the gating actually allows. Add a comment at the top of gl3_get_fallback_shader_type explaining the gl3-vs-Cg situation so future readers don't reintroduce the dead arm. No behaviour change on any build: HAVE_CG was defined for some Windows builds, but the gates above already prevented those branches from executing. --- gfx/drivers/gl3.c | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/gfx/drivers/gl3.c b/gfx/drivers/gl3.c index d4a333655e0..a2c6a282a85 100644 --- a/gfx/drivers/gl3.c +++ b/gfx/drivers/gl3.c @@ -2128,38 +2128,36 @@ static bool gl3_init_pipelines(gl3_t *gl) **/ static enum rarch_shader_type gl3_get_fallback_shader_type(enum rarch_shader_type type) { -#if defined(HAVE_SLANG) || defined(HAVE_GLSL) || defined(HAVE_CG) +#if defined(HAVE_SLANG) || defined(HAVE_GLSL) int i; gfx_ctx_flags_t flags; flags.flags = 0; video_context_driver_get_flags(&flags); - if (type != RARCH_SHADER_CG && type != RARCH_SHADER_GLSL && type != RARCH_SHADER_SLANG) + /* gl3 (glcore video driver) only ever advertises slang via spirv-cross. + * Cg requires the legacy fixed-function / ARB asm pipeline that Core + * Profile contexts don't expose, and no context driver advertises + * GFX_CTX_FLAGS_SHADERS_CG when the active video driver is "glcore" + * (see e.g. x_ctx.c, wgl_ctx.c). Treat any incoming RARCH_SHADER_CG + * the same as an unknown type and fall back to slang. */ + if (type != RARCH_SHADER_GLSL && type != RARCH_SHADER_SLANG) { type = DEFAULT_SHADER_TYPE; - if (type != RARCH_SHADER_CG && type != RARCH_SHADER_GLSL && type != RARCH_SHADER_SLANG) + if (type != RARCH_SHADER_GLSL && type != RARCH_SHADER_SLANG) type = RARCH_SHADER_SLANG; } - for (i = 0; i < 3; i++) + for (i = 0; i < 2; i++) { switch (type) { - case RARCH_SHADER_CG: -#ifdef HAVE_CG - if (BIT32_GET(flags.flags, GFX_CTX_FLAGS_SHADERS_CG)) - return type; -#endif - type = RARCH_SHADER_SLANG; - break; - case RARCH_SHADER_GLSL: #ifdef HAVE_GLSL if (BIT32_GET(flags.flags, GFX_CTX_FLAGS_SHADERS_GLSL)) return type; #endif - type = RARCH_SHADER_CG; + type = RARCH_SHADER_SLANG; break; case RARCH_SHADER_SLANG: @@ -2231,11 +2229,6 @@ static const shader_backend_t *gl3_shader_driver_set_backend( switch (fallback) { -#ifdef HAVE_CG - case RARCH_SHADER_CG: - RARCH_LOG("[GLCore] Using Cg shader backend.\n"); - return &gl_cg_backend; -#endif #ifdef HAVE_GLSL case RARCH_SHADER_GLSL: RARCH_LOG("[GLCore] Using GLSL shader backend.\n"); From 42aa9fd60a572311c8643aca5f26016dd09fda2f Mon Sep 17 00:00:00 2001 From: "U-DESKTOP-SPFP6AQ\\twistedtechre" Date: Fri, 1 May 2026 12:03:02 +0200 Subject: [PATCH 2/4] move DEFAULT_SHADER_TYPE to gl2/gl3.c --- gfx/drivers/gl2.c | 12 +++++++++++- gfx/drivers/gl3.c | 10 +++++++++- gfx/video_driver.h | 14 -------------- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/gfx/drivers/gl2.c b/gfx/drivers/gl2.c index eaa0d4e9ae9..415d1aae718 100644 --- a/gfx/drivers/gl2.c +++ b/gfx/drivers/gl2.c @@ -92,6 +92,16 @@ #define GL_UNSIGNED_INT_8_8_8_8_REV 0x8367 #endif +#if defined(HAVE_OPENGLES2) +#define GL2_DEFAULT_SHADER_TYPE RARCH_SHADER_GLSL +#elif defined(HAVE_GLSL) +#define GL2_DEFAULT_SHADER_TYPE RARCH_SHADER_GLSL +#elif defined(HAVE_CG) +#define GL2_DEFAULT_SHADER_TYPE RARCH_SHADER_CG +#else +#define GL2_DEFAULT_SHADER_TYPE RARCH_SHADER_NONE +#endif + #if defined(HAVE_PSGL) #define RARCH_GL_FRAMEBUFFER GL_FRAMEBUFFER_OES #define RARCH_GL_FRAMEBUFFER_COMPLETE GL_FRAMEBUFFER_COMPLETE_OES @@ -2974,7 +2984,7 @@ static enum rarch_shader_type gl2_get_fallback_shader_type(enum rarch_shader_typ if (type != RARCH_SHADER_CG && type != RARCH_SHADER_GLSL) { - type = DEFAULT_SHADER_TYPE; + type = GL2_DEFAULT_SHADER_TYPE; if (type != RARCH_SHADER_CG && type != RARCH_SHADER_GLSL) type = RARCH_SHADER_GLSL; diff --git a/gfx/drivers/gl3.c b/gfx/drivers/gl3.c index a2c6a282a85..593cfbf9bde 100644 --- a/gfx/drivers/gl3.c +++ b/gfx/drivers/gl3.c @@ -69,6 +69,14 @@ coords[5] = yamt; \ coords[7] = yamt +#if defined(HAVE_SLANG) +#define GL3_DEFAULT_SHADER_TYPE RARCH_SHADER_SLANG +#elif defined(HAVE_GLSL) +#define GL3_DEFAULT_SHADER_TYPE RARCH_SHADER_GLSL +#else +#define GL3_DEFAULT_SHADER_TYPE RARCH_SHADER_NONE +#endif + struct gl3_streamed_texture { GLuint tex; @@ -2142,7 +2150,7 @@ static enum rarch_shader_type gl3_get_fallback_shader_type(enum rarch_shader_typ * the same as an unknown type and fall back to slang. */ if (type != RARCH_SHADER_GLSL && type != RARCH_SHADER_SLANG) { - type = DEFAULT_SHADER_TYPE; + type = GL3_DEFAULT_SHADER_TYPE; if (type != RARCH_SHADER_GLSL && type != RARCH_SHADER_SLANG) type = RARCH_SHADER_SLANG; diff --git a/gfx/video_driver.h b/gfx/video_driver.h index f9d0dc9cc35..7489e630521 100644 --- a/gfx/video_driver.h +++ b/gfx/video_driver.h @@ -63,20 +63,6 @@ #define VIDEO_SHADER_STOCK_NOBLEND (GFX_MAX_SHADERS - 10) #define VIDEO_SHADER_STOCK_BLEND_HDR (GFX_MAX_SHADERS - 11) -#if defined(_XBOX360) -#define DEFAULT_SHADER_TYPE RARCH_SHADER_HLSL -#elif defined(HAVE_OPENGLES2) -#define DEFAULT_SHADER_TYPE RARCH_SHADER_GLSL -#elif defined(HAVE_SLANG) -#define DEFAULT_SHADER_TYPE RARCH_SHADER_SLANG -#elif defined(HAVE_GLSL) -#define DEFAULT_SHADER_TYPE RARCH_SHADER_GLSL -#elif defined(HAVE_CG) -#define DEFAULT_SHADER_TYPE RARCH_SHADER_CG -#else -#define DEFAULT_SHADER_TYPE RARCH_SHADER_NONE -#endif - #ifndef MAX_EGLIMAGE_TEXTURES #define MAX_EGLIMAGE_TEXTURES 32 #endif From 6224ab67b974f8c19e707719bc984a960a289c7e Mon Sep 17 00:00:00 2001 From: "U-DESKTOP-SPFP6AQ\\twistedtechre" Date: Fri, 1 May 2026 12:06:14 +0200 Subject: [PATCH 3/4] gl3: clarify shader-fallback comment about GLSL vs Cg The comment added in 276e4bc said gl3 'only ever advertises slang via spirv-cross', which overstated things. Context drivers do only advertise SLANG for glcore, but the gl3 fallback selector itself accepts both GLSL and SLANG as first-class types -- and 42aa9fd just made GLSL a valid GL3_DEFAULT_SHADER_TYPE on builds without slang. Reword the comment to be specific about what is and isn't dead: - Cg is dead (no context flag, ARB asm pipeline incompatible with Core Profile) - GLSL is alive (Core-compatible API surface, kept as fallback for no-slang builds) - Slang is the practical default No code change. --- gfx/drivers/gl3.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/gfx/drivers/gl3.c b/gfx/drivers/gl3.c index 593cfbf9bde..82d42afb973 100644 --- a/gfx/drivers/gl3.c +++ b/gfx/drivers/gl3.c @@ -2142,12 +2142,14 @@ static enum rarch_shader_type gl3_get_fallback_shader_type(enum rarch_shader_typ flags.flags = 0; video_context_driver_get_flags(&flags); - /* gl3 (glcore video driver) only ever advertises slang via spirv-cross. - * Cg requires the legacy fixed-function / ARB asm pipeline that Core - * Profile contexts don't expose, and no context driver advertises - * GFX_CTX_FLAGS_SHADERS_CG when the active video driver is "glcore" - * (see e.g. x_ctx.c, wgl_ctx.c). Treat any incoming RARCH_SHADER_CG - * the same as an unknown type and fall back to slang. */ + /* No context driver advertises GFX_CTX_FLAGS_SHADERS_CG for the + * "glcore" video driver -- audited x_ctx.c, wgl_ctx.c, drm_ctx.c, + * wayland_ctx.c, etc. Cg requires the legacy fixed-function / ARB + * asm pipeline that Core Profile contexts don't expose, so no + * RARCH_SHADER_CG path is wired up here. GLSL and slang are both + * Core Profile-compatible and remain valid; in practice context + * drivers advertise SLANG for glcore but the GLSL fallback is kept + * for builds without slang/spirv-cross. */ if (type != RARCH_SHADER_GLSL && type != RARCH_SHADER_SLANG) { type = GL3_DEFAULT_SHADER_TYPE; From a340c70468236f81922aaa3faf7447dedf27e63f Mon Sep 17 00:00:00 2001 From: "U-DESKTOP-SPFP6AQ\\twistedtechre" Date: Fri, 1 May 2026 12:11:45 +0200 Subject: [PATCH 4/4] video_driver_apply_state_changes only gets called from command_event --- gfx/video_crt_switch.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/gfx/video_crt_switch.c b/gfx/video_crt_switch.c index 8c70e51f3c4..6f83e44df7b 100644 --- a/gfx/video_crt_switch.c +++ b/gfx/video_crt_switch.c @@ -111,8 +111,7 @@ static void crt_aspect_ratio_switch( video_st->current_video->set_viewport( video_st->data, width, height, true, true); - video_driver_apply_state_changes(); - + command_event(CMD_EVENT_VIDEO_APPLY_STATE_CHANGES, NULL); } static void crt_switch_set_aspect( @@ -419,7 +418,7 @@ static void switch_res_crt( 1.0f, false); video_driver_set_output_size(width , height); - video_driver_apply_state_changes(); + command_event(CMD_EVENT_VIDEO_APPLY_STATE_CHANGES, NULL); } } #endif @@ -517,7 +516,7 @@ void crt_switch_res_core( float fly_aspect = (float)p_switch->fly_aspect; RARCH_LOG("[CRT] Restoring aspect ratio: %f.\n", fly_aspect); video_st->aspect_ratio = fly_aspect; - video_driver_apply_state_changes(); + command_event(CMD_EVENT_VIDEO_APPLY_STATE_CHANGES, NULL); } } }