From 04a995158084acbd1917b4c7e0f8d381e1c9222d Mon Sep 17 00:00:00 2001 From: Danylo Piliaiev Date: Thu, 23 May 2019 19:05:23 +0300 Subject: intel/compiler: add ability to override shader's assembly When dumping shader's assembly with INTEL_DEBUG=vs,tcs,... sha1 of the resulting assembly is also printed, having environment variable INTEL_SHADER_ASM_READ_PATH present driver will try to load a "%sha1%.bin" file from the path and substitute current assembly with the one from the file. Signed-off-by: Danylo Piliaiev Reviewed-by: Sagar Ghuge Reviewed-by: Matt Turner --- src/intel/compiler/brw_eu.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'src/intel/compiler/brw_eu.c') diff --git a/src/intel/compiler/brw_eu.c b/src/intel/compiler/brw_eu.c index ec30579446b..882293e981b 100644 --- a/src/intel/compiler/brw_eu.c +++ b/src/intel/compiler/brw_eu.c @@ -29,6 +29,8 @@ * Keith Whitwell */ +#include +#include #include "brw_eu_defines.h" #include "brw_eu.h" @@ -349,6 +351,47 @@ const unsigned *brw_get_program( struct brw_codegen *p, return (const unsigned *)p->store; } +bool brw_try_override_assembly(struct brw_codegen *p, int start_offset, + const char *identifier) +{ + const char *read_path = getenv("INTEL_SHADER_ASM_READ_PATH"); + if (!read_path) { + return false; + } + + char *name = ralloc_asprintf(NULL, "%s/%s.bin", read_path, identifier); + + int fd = open(name, O_RDONLY); + ralloc_free(name); + + if (fd == -1) { + return false; + } + + struct stat sb; + if (fstat(fd, &sb) != 0 || (!S_ISREG(sb.st_mode))) { + return false; + } + + p->nr_insn -= (p->next_insn_offset - start_offset) / sizeof(brw_inst); + p->nr_insn += sb.st_size / sizeof(brw_inst); + + p->next_insn_offset = start_offset + sb.st_size; + p->store_size = (start_offset + sb.st_size) / sizeof(brw_inst); + p->store = reralloc_size(p->mem_ctx, p->store, p->next_insn_offset); + assert(p->store); + + read(fd, p->store + start_offset, sb.st_size); + close(fd); + + bool valid = brw_validate_instructions(p->devinfo, p->store, + start_offset, p->next_insn_offset, + 0); + assert(valid); + + return true; +} + void brw_disassemble(const struct gen_device_info *devinfo, const void *assembly, int start, int end, FILE *out) -- cgit v1.2.3