Add support for Cg and GLSL shaders in the glcore video driver (#18151)

This commit is contained in:
刘皓 2025-08-05 12:55:29 -04:00 committed by GitHub
parent 248af45eaf
commit c8ab73607c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
15 changed files with 1600 additions and 443 deletions

View File

@ -1687,11 +1687,15 @@ ifeq ($(HAVE_VULKAN), 1)
endif
ifeq ($(HAVE_OPENGL_CORE), 1)
OBJ += gfx/drivers/gl3.o \
gfx/drivers_shader/shader_gl3.o
OBJ += gfx/drivers/gl3.o
DEFINES += -DHAVE_OPENGL_CORE
NEED_CXX_LINKER = 1
ifeq ($(HAVE_SLANG), 1)
OBJ += gfx/drivers_shader/shader_gl3.o
NEED_CXX_LINKER = 1
endif
endif
ifeq ($(HAVE_OMAP), 1)

View File

@ -1385,7 +1385,8 @@ static void gl2_renderchain_render(
rect->img_width, rect->img_height, true, false,
video_scale_integer);
params.data = gl;
params.vp_width = gl->out_vp_width;
params.vp_height = gl->out_vp_height;
params.width = prev_rect->img_width;
params.height = prev_rect->img_height;
params.tex_width = prev_rect->width;
@ -1450,7 +1451,8 @@ static void gl2_renderchain_render(
glClear(GL_COLOR_BUFFER_BIT);
gl2_set_viewport(gl, width, height, false, true, video_scale_integer);
params.data = gl;
params.vp_width = gl->out_vp_width;
params.vp_height = gl->out_vp_height;
params.width = prev_rect->img_width;
params.height = prev_rect->img_height;
params.tex_width = prev_rect->width;
@ -3560,7 +3562,8 @@ static bool gl2_frame(void *data, const void *frame,
glClear(GL_COLOR_BUFFER_BIT);
params.data = gl;
params.vp_width = gl->out_vp_width;
params.vp_height = gl->out_vp_height;
params.width = frame_width;
params.height = frame_height;
params.tex_width = gl->tex_w;

File diff suppressed because it is too large Load Diff

View File

@ -101,14 +101,14 @@ static uint32_t cocoa_gl_gfx_ctx_get_flags(void *data)
break;
case GFX_CTX_OPENGL_API:
if (string_is_equal(video_driver_get_ident(), "gl1")) { }
else if (string_is_equal(video_driver_get_ident(), "glcore"))
{
#if defined(HAVE_SLANG) && defined(HAVE_SPIRV_CROSS)
BIT32_SET(flags, GFX_CTX_FLAGS_SHADERS_SLANG);
#endif
}
else
{
if (string_is_equal(video_driver_get_ident(), "glcore"))
{
#if defined(HAVE_SLANG) && defined(HAVE_SPIRV_CROSS)
BIT32_SET(flags, GFX_CTX_FLAGS_SHADERS_SLANG);
#endif
}
#ifdef HAVE_GLSL
BIT32_SET(flags, GFX_CTX_FLAGS_SHADERS_GLSL);
#endif
@ -327,7 +327,7 @@ static void cocoa_gl_gfx_ctx_swap_buffers(void *data)
return;
if (glk_view)
[glk_view display];
cocoa_ctx->fast_forward_skips =
cocoa_ctx->fast_forward_skips =
(cocoa_ctx->flags & COCOA_CTX_FLAG_IS_SYNCING) ? 0 : 3;
#endif
}
@ -353,12 +353,12 @@ static bool cocoa_gl_gfx_ctx_set_video_mode(void *data,
CocoaView *g_view = (CocoaView*)nsview_get_ptr();
#endif
cocoa_ctx_data_t *cocoa_ctx = (cocoa_ctx_data_t*)data;
static bool
static bool
has_went_fullscreen = false;
cocoa_ctx->width = width;
cocoa_ctx->height = height;
/* NOTE: setWantsBestResolutionOpenGLSurface only
/* NOTE: setWantsBestResolutionOpenGLSurface only
* available on MacOS X 10.7 and up.
* Deprecated as of MacOS X 10.14. */
#if MAC_OS_X_VERSION_10_7
@ -509,7 +509,7 @@ static bool cocoa_gl_gfx_ctx_set_video_mode(void *data,
glk_view.context = g_ctx;
/* TODO: Maybe iOS users should be able to
/* TODO: Maybe iOS users should be able to
* show/hide the status bar here? */
return true;
}
@ -525,12 +525,12 @@ static void *cocoa_gl_gfx_ctx_init(void *video_driver)
#ifndef OSX
cocoa_ctx->flags |= COCOA_CTX_FLAG_IS_SYNCING;
#endif
switch (cocoagl_api)
{
case GFX_CTX_OPENGL_ES_API:
#if defined(HAVE_COCOA_METAL)
/* The Metal build supports both the OpenGL
/* The Metal build supports both the OpenGL
* and Metal video drivers */
[apple_platform setViewType:APPLE_VIEW_TYPE_OPENGL_ES];
#endif
@ -539,7 +539,7 @@ static void *cocoa_gl_gfx_ctx_init(void *video_driver)
default:
break;
}
return cocoa_ctx;
}
#endif

View File

@ -1050,8 +1050,9 @@ static uint32_t gfx_ctx_drm_get_flags(void *data)
BIT32_SET(flags, GFX_CTX_FLAGS_SHADERS_SLANG);
#endif
}
else
BIT32_SET(flags, GFX_CTX_FLAGS_SHADERS_GLSL);
#ifdef HAVE_GLSL
BIT32_SET(flags, GFX_CTX_FLAGS_SHADERS_GLSL);
#endif
BIT32_SET(flags, GFX_CTX_FLAGS_CRT_SWITCHRES);

View File

@ -223,7 +223,7 @@ static bool gfx_ctx_go2_drm_set_video_mode(void *data,
frontend_driver_install_signal_handler();
#ifdef HAVE_MENU
if ( config_get_ptr()->bools.video_ctx_scaling
if ( config_get_ptr()->bools.video_ctx_scaling
&& !(menu_state_get_ptr()->flags & MENU_ST_FLAG_ALIVE))
{
drm->fb_width = av_info->geometry.base_width;
@ -278,13 +278,13 @@ static void gfx_ctx_go2_drm_check_window(void *data, bool *quit,
bool *resize, unsigned *width, unsigned *height)
{
unsigned w, h;
gfx_ctx_go2_drm_data_t
gfx_ctx_go2_drm_data_t
*drm = (gfx_ctx_go2_drm_data_t*)data;
#ifdef HAVE_MENU
settings_t *settings = config_get_ptr();
bool use_ctx_scaling = settings->bools.video_ctx_scaling;
if ( use_ctx_scaling
if ( use_ctx_scaling
&& !(menu_state_get_ptr()->flags & MENU_ST_FLAG_ALIVE))
{
video_driver_state_t *video_st = video_state_get_ptr();
@ -314,10 +314,10 @@ static bool gfx_ctx_go2_drm_suppress_screensaver(void *data, bool enable) { retu
static void gfx_ctx_go2_drm_swap_buffers(void *data)
{
#ifdef HAVE_EGL
go2_surface_t*
go2_surface_t*
surf = NULL;
#endif
gfx_ctx_go2_drm_data_t
gfx_ctx_go2_drm_data_t
*drm = (gfx_ctx_go2_drm_data_t*)data;
int out_w = drm->native_width;
@ -367,8 +367,9 @@ static uint32_t gfx_ctx_go2_drm_get_flags(void *data)
BIT32_SET(flags, GFX_CTX_FLAGS_SHADERS_SLANG);
#endif
}
else
BIT32_SET(flags, GFX_CTX_FLAGS_SHADERS_GLSL);
#ifdef HAVE_GLSL
BIT32_SET(flags, GFX_CTX_FLAGS_SHADERS_GLSL);
#endif
return flags;
}

View File

@ -318,10 +318,9 @@ static uint32_t orbis_ctx_get_flags(void *data)
BIT32_SET(flags, GFX_CTX_FLAGS_SHADERS_SLANG);
#endif
}
else
{
BIT32_SET(flags, GFX_CTX_FLAGS_SHADERS_GLSL);
}
#ifdef HAVE_GLSL
BIT32_SET(flags, GFX_CTX_FLAGS_SHADERS_GLSL);
#endif
return flags;
}

View File

@ -238,12 +238,9 @@ static uint32_t switch_ctx_get_flags(void *data)
BIT32_SET(flags, GFX_CTX_FLAGS_SHADERS_SLANG);
#endif
}
else
{
#ifdef HAVE_GLSL
BIT32_SET(flags, GFX_CTX_FLAGS_SHADERS_GLSL);
BIT32_SET(flags, GFX_CTX_FLAGS_SHADERS_GLSL);
#endif
}
return flags;
}

View File

@ -496,14 +496,14 @@ static void wl_surface_frame_done(void *data, struct wl_callback *cb, uint32_t t
wl_callback_destroy(cb);
}
static const struct wl_callback_listener wl_surface_frame_listener = {
static const struct wl_callback_listener wl_surface_frame_listener = {
.done = wl_surface_frame_done,
};
static void gfx_ctx_wl_swap_buffers(void *data)
{
#ifdef HAVE_EGL
struct wl_callback *cb;
struct wl_callback *cb;
gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)data;
settings_t *settings = config_get_ptr();
unsigned max_swapchain_images = settings->uints.video_max_swapchain_images;
@ -573,14 +573,14 @@ static uint32_t gfx_ctx_wl_get_flags(void *data)
if (wl->core_hw_context_enable)
BIT32_SET(flags, GFX_CTX_FLAGS_GL_CORE_CONTEXT);
if (string_is_equal(video_ident, "glcore"))
if (string_is_equal(video_ident, "glcore") || string_is_equal(video_ident, "gl"))
{
if (string_is_equal(video_ident, "glcore"))
{
#if defined(HAVE_SLANG) && defined(HAVE_SPIRV_CROSS)
BIT32_SET(flags, GFX_CTX_FLAGS_SHADERS_SLANG);
BIT32_SET(flags, GFX_CTX_FLAGS_SHADERS_SLANG);
#endif
}
else if (string_is_equal(video_ident, "gl"))
{
}
#ifdef HAVE_GLSL
BIT32_SET(flags, GFX_CTX_FLAGS_SHADERS_GLSL);
#endif

View File

@ -785,14 +785,14 @@ static uint32_t gfx_ctx_wgl_get_flags(void *data)
BIT32_SET(flags, GFX_CTX_FLAGS_GL_CORE_CONTEXT);
if (string_is_equal(video_driver_get_ident(), "gl1")) { }
else if (string_is_equal(video_driver_get_ident(), "glcore"))
{
#if defined(HAVE_SLANG) && defined(HAVE_SPIRV_CROSS)
BIT32_SET(flags, GFX_CTX_FLAGS_SHADERS_SLANG);
#endif
}
else
{
if (string_is_equal(video_driver_get_ident(), "glcore"))
{
#if defined(HAVE_SLANG) && defined(HAVE_SPIRV_CROSS)
BIT32_SET(flags, GFX_CTX_FLAGS_SHADERS_SLANG);
#endif
}
#ifdef HAVE_CG
if (!(wgl_flags & WGL_FLAG_CORE_HW_CTX_ENABLE))
BIT32_SET(flags, GFX_CTX_FLAGS_SHADERS_CG);

View File

@ -1076,14 +1076,14 @@ static uint32_t gfx_ctx_x_get_flags(void *data)
BIT32_SET(flags, GFX_CTX_FLAGS_MULTISAMPLING);
if (string_is_equal(video_driver_get_ident(), "gl1")) { }
else if (string_is_equal(video_driver_get_ident(), "glcore"))
{
#if defined(HAVE_SLANG) && defined(HAVE_SPIRV_CROSS)
BIT32_SET(flags, GFX_CTX_FLAGS_SHADERS_SLANG);
#endif
}
else
{
if (string_is_equal(video_driver_get_ident(), "glcore"))
{
#if defined(HAVE_SLANG) && defined(HAVE_SPIRV_CROSS)
BIT32_SET(flags, GFX_CTX_FLAGS_SHADERS_SLANG);
#endif
}
#ifdef HAVE_CG
if (!(x->core_hw_context_enable || x->core_es))
BIT32_SET(flags, GFX_CTX_FLAGS_SHADERS_CG);

View File

@ -199,13 +199,13 @@ static EGLint *xegl_fill_attribs(xegl_ctx_data_t *xegl, EGLint *attr)
#ifdef EGL_KHR_create_context
case GFX_CTX_OPENGL_API:
{
unsigned
unsigned
version = xegl->egl.major * 1000 + xegl->egl.minor;
bool core = version >= 3001;
#ifdef GL_DEBUG
bool debug = true;
#else
struct retro_hw_render_callback
struct retro_hw_render_callback
*hwr = video_driver_get_hw_context();
bool debug = hwr->debug_context;
#endif
@ -304,10 +304,10 @@ static bool gfx_ctx_xegl_set_video_mode(void *data,
swa.colormap = g_x11_cmap = XCreateColormap(
g_x11_dpy, RootWindow(g_x11_dpy, vi->screen),
vi->visual, AllocNone);
swa.event_mask = StructureNotifyMask
swa.event_mask = StructureNotifyMask
| KeyPressMask
| ButtonPressMask
| ButtonReleaseMask
| ButtonPressMask
| ButtonReleaseMask
| KeyReleaseMask
| EnterWindowMask
| LeaveWindowMask;
@ -572,10 +572,9 @@ static uint32_t gfx_ctx_xegl_get_flags(void *data)
BIT32_SET(flags, GFX_CTX_FLAGS_SHADERS_SLANG);
#endif
}
else
{
BIT32_SET(flags, GFX_CTX_FLAGS_SHADERS_GLSL);
}
#ifdef HAVE_GLSL
BIT32_SET(flags, GFX_CTX_FLAGS_SHADERS_GLSL);
#endif
return flags;
}

View File

@ -1297,9 +1297,8 @@ static void gl_glsl_set_params(void *dat, void *shader_data)
struct glsl_attrib attribs[32];
float input_size[2], output_size[2], texture_size[2], final_vp_size[2];
video_shader_ctx_params_t *params = (video_shader_ctx_params_t*)dat;
gl2_t *gl_data = (gl2_t*)params->data;
unsigned vp_width = gl_data->out_vp_width;
unsigned vp_height = gl_data->out_vp_height;
unsigned vp_width = params->vp_width;
unsigned vp_height = params->vp_height;
unsigned width = params->width;
unsigned height = params->height;
unsigned tex_width = params->tex_width;

View File

@ -65,7 +65,11 @@
#if defined(_XBOX360)
#define DEFAULT_SHADER_TYPE RARCH_SHADER_HLSL
#elif defined(HAVE_OPENGLES2) || defined(HAVE_GLSL)
#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
@ -275,11 +279,12 @@ typedef struct shader_backend
typedef struct video_shader_ctx_params
{
void *data;
const void *info;
const void *prev_info;
const void *feedback_info;
const void *fbo_info;
unsigned vp_width;
unsigned vp_height;
unsigned width;
unsigned height;
unsigned tex_width;

View File

@ -70,11 +70,11 @@ UI
/*============================================================
VIDEO DRIVER
============================================================ */
#ifdef HAVE_VULKAN
#if defined(HAVE_VULKAN) && defined(HAVE_SLANG)
#include "../gfx/drivers_shader/shader_vulkan.cpp"
#endif
#if defined(HAVE_OPENGL_CORE)
#if defined(HAVE_OPENGL_CORE) && defined(HAVE_SLANG)
#include "../gfx/drivers_shader/shader_gl3.cpp"
#endif