Blender V5.0
gl_shader_log.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2021 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "gl_shader.hh"
10
11#include "GPU_platform.hh"
12
13namespace blender::gpu {
14
15const char *GLLogParser::parse_line(const char *source_combined,
16 const char *log_line,
17 GPULogItem &log_item)
18{
19 /* Skip ERROR: or WARNING:. */
20 log_line = skip_severity_prefix(log_line, log_item);
21 log_line = skip_separators(log_line, "(: ");
22
23 /* Parse error line & char numbers. */
24 if (at_number(log_line)) {
25 const char *error_line_number_end;
26 log_item.cursor.row = parse_number(log_line, &error_line_number_end);
27 /* Try to fetch the error character (not always available). */
28 if (at_any(error_line_number_end, "(:") && at_number(&error_line_number_end[1])) {
29 log_item.cursor.column = parse_number(error_line_number_end + 1, &log_line);
30 }
31 else {
32 log_line = error_line_number_end;
33 }
34 /* There can be a 3rd number (case of mesa driver). */
35 if (at_any(log_line, "(:") && at_number(&log_line[1])) {
36 log_item.cursor.source = log_item.cursor.row;
37 log_item.cursor.row = log_item.cursor.column;
38 log_item.cursor.column = parse_number(log_line + 1, &error_line_number_end);
39 log_line = error_line_number_end;
40 }
41 }
42
43 if ((log_item.cursor.row != -1) && (log_item.cursor.column != -1)) {
45 /* source:row */
46 log_item.cursor.source = log_item.cursor.row;
47 log_item.cursor.row = log_item.cursor.column;
48 log_item.cursor.column = -1;
49 }
51 /* source:row */
52 log_item.cursor.source = log_item.cursor.row;
53 log_item.cursor.row = log_item.cursor.column;
54 log_item.cursor.column = -1;
55 }
56 else {
57 /* line:char */
58 }
59 }
60
61 if (log_item.cursor.row != -1) {
62 /* Get to the wanted line. */
63 size_t line_start_character = line_start_get(source_combined, log_item.cursor.row);
64 if (line_start_character != -1) {
65 StringRef filename = filename_get(source_combined, line_start_character);
66 size_t line_number = source_line_get(source_combined, line_start_character);
67 log_item.cursor.file_name_and_error_line = std::string(filename) + ':' +
68 std::to_string(line_number);
69 if (log_item.cursor.column != -1) {
70 log_item.cursor.file_name_and_error_line += ':' +
71 std::to_string(log_item.cursor.column + 1);
72 }
73 }
74 }
75
76 log_line = skip_separators(log_line, ":) ");
77
78 /* Skip to message. Avoid redundant info. */
79 log_line = skip_severity_keyword(log_line, log_item);
80 log_line = skip_separators(log_line, ":) ");
81
82 return log_line;
83}
84
85const char *GLLogParser::skip_severity_prefix(const char *log_line, GPULogItem &log_item)
86{
87 return skip_severity(log_line, log_item, "ERROR", "WARNING", "NOTE");
88}
89
90const char *GLLogParser::skip_severity_keyword(const char *log_line, GPULogItem &log_item)
91{
92 return skip_severity(log_line, log_item, "error", "warning", "note");
93}
94
95} // namespace blender::gpu
@ GPU_DEVICE_ATI
@ GPU_DEVICE_NVIDIA
bool GPU_type_matches(GPUDeviceType device, GPUOSType os, GPUDriverType driver)
@ GPU_DRIVER_OFFICIAL
@ GPU_OS_UNIX
@ GPU_OS_ANY
const char * parse_line(const char *source_combined, const char *log_line, GPULogItem &log_item) override
const char * skip_severity_prefix(const char *log_line, GPULogItem &log_item)
const char * skip_severity_keyword(const char *log_line, GPULogItem &log_item)
static size_t line_start_get(StringRefNull source_combined, size_t target_line)
static StringRef filename_get(StringRefNull source_combined, size_t pos)
int parse_number(const char *log_line, const char **r_new_position) const
const char * skip_separators(const char *log_line, const StringRef separators) const
bool at_number(const char *log_line) const
static size_t source_line_get(StringRefNull source_combined, size_t pos)
bool at_any(const char *log_line, const StringRef chars) const
const char * skip_severity(const char *log_line, GPULogItem &log_item, const char *error_msg, const char *warning_msg, const char *note_msg) const