mirror of
https://github.com/CTCaer/RetroArch.git
synced 2024-12-30 06:43:53 +00:00
Merge pull request #5454 from rz5/master
Prevent crashes caused by loading shaders in incompatible contexts
This commit is contained in:
commit
59cabfe80f
@ -212,6 +212,8 @@ static gfx_ctx_driver_t current_video_context;
|
||||
|
||||
static void *video_context_data = NULL;
|
||||
|
||||
static enum gfx_ctx_api current_video_context_api = GFX_CTX_NONE;
|
||||
|
||||
shader_backend_t *current_shader = NULL;
|
||||
void *shader_data = NULL;
|
||||
|
||||
@ -2720,6 +2722,9 @@ static const gfx_ctx_driver_t *video_context_driver_init(
|
||||
video_info.shared_context && hw_render_ctx);
|
||||
|
||||
video_context_driver_set_data(ctx_data);
|
||||
|
||||
current_video_context_api = api;
|
||||
|
||||
return ctx;
|
||||
}
|
||||
|
||||
@ -3014,6 +3019,11 @@ bool video_context_driver_set_flags(gfx_ctx_flags_t *flags)
|
||||
return true;
|
||||
}
|
||||
|
||||
enum gfx_ctx_api video_context_driver_get_api(void)
|
||||
{
|
||||
return current_video_context_api;
|
||||
}
|
||||
|
||||
bool video_driver_has_windowed(void)
|
||||
{
|
||||
#if defined(RARCH_CONSOLE) || defined(RARCH_MOBILE)
|
||||
|
@ -1206,6 +1206,8 @@ bool video_context_driver_translate_aspect(gfx_ctx_aspect_t *aspect);
|
||||
|
||||
bool video_context_driver_input_driver(gfx_ctx_input_t *inp);
|
||||
|
||||
enum gfx_ctx_api video_context_driver_get_api(void);
|
||||
|
||||
void video_context_driver_free(void);
|
||||
|
||||
bool video_shader_driver_get_prev_textures(video_shader_ctx_texture_t *texture);
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include <compat/msvc.h>
|
||||
#include <compat/strl.h>
|
||||
#include <file/file_path.h>
|
||||
#include <gfx/video_driver.h> /* video_context_driver_get_api */
|
||||
#include <rhash.h>
|
||||
#include <string/stdstring.h>
|
||||
#include <streams/file_stream.h>
|
||||
@ -1080,6 +1081,15 @@ void video_shader_write_conf_cgp(config_file_t *conf,
|
||||
enum rarch_shader_type video_shader_parse_type(const char *path,
|
||||
enum rarch_shader_type fallback)
|
||||
{
|
||||
enum rarch_shader_type shader_type = RARCH_SHADER_NONE;
|
||||
enum gfx_ctx_api api = video_context_driver_get_api();
|
||||
|
||||
#ifdef HAVE_CG
|
||||
bool cg_supported = true;
|
||||
#else
|
||||
bool cg_supported = false;
|
||||
#endif
|
||||
|
||||
if (!path)
|
||||
return fallback;
|
||||
|
||||
@ -1088,17 +1098,45 @@ enum rarch_shader_type video_shader_parse_type(const char *path,
|
||||
{
|
||||
case FILE_TYPE_SHADER_CG:
|
||||
case FILE_TYPE_SHADER_PRESET_CGP:
|
||||
return RARCH_SHADER_CG;
|
||||
shader_type = RARCH_SHADER_CG;
|
||||
break;
|
||||
case FILE_TYPE_SHADER_GLSL:
|
||||
case FILE_TYPE_SHADER_PRESET_GLSLP:
|
||||
return RARCH_SHADER_GLSL;
|
||||
shader_type = RARCH_SHADER_GLSL;
|
||||
break;
|
||||
case FILE_TYPE_SHADER_SLANG:
|
||||
case FILE_TYPE_SHADER_PRESET_SLANGP:
|
||||
return RARCH_SHADER_SLANG;
|
||||
shader_type = RARCH_SHADER_SLANG;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
switch (api)
|
||||
{
|
||||
case GFX_CTX_OPENGL_API:
|
||||
case GFX_CTX_OPENGL_ES_API:
|
||||
if (shader_type == RARCH_SHADER_GLSL
|
||||
|| (cg_supported && shader_type == RARCH_SHADER_CG))
|
||||
return shader_type;
|
||||
break;
|
||||
case GFX_CTX_DIRECT3D9_API:
|
||||
if (cg_supported && shader_type == RARCH_SHADER_CG)
|
||||
return shader_type;
|
||||
break;
|
||||
case GFX_CTX_VULKAN_API:
|
||||
if (shader_type == RARCH_SHADER_SLANG)
|
||||
return shader_type;
|
||||
break;
|
||||
case GFX_CTX_GDI_API:
|
||||
case GFX_CTX_OPENVG_API:
|
||||
case GFX_CTX_DIRECT3D8_API:
|
||||
case GFX_CTX_NONE:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
RARCH_WARN("Rendering context is incompatible with shader type: %s\n", path);
|
||||
return fallback;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user