diff --git a/CHANGELOG.md b/CHANGELOG.md index a4868b1e6..a7782a1ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,6 +47,8 @@ Versioning](https://semver.org/spec/v2.0.0.html) for `libnopegl`. - `GraphicConfig.depth_write_mask` is renamed to `GraphicConfig.depth_write` - `Circle.count`, `Buffer*.count`, `StreamedBuffer*.count` are now unsigned - `Program.nb_frag_output` is now unsigned +- Line numbers in shader compilation errors are now reported accurately + according to the user input, so shaders are not printed on stderr anymore ### Removed - `Text.aspect_ratio`, it now matches the viewport aspect ratio diff --git a/libnopegl/src/ngpu/opengl/program_gl.c b/libnopegl/src/ngpu/opengl/program_gl.c index 8e86c91ff..fab226c27 100644 --- a/libnopegl/src/ngpu/opengl/program_gl.c +++ b/libnopegl/src/ngpu/opengl/program_gl.c @@ -28,9 +28,7 @@ #include "log.h" #include "ngpu/type.h" #include "program_gl.h" -#include "utils/bstr.h" #include "utils/memory.h" -#include "utils/string.h" static int program_check_status(const struct glcontext *gl, GLuint id, GLenum status) { @@ -120,12 +118,7 @@ int ngpu_program_gl_init(struct ngpu_program *s, const struct ngpu_program_param gl->funcs.CompileShader(shader); ret = program_check_status(gl, shader, GL_COMPILE_STATUS); if (ret < 0) { - char *s_with_numbers = ngli_numbered_lines(shaders[i].src); - if (s_with_numbers) { - LOG(ERROR, "failed to compile shader \"%s\":\n%s", - params->label ? params->label : "", s_with_numbers); - ngli_free(s_with_numbers); - } + LOG(ERROR, "failed to compile shader \"%s\"", params->label ? params->label : ""); goto fail; } gl->funcs.AttachShader(s_priv->id, shader); @@ -134,22 +127,7 @@ int ngpu_program_gl_init(struct ngpu_program *s, const struct ngpu_program_param gl->funcs.LinkProgram(s_priv->id); ret = program_check_status(gl, s_priv->id, GL_LINK_STATUS); if (ret < 0) { - struct bstr *bstr = ngli_bstr_create(); - if (bstr) { - ngli_bstr_printf(bstr, "failed to link shaders \"%s\":", - params->label ? params->label : ""); - for (size_t i = 0; i < NGLI_ARRAY_NB(shaders); i++) { - if (!shaders[i].src) - continue; - char *s_with_numbers = ngli_numbered_lines(shaders[i].src); - if (s_with_numbers) { - ngli_bstr_printf(bstr, "\n\n%s shader:\n%s", shaders[i].name, s_with_numbers); - ngli_free(s_with_numbers); - } - } - LOG(ERROR, "%s", ngli_bstr_strptr(bstr)); - ngli_bstr_freep(&bstr); - } + LOG(ERROR, "failed to link shaders \"%s\"", params->label ? params->label : ""); goto fail; } diff --git a/libnopegl/src/ngpu/pgcraft.c b/libnopegl/src/ngpu/pgcraft.c index adca18a42..c929154ee 100644 --- a/libnopegl/src/ngpu/pgcraft.c +++ b/libnopegl/src/ngpu/pgcraft.c @@ -1076,6 +1076,7 @@ static int craft_vert(struct ngpu_pgcraft *s, const struct ngpu_pgcraft_params * (ret = inject_ublock(s, b, NGPU_PROGRAM_STAGE_VERT)) < 0) return ret; + ngli_bstr_print(b, "#line 1\n"); ngli_bstr_print(b, params->vert_base); return samplers_preproc(s, params, b); } @@ -1128,6 +1129,7 @@ static int craft_frag(struct ngpu_pgcraft *s, const struct ngpu_pgcraft_params * ngli_bstr_print(b, "\n"); + ngli_bstr_print(b, "#line 1\n"); ngli_bstr_print(b, params->frag_base); return samplers_preproc(s, params, b); } @@ -1148,6 +1150,7 @@ static int craft_comp(struct ngpu_pgcraft *s, const struct ngpu_pgcraft_params * (ret = inject_ublock(s, b, NGPU_PROGRAM_STAGE_COMP)) < 0) return ret; + ngli_bstr_print(b, "#line 1\n"); ngli_bstr_print(b, params->comp_base); return samplers_preproc(s, params, b); } diff --git a/libnopegl/src/ngpu/vulkan/program_vk.c b/libnopegl/src/ngpu/vulkan/program_vk.c index 71f1e0c47..c5c792578 100644 --- a/libnopegl/src/ngpu/vulkan/program_vk.c +++ b/libnopegl/src/ngpu/vulkan/program_vk.c @@ -28,7 +28,6 @@ #include "log.h" #include "program_vk.h" #include "utils/memory.h" -#include "utils/string.h" #include "utils/utils.h" #include "vkutils.h" @@ -65,12 +64,7 @@ int ngpu_program_vk_init(struct ngpu_program *s, const struct ngpu_program_param size_t size = 0; int ret = ngli_glslang_compile(shaders[i].stage, shaders[i].src, s->gpu_ctx->config.debug, &data, &size); if (ret < 0) { - char *s_with_numbers = ngli_numbered_lines(shaders[i].src); - if (s_with_numbers) { - LOG(ERROR, "failed to compile shader \"%s\":\n%s", - params->label ? params->label : "", s_with_numbers); - ngli_free(s_with_numbers); - } + LOG(ERROR, "failed to compile shader \"%s\"", params->label ? params->label : ""); return ret; } @@ -82,12 +76,7 @@ int ngpu_program_vk_init(struct ngpu_program *s, const struct ngpu_program_param VkResult res = vkCreateShaderModule(vk->device, &shader_module_create_info, NULL, &s_priv->shaders[i]); ngli_freep(&data); if (res != VK_SUCCESS) { - char *s_with_numbers = ngli_numbered_lines(shaders[i].src); - if (s_with_numbers) { - LOG(ERROR, "failed to compile shader \"%s\":\n%s", - params->label ? params->label : "", s_with_numbers); - ngli_free(s_with_numbers); - } + LOG(ERROR, "failed to compile shader \"%s\"", params->label ? params->label : ""); return ngli_vk_res2ret(res); } } diff --git a/libnopegl/src/test_utils.c b/libnopegl/src/test_utils.c index 78e527e11..76804d181 100644 --- a/libnopegl/src/test_utils.c +++ b/libnopegl/src/test_utils.c @@ -20,18 +20,8 @@ */ #include "utils/crc32.h" -#include "utils/memory.h" -#include "utils/string.h" #include "utils/utils.h" -static void test_numbered_line(uint32_t crc, const char *s) -{ - char *p = ngli_numbered_lines(s); - ngli_assert(p); - ngli_assert(ngli_crc32(p) == crc); - ngli_freep(&p); -} - int main(void) { ngli_assert(ngli_crc32("") == 0); @@ -42,13 +32,5 @@ int main(void) buf[i] = (char)(0xff - i); ngli_assert(ngli_crc32(buf) == 0x5473AA4D); -#define X "x\n" -#define S "foo\nbar\nhello\nworld\nbla\nxxx\nyyy\n" - test_numbered_line(0x2d7f40af, S S S S S S S S); - test_numbered_line(0xbcea3585, "\n"); - test_numbered_line(0xc58462d3, "foo\nbar"); - test_numbered_line(0x00000000, ""); - test_numbered_line(0x25b15360, X X X X X X X X X); - test_numbered_line(0x759455a5, X X X X X X X X X X); return 0; } diff --git a/libnopegl/src/utils/string.c b/libnopegl/src/utils/string.c index 2d2a652fc..981ed51d3 100644 --- a/libnopegl/src/utils/string.c +++ b/libnopegl/src/utils/string.c @@ -24,7 +24,6 @@ #include #include -#include "bstr.h" #include "memory.h" #include "string.h" @@ -64,52 +63,3 @@ char *ngli_asprintf(const char *fmt, ...) return p; } -static int count_lines(const char *s) -{ - int count = 0; - while (*s) { - const size_t len = strcspn(s, "\n"); - count++; - if (!s[len]) - break; - s += len + 1; - } - return count; -} - -static int count_digits(int x) -{ - int n = 1; - while (x /= 10) - n++; - return n; -} - -char *ngli_numbered_lines(const char *s) -{ - struct bstr *b = ngli_bstr_create(); - if (!b) - return NULL; - - const int nb_lines = count_lines(s); - const int nb_digits = count_digits(nb_lines); - int line = 1; - while (*s) { - const size_t len = strcspn(s, "\n"); - ngli_bstr_printf(b, "%*d %.*s\n", nb_digits, line++, (int)len, s); - if (!s[len]) - break; - s += len + 1; - } - - char *ret = ngli_bstr_strdup(b); - ngli_bstr_freep(&b); - if (!ret) - return NULL; - - size_t len = strlen(ret); - while (len && ret[len - 1] == '\n') - ret[--len] = 0; - - return ret; -} diff --git a/libnopegl/src/utils/string.h b/libnopegl/src/utils/string.h index d18b6cdd3..aeb238898 100644 --- a/libnopegl/src/utils/string.h +++ b/libnopegl/src/utils/string.h @@ -32,6 +32,5 @@ char *ngli_strdup(const char *s); char *ngli_asprintf(const char *fmt, ...) ngli_printf_format(1, 2); -char *ngli_numbered_lines(const char *s); #endif /* STRING_H */