Blender V4.5
vk_shader_log.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2022 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "vk_shader_log.hh"
10
11#include "GPU_platform.hh"
12
13namespace blender::gpu {
14
15const char *VKLogParser::parse_line(const char *source_combined,
16 const char *log_line,
17 GPULogItem &log_item)
18{
19 if (at_number(log_line)) {
20 /* Parse error file. */
21 const char *error_line_number_end;
22 log_item.cursor.source = parse_number(log_line, &error_line_number_end);
23 log_line = error_line_number_end;
24 }
25
26 log_line = skip_separators(log_line, ":");
27
28 /* Parse error line & char numbers. */
29 if (at_number(log_line)) {
30 const char *error_line_number_end;
31 log_item.cursor.row = parse_number(log_line, &error_line_number_end);
32 log_line = error_line_number_end;
33 }
34 log_line = skip_separators(log_line, ": ");
35
36 /* Skip to message. Avoid redundant info. */
37 log_line = skip_severity_keyword(log_line, log_item);
38 log_line = skip_separators(log_line, ": ");
39
40 /* TODO: Temporary fix for new line directive. Eventually this whole parsing should be done in
41 * C++ with regex for simplicity. */
42 if (log_item.cursor.source != -1) {
43 StringRefNull src(source_combined);
44 std::string needle = std::string("#line 1 ") + std::to_string(log_item.cursor.source);
45
46 int64_t file_start = src.find(needle);
47 if (file_start == -1) {
48 /* Can be generated code or wrapper code outside of the main sources. */
49 log_item.cursor.row = -1;
50 }
51 else {
52 StringRef previous_sources(source_combined, file_start);
53 for (const char c : previous_sources) {
54 if (c == '\n') {
55 log_item.cursor.row++;
56 }
57 }
58 }
59 }
60
61 return log_line;
62}
63
64const char *VKLogParser::skip_name(const char *log_line)
65{
66 return skip_until(log_line, ':');
67}
68
69const char *VKLogParser::skip_severity_keyword(const char *log_line, GPULogItem &log_item)
70{
71 return skip_severity(log_line, log_item, "error", "warning", "note");
72}
73
74} // namespace blender::gpu
long long int int64_t
constexpr int64_t find(char c, int64_t pos=0) 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_severity_keyword(const char *log_line, GPULogItem &log_item)
const char * skip_name(const char *log_line)