From 4efd580f488b501375507d3b38a9f3cac696e8b2 Mon Sep 17 00:00:00 2001 From: Gert Wollny Date: Fri, 8 Mar 2019 14:03:53 +0100 Subject: [PATCH] vrend,stringbuf: Add line numbers to shader dumps This helps a lot locating errors in the shaders. Signed-off-by: Gert Wollny Reviewed-by: Dave Airlie Signed-off-by: Dave Airlie --- src/vrend_renderer.c | 2 +- src/vrend_strbuf.h | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/vrend_renderer.c b/src/vrend_renderer.c index 074ef87..a5dbed8 100644 --- a/src/vrend_renderer.c +++ b/src/vrend_renderer.c @@ -834,7 +834,7 @@ static void vrend_shader_dump(struct vrend_shader *shader) { const char *prefix = pipe_shader_to_prefix(shader->sel->type); vrend_printf("%s: %d GLSL:\n", prefix, shader->id); - strarray_dump(&shader->glsl_strings); + strarray_dump_with_line_numbers(&shader->glsl_strings); vrend_printf("\n"); } diff --git a/src/vrend_strbuf.h b/src/vrend_strbuf.h index 0b30653..3899f83 100644 --- a/src/vrend_strbuf.h +++ b/src/vrend_strbuf.h @@ -203,4 +203,18 @@ static inline void strarray_dump(struct vrend_strarray *sa) vrend_printf("%s", sa->strings[i].buf); } +static inline void strarray_dump_with_line_numbers(struct vrend_strarray *sa) +{ + int lineno = 1; + for (int i = 0; i < sa->num_strings; i++) { + char *saveptr; + char *line = strtok_r(sa->strings[i].buf, "\n", &saveptr); + while (line) { + vrend_printf("%4d: %s\n", lineno++, line); + line = strtok_r(NULL, "\n", &saveptr); + } + } +} + + #endif