From 4ba944b15a1eb0f28718130f79f01c140f8e1022 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cle=CC=81ment=20Foucault?= Date: Wed, 16 Oct 2024 08:59:36 +0200 Subject: [PATCH] GPU: GLSL Preprocess: Always remove quotes We cannot do this for the MSL files. Also they are written in MSL which should not be processed. So use datatoc for them. Also add quote linting for GLSL files. --- source/blender/gpu/CMakeLists.txt | 2 +- .../gpu/glsl_preprocess/glsl_preprocess.hh | 23 ++++++++++++++----- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt index 19d028fc958..a893b644d7c 100644 --- a/source/blender/gpu/CMakeLists.txt +++ b/source/blender/gpu/CMakeLists.txt @@ -706,7 +706,7 @@ if(WITH_METAL_BACKEND) set(MSL_C) foreach(MSL_FILE ${MSL_SRC}) - glsl_to_c(${MSL_FILE} MSL_C) + data_to_c_simple(${MSL_FILE} MSL_C) endforeach() endif() diff --git a/source/blender/gpu/glsl_preprocess/glsl_preprocess.hh b/source/blender/gpu/glsl_preprocess/glsl_preprocess.hh index b04d993dcf7..0bbcc81d2ae 100644 --- a/source/blender/gpu/glsl_preprocess/glsl_preprocess.hh +++ b/source/blender/gpu/glsl_preprocess/glsl_preprocess.hh @@ -65,7 +65,7 @@ class Preprocessor { bool do_linting, bool do_parse_function, bool do_string_mutation, - bool do_include_mutation, + bool do_include_parsing, bool do_small_type_linting, report_callback report_error) { @@ -75,15 +75,14 @@ class Preprocessor { if (do_parse_function) { parse_library_functions(str); } - if (do_include_mutation) { - preprocessor_parse(str); - str = preprocessor_directive_mutation(str); + if (do_include_parsing) { + include_parse(str); } if (do_string_mutation) { static_strings_parsing(str); str = static_strings_mutation(str); str = printf_processing(str, report_error); - str = remove_quotes(str); + quote_linting(str, report_error); } if (do_linting) { global_scope_constant_linting(str, report_error); @@ -93,6 +92,8 @@ class Preprocessor { if (do_small_type_linting) { small_type_linting(str, report_error); } + str = preprocessor_directive_mutation(str); + str = remove_quotes(str); str = enum_macro_injection(str); str = argument_decorator_macro_injection(str); str = array_constructor_macro_injection(str); @@ -177,7 +178,7 @@ class Preprocessor { return std::regex_replace(str, std::regex(R"(["'])"), " "); } - void preprocessor_parse(const std::string &str) + void include_parse(const std::string &str) { /* Parse include directive before removing them. */ std::regex regex(R"(#\s*include\s*\"(\w+\.\w+)\")"); @@ -475,6 +476,16 @@ class Preprocessor { }); } + void quote_linting(const std::string &str, report_callback report_error) + { + std::regex regex(R"(["'])"); + regex_global_search(str, regex, [&](const std::smatch &match) { + /* This only catches some invalid usage. For the rest, the CI will catch them. */ + const char *msg = "Quotes are forbidden in GLSL."; + report_error(match, msg); + }); + } + template void array_constructor_linting(const std::string &str, const ReportErrorF &report_error) {