22#include <fmt/format.h>
23#include <fmt/ranges.h>
36#define DEBUG_CONTEXT_LINES 0
41#define DEBUG_DEPENDENCIES 0
49 const char line_prefix[] =
" | ";
50 char err_col[] =
"\033[31;1m";
51 char warn_col[] =
"\033[33;1m";
52 char info_col[] =
"\033[0;2m";
53 char reset_col[] =
"\033[0;0m";
54 std::string sources_combined = fmt::to_string(fmt::join(sources,
""));
58 err_col[0] = warn_col[0] = info_col[0] = reset_col[0] =
'\0';
65 dynstr,
"%s%sIncluded files (in order):%s\n", info_col, line_prefix, reset_col);
70 int64_t cursor = 0, line_count = 0;
71 while ((cursor = src.find(
'\n', cursor) + 1)) {
74 if (sources_end_line.is_empty() ==
false) {
75 line_count += sources_end_line.last();
77 sources_end_line.append(line_count);
82 dynstr,
"%s%s %s%s\n", info_col, line_prefix,
filename.c_str(), reset_col);
86 if (sources_end_line.is_empty()) {
87 sources_end_line.append(0);
90 const char *log_line =
log, *line_end;
94 bool found_line_id =
false;
95 while ((line_end = strchr(log_line,
'\n'))) {
97 if (line_end == log_line) {
104 if (logref.
endswith(
" shader failed to compile with the following errors:") ||
105 logref.
endswith(
" No code generated"))
107 log_line += size_t(line_end) - size_t(log_line);
112 log_line =
parser->parse_line(sources_combined.c_str(), log_line, log_item);
115 if ((log_item.
cursor.
row == -1) &&
ELEM(log_line[0],
'\n',
'\0')) {
123 if (log_item.
cursor.
row >= sources_end_line.last()) {
129 found_line_id =
false;
132 const char *src_line = sources_combined.c_str();
134 std::string log_line_str(log_line, (line_end + 1) - log_line);
135 if (log_line_str.ends_with(
" used uninitialized\n")) {
138 log_line = line_end + 1;
155 const char *src_line_end;
156 found_line_id =
false;
158 int src_line_index = 1;
159 while ((src_line_end = strchr(src_line,
'\n'))) {
160 if (src_line_index >= log_item.
cursor.
row) {
161 found_line_id =
true;
169 src_line = src_line_end + 1;
192 src_line = src_line_end + 1;
194 while ((src_line_end = strchr(src_line,
'\n'))) {
201 src_line = src_line_end + 1;
211 if (source_index <= 0) {
212 for (
auto i : sources_end_line.index_range()) {
213 if (log_item.
cursor.
row <= sources_end_line[i]) {
219 if (source_index > 0) {
220 row_in_file -= sources_end_line[source_index - 1];
226 sizeof(name_buf) - 1);
230 else if (source_index > 0) {
232 sources[source_index]);
258 log_line = line_end + 1;
259 previous_location = log_item.
cursor;
278 const char *error_msg,
279 const char *warning_msg,
280 const char *note_msg)
const
282 if (
STREQLEN(log_line, error_msg, strlen(error_msg))) {
283 log_line += strlen(error_msg);
286 else if (
STREQLEN(log_line, warning_msg, strlen(warning_msg))) {
287 log_line += strlen(warning_msg);
290 else if (
STREQLEN(log_line, note_msg, strlen(note_msg))) {
291 log_line += strlen(note_msg);
299 while (
at_any(log_line, separators)) {
307 const char *cursor = log_line;
308 while (!
ELEM(cursor[0],
'\n',
'\0')) {
309 if (cursor[0] == stop_char) {
319 return log_line[0] >=
'0' && log_line[0] <=
'9';
329 return int(strtol(log_line,
const_cast<char **
>(r_new_position), 10));
335 size_t current_line = 1;
336 for (
char c : source_combined) {
337 if (current_line >= target_line) {
352 size_t nearest_line_directive = sub_str.
rfind(directive);
353 if (nearest_line_directive != std::string::npos) {
354 size_t start_of_file_name = nearest_line_directive + directive.
size();
355 size_t end_of_file_name = sub_str.
find(
'\"', start_of_file_name);
356 if (end_of_file_name != std::string::npos) {
357 return sub_str.
substr(start_of_file_name, end_of_file_name - start_of_file_name);
368 size_t nearest_line_directive = sub_str.
rfind(directive);
369 size_t line_count = 1;
370 if (nearest_line_directive != std::string::npos) {
371 sub_str = sub_str.
substr(nearest_line_directive + directive.
size());
372 line_count = std::stoll(sub_str) - 1;
374 return line_count + std::count(sub_str.
begin(), sub_str.
end(),
'\n');
384#if GPU_SHADER_PRINTF_ENABLE == 0
387 if (ctx ==
nullptr) {
401#if GPU_SHADER_PRINTF_ENABLE == 0
404 if (ctx ==
nullptr) {
423 while (cursor < data_len + 1) {
430 printf(
"Printf buffer overflow.\n");
435 switch (block.
type) {
453 printf(block.
fmt.c_str(), *
reinterpret_cast<float *
>(&
data[cursor++]));
A dynamically sized string ADT.
void CLG_log_raw(const CLG_LogType *lg, const char *message)
#define CLOG_CHECK(clg_ref, verbose_level,...)
#define CLOG_AT_LEVEL(clg_ref, verbose_level,...)
int CLG_color_support_get(CLG_LogRef *clg_ref)
#define GPU_storagebuf_create(size)
Read Blender memory allocation and freeing.
#define BLI_assert_unreachable()
#define STREQLEN(a, b, n)
constexpr int64_t size() const
constexpr StringRefNull()
constexpr int64_t rfind(char c, int64_t pos=INT64_MAX) const
constexpr const char * end() const
constexpr const char * begin() const
static constexpr int64_t not_found
constexpr int64_t size() const
constexpr int64_t find(char c, int64_t pos=0) const
constexpr StringRef substr(int64_t start, int64_t size) const
constexpr bool endswith(StringRef suffix) const
Vector< StorageBuf * > printf_buf
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_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
void print_log(Span< StringRefNull > sources, const char *log, const char *stage, bool error, GPULogParser *parser)
#define GPU_SHADER_PRINTF_MAX_CAPACITY
#define DEBUG_CONTEXT_LINES
#define DEBUG_LOG_SHADER_SRC_ON_ERROR
std::string filename(const std::string_view &str, size_t pos)
const PrintfFormat & gpu_shader_dependency_get_printf_format(uint32_t format_hash)
bool gpu_shader_dependency_has_printf()
StringRefNull gpu_shader_dependency_get_filename_from_source_string(const StringRef source_string)
Find the name of the file from which the given string was generated.
void printf_begin(Context *ctx)
void printf_end(Context *ctx)
void BLI_dynstr_appendf(DynStr *__restrict ds, const char *__restrict format,...) ATTR_PRINTF_FORMAT(2
void GPU_storagebuf_clear_to_zero(gpu::StorageBuf *ssbo)
void BLI_dynstr_nappend(DynStr *__restrict ds, const char *cstr, int len) ATTR_NONNULL()
void BLI_dynstr_free(DynStr *ds) ATTR_NONNULL()
void BLI_dynstr_append(DynStr *__restrict ds, const char *cstr) ATTR_NONNULL()
BMesh const char void * data
char * BLI_dynstr_get_cstring(const DynStr *ds) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
void GPU_storagebuf_free(gpu::StorageBuf *ssbo)
DynStr * BLI_dynstr_new() ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
void GPU_storagebuf_read(gpu::StorageBuf *ssbo, void *data)
std::string file_name_and_error_line