Skip to contentSkip to conversation

Fragment shader debugging

PATCH In review Ben Widawsky 2 participants 16 messages Jun 24, 2011 – Jun 26, 2011 Library code

lore
Share & tools
lore
#0 lore raw

cover Fragment shader debugging

These patches enable support for the GEN6+ based hardware to do shader debugging.

Currently only fragment shader trace-like debugging is supported. This means that you can get an architectural snapshot at each EU instruction, and that's about it. Further improvements will be made over time, but almost all of that code will go into intel-gpu-tools, and will be less risky.

There is one missing patch: the kernel hangcheck timer disable which is currently in discussion. That patch is separate enough that I don't think it's worth waiting to submit these.

#1 lore raw

PATCH 1/11 intel: shared header for shader debugging

---
 intel/Makefile.am   |    3 ++-
 intel/intel_debug.h |   44 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+), 1 deletions(-)
intel/Makefile.am +2 -1
index b6a9014..7a44aaf 100644
@@ -45,6 +45,7 @@ libdrm_intel_la_SOURCES = \
 	mm.h
 
 libdrm_intelincludedir = ${includedir}/libdrm
-libdrm_intelinclude_HEADERS = intel_bufmgr.h
+libdrm_intelinclude_HEADERS = intel_bufmgr.h \
+			      intel_debug.h
 
 pkgconfig_DATA = libdrm_intel.pc
intel/intel_debug.h new file +44 -0

44 lines not on this page · raw message

Signature · 6 lines
1.7.5.2

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#2 lore raw

PATCH 2/11 i965: step message register allocation

In reply to Ben Widawsky

The system routine requires m0 be reserved. for saving off architectural state. Moved the allocation to start at 2 instead of 0.

---
 src/mesa/drivers/dri/i965/brw_fs_visitor.cpp |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)
src/mesa/drivers/dri/i965/brw_fs_visitor.cpp +5 -5
index b485787..d8957c5 100644
@@ -1466,7 +1466,7 @@ fs_visitor::emit_dummy_fs()
 
    fs_inst *write;
    write = emit(FS_OPCODE_FB_WRITE, fs_reg(0), fs_reg(0));
-   write->base_mrf = 0;
+   write->base_mrf = 2;
 }
 
 /* The register location here is relative to the start of the URB
@@ -1627,7 +1627,7 @@ fs_visitor::emit_fb_writes()
 {
    this->current_annotation = "FB write header";
    GLboolean header_present = GL_TRUE;
-   int nr = 0;
+   int nr = 2;
    int reg_width = c->dispatch_width / 8;
 
    if (intel->gen >= 6 &&
@@ -1637,7 +1637,7 @@ fs_visitor::emit_fb_writes()
    }
 
    if (header_present) {
-      /* m0, m1 header */
+      /* m2, m3 header */
       nr += 2;
    }
 
@@ -1706,7 +1706,7 @@ fs_visitor::emit_fb_writes()
 
       fs_inst *inst = emit(FS_OPCODE_FB_WRITE);
       inst->target = target;
-      inst->base_mrf = 0;
+      inst->base_mrf = 2;
       inst->mlen = nr;
       if (target == c->key.nr_color_regions - 1)
 	 inst->eot = true;
@@ -1724,7 +1724,7 @@ fs_visitor::emit_fb_writes()
       }
 
       fs_inst *inst = emit(FS_OPCODE_FB_WRITE);
-      inst->base_mrf = 0;
+      inst->base_mrf = 2;
       inst->mlen = nr;
       inst->eot = true;
       inst->header_present = header_present;
Signature · 1 line
1.7.5.2
Reviewed-by on v1 2/11
#3 lore raw

Re: [PATCH 02/11] i965: step message register allocation

Quoted 4 lines · Ben Widawsky

The system routine requires m0 be reserved. for saving off architectural state. Moved the allocation to start at 2 instead of 0.

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#4 lore raw

PATCH 3/11 i965: copy in system routine, reserve extra scratch

In reply to Ben Widawsky

The debugger shared memory needs to be a fixed size. Since this is scratch memory that is already used by register spilling, add appropriate hooks to do the right thing when debugging.

Also copy in a binary blob system routine based on an environment variable. This blob will need to be relocated, and emitted as part of the state setup. We do this part now since there is no point debugging if that fails.

---
 src/mesa/drivers/dri/i965/brw_context.c  |   11 +++++
 src/mesa/drivers/dri/i965/brw_context.h  |    4 ++
 src/mesa/drivers/dri/i965/brw_wm.c       |   38 +++++++++-------
 src/mesa/drivers/dri/i965/brw_wm.h       |    2 +
 src/mesa/drivers/dri/i965/brw_wm_debug.c |   69 ++++++++++++++++++++++++++++++
 5 files changed, 107 insertions(+), 17 deletions(-)
src/mesa/drivers/dri/i965/brw_context.c +11 -0
index d6a99ab..b40771b 100644
@@ -230,6 +230,17 @@ GLboolean brwCreateContext( int api,
       brw->wm_max_threads = 1;
    }
 
