summaryrefslogtreecommitdiffstats
path: root/src/intel/compiler/brw_eu.c
diff options
context:
space:
mode:
authorDanylo Piliaiev <[email protected]>2019-05-23 19:05:23 +0300
committerMatt Turner <[email protected]>2019-08-05 17:19:09 +0000
commit04a995158084acbd1917b4c7e0f8d381e1c9222d (patch)
tree5e719246b49db173196dc71853dea02bf95fa986 /src/intel/compiler/brw_eu.c
parent430823c96b1ab9c5e99fedbf06856a2a24d36d91 (diff)
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 <[email protected]> Reviewed-by: Sagar Ghuge <[email protected]> Reviewed-by: Matt Turner <[email protected]>
Diffstat (limited to 'src/intel/compiler/brw_eu.c')
-rw-r--r--src/intel/compiler/brw_eu.c43
1 files changed, 43 insertions, 0 deletions
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 <[email protected]>
*/
+#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)