From 4a9325d01d064023846ad4f40dc8b244fa877171 Mon Sep 17 00:00:00 2001 From: r5 Date: Mon, 18 Sep 2017 03:46:17 +0100 Subject: [PATCH 1/7] (shaders) Avoid certain shader types when context isn't compatible. @bparker06 to the rescue. --- gfx/video_driver.c | 10 ++++++++++ gfx/video_driver.h | 2 ++ gfx/video_shader_parse.c | 36 ++++++++++++++++++++++++++++++++---- 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/gfx/video_driver.c b/gfx/video_driver.c index 0d9d00740f..f5396f3509 100644 --- a/gfx/video_driver.c +++ b/gfx/video_driver.c @@ -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; @@ -2718,6 +2720,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; } @@ -3012,6 +3017,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) diff --git a/gfx/video_driver.h b/gfx/video_driver.h index 1bf7965e5e..1172dc978a 100644 --- a/gfx/video_driver.h +++ b/gfx/video_driver.h @@ -1208,6 +1208,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); diff --git a/gfx/video_shader_parse.c b/gfx/video_shader_parse.c index 0f1f22710e..81ea705fb5 100644 --- a/gfx/video_shader_parse.c +++ b/gfx/video_shader_parse.c @@ -1083,23 +1083,51 @@ enum rarch_shader_type video_shader_parse_type(const char *path, if (!path) return fallback; + enum rarch_shader_type shader_type = RARCH_SHADER_NONE; switch (msg_hash_to_file_type( msg_hash_calculate(path_get_extension(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; } - return fallback; + enum gfx_ctx_api api = video_context_driver_get_api(); + + + switch (api) + { + case GFX_CTX_OPENGL_API: + if (shader_type == RARCH_SHADER_GLSL || shader_type == RARCH_SHADER_CG) + return shader_type; + case GFX_CTX_OPENGL_ES_API: + if (shader_type == RARCH_SHADER_GLSL) + return shader_type; + case GFX_CTX_DIRECT3D9_API: + if (shader_type == RARCH_SHADER_CG) + return shader_type; + case GFX_CTX_VULKAN_API: + if (shader_type == RARCH_SHADER_SLANG) + return fallback; + case GFX_CTX_NONE: + case GFX_CTX_GDI_API: + case GFX_CTX_OPENVG_API: + case GFX_CTX_DIRECT3D8_API: + default: + return fallback; + } } /** From da0abc31268af8613e08653b266013ac56af2ed0 Mon Sep 17 00:00:00 2001 From: r5 Date: Mon, 18 Sep 2017 04:09:28 +0100 Subject: [PATCH 2/7] Try to fix C89 build --- gfx/video_shader_parse.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gfx/video_shader_parse.c b/gfx/video_shader_parse.c index 81ea705fb5..3fc081c6c6 100644 --- a/gfx/video_shader_parse.c +++ b/gfx/video_shader_parse.c @@ -1080,10 +1080,11 @@ 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; + if (!path) return fallback; - enum rarch_shader_type shader_type = RARCH_SHADER_NONE; switch (msg_hash_to_file_type( msg_hash_calculate(path_get_extension(path)))) { @@ -1106,7 +1107,6 @@ enum rarch_shader_type video_shader_parse_type(const char *path, enum gfx_ctx_api api = video_context_driver_get_api(); - switch (api) { case GFX_CTX_OPENGL_API: From fdccf4a6b0bbfd04bdf6c1539bac47d5645f36d1 Mon Sep 17 00:00:00 2001 From: r5 Date: Mon, 18 Sep 2017 04:21:59 +0100 Subject: [PATCH 3/7] (C89) Should be able to build now @bparker06 to the rescue again. --- gfx/video_shader_parse.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/gfx/video_shader_parse.c b/gfx/video_shader_parse.c index 3fc081c6c6..671ebbd921 100644 --- a/gfx/video_shader_parse.c +++ b/gfx/video_shader_parse.c @@ -1080,7 +1080,8 @@ 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 rarch_shader_type shader_type = RARCH_SHADER_NONE; + enum gfx_ctx_api api = video_context_driver_get_api(); if (!path) return fallback; @@ -1105,8 +1106,6 @@ enum rarch_shader_type video_shader_parse_type(const char *path, break; } - enum gfx_ctx_api api = video_context_driver_get_api(); - switch (api) { case GFX_CTX_OPENGL_API: From f5988b232312cc0d0e3b834080c048fefc44e0d6 Mon Sep 17 00:00:00 2001 From: r5 Date: Mon, 18 Sep 2017 04:43:08 +0100 Subject: [PATCH 4/7] (shaders) Log a warning when using the shader fallback type Only allow using Cg shaders when HAVE_CG is set --- gfx/video_shader_parse.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/gfx/video_shader_parse.c b/gfx/video_shader_parse.c index 671ebbd921..da6d93597f 100644 --- a/gfx/video_shader_parse.c +++ b/gfx/video_shader_parse.c @@ -1081,7 +1081,13 @@ 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(); + 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; @@ -1109,22 +1115,22 @@ enum rarch_shader_type video_shader_parse_type(const char *path, switch (api) { case GFX_CTX_OPENGL_API: - if (shader_type == RARCH_SHADER_GLSL || shader_type == RARCH_SHADER_CG) - return shader_type; case GFX_CTX_OPENGL_ES_API: - if (shader_type == RARCH_SHADER_GLSL) + if (shader_type == RARCH_SHADER_GLSL + || (cg_supported && shader_type == RARCH_SHADER_CG)) return shader_type; case GFX_CTX_DIRECT3D9_API: - if (shader_type == RARCH_SHADER_CG) + if (cg_supported && shader_type == RARCH_SHADER_CG) return shader_type; case GFX_CTX_VULKAN_API: if (shader_type == RARCH_SHADER_SLANG) return fallback; - case GFX_CTX_NONE: case GFX_CTX_GDI_API: case GFX_CTX_OPENVG_API: case GFX_CTX_DIRECT3D8_API: + case GFX_CTX_NONE: default: + RARCH_WARN("Current video context is incompatible with file: %s", path); return fallback; } } From 33431b7b36ce880f87778ca0482e39ed4591933e Mon Sep 17 00:00:00 2001 From: r5 Date: Mon, 18 Sep 2017 10:51:38 +0100 Subject: [PATCH 5/7] (shaders) Fix a bug when context is Vulkan. Remove smart code. --- gfx/video_shader_parse.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/gfx/video_shader_parse.c b/gfx/video_shader_parse.c index da6d93597f..6494dd702d 100644 --- a/gfx/video_shader_parse.c +++ b/gfx/video_shader_parse.c @@ -1095,7 +1095,6 @@ enum rarch_shader_type video_shader_parse_type(const char *path, switch (msg_hash_to_file_type( msg_hash_calculate(path_get_extension(path)))) { - case FILE_TYPE_SHADER_CG: case FILE_TYPE_SHADER_PRESET_CGP: shader_type = RARCH_SHADER_CG; @@ -1119,20 +1118,25 @@ enum rarch_shader_type video_shader_parse_type(const char *path, 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 fallback; + return shader_type; + break; case GFX_CTX_GDI_API: case GFX_CTX_OPENVG_API: case GFX_CTX_DIRECT3D8_API: case GFX_CTX_NONE: default: - RARCH_WARN("Current video context is incompatible with file: %s", path); - return fallback; + break; } + + RARCH_WARN("Current video context is incompatible with file: %s", path); + return fallback; } /** From cc5adc56ac10e84d877e44f511a17f00e49b20a6 Mon Sep 17 00:00:00 2001 From: r5 Date: Mon, 18 Sep 2017 18:12:00 +0100 Subject: [PATCH 6/7] (shaders) Change RARCH_WARN message, add missing newline --- gfx/video_shader_parse.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gfx/video_shader_parse.c b/gfx/video_shader_parse.c index 6494dd702d..b0866bfe40 100644 --- a/gfx/video_shader_parse.c +++ b/gfx/video_shader_parse.c @@ -1135,7 +1135,7 @@ enum rarch_shader_type video_shader_parse_type(const char *path, break; } - RARCH_WARN("Current video context is incompatible with file: %s", path); + RARCH_WARN("Rendering context is incompatible with shader type: %s\n", path); return fallback; } From d5321c200124ea6d327f5eab4a74340081a5a3df Mon Sep 17 00:00:00 2001 From: r5 Date: Tue, 19 Sep 2017 13:49:51 +0100 Subject: [PATCH 7/7] Fix missing include --- gfx/video_shader_parse.c | 1 + 1 file changed, 1 insertion(+) diff --git a/gfx/video_shader_parse.c b/gfx/video_shader_parse.c index b0866bfe40..18ef05076c 100644 --- a/gfx/video_shader_parse.c +++ b/gfx/video_shader_parse.c @@ -21,6 +21,7 @@ #include #include #include +#include /* video_context_driver_get_api */ #include #include #include