This is motivated by the latest changes to the preprocessor which outputs a lot of line directives when code is generated or unrolled. In this case the reported line would be correct but not correctly displayed. Moreover the system of outputing hashes inside the `#line` directive proved to be incompatible with some compilers and tools (renderdoc). This commit always comments the line directives before compilation (solves the compatibility issue). When error logging, we then scan the commented directives to output the correct filename and source line. The log line is kept untouched and will show the correct final generated code that triggered the error. This also fixed the error line parsing for vulkan. Pull Request: https://projects.blender.org/blender/blender/pulls/145096
67 lines
2.0 KiB
C++
67 lines
2.0 KiB
C++
/* SPDX-FileCopyrightText: 2022 Blender Authors
|
|
*
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
|
|
/** \file
|
|
* \ingroup gpu
|
|
*/
|
|
|
|
#include "vk_shader_log.hh"
|
|
|
|
#include "GPU_platform.hh"
|
|
|
|
namespace blender::gpu {
|
|
|
|
const char *VKLogParser::parse_line(const char *source_combined,
|
|
const char *log_line,
|
|
GPULogItem &log_item)
|
|
{
|
|
/* Shader name. */
|
|
log_line = skip_name(log_line);
|
|
log_line = skip_separators(log_line, ":");
|
|
|
|
/* Parse error line & char numbers. */
|
|
if (at_number(log_line)) {
|
|
const char *error_line_number_end;
|
|
log_item.cursor.row = parse_number(log_line, &error_line_number_end);
|
|
log_line = error_line_number_end;
|
|
log_line = skip_separators(log_line, ": ");
|
|
}
|
|
if (at_number(log_line)) {
|
|
const char *number_end;
|
|
log_item.cursor.column = parse_number(log_line, &number_end);
|
|
log_line = number_end;
|
|
}
|
|
log_line = skip_separators(log_line, ": ");
|
|
|
|
/* Skip to message. Avoid redundant info. */
|
|
log_line = skip_severity_keyword(log_line, log_item);
|
|
log_line = skip_separators(log_line, ": ");
|
|
|
|
if (log_item.cursor.row != -1) {
|
|
/* Get to the wanted line. */
|
|
size_t line_start_character = line_start_get(source_combined, log_item.cursor.row);
|
|
StringRef filename = filename_get(source_combined, line_start_character);
|
|
size_t line_number = source_line_get(source_combined, line_start_character);
|
|
log_item.cursor.file_name_and_error_line = std::string(filename) + ':' +
|
|
std::to_string(line_number);
|
|
if (log_item.cursor.column != -1) {
|
|
log_item.cursor.file_name_and_error_line += ':' + std::to_string(log_item.cursor.column + 1);
|
|
}
|
|
}
|
|
|
|
return log_line;
|
|
}
|
|
|
|
const char *VKLogParser::skip_name(const char *log_line)
|
|
{
|
|
return skip_until(log_line, ':');
|
|
}
|
|
|
|
const char *VKLogParser::skip_severity_keyword(const char *log_line, GPULogItem &log_item)
|
|
{
|
|
return skip_severity(log_line, log_item, "error", "warning", "note");
|
|
}
|
|
|
|
} // namespace blender::gpu
|