diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2020-10-23 20:29:27 +0300 |
---|---|---|
committer | Howard Trickey <howard.trickey@gmail.com> | 2020-10-24 21:07:05 +0300 |
commit | 0d1f65e5166c4822d9e01e7d3ce20f7df972550b (patch) | |
tree | a93ada3a93d26fbdc3e6ebdfe762389ef292b1a7 /source/blender/gpu/intern | |
parent | e856443c99d5175b3de6370590142a8d03054bb3 (diff) |
GPU: Use CLOG to for debug output
This removes the escape color control caracters when the output
does not supports it (i.e: file output, windows cmd).
Diffstat (limited to 'source/blender/gpu/intern')
-rw-r--r-- | source/blender/gpu/intern/gpu_debug.cc | 2 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_shader.cc | 60 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_shader_interface.cc | 1 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_shader_private.hh | 2 |
4 files changed, 44 insertions, 21 deletions
diff --git a/source/blender/gpu/intern/gpu_debug.cc b/source/blender/gpu/intern/gpu_debug.cc index d7944f0de50..63e7024b74b 100644 --- a/source/blender/gpu/intern/gpu_debug.cc +++ b/source/blender/gpu/intern/gpu_debug.cc @@ -74,7 +74,7 @@ void GPU_debug_get_groups_names(int name_buf_len, char *r_name_buf) for (StringRef &name : stack) { sz += BLI_snprintf_rlen(r_name_buf + sz, name_buf_len - sz, "%s > ", name.data()); } - r_name_buf[sz - 2] = ':'; + r_name_buf[sz - 3] = '\0'; } /* Return true if inside a debug group with the same name. */ diff --git a/source/blender/gpu/intern/gpu_shader.cc b/source/blender/gpu/intern/gpu_shader.cc index 05c81c2efeb..5f46f57c09a 100644 --- a/source/blender/gpu/intern/gpu_shader.cc +++ b/source/blender/gpu/intern/gpu_shader.cc @@ -23,6 +23,7 @@ #include "MEM_guardedalloc.h" +#include "BLI_dynstr.h" #include "BLI_math_base.h" #include "BLI_math_vector.h" #include "BLI_path_util.h" @@ -47,8 +48,12 @@ #include "gpu_context_private.hh" #include "gpu_shader_private.hh" +#include "CLG_log.h" + extern "C" char datatoc_gpu_shader_colorspace_lib_glsl[]; +static CLG_LogRef LOG = {"gpu.shader"}; + using namespace blender; using namespace blender::gpu; @@ -56,12 +61,21 @@ using namespace blender::gpu; /** \name Debug functions * \{ */ -void Shader::print_errors(Span<const char *> sources, char *log, const char *stage) +void Shader::print_log(Span<const char *> sources, char *log, const char *stage, const bool error) { const char line_prefix[] = " | "; + char err_col[] = "\033[31;1m"; + char warn_col[] = "\033[33;1m"; + char info_col[] = "\033[0;2m"; + char reset_col[] = "\033[0;0m"; char *sources_combined = BLI_string_join_arrayN((const char **)sources.data(), sources.size()); + DynStr *dynstr = BLI_dynstr_new(); + + if (!CLG_color_support_get(&LOG)) { + err_col[0] = warn_col[0] = info_col[0] = reset_col[0] = '\0'; + } - fprintf(stderr, "GPUShader: Compilation Log : %s : %s\n", this->name, stage); + BLI_dynstr_appendf(dynstr, "\n"); char *log_line = log, *line_end; char *error_line_number_end; @@ -136,10 +150,10 @@ void Shader::print_errors(Span<const char *> sources, char *log, const char *sta } /* Separate from previous block. */ if (last_error_line != error_line) { - fprintf(stderr, "\033[90m%s\033[39m\n", line_prefix); + BLI_dynstr_appendf(dynstr, "%s%s%s\n", info_col, line_prefix, reset_col); } else if (error_char != last_error_char) { - fprintf(stderr, "%s\n", line_prefix); + BLI_dynstr_appendf(dynstr, "%s\n", line_prefix); } /* Print line from the source file that is producing the error. */ if ((error_line != -1) && (error_line != last_error_line || error_char != last_error_char)) { @@ -159,24 +173,24 @@ void Shader::print_errors(Span<const char *> sources, char *log, const char *sta /* Print error source. */ if (found_line_id) { if (error_line != last_error_line) { - fprintf(stderr, "%5d | ", src_line_index); + BLI_dynstr_appendf(dynstr, "%5d | ", src_line_index); } else { - fprintf(stderr, line_prefix); + BLI_dynstr_appendf(dynstr, line_prefix); } - fwrite(src_line, (src_line_end + 1) - src_line, 1, stderr); + BLI_dynstr_nappend(dynstr, src_line, (src_line_end + 1) - src_line); /* Print char offset. */ - fprintf(stderr, line_prefix); + BLI_dynstr_appendf(dynstr, line_prefix); if (error_char != -1) { for (int i = 0; i < error_char; i++) { - fprintf(stderr, " "); + BLI_dynstr_appendf(dynstr, " "); } - fprintf(stderr, "^"); + BLI_dynstr_appendf(dynstr, "^"); } - fprintf(stderr, "\n"); + BLI_dynstr_appendf(dynstr, "\n"); } } - fprintf(stderr, line_prefix); + BLI_dynstr_appendf(dynstr, line_prefix); /* Skip to message. Avoid redundant info. */ const char *keywords[] = {"error", "warning"}; for (int i = 0; i < ARRAY_SIZE(prefix); i++) { @@ -191,22 +205,32 @@ void Shader::print_errors(Span<const char *> sources, char *log, const char *sta log_line++; } if (type == 0) { - fprintf(stderr, "\033[31;1mError\033[0;2m: "); + BLI_dynstr_appendf(dynstr, "%s%s%s: ", err_col, "Error", info_col); } else if (type == 1) { - fprintf(stderr, "\033[33;1mWarning\033[0;2m: "); + BLI_dynstr_appendf(dynstr, "%s%s%s: ", warn_col, "Warning", info_col); } /* Print the error itself. */ - fprintf(stderr, "\033[2m"); - fwrite(log_line, (line_end + 1) - log_line, 1, stderr); - fprintf(stderr, "\033[0m"); + BLI_dynstr_appendf(dynstr, info_col); + BLI_dynstr_nappend(dynstr, log_line, (line_end + 1) - log_line); + BLI_dynstr_appendf(dynstr, reset_col); /* Continue to next line. */ log_line = line_end + 1; last_error_line = error_line; last_error_char = error_char; } - fprintf(stderr, "\n"); MEM_freeN(sources_combined); + + CLG_Severity severity = error ? CLG_SEVERITY_ERROR : CLG_SEVERITY_WARN; + + if (((LOG.type->flag & CLG_FLAG_USE) && (LOG.type->level >= 0)) || + (severity >= CLG_SEVERITY_WARN)) { + const char *_str = BLI_dynstr_get_cstring(dynstr); + CLG_log_str(LOG.type, severity, this->name, stage, _str); + MEM_freeN((void *)_str); + } + + BLI_dynstr_free(dynstr); } /** \} */ diff --git a/source/blender/gpu/intern/gpu_shader_interface.cc b/source/blender/gpu/intern/gpu_shader_interface.cc index 4a7c7bc15a3..e5fb8025e7f 100644 --- a/source/blender/gpu/intern/gpu_shader_interface.cc +++ b/source/blender/gpu/intern/gpu_shader_interface.cc @@ -85,7 +85,6 @@ void ShaderInterface::debug_print(void) char *name_buf = name_buffer_; const char format[] = " | %.8x : %4d : %s\n"; - printf(" \033[1mGPUShaderInterface : \033[0m\n"); if (attrs.size() > 0) { printf("\n Attributes :\n"); } diff --git a/source/blender/gpu/intern/gpu_shader_private.hh b/source/blender/gpu/intern/gpu_shader_private.hh index b7acc0f9353..eac39dccd81 100644 --- a/source/blender/gpu/intern/gpu_shader_private.hh +++ b/source/blender/gpu/intern/gpu_shader_private.hh @@ -70,7 +70,7 @@ class Shader { }; protected: - void print_errors(Span<const char *> sources, char *log, const char *stage); + void print_log(Span<const char *> sources, char *log, const char *stage, const bool error); }; /* Syntacting suggar. */ |