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 <danylo.piliaiev@globallogic.com>
Reviewed-by: Sagar Ghuge <sagar.ghuge@intel.com>
Reviewed-by: Matt Turner <mattst88@gmail.com>
This commit is contained in:
Danylo Piliaiev
2019-05-23 19:05:23 +03:00
committed by Matt Turner
parent 430823c96b
commit 04a9951580
4 changed files with 84 additions and 11 deletions

View File

@@ -29,6 +29,8 @@
* Keith Whitwell <keithw@vmware.com>
*/
#include <sys/stat.h>
#include <fcntl.h>
#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)