From 3703c88ac18063a35fd8c0fc52fee52d8c669638 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Wed, 1 Jul 2015 16:23:45 -0700 Subject: glamor: Use GL_ARB_debug_output to log GL errors. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This should help people debugging when glamor does something stupid on their driver. Signed-off-by: Eric Anholt Reviewed-by: Michel Dänzer --- glamor/glamor.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'glamor') diff --git a/glamor/glamor.c b/glamor/glamor.c index 702efd120..50d85ff22 100644 --- a/glamor/glamor.c +++ b/glamor/glamor.c @@ -384,6 +384,45 @@ glamor_check_instruction_count(int gl_version) return TRUE; } +static void GLAPIENTRY +glamor_debug_output_callback(GLenum source, + GLenum type, + GLuint id, + GLenum severity, + GLsizei length, + const GLchar *message, + const void *userParam) +{ + ScreenPtr screen = (void *)userParam; + LogMessageVerb(X_ERROR, 0, "glamor%d: GL error: %*s\n", + screen->myNum, length, message); +} + +/** + * Configures GL_ARB_debug_output to give us immediate callbacks when + * GL errors occur, so that we can log them. + */ +static void +glamor_setup_debug_output(ScreenPtr screen) +{ + if (!epoxy_has_gl_extension("GL_ARB_debug_output")) + return; + + glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); + glDebugMessageControl(GL_DEBUG_SOURCE_API, + GL_DEBUG_TYPE_ERROR, + GL_DONT_CARE, + 0, NULL, GL_TRUE); + glDebugMessageCallback(glamor_debug_output_callback, + screen); + + /* If KHR_debug is present, all debug output is disabled by + * default on non-debug contexts. + */ + if (epoxy_has_gl_extension("GL_KHR_debug")) + glEnable(GL_DEBUG_OUTPUT); +} + /** Set up glamor for an already-configured GL context. */ Bool glamor_init(ScreenPtr screen, unsigned int flags) @@ -531,6 +570,8 @@ glamor_init(ScreenPtr screen, unsigned int flags) epoxy_gl_version() >= 30 || epoxy_has_gl_extension("GL_NV_pack_subimage"); + glamor_setup_debug_output(screen); + glamor_priv->use_quads = (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP); /* Driver-specific hack: Avoid using GL_QUADS on VC4, where * they'll be emulated more expensively than we can with our -- cgit v1.2.3