[Mesa-dev] [PATCH 20/23] i965: Plumb compiler debug logging through a function pointer in brw_compiler

Jason Ekstrand jason at jlekstrand.net
Fri Apr 17 19:12:00 PDT 2015


---
 src/mesa/drivers/dri/i965/brw_fs_generator.cpp   | 11 ++++++-----
 src/mesa/drivers/dri/i965/brw_shader.cpp         | 13 +++++++++++++
 src/mesa/drivers/dri/i965/brw_shader.h           |  2 ++
 src/mesa/drivers/dri/i965/brw_vec4_generator.cpp | 11 ++++++-----
 4 files changed, 27 insertions(+), 10 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_fs_generator.cpp b/src/mesa/drivers/dri/i965/brw_fs_generator.cpp
index 35bc241..123bdf7 100644
--- a/src/mesa/drivers/dri/i965/brw_fs_generator.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs_generator.cpp
@@ -2111,15 +2111,16 @@ fs_generator::generate_code(const cfg_t *cfg, int dispatch_width)
       ralloc_free(annotation.ann);
    }
 
-   static GLuint msg_id = 0;
-   _mesa_gl_debug(&brw->ctx, &msg_id,
-                  MESA_DEBUG_SOURCE_SHADER_COMPILER,
-                  MESA_DEBUG_TYPE_OTHER,
-                  MESA_DEBUG_SEVERITY_NOTIFICATION,
+   const int debug_str_size = 160;
+   char debug_str[debug_str_size];
+   int len;
+   len = snprintf(debug_str, debug_str_size,
                   "%s SIMD%d shader: %d inst, %d loops, %d:%d spills:fills, "
                   "Promoted %u constants, compacted %d to %d bytes.\n",
                   stage_abbrev, dispatch_width, before_size / 16, loop_count,
                   spill_count, fill_count, promoted_constants, before_size, after_size);
+   assert(len < debug_str_size); (void)len;
+   brw->intelScreen->compiler->shader_debug_log(debug_str);
 
    return start_offset;
 }
diff --git a/src/mesa/drivers/dri/i965/brw_shader.cpp b/src/mesa/drivers/dri/i965/brw_shader.cpp
index e340b0a..fb4b570 100644
--- a/src/mesa/drivers/dri/i965/brw_shader.cpp
+++ b/src/mesa/drivers/dri/i965/brw_shader.cpp
@@ -32,12 +32,25 @@
 #include "glsl/glsl_parser_extras.h"
 #include "main/shaderapi.h"
 
+static void
+shader_debug_log_mesa(const char *str)
+{
+   GET_CURRENT_CONTEXT(ctx);
+
+   GLuint msg_id = 0;
+   _mesa_gl_debug(ctx, &msg_id,
+                  MESA_DEBUG_SOURCE_SHADER_COMPILER,
+                  MESA_DEBUG_TYPE_OTHER,
+                  MESA_DEBUG_SEVERITY_NOTIFICATION, "%s", str);
+}
+
 struct brw_compiler *
 brw_compiler_create(void *mem_ctx, const struct brw_device_info *devinfo)
 {
    struct brw_compiler *compiler = rzalloc(mem_ctx, struct brw_compiler);
 
    compiler->devinfo = devinfo;
+   compiler->shader_debug_log = shader_debug_log_mesa;
 
    brw_fs_alloc_reg_sets(compiler);
    brw_vec4_alloc_reg_set(compiler);
diff --git a/src/mesa/drivers/dri/i965/brw_shader.h b/src/mesa/drivers/dri/i965/brw_shader.h
index ac4e62a..c6d7945 100644
--- a/src/mesa/drivers/dri/i965/brw_shader.h
+++ b/src/mesa/drivers/dri/i965/brw_shader.h
@@ -86,6 +86,8 @@ struct brw_compiler {
        */
       int aligned_pairs_class;
    } fs_reg_sets[2];
+
+   void (*shader_debug_log)(const char *str);
 };
 
 enum PACKED register_file {
diff --git a/src/mesa/drivers/dri/i965/brw_vec4_generator.cpp b/src/mesa/drivers/dri/i965/brw_vec4_generator.cpp
index 80e297f..5f439c0 100644
--- a/src/mesa/drivers/dri/i965/brw_vec4_generator.cpp
+++ b/src/mesa/drivers/dri/i965/brw_vec4_generator.cpp
@@ -1618,16 +1618,17 @@ vec4_generator::generate_code(const cfg_t *cfg)
       ralloc_free(annotation.ann);
    }
 
-   static GLuint msg_id = 0;
-   _mesa_gl_debug(&brw->ctx, &msg_id,
-                  MESA_DEBUG_SOURCE_SHADER_COMPILER,
-                  MESA_DEBUG_TYPE_OTHER,
-                  MESA_DEBUG_SEVERITY_NOTIFICATION,
+   const int debug_str_size = 160;
+   char debug_str[debug_str_size];
+   int len;
+   len = snprintf(debug_str, debug_str_size,
                   "%s vec4 shader: %d inst, %d loops, "
                   "compacted %d to %d bytes.\n",
                   stage_abbrev,
                   before_size / 16, loop_count,
                   before_size, after_size);
+   assert(len < debug_str_size); (void)len;
+   brw->intelScreen->compiler->shader_debug_log(debug_str);
 }
 
 const unsigned *
-- 
2.3.5



More information about the mesa-dev mailing list