From 606e37fcbdd6490deba838ef4c35b2c282cb610e Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sun, 11 Sep 2016 15:07:07 +0200 Subject: [PATCH] Cleanups --- .../d3d_renderchains/render_chain_cg.cpp | 14 ++-- gfx/drivers_font/d3d_w32_font.cpp | 6 +- gfx/drivers_font/xdk1_xfonts.c | 6 +- gfx/drivers_font/xdk360_fonts.cpp | 8 ++- gfx/drivers_font_renderer/coretext.c | 7 +- gfx/drivers_shader/glslang_util.cpp | 67 ++++++++++++------- gfx/drivers_shader/shader_null.c | 5 +- gfx/drivers_shader/slang_reflection.hpp | 2 +- 8 files changed, 77 insertions(+), 38 deletions(-) diff --git a/gfx/drivers/d3d_renderchains/render_chain_cg.cpp b/gfx/drivers/d3d_renderchains/render_chain_cg.cpp index 7981ad6839..d760dc1079 100644 --- a/gfx/drivers/d3d_renderchains/render_chain_cg.cpp +++ b/gfx/drivers/d3d_renderchains/render_chain_cg.cpp @@ -20,6 +20,10 @@ #include #include +#ifdef HAVE_CONFIG_H +#include "../../config.h" +#endif + #include "../../include/Cg/cg.h" #include "../../include/Cg/cgD3D9.h" @@ -27,15 +31,15 @@ #include #include +#include "../d3d.h" +#include "../d3d_shaders/opaque.cg.d3d9.h" + #include "render_chain_driver.h" #include "../../video_driver.h" -#include "../../../configuration.h" -#include "../../../general.h" #include "../../../performance_counters.h" +#include "../../../configuration.h" +#include "../../../runloop.h" #include "../../../verbosity.h" -#include "../d3d.h" - -#include "../d3d_shaders/opaque.cg.d3d9.h" #define cg_d3d9_set_param_1f(param, x) if (param) cgD3D9SetUniform(param, x) namespace { diff --git a/gfx/drivers_font/d3d_w32_font.cpp b/gfx/drivers_font/d3d_w32_font.cpp index ac1794b893..792072d7bb 100644 --- a/gfx/drivers_font/d3d_w32_font.cpp +++ b/gfx/drivers_font/d3d_w32_font.cpp @@ -14,11 +14,15 @@ * If not, see . */ +#ifdef HAVE_CONFIG_H +#include "../../config.h" +#endif + #include "../drivers/d3d.h" #include "../font_driver.h" #include "../../configuration.h" -#include "../../general.h" +#include "../../runloop.h" #include "../include/d3d9/d3dx9core.h" diff --git a/gfx/drivers_font/xdk1_xfonts.c b/gfx/drivers_font/xdk1_xfonts.c index 4e469c090b..e488b0d98e 100644 --- a/gfx/drivers_font/xdk1_xfonts.c +++ b/gfx/drivers_font/xdk1_xfonts.c @@ -16,8 +16,12 @@ #include +#ifdef HAVE_CONFIG_H +#include "../../config.h" +#endif + #include "../font_driver.h" -#include "../../general.h" +#include "../../runloop.h" typedef struct { diff --git a/gfx/drivers_font/xdk360_fonts.cpp b/gfx/drivers_font/xdk360_fonts.cpp index fa5a9df0ad..3e8f84339c 100644 --- a/gfx/drivers_font/xdk360_fonts.cpp +++ b/gfx/drivers_font/xdk360_fonts.cpp @@ -18,9 +18,13 @@ #include -#include "../font_driver.h" +#ifdef HAVE_CONFIG_H +#include "../../runloop.h" +#endif + #include "../d3d/d3d.h" -#include "../../general.h" +#include "../font_driver.h" +#include "../../runloop.h" #include "../drivers/d3d_shaders/font.hlsl.d3d9.h" diff --git a/gfx/drivers_font_renderer/coretext.c b/gfx/drivers_font_renderer/coretext.c index f63bb04d34..a77ad9db89 100644 --- a/gfx/drivers_font_renderer/coretext.c +++ b/gfx/drivers_font_renderer/coretext.c @@ -19,6 +19,11 @@ #include #include + +#ifdef HAVE_CONFIG_H +#include "../../config.h" +#endif + #ifdef IOS #include #include @@ -27,7 +32,7 @@ #endif #include "../font_driver.h" -#include "../../general.h" +#include "../../runloop.h" #define CT_ATLAS_ROWS 16 #define CT_ATLAS_COLS 16 diff --git a/gfx/drivers_shader/glslang_util.cpp b/gfx/drivers_shader/glslang_util.cpp index 54f5f8f407..d00f6d3002 100644 --- a/gfx/drivers_shader/glslang_util.cpp +++ b/gfx/drivers_shader/glslang_util.cpp @@ -14,29 +14,32 @@ */ #include +#include #include #include #include +#include #include #include +#include #include "glslang_util.hpp" #include "glslang.hpp" -#include "../../general.h" -#include "../../libretro-common/include/file/file_path.h" +#include "../../verbosity.h" using namespace std; static bool read_shader_file(const char *path, vector *output, bool root_file) { - char *buf = nullptr; - ssize_t len = 0; - const char *basename = path_basename(path); - char include_path[PATH_MAX]; - char tmp[PATH_MAX]; vector lines; + char *ptr = NULL; + char *buf = nullptr; + ssize_t len = 0; + char include_path[PATH_MAX_LENGTH] = {0}; + char tmp[PATH_MAX_LENGTH] = {0}; + const char *basename = path_basename(path); if (!filestream_read_file(path, (void**)&buf, &len)) { @@ -44,8 +47,9 @@ static bool read_shader_file(const char *path, vector *output, bool root return false; } - // Cannot use string_split since it removes blank lines (strtok). - char *ptr = buf; + /* Cannot use string_split since it removes blank lines (strtok). */ + ptr = buf; + while (ptr && *ptr) { lines.push_back(ptr); @@ -75,13 +79,14 @@ static bool read_shader_file(const char *path, vector *output, bool root } output->push_back(lines[0]); - // Allows us to use #line to make dealing with shader errors easier. - // This is supported by glslang, but since we always use glslang statically, - // this is fine. + /* Allows us to use #line to make dealing with shader errors easier. + * This is supported by glslang, but since we always use glslang statically, + * this is fine. */ output->push_back("#extension GL_GOOGLE_cpp_style_line_directive : require"); } - // At least VIM treats the first line as line #1, so offset everything by one. + /* At least VIM treats the first line as line #1, + * so offset everything by one. */ snprintf(tmp, sizeof(tmp), "#line %u \"%s\"", root_file ? 2 : 1, basename); output->push_back(tmp); @@ -90,7 +95,9 @@ static bool read_shader_file(const char *path, vector *output, bool root const char *line = lines[i]; if (strstr(line, "#include ") == line) { - char *c = (char*)strchr(line, '"'); + char *closing = NULL; + char *c = (char*)strchr(line, '"'); + if (!c) { RARCH_ERR("Invalid include statement \"%s\".\n", line); @@ -98,14 +105,18 @@ static bool read_shader_file(const char *path, vector *output, bool root return false; } c++; - char *closing = (char*)strchr(c, '"'); + + closing = (char*)strchr(c, '"'); + if (!closing) { RARCH_ERR("Invalid include statement \"%s\".\n", line); free(buf); return false; } + *closing = '\0'; + fill_pathname_resolve_relative(include_path, path, c, sizeof(include_path)); if (!read_shader_file(include_path, output, false)) @@ -114,15 +125,18 @@ static bool read_shader_file(const char *path, vector *output, bool root return false; } - // After including a file, use line directive to pull it back to current file. + /* After including a file, use line directive + * to pull it back to current file. */ snprintf(tmp, sizeof(tmp), "#line %u \"%s\"", unsigned(i + 1), basename); output->push_back(tmp); } else if (strstr(line, "#endif") || strstr(line, "#pragma")) { - // #line seems to be ignored if preprocessor tests fail, - // so we should reapply #line after each #endif. - // Add extra offset here since we're setting #line for the line after this one. + /* #line seems to be ignored if preprocessor tests fail, + * so we should reapply #line after each #endif. + * Add extra offset here since we're setting #line + * for the line after this one. + */ snprintf(tmp, sizeof(tmp), "#line %u \"%s\"", unsigned(i + 2), basename); output->push_back(line); output->push_back(tmp); @@ -140,7 +154,7 @@ static string build_stage_source(const vector &lines, const char *stage) ostringstream str; bool active = true; - // Version header. + /* Version header. */ str << lines.front(); str << '\n'; @@ -157,7 +171,7 @@ static string build_stage_source(const vector &lines, const char *stage) else if (itr->find("#pragma name ") == 0 || itr->find("#pragma format ") == 0) { - // Ignore + /* Ignore */ } else if (active) str << *itr; @@ -253,10 +267,11 @@ static glslang_format glslang_find_format(const char *fmt) static bool glslang_parse_meta(const vector &lines, glslang_meta *meta) { - char id[64] = {}; + char id[64] = {}; char desc[64] = {}; *meta = glslang_meta{}; + for (auto &line : lines) { if (line.find("#pragma name ") == 0) @@ -290,7 +305,8 @@ static bool glslang_parse_meta(const vector &lines, glslang_meta *meta) return param.id == id; }); - // Allow duplicate #pragma parameter, but only if they are exactly the same. + /* Allow duplicate #pragma parameter, but only + * if they are exactly the same. */ if (itr != end(meta->parameters)) { if (itr->desc != desc || @@ -314,13 +330,16 @@ static bool glslang_parse_meta(const vector &lines, glslang_meta *meta) } else if (line.find("#pragma format ") == 0) { + const char *str = NULL; + if (meta->rt_format != SLANG_FORMAT_UNKNOWN) { RARCH_ERR("[slang]: Trying to declare format multiple times for file.\n"); return false; } - const char *str = line.c_str() + strlen("#pragma format "); + str = line.c_str() + strlen("#pragma format "); + while (*str == ' ') str++; diff --git a/gfx/drivers_shader/shader_null.c b/gfx/drivers_shader/shader_null.c index e524b0bb98..0d20a3c6ab 100644 --- a/gfx/drivers_shader/shader_null.c +++ b/gfx/drivers_shader/shader_null.c @@ -23,9 +23,6 @@ #include #include -#include "../video_state_tracker.h" -#include "../../dynamic.h" - #ifdef HAVE_CONFIG_H #include "../../config.h" #endif @@ -35,6 +32,8 @@ #endif #include "../video_shader_driver.h" +#include "../video_state_tracker.h" +#include "../../dynamic.h" typedef struct null_shader_data { diff --git a/gfx/drivers_shader/slang_reflection.hpp b/gfx/drivers_shader/slang_reflection.hpp index b50e650e8c..b2a9157286 100644 --- a/gfx/drivers_shader/slang_reflection.hpp +++ b/gfx/drivers_shader/slang_reflection.hpp @@ -80,7 +80,7 @@ enum slang_stage SLANG_STAGE_FRAGMENT_MASK = 1 << 1 }; -// Vulkan minimum limit. +/* Vulkan minimum limit. */ #define SLANG_NUM_BINDINGS 16 struct slang_texture_semantic_meta