Cleanup: GPU: Use function parameters instead of template

This commit is contained in:
Clément Foucault
2024-10-12 13:48:45 +02:00
parent d9aad850b0
commit 191b347f58
3 changed files with 13 additions and 13 deletions

View File

@@ -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();

View File

@@ -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<bool no_linting = false> class Preprocessor {
class Preprocessor {
using uint = unsigned int;
struct SharedVar {
std::string type;
std::string name;
@@ -36,7 +38,11 @@ template<bool no_linting = false> class Preprocessor {
public:
/* Takes a whole source file and output processed source. */
template<typename ReportErrorF>
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<bool no_linting = false> 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<bool no_linting = false> class Preprocessor {
template<typename ReportErrorF>
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<bool no_linting = false> class Preprocessor {
template<typename ReportErrorF>
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<bool no_linting = false> class Preprocessor {
}
};
using PreprocessorPython = Preprocessor<true>;
} // namespace blender::gpu::shader

View File

@@ -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);
};