diff --git a/source/blender/gpu/glsl_preprocess/glsl_preprocess.cc b/source/blender/gpu/glsl_preprocess/glsl_preprocess.cc index b2319588e42..832a3280512 100644 --- a/source/blender/gpu/glsl_preprocess/glsl_preprocess.cc +++ b/source/blender/gpu/glsl_preprocess/glsl_preprocess.cc @@ -59,6 +59,7 @@ int main(int argc, char **argv) }; const bool is_info = std::string(output_file_name).find("info.hh") != std::string::npos; + const bool is_glsl = std::string(output_file_name).find(".glsl") != std::string::npos; if (is_info) { std::cerr << "File " << output_file_name @@ -68,7 +69,7 @@ int main(int argc, char **argv) blender::gpu::shader::Preprocessor processor; - output_file << processor.process(buffer.str(), report_error); + output_file << processor.process(buffer.str(), true, is_glsl, is_glsl, report_error); input_file.close(); output_file.close(); diff --git a/source/blender/gpu/glsl_preprocess/glsl_preprocess.hh b/source/blender/gpu/glsl_preprocess/glsl_preprocess.hh index 94dac8afe2a..d8dd0429b30 100644 --- a/source/blender/gpu/glsl_preprocess/glsl_preprocess.hh +++ b/source/blender/gpu/glsl_preprocess/glsl_preprocess.hh @@ -23,7 +23,9 @@ namespace blender::gpu::shader { * Implementation speed is not a huge concern as we only apply this at compile time or on python * shaders source. */ -template class Preprocessor { +class Preprocessor { + using uint = unsigned int; + struct SharedVar { std::string type; std::string name; @@ -36,7 +38,11 @@ template class Preprocessor { public: /* Takes a whole source file and output processed source. */ template - std::string process(std::string str, const ReportErrorF &report_error) + std::string process(std::string str, + bool do_linting, + bool do_string_mutation, + bool do_include_mutation, + const ReportErrorF &report_error) { str = remove_comments(str, report_error); threadgroup_variable_parsing(str); @@ -48,10 +54,11 @@ template class Preprocessor { return str + suffix(); } + /* Variant use for python shaders. */ std::string process(const std::string &str) { auto no_err_report = [](std::string, std::smatch, const char *) {}; - return process(str, no_err_report); + return process(str, false, false, false, no_err_report); } private: @@ -137,9 +144,6 @@ template class Preprocessor { template void matrix_constructor_linting(std::string str, const ReportErrorF &report_error) { - if constexpr (no_linting) { - return; - } /* Example: `mat4(other_mat)`. */ std::regex regex("\\s+(mat(\\d|\\dx\\d)|float\\dx\\d)\\([^,\\s\\d]+\\)"); for (std::smatch match; std::regex_search(str, match, regex); str = match.suffix()) { @@ -154,9 +158,6 @@ template class Preprocessor { template void array_constructor_linting(std::string str, const ReportErrorF &report_error) { - if constexpr (no_linting) { - return; - } std::regex regex("=\\s*(\\w+)\\s*\\[[^\\]]*\\]\\s*\\("); for (std::smatch match; std::regex_search(str, match, regex); str = match.suffix()) { /* This only catches some invalid usage. For the rest, the CI will catch them. */ @@ -255,6 +256,4 @@ template class Preprocessor { } }; -using PreprocessorPython = Preprocessor; - } // namespace blender::gpu::shader diff --git a/source/blender/gpu/intern/gpu_shader.cc b/source/blender/gpu/intern/gpu_shader.cc index 32e32de0dc3..84e7bf135d6 100644 --- a/source/blender/gpu/intern/gpu_shader.cc +++ b/source/blender/gpu/intern/gpu_shader.cc @@ -303,7 +303,7 @@ GPUShader *GPU_shader_create_from_info(const GPUShaderCreateInfo *_info) static std::string preprocess_source(StringRefNull original) { - gpu::shader::PreprocessorPython processor; + gpu::shader::Preprocessor processor; return processor.process(original); };