i965: Set shader name for generator from call site
authorKristian Høgsberg <krh@bitplanet.net>
Tue, 28 Oct 2014 02:40:47 +0000 (19:40 -0700)
committerKristian Høgsberg <krh@bitplanet.net>
Wed, 10 Dec 2014 20:28:51 +0000 (12:28 -0800)
fs_generator no longer knows what stage it's generating code for, so
we have to set the debug name of the shader from the call site.

Signed-off-by: Kristian Høgsberg <krh@bitplanet.net>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
src/mesa/drivers/dri/i965/brw_blorp_blit_eu.cpp
src/mesa/drivers/dri/i965/brw_fs.cpp
src/mesa/drivers/dri/i965/brw_fs.h
src/mesa/drivers/dri/i965/brw_fs_generator.cpp

index 86ed953e2abfc672b6074572a61724805fcbdc88..f6d0b68768d61c7ddf44237476f2a2a274de04d6 100644 (file)
@@ -31,8 +31,10 @@ brw_blorp_eu_emitter::brw_blorp_eu_emitter(struct brw_context *brw,
    : mem_ctx(ralloc_context(NULL)),
      generator(brw, mem_ctx, (void *) rzalloc(mem_ctx, struct brw_wm_prog_key),
                (struct brw_stage_prog_data *) rzalloc(mem_ctx, struct brw_wm_prog_data),
-               NULL, NULL, false, debug_flag)
+               NULL, NULL, false)
 {
+   if (debug_flag)
+      generator.enable_debug("blorp");
 }
 
 brw_blorp_eu_emitter::~brw_blorp_eu_emitter()
index b4db1ca2ccd5ec181f78b0aea150b57e5ea3931f..feca1e7f7ab92d71c908e7f827eea5707a63ef0c 100644 (file)
@@ -3716,8 +3716,21 @@ brw_wm_fs_emit(struct brw_context *brw,
       prog_data->no_8 = false;
    }
 
-   fs_generator g(brw, mem_ctx, (void *) key, &prog_data->base, prog, &fp->Base,
-                  v.runtime_check_aads_emit, INTEL_DEBUG & DEBUG_WM);
+   fs_generator g(brw, mem_ctx, (void *) key, &prog_data->base, prog,
+                  &fp->Base, v.runtime_check_aads_emit);
+
+   if (unlikely(INTEL_DEBUG & DEBUG_WM)) {
+      char *name;
+      if (prog)
+         name = ralloc_asprintf(mem_ctx, "%s fragment shader %d",
+                                prog->Label ? prog->Label : "unnamed",
+                                prog->Name);
+      else
+         name = ralloc_asprintf(mem_ctx, "fragment program %d", fp->Base.Id);
+
+      g.enable_debug(name);
+   }
+
    if (simd8_cfg)
       g.generate_code(simd8_cfg, 8);
    if (simd16_cfg)
index 5b33ad27fe138917ac1f624d0601eb80953a5058..ce9f3b8a66291a6374719fa8d5740d71eaf1bf93 100644 (file)
@@ -693,10 +693,10 @@ public:
                 struct brw_stage_prog_data *prog_data,
                 struct gl_shader_program *shader_prog,
                 struct gl_program *fp,
-                bool runtime_check_aads_emit,
-                bool debug_flag);
+                bool runtime_check_aads_emit);
    ~fs_generator();
 
+   void enable_debug(const char *shader_name);
    int generate_code(const cfg_t *cfg, int dispatch_width);
    const unsigned *get_assembly(unsigned int *assembly_size);
 
@@ -804,7 +804,8 @@ private:
 
    exec_list discard_halt_patches;
    bool runtime_check_aads_emit;
-   const bool debug_flag;
+   bool debug_flag;
+   const char *shader_name;
    void *mem_ctx;
 };
 
index 6c528c6ba1e2f8d88a1427dccfc252ade126ffe3..1d88fda109c8b08f88745b016395ca730eb25fec 100644 (file)
@@ -126,13 +126,12 @@ fs_generator::fs_generator(struct brw_context *brw,
                            struct brw_stage_prog_data *prog_data,
                            struct gl_shader_program *shader_prog,
                            struct gl_program *prog,
-                           bool runtime_check_aads_emit,
-                           bool debug_flag)
+                           bool runtime_check_aads_emit)
 
    : brw(brw), key(key),
      prog_data(prog_data), shader_prog(shader_prog),
      prog(prog), runtime_check_aads_emit(runtime_check_aads_emit),
-     debug_flag(debug_flag), mem_ctx(mem_ctx)
+     debug_flag(false), mem_ctx(mem_ctx)
 {
    ctx = &brw->ctx;
 
@@ -1512,6 +1511,13 @@ fs_generator::generate_untyped_surface_read(fs_inst *inst, struct brw_reg dst,
    brw_mark_surface_used(prog_data, surf_index.dw1.ud);
 }
 
+void
+fs_generator::enable_debug(const char *shader_name)
+{
+   debug_flag = true;
+   this->shader_name = shader_name;
+}
+
 int
 fs_generator::generate_code(const cfg_t *cfg, int dispatch_width)
 {
@@ -2015,21 +2021,10 @@ fs_generator::generate_code(const cfg_t *cfg, int dispatch_width)
    int after_size = p->next_insn_offset - start_offset;
 
    if (unlikely(debug_flag)) {
-      if (shader_prog) {
-         fprintf(stderr,
-                 "Native code for %s fragment shader %d (SIMD%d dispatch):\n",
-                 shader_prog->Label ? shader_prog->Label : "unnamed",
-                 shader_prog->Name, dispatch_width);
-      } else if (prog) {
-         fprintf(stderr,
-                 "Native code for fragment program %d (SIMD%d dispatch):\n",
-                 prog->Id, dispatch_width);
-      } else {
-         fprintf(stderr, "Native code for blorp program (SIMD%d dispatch):\n",
-                 dispatch_width);
-      }
-      fprintf(stderr, "SIMD%d shader: %d instructions. %d loops. Compacted %d to %d"
-                      " bytes (%.0f%%)\n",
+      fprintf(stderr, "Native code for %s\n"
+              "SIMD%d shader: %d instructions. %d loops. Compacted %d to %d"
+              " bytes (%.0f%%)\n",
+              shader_name,
               dispatch_width, before_size / 16, loop_count, before_size, after_size,
               100.0f * (before_size - after_size) / before_size);