From cd724208d3e1e3307f84a794f2c1fc83b69ccf8a Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Tue, 15 Nov 2016 15:56:04 -0700 Subject: mesa: if MESA_DEBUG=context, create a debug context MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A number of drivers report useful debug/perf information accessible through GL_ARB_debug_output and with debug contexts (i.e. setting the GLX_CONTEXT_DEBUG_BIT_ARB flag). But few applications actually use the GL_ARB_debug_output extension. This change lets one set the MESA_DEBUG env var to "context" to force-set a debug context and report debug/perf messages to stderr (or whatever file MESA_LOG_FILE is set to). This is a useful debugging tool. The small change in st_api_create_context() is needed so that st_update_debug_callback() gets called to hook up the driver debug callbacks when ST_CONTEXT_FLAG_DEBUG was not set, but MESA_DEBUG=context. v2: use %.*s format string instead of allocating temporary buffer. Reviewed-by: Nicolai Hähnle --- src/mesa/main/debug.c | 3 ++- src/mesa/main/debug_output.c | 21 +++++++++++++++++++++ src/mesa/main/mtypes.h | 3 ++- src/mesa/state_tracker/st_manager.c | 2 ++ 4 files changed, 27 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/mesa/main/debug.c b/src/mesa/main/debug.c index 5ca7d5ce500..3471b26aad8 100644 --- a/src/mesa/main/debug.c +++ b/src/mesa/main/debug.c @@ -189,7 +189,8 @@ set_debug_flags(const char *str) { "silent", DEBUG_SILENT }, /* turn off debug messages */ { "flush", DEBUG_ALWAYS_FLUSH }, /* flush after each drawing command */ { "incomplete_tex", DEBUG_INCOMPLETE_TEXTURE }, - { "incomplete_fbo", DEBUG_INCOMPLETE_FBO } + { "incomplete_fbo", DEBUG_INCOMPLETE_FBO }, + { "context", DEBUG_CONTEXT } /* force set GL_CONTEXT_FLAG_DEBUG_BIT flag */ }; GLuint i; diff --git a/src/mesa/main/debug_output.c b/src/mesa/main/debug_output.c index 85f64bd459f..4e9209b2377 100644 --- a/src/mesa/main/debug_output.c +++ b/src/mesa/main/debug_output.c @@ -99,6 +99,7 @@ struct gl_debug_state const void *CallbackData; GLboolean SyncOutput; GLboolean DebugOutput; + GLboolean LogToStderr; struct gl_debug_group *Groups[MAX_DEBUG_GROUP_STACK_DEPTH]; struct gl_debug_message GroupMessages[MAX_DEBUG_GROUP_STACK_DEPTH]; @@ -617,6 +618,10 @@ debug_log_message(struct gl_debug_state *debug, GLint nextEmpty; struct gl_debug_message *emptySlot; + if (debug->LogToStderr) { + _mesa_log("Mesa debug output: %.*s\n", len, buf); + } + assert(len < MAX_DEBUG_MESSAGE_LENGTH); if (log->NumMessages == MAX_DEBUG_LOGGED_MESSAGES) @@ -845,6 +850,7 @@ log_msg_locked_and_unlock(struct gl_context *ctx, } if (ctx->Debug->Callback) { + /* Call the user's callback function */ GLenum gl_source = debug_source_enums[source]; GLenum gl_type = debug_type_enums[type]; GLenum gl_severity = debug_severity_enums[severity]; @@ -860,6 +866,7 @@ log_msg_locked_and_unlock(struct gl_context *ctx, callback(gl_source, gl_type, id, gl_severity, len, buf, data); } else { + /* add debug message to queue */ debug_log_message(ctx->Debug, source, type, id, severity, len, buf); _mesa_unlock_debug_state(ctx); } @@ -1267,6 +1274,20 @@ void _mesa_init_debug_output(struct gl_context *ctx) { mtx_init(&ctx->DebugMutex, mtx_plain); + + if (MESA_DEBUG_FLAGS & DEBUG_CONTEXT) { + /* If the MESA_DEBUG env is set to "context", we'll turn on the + * GL_CONTEXT_FLAG_DEBUG_BIT context flag and log debug output + * messages to stderr (or whatever MESA_LOG_FILE points at). + */ + struct gl_debug_state *debug = _mesa_lock_debug_state(ctx); + if (!debug) { + return; + } + debug->DebugOutput = GL_TRUE; + debug->LogToStderr = GL_TRUE; + ctx->Const.ContextFlags |= GL_CONTEXT_FLAG_DEBUG_BIT; + } } diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index 5e9804036c0..66bc07e5963 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -4679,7 +4679,8 @@ enum _debug DEBUG_SILENT = (1 << 0), DEBUG_ALWAYS_FLUSH = (1 << 1), DEBUG_INCOMPLETE_TEXTURE = (1 << 2), - DEBUG_INCOMPLETE_FBO = (1 << 3) + DEBUG_INCOMPLETE_FBO = (1 << 3), + DEBUG_CONTEXT = (1 << 4) }; #ifdef __cplusplus diff --git a/src/mesa/state_tracker/st_manager.c b/src/mesa/state_tracker/st_manager.c index 0f71e6311b1..c3d8286b5a7 100644 --- a/src/mesa/state_tracker/st_manager.c +++ b/src/mesa/state_tracker/st_manager.c @@ -680,7 +680,9 @@ st_api_create_context(struct st_api *stapi, struct st_manager *smapi, } st->ctx->Const.ContextFlags |= GL_CONTEXT_FLAG_DEBUG_BIT; + } + if (st->ctx->Const.ContextFlags & GL_CONTEXT_FLAG_DEBUG_BIT) { st_update_debug_callback(st); } -- cgit v1.2.3