[Mesa-dev] [PATCH v2 10/11] intel: decoder: add function to query shader length

Lionel Landwerlin lionel.g.landwerlin at intel.com
Wed Nov 1 18:12:17 UTC 2017


Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin at intel.com>
---
 src/intel/tools/disasm.c     | 34 ++++++++++++++++++++++++++++++++++
 src/intel/tools/gen_disasm.h |  2 ++
 2 files changed, 36 insertions(+)

diff --git a/src/intel/tools/disasm.c b/src/intel/tools/disasm.c
index 251acd313dc..fbf4f9e8999 100644
--- a/src/intel/tools/disasm.c
+++ b/src/intel/tools/disasm.c
@@ -26,6 +26,8 @@
 #include "compiler/brw_inst.h"
 #include "compiler/brw_eu.h"
 
+#include "common/gen_decoder.h"
+
 #include "gen_disasm.h"
 
 uint64_t INTEL_DEBUG;
@@ -43,6 +45,38 @@ is_send(uint32_t opcode)
            opcode == BRW_OPCODE_SENDSC );
 }
 
+uint32_t
+gen_disasm_get_assembly_size(struct gen_disasm *disasm,
+                             const struct gen_dword_reader *reader)
+{
+   struct gen_device_info *devinfo = &disasm->devinfo;
+   uint32_t size = 0;
+
+   /* This loop exits when send-with-EOT or when opcode is 0 */
+   while (true) {
+      union {
+         brw_inst insn;
+         uint32_t data[sizeof(brw_inst) / sizeof(uint32_t)];
+      } data;
+      for (int i = 0; i < ARRAY_SIZE(data.data); i++)
+         data.data[i] = gen_read_dword(reader, size / 4 + i);
+
+      if (brw_inst_cmpt_control(devinfo, &data.insn)) {
+         size += 8;
+      } else {
+         size += 16;
+      }
+
+      /* Simplistic, but efficient way to terminate disasm */
+      uint32_t opcode = brw_inst_opcode(devinfo, &data.insn);
+      if (opcode == 0 || (is_send(opcode) && brw_inst_eot(devinfo, &data.insn))) {
+         break;
+      }
+   }
+
+   return size;
+}
+
 static int
 gen_disasm_find_end(struct gen_disasm *disasm, void *assembly, int start)
 {
diff --git a/src/intel/tools/gen_disasm.h b/src/intel/tools/gen_disasm.h
index d2764bb90b7..bf72759f410 100644
--- a/src/intel/tools/gen_disasm.h
+++ b/src/intel/tools/gen_disasm.h
@@ -31,6 +31,8 @@ extern "C" {
 struct gen_disasm;
 
 struct gen_disasm *gen_disasm_create(int pciid);
+uint32_t gen_disasm_get_assembly_size(struct gen_disasm *disasm,
+                                      const struct gen_dword_reader *reader);
 void gen_disasm_disassemble(struct gen_disasm *disasm,
                             void *assembly, int start, FILE *out);
 
-- 
2.15.0



More information about the mesa-dev mailing list