[Mesa-dev] [PATCH] mesa: if MESA_DEBUG=context, create a debug context

Brian Paul brianp at vmware.com
Wed Nov 16 16:34:46 UTC 2016


On 11/16/2016 02:56 AM, Nicolai Hähnle wrote:
> On 16.11.2016 00:05, Brian Paul wrote:
>> 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.
>> ---
>>  src/mesa/main/debug.c               |  3 ++-
>>  src/mesa/main/debug_output.c        | 28 ++++++++++++++++++++++++++++
>>  src/mesa/main/mtypes.h              |  3 ++-
>>  src/mesa/state_tracker/st_manager.c |  2 ++
>>  4 files changed, 34 insertions(+), 2 deletions(-)
>>
>> diff --git a/src/mesa/main/debug.c b/src/mesa/main/debug.c
>> index 5ca7d5c..3471b26 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 85f64bd..290d626 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,17 @@ debug_log_message(struct gl_debug_state *debug,
>>     GLint nextEmpty;
>>     struct gl_debug_message *emptySlot;
>>
>> +   if (debug->LogToStderr) {
>> +      /* since 'buf' is not null terminated, make a copy and add \0 */
>> +      char *buf2 = malloc(len + 1);
>> +      if (buf2) {
>> +         memcpy(buf2, buf, len);
>> +         buf2[len] = 0;
>> +         _mesa_log("Mesa debug output: %s\n", buf2);
>> +         free(buf2);
>> +      }
>
> Using
>
>     _mesa_log("Mesa debug output: %.*s\n", len, buf);
>
> should have the same effect without the additional allocation and copy.

Good idea.  I'll make that change.


> Apart from that, this patch looks like a very good idea and is
>
> Reviewed-by: Nicolai Hähnle <nicolai.haehnle at amd.com>

Thanks!

-Brian




More information about the mesa-dev mailing list