Module: Mesa Branch: main Commit: 2432f14d003ee6ced94cb48a626a9a72a80c88c5 URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=2432f14d003ee6ced94cb48a626a9a72a80c88c5
Author: Emma Anholt <[email protected]> Date: Tue Oct 3 12:25:42 2023 -0700 i915: Save fragment program compile error messages in the fragment shader. We'll want this for doing linking failure messages for shaders that are too long. Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25533> --- src/gallium/drivers/i915/i915_context.h | 2 ++ src/gallium/drivers/i915/i915_fpc.h | 2 +- src/gallium/drivers/i915/i915_fpc_translate.c | 33 +++++++++++++++------------ src/gallium/drivers/i915/i915_state.c | 1 + 4 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/gallium/drivers/i915/i915_context.h b/src/gallium/drivers/i915/i915_context.h index b24f716e2f0..be2c65d21ca 100644 --- a/src/gallium/drivers/i915/i915_context.h +++ b/src/gallium/drivers/i915/i915_context.h @@ -136,6 +136,8 @@ struct i915_fragment_shader { /* Set if the shader is an internal (blit, etc.) shader that shouldn't debug * log by default. */ bool internal; + + char *error; /* Any error message from compiling this shader (or NULL) */ }; struct i915_cache_context; diff --git a/src/gallium/drivers/i915/i915_fpc.h b/src/gallium/drivers/i915/i915_fpc.h index 8e17c90f7f8..a1d85604534 100644 --- a/src/gallium/drivers/i915/i915_fpc.h +++ b/src/gallium/drivers/i915/i915_fpc.h @@ -74,7 +74,7 @@ struct i915_fp_compile { uint32_t nr_decl_insn; bool log_program_errors; - bool error; /**< Set if i915_program_error() is called */ + char *error; uint32_t NumNativeInstructions; uint32_t NumNativeAluInstructions; uint32_t NumNativeTexInstructions; diff --git a/src/gallium/drivers/i915/i915_fpc_translate.c b/src/gallium/drivers/i915/i915_fpc_translate.c index e54e9aba2be..d6201cc45ae 100644 --- a/src/gallium/drivers/i915/i915_fpc_translate.c +++ b/src/gallium/drivers/i915/i915_fpc_translate.c @@ -39,6 +39,7 @@ #include "tgsi/tgsi_info.h" #include "tgsi/tgsi_parse.h" #include "util/log.h" +#include "util/ralloc.h" #include "util/u_math.h" #include "util/u_memory.h" #include "util/u_string.h" @@ -96,15 +97,10 @@ i915_use_passthrough_shader(struct i915_fragment_shader *fs) void i915_program_error(struct i915_fp_compile *p, const char *msg, ...) { - if (p->log_program_errors) { - va_list args; - - va_start(args, msg); - mesa_loge_v(msg, args); - va_end(args); - } - - p->error = 1; + va_list args; + va_start(args, msg); + ralloc_vasprintf_append(&p->error, msg, args); + va_end(args); } static uint32_t @@ -931,18 +927,19 @@ i915_translate_instructions(struct i915_fp_compile *p, struct i915_fragment_shader *fs) { int i; - for (i = 0; i < tokens->NumTokens && !p->error; i++) { + for (i = 0; i < tokens->NumTokens && !p->error[0]; i++) { i915_translate_token(p, &tokens->Tokens[i], fs); } } static struct i915_fp_compile * -i915_init_compile(struct i915_context *i915, struct i915_fragment_shader *ifs) +i915_init_compile(struct i915_fragment_shader *ifs) { struct i915_fp_compile *p = CALLOC_STRUCT(i915_fp_compile); int i; p->shader = ifs; + p->error = ralloc_strdup(NULL, ""); /* Put new constants at end of const buffer, growing downward. * The problem is we don't know how many user-defined constants might @@ -958,8 +955,6 @@ i915_init_compile(struct i915_context *i915, struct i915_fragment_shader *ifs) for (i = 0; i < I915_TEX_UNITS; i++) ifs->texcoords[i].semantic = -1; - p->log_program_errors = !i915->no_log_program_errors; - p->first_instruction = true; p->nr_tex_indirect = 1; /* correct? */ @@ -1017,7 +1012,7 @@ i915_fini_compile(struct i915_context *i915, struct i915_fp_compile *p) if (ifs->info.num_instructions == 1) i915_program_error(p, "Empty fragment shader"); - if (p->error) { + if (strlen(p->error) != 0) { p->NumNativeInstructions = 0; p->NumNativeAluInstructions = 0; p->NumNativeTexInstructions = 0; @@ -1052,6 +1047,11 @@ i915_fini_compile(struct i915_context *i915, struct i915_fp_compile *p) p->shader->info.file_max[TGSI_FILE_TEMPORARY] + 1, ifs->num_constants); } + if (strlen(p->error) != 0) + ifs->error = p->error; + else + ralloc_free(p->error); + /* Release the compilation struct: */ FREE(p); @@ -1095,7 +1095,7 @@ i915_translate_fragment_program(struct i915_context *i915, tgsi_dump(tokens, 0); } - p = i915_init_compile(i915, fs); + p = i915_init_compile(fs); i_tokens = i915_optimize(tokens); i915_translate_instructions(p, i_tokens, fs); @@ -1105,6 +1105,9 @@ i915_translate_fragment_program(struct i915_context *i915, i915_optimize_free(i_tokens); if (debug) { + if (fs->error) + mesa_loge("%s", fs->error); + mesa_logi("i915 fragment shader with %d constants%s", fs->num_constants, fs->num_constants ? ":" : ""); diff --git a/src/gallium/drivers/i915/i915_state.c b/src/gallium/drivers/i915/i915_state.c index b380ccc1022..151d1c7928e 100644 --- a/src/gallium/drivers/i915/i915_state.c +++ b/src/gallium/drivers/i915/i915_state.c @@ -595,6 +595,7 @@ i915_delete_fs_state(struct pipe_context *pipe, void *shader) { struct i915_fragment_shader *ifs = (struct i915_fragment_shader *)shader; + ralloc_free(ifs->error); FREE(ifs->program); ifs->program = NULL; FREE((struct tgsi_token *)ifs->state.tokens);
