From 52db0e14800fb3eba1ad970c7d49db9dca0e825c Mon Sep 17 00:00:00 2001 From: Caleb Callaway Date: Fri, 23 May 2025 22:29:10 +0000 Subject: [PATCH] intel/compiler: fix SHA generation for shader replace Reviewed-by: Jordan Justen Part-of: --- src/intel/compiler/brw_eu.c | 4 +--- src/intel/compiler/brw_eu.h | 2 +- src/intel/compiler/brw_generator.cpp | 11 ++++++++--- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/intel/compiler/brw_eu.c b/src/intel/compiler/brw_eu.c index 053ed65dc79..4f32758f907 100644 --- a/src/intel/compiler/brw_eu.c +++ b/src/intel/compiler/brw_eu.c @@ -342,10 +342,8 @@ void brw_dump_shader_bin(void *assembly, int start_offset, int end_offset, } bool brw_try_override_assembly(struct brw_codegen *p, int start_offset, - const char *identifier) + const char *read_path, const char *identifier) { - const char *read_path = getenv("INTEL_SHADER_ASM_READ_PATH"); - char *name = ralloc_asprintf(NULL, "%s/%s.bin", read_path, identifier); int fd = open(name, O_RDONLY); diff --git a/src/intel/compiler/brw_eu.h b/src/intel/compiler/brw_eu.h index cd641de2b4a..724f34aa505 100644 --- a/src/intel/compiler/brw_eu.h +++ b/src/intel/compiler/brw_eu.h @@ -165,7 +165,7 @@ void brw_dump_shader_bin(void *assembly, int start_offset, int end_offset, const char *identifier); bool brw_try_override_assembly(struct brw_codegen *p, int start_offset, - const char *identifier); + const char *read_path, const char *identifier); void brw_realign(struct brw_codegen *p, unsigned alignment); int brw_append_data(struct brw_codegen *p, void *data, diff --git a/src/intel/compiler/brw_generator.cpp b/src/intel/compiler/brw_generator.cpp index e160b40ba48..e6b42570ce9 100644 --- a/src/intel/compiler/brw_generator.cpp +++ b/src/intel/compiler/brw_generator.cpp @@ -642,6 +642,9 @@ brw_generator::generate_halt(brw_inst *) brw_HALT(p); } +DEBUG_GET_ONCE_OPTION(shader_bin_override_path, "INTEL_SHADER_ASM_READ_PATH", + NULL); + /* The A32 messages take a buffer base address in header.5:[31:0] (See * MH1_A32_PSM for typed messages or MH_A32_GO for byte/dword scattered * and OWord block messages in the SKL PRM Vol. 2d for more details.) @@ -1393,7 +1396,8 @@ brw_generator::generate_code(const cfg_t *cfg, int dispatch_width, unsigned char sha1[21]; char sha1buf[41]; - if (unlikely(debug_flag || dump_shader_bin)) { + auto override_path = debug_get_option_shader_bin_override_path(); + if (unlikely(debug_flag || dump_shader_bin || override_path != NULL)) { _mesa_sha1_compute(p->store + start_offset / sizeof(brw_eu_inst), after_size, sha1); _mesa_sha1_format(sha1buf, sha1); @@ -1403,8 +1407,9 @@ brw_generator::generate_code(const cfg_t *cfg, int dispatch_width, brw_dump_shader_bin(p->store, start_offset, p->next_insn_offset, sha1buf); - const char *override_path = getenv("INTEL_SHADER_ASM_READ_PATH"); - if (override_path && brw_try_override_assembly(p, start_offset, sha1buf)) { + if (unlikely(override_path != NULL && + brw_try_override_assembly(p, start_offset, override_path, + sha1buf))) { fprintf(stderr, "Successfully overrode shader with sha1 %s\n", sha1buf); /* disasm_info and stats are no longer valid as we gathered * them based on the original shader.