Blender V4.3
mtl_shader_log.mm
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2022 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#include "BLI_string_ref.hh"
10
11#include "GPU_platform.hh"
12
13#include "mtl_shader_log.hh"
14
15namespace blender::gpu {
16
17const char *MTLLogParser::parse_line(const char *source_combined,
18 const char *log_line,
19 GPULogItem &log_item)
20{
21 const char *name_start = log_line;
22 log_line = skip_name(log_line);
23 const char *name_end = log_line;
24 log_line = skip_separators(log_line, ":");
25
26 /* Parse error line & char numbers. */
27 if (at_number(log_line)) {
28 /* Reset skip line if two errors follow. */
29 parsed_error_ = false;
30 wrapper_error_ = false;
31
32 const char *error_line_number_end;
33
34 log_item.cursor.row = parse_number(log_line, &error_line_number_end);
35 log_line = error_line_number_end;
36 log_line = skip_separators(log_line, ": ");
37 log_item.cursor.column = parse_number(log_line, &error_line_number_end);
38 /* For some reason the column is off by one. */
39 log_item.cursor.column--;
40 log_line = error_line_number_end;
41 /* Simply copy the start of the error line since it is already in the format we want. */
42 log_item.cursor.file_name_and_error_line = StringRef(name_start, error_line_number_end);
43
44 StringRef source_name(name_start, name_end);
45
46 if (source_name == "msl_wrapper_code") {
47 /* In this case the issue is in the wrapper. We cannot access it.
48 * So we still display the internal error lines for some more infos. */
49 log_item.cursor.row = -1;
50 wrapper_error_ = true;
51 }
52 else if (!source_name.is_empty()) {
53 std::string needle = std::string("#line 1 \"") + source_name + "\"";
54
55 StringRefNull src(source_combined);
56 int64_t file_start = src.find(needle);
57 if (file_start == -1) {
58 /* Can be generated code or wrapper code outside of the main sources.
59 * But should be already caught by the above case. */
60 log_item.cursor.row = -1;
61 wrapper_error_ = true;
62 }
63 else {
64 StringRef previous_sources(source_combined, file_start);
65 for (const char c : previous_sources) {
66 if (c == '\n') {
67 log_item.cursor.row++;
68 }
69 }
70 /* Count the needle end of line too. */
71 log_item.cursor.row++;
72 parsed_error_ = true;
73 }
74 }
75 }
76 else if (parsed_error_) {
77 /* Skip the redundant lines that we be outputted above the error. */
78 return skip_line(log_line);
79 }
80 else if (wrapper_error_) {
81 /* Display full lines of error in case of wrapper (non parsed) errors.
82 * Avoids weirdly aligned '^' and underlined suggestions. */
83 return name_start;
84 }
85 log_line = skip_separators(log_line, ": ");
86
87 /* Skip to message. Avoid redundant info. */
88 log_line = skip_severity_keyword(log_line, log_item);
89 log_line = skip_separators(log_line, ": ");
90
91 return log_line;
92}
93
94const char *MTLLogParser::skip_name(const char *log_line)
95{
96 return skip_until(log_line, ':');
97}
98
99const char *MTLLogParser::skip_severity_keyword(const char *log_line, GPULogItem &log_item)
100{
101 return skip_severity(log_line, log_item, "error", "warning", "note");
102}
103
104const char *MTLLogParser::skip_line(const char *cursor) const
105{
106 while (!ELEM(cursor[0], '\n', '\0')) {
107 cursor++;
108 }
109 return cursor;
110}
111
112} // namespace blender::gpu
#define ELEM(...)
constexpr int64_t find(char c, int64_t pos=0) const
constexpr bool is_empty() const
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
const char * skip_until(const char *log_line, char stop_char) 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
const char * parse_line(const char *source_combined, const char *log_line, GPULogItem &log_item) override
const char * skip_line(const char *cursor) const
const char * skip_name(const char *log_line)
const char * skip_severity_keyword(const char *log_line, GPULogItem &log_item)
__int64 int64_t
Definition stdint.h:89