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>
This commit is contained in:
Emma Anholt
2023-10-03 12:25:42 -07:00
committed by Marge Bot
parent 8e81aff4bb
commit 2432f14d00
4 changed files with 22 additions and 16 deletions

View File

@@ -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;

View File

@@ -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;

View File

@@ -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 ? ":" : "");

View File

@@ -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);