+   if (getenv("INTEL_SHADER_DEBUG") &&
+      (!strncmp("wm", getenv("INTEL_SHADER_DEBUG"), 2))) {
+      char *sr_path;
+      if ((sr_path = getenv("INTEL_SYSTEM_ROUTINE_PATH"))) {
+         brw_wm_init_debug( brw, (const char *)sr_path );
+      } else {
+	 fprintf(stderr, "please add INTEL_SYSTEM_ROUTINE_PATH "
+			 "environment variable\n");
+      }
+   }
+
    brw_init_state( brw );
 
    brw->curbe.last_buf = calloc(1, 4096);
src/mesa/drivers/dri/i965/brw_context.h +4 -0
index 621b6f8..1557a7a 100644
@@ -713,6 +713,10 @@ struct brw_context
        * Pre-gen6, push constants live in the CURBE.
        */
       uint32_t push_const_offset;
+
+      /** Debug the wm shaders with the system routine */
+      GLboolean debugging;
+      drm_intel_bo *system_routine;
    } wm;
 
 
src/mesa/drivers/dri/i965/brw_wm.c +21 -17
index 1aebd12..8d9976c 100644
@@ -194,6 +194,7 @@ bool do_wm_prog(struct brw_context *brw,
    struct brw_wm_compile *c;
    const GLuint *program;
    GLuint program_size;
+   uint32_t total_scratch = 0;
 
    c = brw->wm.compile_data;
    if (c == NULL) {
@@ -239,30 +240,33 @@ bool do_wm_prog(struct brw_context *brw,
       c->prog_data.dispatch_width = 16;
    }
 
-   /* Scratch space is used for register spilling */
-   if (c->last_scratch) {
-      uint32_t total_scratch;
-
-      /* Per-thread scratch space is power-of-two sized. */
-      for (c->prog_data.total_scratch = 1024;
-	   c->prog_data.total_scratch <= c->last_scratch;
-	   c->prog_data.total_scratch *= 2) {
-	 /* empty */
-      }
-      total_scratch = c->prog_data.total_scratch * brw->wm_max_threads;
-
+   /* Scratch space is used for register spilling and debugger shared memory.
+    * Since the debugger must know the size in advance, we try for a fixed size,
+    * and hope it's large enough
+    */
+   if (c->last_scratch && !brw->wm.debugging) {
+	 /* Per-thread scratch space is power-of-two sized. */
+	 for (c->prog_data.total_scratch = 1024;
+	    c->prog_data.total_scratch <= c->last_scratch;
+	    c->prog_data.total_scratch *= 2) {
+	    /* empty */
+	 }
       if (brw->wm.scratch_bo && total_scratch > brw->wm.scratch_bo->size) {
-	 drm_intel_bo_unreference(brw->wm.scratch_bo);
-	 brw->wm.scratch_bo = NULL;
+         drm_intel_bo_unreference(brw->wm.scratch_bo);
+         brw->wm.scratch_bo = NULL;
       }
       if (brw->wm.scratch_bo == NULL) {
-	 brw->wm.scratch_bo = drm_intel_bo_alloc(intel->bufmgr,
+         brw->wm.scratch_bo = drm_intel_bo_alloc(intel->bufmgr,
 						 "wm scratch",
 						 total_scratch,
 						 4096);
       }
-   }
-   else {
+   } else if (brw->wm.debugging) {
+      uint32_t thread_scratch = brw->wm.scratch_bo->size / brw->wm_max_threads;
+      assert(brw->wm.scratch_bo);
+      assert(thread_scratch / 2 >= c->last_scratch);
+      c->prog_data.total_scratch = thread_scratch;
+   } else {
       c->prog_data.total_scratch = 0;
    }
 
src/mesa/drivers/dri/i965/brw_wm.h +2 -0
index e244b55..9e94928 100644
@@ -309,6 +309,8 @@ void brw_wm_print_insn( struct brw_wm_compile *c,
 void brw_wm_print_program( struct brw_wm_compile *c,
 			   const char *stage );
 
+void brw_wm_init_debug( struct brw_context *brw, const char *sr_path );
+
 void brw_wm_lookup_iz(struct intel_context *intel,
 		      struct brw_wm_compile *c);
 
src/mesa/drivers/dri/i965/brw_wm_debug.c +69 -0

72 lines not on this page · raw message

Signature · 1 line
1.7.5.2
#5 lore raw

Re: [PATCH 03/11] i965: copy in system routine, reserve extra scratch

Quoted 10 lines · Ben Widawsky

The debugger shared memory needs to be a fixed size. Since this is scratch memory that is already used by register spilling, add appropriate hooks to do the right thing when debugging.

Also copy in a binary blob system routine based on an environment variable. This blob will need to be relocated, and emitted as part of the state setup. We do this part now since there is no point debugging if that fails.

This patch loads a file from a user-defined path into graphics memory, which is accessible by any user with DRI permissions. If the X Server is setuid, then it seems this patch would allow loading any file on the system by a user with permission to start the setuid X Server.

Quoted 13 lines
---
 src/mesa/drivers/dri/i965/brw_context.c  |   11 +++++
 src/mesa/drivers/dri/i965/brw_context.h  |    4 ++
 src/mesa/drivers/dri/i965/brw_wm.c       |   38 +++++++++-------
 src/mesa/drivers/dri/i965/brw_wm.h       |    2 +
 src/mesa/drivers/dri/i965/brw_wm_debug.c |   69 ++++++++++++++++++++++++++++++
 5 files changed, 107 insertions(+), 17 deletions(-)
src/mesa/drivers/dri/i965/brw_context.c +0 -0
index d6a99ab..b40771b 100644

src/mesa/drivers/dri/i965/brw_context.c GLboolean brwCreateContext( int api, · line 237

Quoted 8 lines
src/mesa/drivers/dri/i965/brw_context.c +5 -0
@@ -230,6 +230,17 @@ GLboolean brwCreateContext( int api,
       brw->wm_max_threads = 1;
    }
 
+   if (getenv("INTEL_SHADER_DEBUG") &&
+      (!strncmp("wm", getenv("INTEL_SHADER_DEBUG"), 2))) {
+      char *sr_path;
+      if ((sr_path = getenv("INTEL_SYSTEM_ROUTINE_PATH"))) {
+         brw_wm_init_debug( brw, (const char *)sr_path );

(you shouldn't need to cast from char * to const char *)

Quoted 14 lines
src/mesa/drivers/dri/i965/brw_context.c +6 -0
+      } else {
+	 fprintf(stderr, "please add INTEL_SYSTEM_ROUTINE_PATH "
+			 "environment variable\n");
+      }
+   }
+
    brw_init_state( brw );
 
    brw->curbe.last_buf = calloc(1, 4096);
src/mesa/drivers/dri/i965/brw_context.h +0 -0
index 621b6f8..1557a7a 100644

src/mesa/drivers/dri/i965/brw_context.h struct brw_context · line 718

Quoted 6 lines
src/mesa/drivers/dri/i965/brw_context.h +3 -0
@@ -713,6 +713,10 @@ struct brw_context
        * Pre-gen6, push constants live in the CURBE.
        */
       uint32_t push_const_offset;
+
+      /** Debug the wm shaders with the system routine */
+      GLboolean debugging;

We spell this "bool" these days.

Quoted 35 lines
src/mesa/drivers/dri/i965/brw_context.h +1 -0
+      drm_intel_bo *system_routine;
    } wm;
 
 
src/mesa/drivers/dri/i965/brw_wm.c +2 -12
index 1aebd12..8d9976c 100644
@@ -194,6 +194,7 @@ bool do_wm_prog(struct brw_context *brw,
    struct brw_wm_compile *c;
    const GLuint *program;
    GLuint program_size;
+   uint32_t total_scratch = 0;
 
    c = brw->wm.compile_data;
    if (c == NULL) {
@@ -239,30 +240,33 @@ bool do_wm_prog(struct brw_context *brw,
       c->prog_data.dispatch_width = 16;
    }
 
-   /* Scratch space is used for register spilling */
-   if (c->last_scratch) {
-      uint32_t total_scratch;
-
-      /* Per-thread scratch space is power-of-two sized. */
-      for (c->prog_data.total_scratch = 1024;
-	   c->prog_data.total_scratch <= c->last_scratch;
-	   c->prog_data.total_scratch *= 2) {
-	 /* empty */
-      }
-      total_scratch = c->prog_data.total_scratch * brw->wm_max_threads;
-
+   /* Scratch space is used for register spilling and debugger shared memory.

src/mesa/drivers/dri/i965/brw_wm.c bool do_wm_prog(struct brw_context *brw, · line 253

Quoted 10 lines
src/mesa/drivers/dri/i965/brw_wm.c +10 -0
+    * Since the debugger must know the size in advance, we try for a fixed size,
+    * and hope it's large enough
+    */
+   if (c->last_scratch && !brw->wm.debugging) {
+	 /* Per-thread scratch space is power-of-two sized. */
+	 for (c->prog_data.total_scratch = 1024;
+	    c->prog_data.total_scratch <= c->last_scratch;
+	    c->prog_data.total_scratch *= 2) {
+	    /* empty */
+	 }

Something seems to have gone wrong with your indentation here. It looks like there should be no diff here except for the if expression.

src/mesa/drivers/dri/i965/brw_wm.c bool do_wm_prog(struct brw_context *brw, · line 254

Quoted 1 line
src/mesa/drivers/dri/i965/brw_wm.c +0 -0
       if (brw->wm.scratch_bo && total_scratch > brw->wm.scratch_bo->size) {

You stopped initializing the local total_scratch variable, though?

src/mesa/drivers/dri/i965/brw_wm.c bool do_wm_prog(struct brw_context *brw, · line 262

Quoted 11 lines
src/mesa/drivers/dri/i965/brw_wm.c +3 -3
-	 drm_intel_bo_unreference(brw->wm.scratch_bo);
-	 brw->wm.scratch_bo = NULL;
+         drm_intel_bo_unreference(brw->wm.scratch_bo);
+         brw->wm.scratch_bo = NULL;
       }
       if (brw->wm.scratch_bo == NULL) {
-	 brw->wm.scratch_bo = drm_intel_bo_alloc(intel->bufmgr,
+         brw->wm.scratch_bo = drm_intel_bo_alloc(intel->bufmgr,
 						 "wm scratch",
 						 total_scratch,
 						 4096);

More broken indentation.

Quoted 109 lines
src/mesa/drivers/dri/i965/brw_wm.c +6 -2
       }
-   }
-   else {
+   } else if (brw->wm.debugging) {
+      uint32_t thread_scratch = brw->wm.scratch_bo->size / brw->wm_max_threads;
+      assert(brw->wm.scratch_bo);
+      assert(thread_scratch / 2 >= c->last_scratch);
+      c->prog_data.total_scratch = thread_scratch;
+   } else {
       c->prog_data.total_scratch = 0;
    }
 
src/mesa/drivers/dri/i965/brw_wm.h +2 -0
index e244b55..9e94928 100644
@@ -309,6 +309,8 @@ void brw_wm_print_insn( struct brw_wm_compile *c,
 void brw_wm_print_program( struct brw_wm_compile *c,
 			   const char *stage );
 
+void brw_wm_init_debug( struct brw_context *brw, const char *sr_path );
+
 void brw_wm_lookup_iz(struct intel_context *intel,
 		      struct brw_wm_compile *c);
 
src/mesa/drivers/dri/i965/brw_wm_debug.c +69 -0
index 6a91251..41ee926 100644
@@ -172,3 +172,72 @@ void brw_wm_print_program( struct brw_wm_compile *c,
    printf("\n");
 }
 
+/* This define should be shared with the debugger. Not sure of the best place
+ * for it */
+#define SCRATCH_SIZE (512 * 1024)
+void brw_wm_init_debug( struct brw_context *brw,
+			const char *sr_path )
+{
+   struct intel_context *intel = &brw->intel;
+   struct drm_i915_gem_set_domain domain;
+   struct brw_instruction *insn;
+   int sr_insns, i;
+   FILE *stream;
+   size_t size;
+   uint32_t name;
+   int ret;
+
+   stream = fopen(sr_path, "rb");
+   if (stream == NULL) {
+      fprintf(stderr, "Couldn't find the system routine in %s, shader debugging"
+	      " will be disabled\n", sr_path);
+      brw->wm.debugging = GL_FALSE;
+      return;
+   }
+
+   /* can we use sys headers? */
+   fseek(stream, 0, SEEK_END);
+   sr_insns = ftell(stream) / sizeof(*insn);
+   insn = calloc(sr_insns, sizeof(*insn));
+   fseek(stream, 0, SEEK_SET);
+
+   for (i = 0; i < sr_insns; i++) {
+      size = fread(&insn[i], sizeof(*insn), 1, stream);
+      if (size != 1)
+	 break;
+   }
+
+   if (i != sr_insns) {
+      fprintf(stderr, "Not all system routine bytes absorbed (%d/%d)\n",
+		      i, sr_insns);
+      goto done;
+   }
+
+   brw->wm.system_routine = drm_intel_bo_alloc(intel->bufmgr, "system routine",
+					       i * sizeof(*insn), 4096);
+   drm_intel_bo_subdata(brw->wm.system_routine, 0, i * sizeof(*insn), insn);
+
+   /* In the debug case, we allocate the buffer now because we'll need to attach
+    * with the debugger at a later time when flink will not work (the ring /
+    * struct_mutex are likely to be frozen). If we make the buffer visible early
+    * enough, the debugger can map it before the first breakpoint.
+    */
+   brw->wm.scratch_bo = drm_intel_bo_alloc(intel->bufmgr,
+					   "wm scratch",
+					   SCRATCH_SIZE * brw->wm_max_threads,
+					   4096);
+   assert(brw->wm.scratch_bo);
+
+   drm_intel_bo_map(brw->wm.scratch_bo, 0);
+   memset(brw->wm.scratch_bo->virtual, 0xa5, SCRATCH_SIZE * brw->wm_max_threads);
+   drm_intel_bo_unmap(brw->wm.scratch_bo);
+
+   ret = drm_intel_bo_flink(brw->wm.scratch_bo, &name);
+   assert(ret == 0);
+
+   brw->wm.debugging = GL_TRUE;
+
+done:
+   free(insn);
+   fclose(stream);
+}
Signature · 6 lines
1.7.5.2

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#6 lore raw

Re: [PATCH 03/11] i965: copy in system routine, reserve extra scratch

Quoted 10 lines · Eric Anholt
Quoted 9 lines · Ben Widawsky

The debugger shared memory needs to be a fixed size. Since this is scratch memory that is already used by register spilling, add appropriate hooks to do the right thing when debugging.

Also copy in a binary blob system routine based on an environment variable. This blob will need to be relocated, and emitted as part of the state setup. We do this part now since there is no point debugging if that fails.

Quoted 6 lines
Quoted 1 line

This patch loads a file from a user-defined path into graphics memory, which is accessible by any user with DRI permissions. If the X Server is setuid, then it seems this patch would allow loading any file on the system by a user with permission to start the setuid X Server.

Well since you put it that way, that does sound like a really bad idea. Do you have a recommendation? I suppose I can get a make install working to install the system routine to wherever mesa was installed and read it from there when mesa runs. Does that sound like the best solution to you?

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#7 lore raw

PATCH 4/11 i965: Move register spill offsets

In reply to Ben Widawsky

Since the debug system routine will share scratch space with threads doing register spilling, we must offset the registers to accomodate. This is more easily accomplished (and less bug prone) in Mesa, so there you go...

---
 src/mesa/drivers/dri/i965/brw_fs_emit.cpp |   15 +++++++++++++--
 src/mesa/drivers/dri/i965/brw_wm_emit.c   |    2 ++
 2 files changed, 15 insertions(+), 2 deletions(-)
src/mesa/drivers/dri/i965/brw_fs_emit.cpp +13 -2
index 6b7c434..ac48d8f 100644
@@ -452,6 +452,17 @@ fs_visitor::generate_discard(fs_inst *inst)
    }
 }
 
+static GLuint
+brw_get_scratch_offset(struct brw_context *brw, fs_inst *inst)
+{
+   /* Split buffer 50-50 */
+   if (brw->wm.debugging) {
+      return inst->offset + (brw->wm.scratch_bo->size / brw->wm_max_threads) / 2;
+   } else {
+      return inst->offset;
+   }
+}
+
 void
 fs_visitor::generate_spill(fs_inst *inst, struct brw_reg src)
 {
@@ -461,7 +472,7 @@ fs_visitor::generate_spill(fs_inst *inst, struct brw_reg src)
 	   retype(brw_message_reg(inst->base_mrf + 1), BRW_REGISTER_TYPE_UD),
 	   retype(src, BRW_REGISTER_TYPE_UD));
    brw_oword_block_write_scratch(p, brw_message_reg(inst->base_mrf), 1,
-				 inst->offset);
+				 brw_get_scratch_offset(brw, inst));
 }
 
 void
@@ -483,7 +494,7 @@ fs_visitor::generate_unspill(fs_inst *inst, struct brw_reg dst)
       brw_MOV(p, brw_null_reg(), dst);
 
    brw_oword_block_read_scratch(p, dst, brw_message_reg(inst->base_mrf), 1,
-				inst->offset);
+				brw_get_scratch_offset(brw, inst));
 
    if (intel->gen == 4 && !intel->is_g4x) {
       /* gen4 errata: destination from a send can't be used as a
src/mesa/drivers/dri/i965/brw_wm_emit.c +2 -0
index f61757a..4ac94ee 100644
@@ -1560,6 +1560,8 @@ static void emit_spill( struct brw_wm_compile *c,
      mov (1) r0.2<1>:d    0x00000080:d     { Align1 NoMask }
      send (16) null.0<1>:uw m1               r0.0<8;8,1>:uw   0x053003ff:ud    { Align1 }
    */
+   if (p->brw->wm.debugging)
+      abort();
    brw_oword_block_write_scratch(p, brw_message_reg(1), 2, slot);
 }
 
Signature · 1 line
1.7.5.2
#8 lore raw

PATCH 5/11 i965: setup system routine

In reply to Ben Widawsky

Upload the system routine as part of the invariant state if debugging.

Remove SIP setting if not debugging to make it more friendly for others that may be debugging shaders or media kernels.

---
 src/mesa/drivers/dri/i965/brw_misc_state.c |   24 +++++++++++-------------
 1 files changed, 11 insertions(+), 13 deletions(-)
src/mesa/drivers/dri/i965/brw_misc_state.c +11 -13
index 1f3b64f..2465bc0 100644
@@ -633,19 +633,17 @@ static void upload_invarient_state( struct brw_context *brw )
 	 }
       }
    }
-
-   /* 0x61020000  State Instruction Pointer */
-   {
-      struct brw_system_instruction_pointer sip;
-      memset(&sip, 0, sizeof(sip));
-
-      sip.header.opcode = CMD_STATE_INSN_POINTER;
-      sip.header.length = 0;
-      sip.bits0.pad = 0;
-      sip.bits0.system_instruction_pointer = 0;
-      BRW_BATCH_STRUCT(brw, &sip);
-   }
-
+     /* The system routine must be set after a change to Instruction base */
+     if (brw->wm.debugging)  {
+       assert(brw->wm.system_routine != NULL);
+       /* assert instruction base == 0 */
+       BEGIN_BATCH(4);
+       OUT_BATCH(CMD_STATE_INSN_POINTER << 16);
+       OUT_RELOC(brw->wm.system_routine, I915_GEM_DOMAIN_RENDER, 0, 0);
+       OUT_BATCH(MI_FLUSH | 1 << 1);
+       OUT_BATCH(MI_NOOP);
+       ADVANCE_BATCH();
+     }
 
    {
       struct brw_vf_statistics vfs;
Signature · 1 line
1.7.5.2
#9 lore raw

Re: [PATCH 05/11] i965: setup system routine

Quoted 4 lines · Ben Widawsky

Upload the system routine as part of the invariant state if debugging.

Remove SIP setting if not debugging to make it more friendly for others that may be debugging shaders or media kernels.

Instructions are from an offset of the brw->cache.bo these days. So you'd need to load the program data into there, and be careful to retain the SIP when brw_clear_cache() is called.

Quoted 47 lines
---
 src/mesa/drivers/dri/i965/brw_misc_state.c |   24 +++++++++++-------------
 1 files changed, 11 insertions(+), 13 deletions(-)
src/mesa/drivers/dri/i965/brw_misc_state.c +11 -13
index 1f3b64f..2465bc0 100644
@@ -633,19 +633,17 @@ static void upload_invarient_state( struct brw_context *brw )
 	 }
       }
    }
-
-   /* 0x61020000  State Instruction Pointer */
-   {
-      struct brw_system_instruction_pointer sip;
-      memset(&sip, 0, sizeof(sip));
-
-      sip.header.opcode = CMD_STATE_INSN_POINTER;
-      sip.header.length = 0;
-      sip.bits0.pad = 0;
-      sip.bits0.system_instruction_pointer = 0;
-      BRW_BATCH_STRUCT(brw, &sip);
-   }
-
+     /* The system routine must be set after a change to Instruction base */
+     if (brw->wm.debugging)  {
+       assert(brw->wm.system_routine != NULL);
+       /* assert instruction base == 0 */
+       BEGIN_BATCH(4);
+       OUT_BATCH(CMD_STATE_INSN_POINTER << 16);
+       OUT_RELOC(brw->wm.system_routine, I915_GEM_DOMAIN_RENDER, 0, 0);
+       OUT_BATCH(MI_FLUSH | 1 << 1);
+       OUT_BATCH(MI_NOOP);
+       ADVANCE_BATCH();
+     }
 
    {
       struct brw_vf_statistics vfs;
Signature · 6 lines
1.7.5.2

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#10 lore raw

PATCH 6/11 i965: emit breakpoints

In reply to Ben Widawsky

Provide a function to allow emitting breakpoints in the instruction oword. Use breakpoints when debugging.

---
 src/mesa/drivers/dri/i965/brw_eu.c |    6 ++++++
 src/mesa/drivers/dri/i965/brw_eu.h |    1 +
 src/mesa/drivers/dri/i965/brw_wm.c |    3 +++
 3 files changed, 10 insertions(+), 0 deletions(-)
src/mesa/drivers/dri/i965/brw_eu.c +6 -0
index c1f2520..1af232c 100644
@@ -150,6 +150,12 @@ void brw_set_acc_write_control(struct brw_compile *p, GLuint value)
       p->current->header.acc_wr_control = value;
 }
 
+void brw_set_breakpoint(struct brw_compile *p)
+{
+   if (p->brw->intel.gen >= 6)
+      p->current->header.debug_control = 1;
+}
+
 void brw_push_insn_state( struct brw_compile *p )
 {
    assert(p->current != &p->stack[BRW_EU_MAX_INSN_STACK-1]);
src/mesa/drivers/dri/i965/brw_eu.h +1 -0
index 72d50ea..ec7019f 100644
@@ -793,6 +793,7 @@ void brw_set_predicate_control( struct brw_compile *p, GLuint pc );
 void brw_set_predicate_inverse(struct brw_compile *p, bool predicate_inverse);
 void brw_set_conditionalmod( struct brw_compile *p, GLuint conditional );
 void brw_set_acc_write_control(struct brw_compile *p, GLuint value);
+void brw_set_breakpoint( struct brw_compile *p );
 
 void brw_init_compile(struct brw_context *, struct brw_compile *p,
 		      void *mem_ctx);
src/mesa/drivers/dri/i965/brw_wm.c +3 -0
index 8d9976c..24589e4 100644
@@ -229,6 +229,9 @@ bool do_wm_prog(struct brw_context *brw,
 
    brw_init_compile(brw, &c->func, c);
 
+   if (brw->wm.debugging)
+      brw_set_breakpoint(&c->func);
+
    if (prog && prog->FragmentProgram) {
       if (!brw_wm_fs_emit(brw, c, prog))
 	 return false;
Signature · 1 line
1.7.5.2
#11 lore raw

PATCH 7/11 i965: attach to a listening debugger

In reply to Ben Widawsky

Use unix domain sockets to connect to a debugger and send the information the debugger will use to properly handle debug events.

---
 src/mesa/drivers/dri/i965/brw_wm_debug.c |   66 ++++++++++++++++++++++++++++-
 1 files changed, 63 insertions(+), 3 deletions(-)
src/mesa/drivers/dri/i965/brw_wm_debug.c +63 -3
index 41ee926..bc84aa0 100644
@@ -172,9 +172,60 @@ void brw_wm_print_program( struct brw_wm_compile *c,
    printf("\n");
 }
 
-/* This define should be shared with the debugger. Not sure of the best place
- * for it */
-#define SCRATCH_SIZE (512 * 1024)
+#define SCRATCH_SIZE (1 << 20)
+#ifndef NO_DEBUGGER_LISTENING
+#include <unistd.h>
+#include <sys/un.h>
+#include <sys/socket.h>
+#include "intel_debug.h"
+
+static int
+attach_to_debugger(int flink_handle)
+{
+   struct sockaddr_un addr;
+   struct debug_handshake dh;
+   int reply, fd, ret;
+
+   fd = socket(AF_UNIX, SOCK_STREAM, 0);
+   if (fd == -1)
+      return -1;
+
+   memset(&addr, 0, sizeof(addr));
+   addr.sun_family = AF_UNIX;
+   strncpy(addr.sun_path, SHADER_DEBUG_SOCKET, sizeof(addr.sun_path) - 1);
+
+   ret = connect(fd, &addr, sizeof(addr));
+   if (ret == -1)
+      goto done;
+
+   dh.version = DEBUG_HANDSHAKE_VERSION;
+   dh.flink_handle = flink_handle;
+   dh.per_thread_scratch = SCRATCH_SIZE;
+   ret = write(fd, &dh, sizeof(dh));
+   if (ret != sizeof(dh)) {
+      ret = -1;
+      goto done;
+   }
+
+   ret = read(fd, &reply, sizeof(reply));
+   if (ret != sizeof(reply)) {
+      ret = -1;
+      goto done;
+   }
+
+   if (strncmp(DEBUG_HANDSHAKE_ACK, (char *)&reply, strlen(DEBUG_HANDSHAKE_ACK))) {
+      ret = 1;
+      goto done;
+   }
+
+   ret = 0;
+
+done:
+   close(fd);
+   return ret;
+}
+#endif
+
 void brw_wm_init_debug( struct brw_context *brw,
 			const char *sr_path )
 {
@@ -228,6 +279,7 @@ void brw_wm_init_debug( struct brw_context *brw,
 					   4096);
    assert(brw->wm.scratch_bo);
 
+   /* Put a nice pattern in the buffer to hopefully help detect errors */
    drm_intel_bo_map(brw->wm.scratch_bo, 0);
    memset(brw->wm.scratch_bo->virtual, 0xa5, SCRATCH_SIZE * brw->wm_max_threads);
    drm_intel_bo_unmap(brw->wm.scratch_bo);
@@ -235,6 +287,14 @@ void brw_wm_init_debug( struct brw_context *brw,
    ret = drm_intel_bo_flink(brw->wm.scratch_bo, &name);
    assert(ret == 0);
 
+   /* Simple system routines do not need a debugger present */
+   #ifndef NO_DEBUGGER_LISTENING
+   if (attach_to_debugger(name) != 0) {
+      fprintf(stderr, "Failed to attach to debugger\n");
+      goto done;
+   }
+   #endif
+
    brw->wm.debugging = GL_TRUE;
 
 done:
Signature · 1 line
1.7.5.2
#12 lore raw

PATCH 8/11 intel-gpu-tools: register range handling for forcewake hooks

In reply to Ben Widawsky

We can deprecate the old code by using the non-safe flag in the new API. The safe flag should allow the previous behavior to continue.

The code also adds some range checking on register access. This code is gives hooks to prevent tools from doing bad things.

---
 lib/Makefile.am       |    1 +
 lib/intel_chipset.h   |    8 ++
 lib/intel_gpu_tools.h |   27 ++++++++
 lib/intel_mmio.c      |  178 +++++++++++++++++++++++++++++++++++++++++++++++++
 lib/intel_reg_map.c   |  174 +++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 388 insertions(+), 0 deletions(-)
lib/Makefile.am +1 -0
index 0c9380d..4612cd5 100644
@@ -8,6 +8,7 @@ libintel_tools_la_SOURCES = \
 	intel_mmio.c \
 	intel_pci.c \
 	intel_reg.h \
+	intel_reg_map.c \
 	instdone.c \
 	instdone.h \
 	drmtest.h
lib/intel_chipset.h +8 -0
index c3db3ab..a38f661 100755
@@ -168,3 +168,11 @@
 
 #define HAS_BLT_RING(devid)	(IS_GEN6(devid) || \
 				 IS_GEN7(devid))
+
+#define IS_BROADWATER(devid)	(devid == PCI_CHIP_I946_GZ || \
+				 devid == PCI_CHIP_I965_G_1 || \
+				 devid == PCI_CHIP_I965_Q || \
+				 devid == PCI_CHIP_I965_G)
+
+#define IS_CRESTLINE(devid)	(devid == PCI_CHIP_I965_GM || \
+				 devid == PCI_CHIP_I965_GME)
lib/intel_gpu_tools.h +27 -0
index acee657..a145fb9 100644
@@ -37,6 +37,33 @@
 extern void *mmio;
 void intel_get_mmio(struct pci_device *pci_dev);
 
+/* New style register access API */
+int intel_register_access_init(struct pci_device *pci_dev, int safe);
+void intel_register_access_fini(void);
+uint32_t intel_register_read(uint32_t reg);
+void intel_register_write(uint32_t reg, uint32_t val);
+
+#define INTEL_RANGE_RSVD	(0<<0) /*  Shouldn't be read or written */
+#define INTEL_RANGE_READ	(1<<0)
+#define INTEL_RANGE_WRITE	(1<<1)
+#define INTEL_RANGE_RW		(INTEL_RANGE_READ | INTEL_RANGE_WRITE)
+#define INTEL_RANGE_END		(1<<31)
+
+struct intel_register_range {
+	uint32_t base;
+	uint32_t size;
+	uint32_t flags;
+};
+
+struct intel_register_map {
+	struct intel_register_range *map;
+	uint32_t top;
+	uint32_t alignment_mask;
+};
+struct intel_register_map intel_get_register_map(uint32_t devid);
+struct intel_register_range *intel_get_register_range(struct intel_register_map map, uint32_t offset, int mode);
+
+
 static inline uint32_t
 INREG(uint32_t reg)
 {
lib/intel_mmio.c +178 -0

199 lines not on this page · raw message

lib/intel_reg_map.c new file +174 -0

174 lines not on this page · raw message

Signature · 1 line
1.7.5.2

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#13 lore raw

PATCH 9/11 intel-gpu-tools/forcewaked: simple forcewake app

In reply to Ben Widawsky

This app is required for debug features which seem to (undocumented) reset themselves if/when the GT goes to sleep.

---
 tools/Makefile.am  |    1 +
 tools/forcewaked.c |   45 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+), 0 deletions(-)
tools/Makefile.am +1 -0
index c777778..2a6c82d 100644
@@ -12,6 +12,7 @@ bin_PROGRAMS = \
 	intel_reg_snapshot \
 	intel_reg_write \
 	intel_reg_read \
+	forcewaked \
 	$(NULL)
 
 noinst_PROGRAMS = \
tools/forcewaked.c new file +45 -0

45 lines not on this page · raw message

Signature · 6 lines
1.7.5.2

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#14 lore raw

PATCH 10/11 debugging: add important debug regs

In reply to Ben Widawsky
---
 lib/intel_reg.h |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
lib/intel_reg.h +5 -0
index 48d8f66..ef9cb63 100644
@@ -3488,5 +3488,10 @@ typedef enum {
 #define  TRANS_DP_HSYNC_ACTIVE_HIGH     (1<<3)
 #define  TRANS_DP_HSYNC_ACTIVE_LOW      0
 
+/* Debug */
+#define INSTPM			0x20c0
+#define  INSTPM_GLOBAL_DEBUG_EN	(1<<4)
+#define GEN6_TD_CTL		0x7000
+#define  TD_CTL_FORCE_TD_BKPT	(1<<4)
 
 #endif /* _I810_REG_H */
Signature · 1 line
1.7.5.2
#15 lore raw

PATCH 11/11 debugging: shader debugging

In reply to Ben Widawsky

high level summary of the files:
* debug_rdata - get current state from debug registers. Helpful when developing the debugger, and could serve some purpose in the future.
* eudb - the debugger itself
* eviction_macro - generate the proper macro to flush the EU render cache until I get control flow working
* pre_cpp - an evaluating c preprocesser like thing, to be used before cpp
* sr - the system routine, exception handler which runs on the EU
* test - a very basic test system routine
* debug.h

---
 configure.ac                             |    1 +
 debugger/Makefile.am                     |   12 +
 debugger/debug_rdata.c                   |  141 +++++++
 debugger/eudb.c                          |  592 ++++++++++++++++++++++++++++++
 debugger/system_routine/Makefile         |   84 +++++
 debugger/system_routine/eviction_macro.c |   48 +++
 debugger/system_routine/pre_cpp.py       |  123 ++++++
 debugger/system_routine/sr.g4a           |  277 ++++++++++++++
 debugger/system_routine/test.g4a         |   64 ++++
 lib/debug.h                              |   92 +++++
 10 files changed, 1434 insertions(+), 0 deletions(-)
configure.ac +1 -0
index 4eb1c48..d2b30dc 100644
@@ -98,5 +98,6 @@ AC_CONFIG_FILES([
 	scripts/Makefile
 	tests/Makefile
 	tools/Makefile
+	debugger/Makefile
 ])
 AC_OUTPUT
debugger/Makefile.am new file +12 -0
new file mode 100644
index 0000000..eff4e2d
@@ -0,0 +1,12 @@
+SUBDIRS=system_routine
+
+bin_PROGRAMS = \
+	eudb \
+	debug_rdata \
+	$(NULL)
+
+LDADD = ../lib/libintel_tools.la $(DRM_LIBS) $(PCIACCESS_LIBS)
+
+AM_CFLAGS = $(DRM_CFLAGS) $(PCIACCESS_CFLAGS) $(WARN_CFLAGS) \
+	-I$(srcdir)/.. \
+	-I$(srcdir)/../lib
debugger/debug_rdata.c new file +141 -0

141 lines not on this page · raw message

debugger/eudb.c new file +592 -0

592 lines not on this page · raw message

debugger/system_routine/Makefile new file +84 -0

84 lines not on this page · raw message

debugger/system_routine/eviction_macro.c new file +48 -0

48 lines not on this page · raw message

debugger/system_routine/pre_cpp.py new file +123 -0

123 lines not on this page · raw message

debugger/system_routine/sr.g4a new file +277 -0

277 lines not on this page · raw message

debugger/system_routine/test.g4a new file +64 -0

64 lines not on this page · raw message

lib/debug.h new file +92 -0

92 lines not on this page · raw message

Signature · 6 lines
1.7.5.2

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx