[Mesa-dev] [PATCH] gallium: expose a debug message callback settable by context owner

Ilia Mirkin imirkin at alum.mit.edu
Fri Oct 30 00:17:35 PDT 2015


This will allow gallium drivers to send messages to KHR_debug endpoints

Signed-off-by: Ilia Mirkin <imirkin at alum.mit.edu>
---

This patch has a major problem in that it uses GET_CURRENT_CONTEXT. I
was thinking of maybe adding a userdata thing into the pipe_context to
be passed into that callback? Wanted to get more feedback on the
design first. I didn't want to use a set_callback() since then a
helper like the one I made would be difficult to reuse.

 src/gallium/auxiliary/util/u_debug.h | 38 ++++++++++++++++++++++++++++++++++++
 src/gallium/include/pipe/p_context.h | 22 +++++++++++++++++++++
 src/gallium/include/pipe/p_defines.h | 35 +++++++++++++++++++++++++++++++++
 src/mesa/state_tracker/st_context.c  | 14 +++++++++++++
 4 files changed, 109 insertions(+)

diff --git a/src/gallium/auxiliary/util/u_debug.h b/src/gallium/auxiliary/util/u_debug.h
index 926063a..37ee048 100644
--- a/src/gallium/auxiliary/util/u_debug.h
+++ b/src/gallium/auxiliary/util/u_debug.h
@@ -42,6 +42,7 @@
 #include "os/os_misc.h"
 
 #include "pipe/p_format.h"
+#include "pipe/p_context.h"
 
 
 #ifdef	__cplusplus
@@ -262,6 +263,43 @@ void _debug_assert_fail(const char *expr,
    _debug_printf("error: %s\n", __msg)
 #endif
 
+/**
+ * Output a debug log message to the context.
+ */
+#define pipe_debug_message(pipe, source, type, severity, fmt, ...) do { \
+  static unsigned id = 0; \
+  _pipe_debug_message(pipe, &id, \
+                      PIPE_DEBUG_SOURCE_ ## source,\
+                      PIPE_DEBUG_TYPE_ ## type, \
+                      PIPE_DEBUG_SEVERITY_ ## severity, \
+                      fmt, __VA_ARGS__); \
+} while (0)
+
+static inline void _pipe_debug_message(
+      struct pipe_context *pipe,
+      unsigned *id,
+      enum pipe_debug_source source,
+      enum pipe_debug_type type,
+      enum pipe_debug_severity severity,
+      const char *fmt,
+      ...) _util_printf_format(6, 7);
+
+static inline void _pipe_debug_message(
+      struct pipe_context *pipe,
+      unsigned *id,
+      enum pipe_debug_source source,
+      enum pipe_debug_type type,
+      enum pipe_debug_severity severity,
+      const char *fmt,
+      ...)
+{
+   va_list args;
+   va_start(args, fmt);
+   if (pipe->debug_message)
+      pipe->debug_message(pipe, id, source, type, severity, fmt, args);
+   va_end(args);
+}
+
 
 /**
  * Used by debug_dump_enum and debug_dump_flags to describe symbols.
diff --git a/src/gallium/include/pipe/p_context.h b/src/gallium/include/pipe/p_context.h
index 6f9fe76..05b92e4 100644
--- a/src/gallium/include/pipe/p_context.h
+++ b/src/gallium/include/pipe/p_context.h
@@ -636,6 +636,28 @@ struct pipe_context {
     */
    void (*dump_debug_state)(struct pipe_context *ctx, FILE *stream,
                             unsigned flags);
+
+   /**
+    * Allow the driver to provide information about current state,
+    * e.g. errors, performance info, etc. This function is expected to be set
+    * by the state tracker.
+    *
+    * \param ctx        pipe context
+    * \param id         message type identifier, if pointed value is 0, then a
+    *                   new id is assigned
+    * \param source     PIPE_DEBUG_SOURCE_*
+    * \param type       PIPE_DEBUG_TYPE_*
+    * \param severity   PIPE_DEBUG_SEVERITY_*
+    * \param format     printf-style format string
+    * \param args       args for format string
+    */
+   void (*debug_message)(struct pipe_context *ctx,
+                         unsigned *id,
+                         enum pipe_debug_source source,
+                         enum pipe_debug_type type,
+                         enum pipe_debug_severity severity,
+                         const char *fmt,
+                         va_list args);
 };
 
 
diff --git a/src/gallium/include/pipe/p_defines.h b/src/gallium/include/pipe/p_defines.h
index b15c880..860ebc6 100644
--- a/src/gallium/include/pipe/p_defines.h
+++ b/src/gallium/include/pipe/p_defines.h
@@ -868,6 +868,41 @@ struct pipe_driver_query_group_info
    unsigned num_queries;
 };
 
+enum pipe_debug_source
+{
+   PIPE_DEBUG_SOURCE_API,
+   PIPE_DEBUG_SOURCE_WINDOW_SYSTEM,
+   PIPE_DEBUG_SOURCE_SHADER_COMPILER,
+   PIPE_DEBUG_SOURCE_THIRD_PARTY,
+   PIPE_DEBUG_SOURCE_APPLICATION,
+   PIPE_DEBUG_SOURCE_OTHER,
+   PIPE_DEBUG_SOURCE_COUNT
+};
+
+enum pipe_debug_type
+{
+   PIPE_DEBUG_TYPE_ERROR,
+   PIPE_DEBUG_TYPE_DEPRECATED,
+   PIPE_DEBUG_TYPE_UNDEFINED,
+   PIPE_DEBUG_TYPE_PORTABILITY,
+   PIPE_DEBUG_TYPE_PERFORMANCE,
+   PIPE_DEBUG_TYPE_OTHER,
+   PIPE_DEBUG_TYPE_MARKER,
+   PIPE_DEBUG_TYPE_PUSH_GROUP,
+   PIPE_DEBUG_TYPE_POP_GROUP,
+   PIPE_DEBUG_TYPE_COUNT
+};
+
+enum pipe_debug_severity
+{
+   PIPE_DEBUG_SEVERITY_LOW,
+   PIPE_DEBUG_SEVERITY_MEDIUM,
+   PIPE_DEBUG_SEVERITY_HIGH,
+   PIPE_DEBUG_SEVERITY_NOTIFICATION,
+   PIPE_DEBUG_SEVERITY_COUNT
+};
+
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c
index 6e20fd1..2ad4469 100644
--- a/src/mesa/state_tracker/st_context.c
+++ b/src/mesa/state_tracker/st_context.c
@@ -106,6 +106,19 @@ void st_invalidate_state(struct gl_context * ctx, GLuint new_state)
    _vbo_InvalidateState(ctx, new_state);
 }
 
+static void
+st_debug_message(struct pipe_context *pipe,
+                 unsigned *id,
+                 enum pipe_debug_source source,
+                 enum pipe_debug_type type,
+                 enum pipe_debug_severity severity,
+                 const char *fmt,
+                 va_list args)
+{
+   GET_CURRENT_CONTEXT(ctx);
+   _mesa_gl_vdebug(ctx, id, source, type, severity, fmt, args);
+}
+
 
 static void
 st_destroy_context_priv(struct st_context *st)
@@ -162,6 +175,7 @@ st_create_context_priv( struct gl_context *ctx, struct pipe_context *pipe,
 
    /* XXX: this is one-off, per-screen init: */
    st_debug_init();
+   pipe->debug_message = st_debug_message;
    
    /* state tracker needs the VBO module */
    _vbo_CreateContext(ctx);
-- 
2.4.10



More information about the mesa-dev mailing list