This should give substantially better decoding, as the public libdrm
decoder hasn't been properly maintained in years.

For now, we reuse the existing state dumping mechanism.  We'll improve
that in the next patch.
---
 src/mesa/drivers/dri/i965/Makefile.am         |  1 +
 src/mesa/drivers/dri/i965/Makefile.sources    |  1 +
 src/mesa/drivers/dri/i965/decoder.c           |  1 +
 src/mesa/drivers/dri/i965/intel_batchbuffer.c | 56 +++++++++++++++++----------
 4 files changed, 38 insertions(+), 21 deletions(-)
 create mode 120000 src/mesa/drivers/dri/i965/decoder.c

diff --git a/src/mesa/drivers/dri/i965/Makefile.am 
b/src/mesa/drivers/dri/i965/Makefile.am
index 246fe41ca97..98a70e1ec48 100644
--- a/src/mesa/drivers/dri/i965/Makefile.am
+++ b/src/mesa/drivers/dri/i965/Makefile.am
@@ -38,6 +38,7 @@ AM_CFLAGS = \
        -I$(top_srcdir)/src/compiler/nir \
        -I$(top_builddir)/src/intel \
        -I$(top_srcdir)/src/intel \
+       -I$(top_srcdir)/src/intel/tools \
        $(DEFINES) \
        $(VISIBILITY_CFLAGS) \
        $(INTEL_CFLAGS)
diff --git a/src/mesa/drivers/dri/i965/Makefile.sources 
b/src/mesa/drivers/dri/i965/Makefile.sources
index 6456df5dc01..13adb739aa3 100644
--- a/src/mesa/drivers/dri/i965/Makefile.sources
+++ b/src/mesa/drivers/dri/i965/Makefile.sources
@@ -1,4 +1,5 @@
 i965_FILES = \
+       decoder.c \
        brw_binding_tables.c \
        brw_blorp.c \
        brw_blorp.h \
diff --git a/src/mesa/drivers/dri/i965/decoder.c 
b/src/mesa/drivers/dri/i965/decoder.c
new file mode 120000
index 00000000000..0cd95ba1038
--- /dev/null
+++ b/src/mesa/drivers/dri/i965/decoder.c
@@ -0,0 +1 @@
+../../../../intel/tools/decoder.c
\ No newline at end of file
diff --git a/src/mesa/drivers/dri/i965/intel_batchbuffer.c 
b/src/mesa/drivers/dri/i965/intel_batchbuffer.c
index 887504273ab..319b640b2fd 100644
--- a/src/mesa/drivers/dri/i965/intel_batchbuffer.c
+++ b/src/mesa/drivers/dri/i965/intel_batchbuffer.c
@@ -31,6 +31,7 @@
 #include "brw_context.h"
 #include "brw_defines.h"
 #include "brw_state.h"
+#include "intel/tools/decoder.h"
 
 #include <xf86drm.h>
 #include <i915_drm.h>
@@ -135,44 +136,57 @@ intel_batchbuffer_require_space(struct brw_context *brw, 
GLuint sz,
    brw->batch.ring = ring;
 }
 
+#define CSI "\e["
+#define BLUE_HEADER  CSI "0;44m"
+#define NORMAL       CSI "0m"
+
 static void
 do_batch_dump(struct brw_context *brw)
 {
-   struct drm_intel_decode *decode;
    struct intel_batchbuffer *batch = &brw->batch;
-   int ret;
+   struct gen_spec *spec = gen_spec_load(&brw->screen->devinfo);
 
-   decode = drm_intel_decode_context_alloc(brw->screen->deviceID);
-   if (!decode)
+   if (batch->ring != RENDER_RING)
       return;
 
-   ret = drm_intel_bo_map(batch->bo, false);
-   if (ret == 0) {
-      drm_intel_decode_set_batch_pointer(decode,
-                                        batch->bo->virtual,
-                                        batch->bo->offset64,
-                                         USED_BATCH(*batch));
-   } else {
+   int ret = drm_intel_bo_map(batch->bo, false);
+   if (ret != 0) {
       fprintf(stderr,
              "WARNING: failed to map batchbuffer (%s), "
              "dumping uploaded data instead.\n", strerror(ret));
-
-      drm_intel_decode_set_batch_pointer(decode,
-                                        batch->map,
-                                        batch->bo->offset64,
-                                         USED_BATCH(*batch));
    }
 
-   drm_intel_decode_set_output_file(decode, stderr);
-   drm_intel_decode(decode);
+   uint32_t *data = batch->bo->virtual ? batch->bo->virtual : batch->map;
+   uint32_t *end = data + USED_BATCH(*batch);
+   uint32_t gtt_offset = batch->bo->virtual ? batch->bo->offset64 : 0;
+   unsigned int length;
+
+   bool color = INTEL_DEBUG & DEBUG_COLOR;
+   const char *header_color = color ? BLUE_HEADER : "";
+   const char *reset_color  = color ? NORMAL : "";
+
+   for (uint32_t *p = data; p < end; p += length) {
+      struct gen_group *inst = gen_spec_find_instruction(spec, p);
+      if (inst == NULL) {
+         fprintf(stderr, "unknown instruction %08x\n", p[0]);
+         length = (p[0] & 0xff) + 2;
+         continue;
+      }
+
+      uint64_t offset = gtt_offset + 4 * (p - data);
+
+      fprintf(stderr, "%s0x%08"PRIx64":  0x%08x:  %-80s%s\n", header_color,
+              offset, p[0], gen_group_get_name(inst), reset_color);
 
-   drm_intel_decode_context_free(decode);
+      gen_print_group(stderr, inst, offset, p, 1, color);
+      length = gen_group_get_length(inst, p);
+   }
 
    if (ret == 0) {
       drm_intel_bo_unmap(batch->bo);
-
-      brw_debug_batch(brw);
    }
+
+   brw_debug_batch(brw);
 }
 
 /**
-- 
2.12.0

_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to