Blender V4.5
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 /* TODO: Temporary fix for new line directive. Eventually this whole parsing should be done in
62 * C++ with regex for simplicity. */
63 if (log_item.cursor.source != -1) {
64 StringRefNull src(source_combined);
65 std::string needle = std::string("#line 1 ") + std::to_string(log_item.cursor.source);
66
67 int64_t file_start = src.find(needle);
68 if (file_start == -1) {
69 /* Can be generated code or wrapper code outside of the main sources. */
70 log_item.cursor.row = -1;
71 }
72 else {
73 StringRef previous_sources(source_combined, file_start);
74 for (const char c : previous_sources) {
75 if (c == '\n') {
76 log_item.cursor.row++;
77 }
78 }
79 }
80 }
81
82 log_line = skip_separators(log_line, ":) ");
83
84 /* Skip to message. Avoid redundant info. */
85 log_line = skip_severity_keyword(log_line, log_item);
86 log_line = skip_separators(log_line, ":) ");
87
88 return log_line;
89}
90
91const char *GLLogParser::skip_severity_prefix(const char *log_line, GPULogItem &log_item)
92{
93 return skip_severity(log_line, log_item, "ERROR", "WARNING", "NOTE");
94}
95
96const char *GLLogParser::skip_severity_keyword(const char *log_line, GPULogItem &log_item)
97{
98 return skip_severity(log_line, log_item, "error", "warning", "note");
99}
100
101} // namespace blender::gpu
@ GPU_DRIVER_OFFICIAL
@ GPU_OS_UNIX
@ GPU_OS_ANY
@ GPU_DEVICE_ATI
@ GPU_DEVICE_NVIDIA
bool GPU_type_matches(eGPUDeviceType device, eGPUOSType os, eGPUDriverType driver)
long long int int64_t
constexpr int64_t find(char c, int64_t pos=0) const
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)
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
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