Skip to contentSkip to conversation

i965 fs shader debugging

PATCH New Ben Widawsky 1 participant 7 messages Jun 20, 2011

lore
Share & tools
lore
#0 lore raw

These are the mesa patches that go with the patches that I posted to intel-gfx for intel-gpu-tools:
<[email protected]> which begin to allow HW supported shader debugging on Gen6 and above.

I'll send out a big patch series with all the components when ready, but I can start taking feedback on these now.

Thanks.
Ben

#1 lore raw

PATCH 1/6 i965: step message register allocation

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
#2 lore raw

PATCH 2/6 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       |   37 +++++++++-------
 src/mesa/drivers/dri/i965/brw_wm.h       |    2 +
 src/mesa/drivers/dri/i965/brw_wm_debug.c |   69 ++++++++++++++++++++++++++++++
 5 files changed, 106 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 +20 -17
index 1aebd12..5ed39df 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,32 @@ 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) {
+      assert(brw->wm.scratch_bo);
+      assert(brw->wm.scratch_bo->size / 2 >= c->last_scratch);
+      c->prog_data.total_scratch = brw->wm.scratch_bo->size;
+   } 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
#3 lore raw

PATCH 3/6 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
#4 lore raw

PATCH 4/6 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
#5 lore raw

PATCH 5/6 i965: function to emit breakpoints

In reply to Ben Widawsky

Provide a function to allow emitting breakpoints in the instruction qword.

---
 src/mesa/drivers/dri/i965/brw_eu.c |    6 ++++++
 src/mesa/drivers/dri/i965/brw_eu.h |    1 +
 2 files changed, 7 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);
Signature · 1 line
1.7.5.2
#6 lore raw

PATCH 6/6 i965: Set breakpoints

In reply to Ben Widawsky

Add the breakpoint flag for all instructions when doing wm shader debugging.

---
 src/mesa/drivers/dri/i965/brw_wm.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
src/mesa/drivers/dri/i965/brw_wm.c +3 -0
index 5ed39df..651e217 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