diff options
Diffstat (limited to 'source/blender/gpu')
-rw-r--r-- | source/blender/gpu/CMakeLists.txt | 2 | ||||
-rw-r--r-- | source/blender/gpu/GPU_debug.h | 3 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_debug.cc | 220 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_init_exit.c | 8 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_private.h | 4 | ||||
-rw-r--r-- | source/blender/gpu/opengl/gl_context.cc | 7 | ||||
-rw-r--r-- | source/blender/gpu/opengl/gl_debug.cc | 140 | ||||
-rw-r--r-- | source/blender/gpu/opengl/gl_debug.hh | 31 |
8 files changed, 180 insertions, 235 deletions
diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt index 549a7585e1b..cf0399b776d 100644 --- a/source/blender/gpu/CMakeLists.txt +++ b/source/blender/gpu/CMakeLists.txt @@ -90,6 +90,7 @@ set(SRC opengl/gl_batch.cc opengl/gl_context.cc opengl/gl_drawlist.cc + opengl/gl_debug.cc opengl/gl_framebuffer.cc opengl/gl_immediate.cc opengl/gl_shader.cc @@ -148,6 +149,7 @@ set(SRC opengl/gl_backend.hh opengl/gl_batch.hh opengl/gl_context.hh + opengl/gl_debug.hh opengl/gl_drawlist.hh opengl/gl_framebuffer.hh opengl/gl_immediate.hh diff --git a/source/blender/gpu/GPU_debug.h b/source/blender/gpu/GPU_debug.h index be822056678..09dc02c0fc6 100644 --- a/source/blender/gpu/GPU_debug.h +++ b/source/blender/gpu/GPU_debug.h @@ -30,9 +30,6 @@ extern "C" { /* prints something if debug mode is active only */ void GPU_print_error_debug(const char *str); -/* inserts a debug marker message for the debug context messaging system */ -void GPU_string_marker(const char *str); - #ifdef __cplusplus } #endif diff --git a/source/blender/gpu/intern/gpu_debug.cc b/source/blender/gpu/intern/gpu_debug.cc index f7d6236071d..f179a241926 100644 --- a/source/blender/gpu/intern/gpu_debug.cc +++ b/source/blender/gpu/intern/gpu_debug.cc @@ -36,226 +36,6 @@ #include <stdlib.h> #include <string.h> -#ifndef __APPLE__ /* only non-Apple systems implement OpenGL debug callbacks */ - -/* control whether we use older AMD_debug_output extension - * some supported GPU + OS combos do not have the newer extensions */ -# define LEGACY_DEBUG 1 - -/* Debug callbacks need the same calling convention as OpenGL functions. */ -# if defined(_WIN32) -# define APIENTRY __stdcall -# else -# define APIENTRY -# endif - -static const char *source_name(GLenum source) -{ - switch (source) { - case GL_DEBUG_SOURCE_API: - return "API"; - case GL_DEBUG_SOURCE_WINDOW_SYSTEM: - return "window system"; - case GL_DEBUG_SOURCE_SHADER_COMPILER: - return "shader compiler"; - case GL_DEBUG_SOURCE_THIRD_PARTY: - return "3rd party"; - case GL_DEBUG_SOURCE_APPLICATION: - return "application"; - case GL_DEBUG_SOURCE_OTHER: - return "other"; - default: - return "???"; - } -} - -static const char *message_type_name(GLenum message) -{ - switch (message) { - case GL_DEBUG_TYPE_ERROR: - return "error"; - case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR: - return "deprecated behavior"; - case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR: - return "undefined behavior"; - case GL_DEBUG_TYPE_PORTABILITY: - return "portability"; - case GL_DEBUG_TYPE_PERFORMANCE: - return "performance"; - case GL_DEBUG_TYPE_OTHER: - return "other"; - case GL_DEBUG_TYPE_MARKER: - return "marker"; /* KHR has this, ARB does not */ - default: - return "???"; - } -} - -static void APIENTRY gpu_debug_proc(GLenum source, - GLenum type, - GLuint UNUSED(id), - GLenum severity, - GLsizei UNUSED(length), - const GLchar *message, - const GLvoid *UNUSED(userParm)) -{ - bool backtrace = false; - - switch (severity) { - case GL_DEBUG_SEVERITY_HIGH: - backtrace = true; - ATTR_FALLTHROUGH; - case GL_DEBUG_SEVERITY_MEDIUM: - case GL_DEBUG_SEVERITY_LOW: - case GL_DEBUG_SEVERITY_NOTIFICATION: /* KHR has this, ARB does not */ - fprintf(stderr, "GL %s %s: %s\n", source_name(source), message_type_name(type), message); - } - - if (backtrace) { - BLI_system_backtrace(stderr); - fflush(stderr); - } -} - -# if LEGACY_DEBUG - -static const char *category_name_amd(GLenum category) -{ - switch (category) { - case GL_DEBUG_CATEGORY_API_ERROR_AMD: - return "API error"; - case GL_DEBUG_CATEGORY_WINDOW_SYSTEM_AMD: - return "window system"; - case GL_DEBUG_CATEGORY_DEPRECATION_AMD: - return "deprecated behavior"; - case GL_DEBUG_CATEGORY_UNDEFINED_BEHAVIOR_AMD: - return "undefined behavior"; - case GL_DEBUG_CATEGORY_PERFORMANCE_AMD: - return "performance"; - case GL_DEBUG_CATEGORY_SHADER_COMPILER_AMD: - return "shader compiler"; - case GL_DEBUG_CATEGORY_APPLICATION_AMD: - return "application"; - case GL_DEBUG_CATEGORY_OTHER_AMD: - return "other"; - default: - return "???"; - } -} - -static void APIENTRY gpu_debug_proc_amd(GLuint UNUSED(id), - GLenum category, - GLenum severity, - GLsizei UNUSED(length), - const GLchar *message, - GLvoid *UNUSED(userParm)) -{ - bool backtrace = false; - - switch (severity) { - case GL_DEBUG_SEVERITY_HIGH: - backtrace = true; - ATTR_FALLTHROUGH; - case GL_DEBUG_SEVERITY_MEDIUM: - case GL_DEBUG_SEVERITY_LOW: - fprintf(stderr, "GL %s: %s\n", category_name_amd(category), message); - } - - if (backtrace) { - BLI_system_backtrace(stderr); - fflush(stderr); - } -} -# endif /* LEGACY_DEBUG */ - -# undef APIENTRY -#endif /* not Apple */ - -void gpu_debug_init(void) -{ -#ifdef __APPLE__ - fprintf(stderr, "OpenGL debug callback is not available on Apple.\n"); -#else /* not Apple */ - const char success[] = "Successfully hooked OpenGL debug callback."; - - if (GLEW_VERSION_4_3 || GLEW_KHR_debug) { - fprintf(stderr, - "Using %s\n", - GLEW_VERSION_4_3 ? "OpenGL 4.3 debug facilities" : "KHR_debug extension"); - glEnable(GL_DEBUG_OUTPUT); - glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); - glDebugMessageCallback((GLDEBUGPROC)gpu_debug_proc, NULL); - glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, NULL, GL_TRUE); - GPU_string_marker(success); - } - else if (GLEW_ARB_debug_output) { - fprintf(stderr, "Using ARB_debug_output extension\n"); - glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); - glDebugMessageCallbackARB((GLDEBUGPROCARB)gpu_debug_proc, NULL); - glDebugMessageControlARB(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, NULL, GL_TRUE); - GPU_string_marker(success); - } -# if LEGACY_DEBUG - else if (GLEW_AMD_debug_output) { - fprintf(stderr, "Using AMD_debug_output extension\n"); - glDebugMessageCallbackAMD(gpu_debug_proc_amd, NULL); - glDebugMessageEnableAMD(GL_DONT_CARE, GL_DONT_CARE, 0, NULL, GL_TRUE); - GPU_string_marker(success); - } -# endif - else { - fprintf(stderr, "Failed to hook OpenGL debug callback.\n"); - } -#endif /* not Apple */ -} - -void gpu_debug_exit(void) -{ -#ifndef __APPLE__ - if (GLEW_VERSION_4_3 || GLEW_KHR_debug) { - glDebugMessageCallback(NULL, NULL); - } - else if (GLEW_ARB_debug_output) { - glDebugMessageCallbackARB(NULL, NULL); - } -# if LEGACY_DEBUG - else if (GLEW_AMD_debug_output) { - glDebugMessageCallbackAMD(NULL, NULL); - } -# endif -#endif -} - -void GPU_string_marker(const char *buf) -{ -#ifdef __APPLE__ - UNUSED_VARS(buf); -#else /* not Apple */ - if (GLEW_VERSION_4_3 || GLEW_KHR_debug) { - glDebugMessageInsert(GL_DEBUG_SOURCE_APPLICATION, - GL_DEBUG_TYPE_MARKER, - 0, - GL_DEBUG_SEVERITY_NOTIFICATION, - -1, - buf); - } - else if (GLEW_ARB_debug_output) { - glDebugMessageInsertARB(GL_DEBUG_SOURCE_APPLICATION_ARB, - GL_DEBUG_TYPE_OTHER_ARB, - 0, - GL_DEBUG_SEVERITY_LOW_ARB, - -1, - buf); - } -# if LEGACY_DEBUG - else if (GLEW_AMD_debug_output) { - glDebugMessageInsertAMD( - GL_DEBUG_CATEGORY_APPLICATION_AMD, GL_DEBUG_SEVERITY_LOW_AMD, 0, 0, buf); - } -# endif -#endif /* not Apple */ -} - void GPU_print_error_debug(const char *str) { if (G.debug & G_DEBUG) { diff --git a/source/blender/gpu/intern/gpu_init_exit.c b/source/blender/gpu/intern/gpu_init_exit.c index 9ae13771842..4cb43db9bce 100644 --- a/source/blender/gpu/intern/gpu_init_exit.c +++ b/source/blender/gpu/intern/gpu_init_exit.c @@ -54,10 +54,6 @@ void GPU_init(void) gpu_codegen_init(); gpu_material_library_init(); - if (G.debug & G_DEBUG_GPU) { - gpu_debug_init(); - } - gpu_batch_init(); if (!G.background) { @@ -81,10 +77,6 @@ void GPU_exit(void) gpu_batch_exit(); - if (G.debug & G_DEBUG_GPU) { - gpu_debug_exit(); - } - gpu_material_library_exit(); gpu_codegen_exit(); diff --git a/source/blender/gpu/intern/gpu_private.h b/source/blender/gpu/intern/gpu_private.h index 92663190b8f..505ac3b0278 100644 --- a/source/blender/gpu/intern/gpu_private.h +++ b/source/blender/gpu/intern/gpu_private.h @@ -32,10 +32,6 @@ void gpu_platform_exit(void); void gpu_extensions_init(void); void gpu_extensions_exit(void); -/* gpu_debug.c */ -void gpu_debug_init(void); -void gpu_debug_exit(void); - /* gpu_pbvh.c */ void gpu_pbvh_init(void); void gpu_pbvh_exit(void); diff --git a/source/blender/gpu/opengl/gl_context.cc b/source/blender/gpu/opengl/gl_context.cc index e89eeca1c8a..7d564004a01 100644 --- a/source/blender/gpu/opengl/gl_context.cc +++ b/source/blender/gpu/opengl/gl_context.cc @@ -25,12 +25,15 @@ #include "BLI_system.h" #include "BLI_utildefines.h" +#include "BKE_global.h" + #include "GPU_framebuffer.h" #include "GHOST_C-api.h" #include "gpu_context_private.hh" +#include "gl_debug.hh" #include "gl_immediate.hh" #include "gl_state.hh" @@ -47,6 +50,10 @@ using namespace blender::gpu; GLContext::GLContext(void *ghost_window, GLSharedOrphanLists &shared_orphan_list) : shared_orphan_list_(shared_orphan_list) { + if (G.debug & G_DEBUG_GPU) { + debug::init_gl_callbacks(); + } + float data[4] = {0.0f, 0.0f, 0.0f, 1.0f}; glGenBuffers(1, &default_attr_vbo_); glBindBuffer(GL_ARRAY_BUFFER, default_attr_vbo_); diff --git a/source/blender/gpu/opengl/gl_debug.cc b/source/blender/gpu/opengl/gl_debug.cc new file mode 100644 index 00000000000..1300cf4065e --- /dev/null +++ b/source/blender/gpu/opengl/gl_debug.cc @@ -0,0 +1,140 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2005 Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup gpu + * + * Debug features of OpenGL. + */ + +#include "BLI_compiler_attrs.h" +#include "BLI_string.h" +#include "BLI_system.h" +#include "BLI_utildefines.h" + +#include "glew-mx.h" + +#include "gl_debug.hh" + +#include <stdio.h> + +namespace blender::gpu::debug { + +/* -------------------------------------------------------------------- */ +/** \name Debug Callbacks + * + * Hooks up debug callbacks to a debug OpenGL context using extensions or 4.3 core debug + * capabiliities. + * \{ */ + +/* Debug callbacks need the same calling convention as OpenGL functions. */ +#if defined(_WIN32) +# define APIENTRY __stdcall +#else +# define APIENTRY +#endif + +#define VERBOSE 1 + +static void APIENTRY debug_callback(GLenum UNUSED(source), + GLenum type, + GLuint UNUSED(id), + GLenum severity, + GLsizei UNUSED(length), + const GLchar *message, + const GLvoid *UNUSED(userParm)) +{ + const char format[] = "GPUDebug: %s%s\e[0m\n"; + + if (ELEM(severity, GL_DEBUG_SEVERITY_LOW, GL_DEBUG_SEVERITY_NOTIFICATION)) { + if (VERBOSE) { + fprintf(stderr, format, "\e[2m", message); + } + } + else { + switch (type) { + case GL_DEBUG_TYPE_ERROR: + case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR: + case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR: + fprintf(stderr, format, "\e[31;1mError\e[39m: ", message); + break; + case GL_DEBUG_TYPE_PORTABILITY: + case GL_DEBUG_TYPE_PERFORMANCE: + case GL_DEBUG_TYPE_OTHER: + case GL_DEBUG_TYPE_MARKER: /* KHR has this, ARB does not */ + default: + fprintf(stderr, format, "\e[33;1mWarning\e[39m: ", message); + break; + } + + if (VERBOSE && severity == GL_DEBUG_SEVERITY_HIGH) { + /* Focus on error message. */ + fprintf(stderr, "\e[2m"); + BLI_system_backtrace(stderr); + fprintf(stderr, "\e[0m\n"); + fflush(stderr); + } + } +} + +#undef APIENTRY + +void init_gl_callbacks(void) +{ +#ifdef __APPLE__ + fprintf(stderr, "GPUDebug: OpenGL debug callback is not available on Apple\n"); + return; +#endif /* not Apple */ + + char msg[256] = ""; + const char format[] = "Successfully hooked OpenGL debug callback using %s"; + + if (GLEW_VERSION_4_3 || GLEW_KHR_debug) { + SNPRINTF(msg, format, GLEW_VERSION_4_3 ? "OpenGL 4.3" : "KHR_debug extension"); + glEnable(GL_DEBUG_OUTPUT); + glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); + glDebugMessageCallback((GLDEBUGPROC)debug_callback, NULL); + glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, NULL, GL_TRUE); + glDebugMessageInsert(GL_DEBUG_SOURCE_APPLICATION, + GL_DEBUG_TYPE_MARKER, + 0, + GL_DEBUG_SEVERITY_NOTIFICATION, + -1, + msg); + } + else if (GLEW_ARB_debug_output) { + SNPRINTF(msg, format, "ARB_debug_output"); + glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); + glDebugMessageCallbackARB((GLDEBUGPROCARB)debug_callback, NULL); + glDebugMessageControlARB(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, NULL, GL_TRUE); + glDebugMessageInsertARB(GL_DEBUG_SOURCE_APPLICATION_ARB, + GL_DEBUG_TYPE_OTHER_ARB, + 0, + GL_DEBUG_SEVERITY_LOW_ARB, + -1, + msg); + } + else { + fprintf(stderr, "GPUDebug: Failed to hook OpenGL debug callback\n"); + } +} + +/** \} */ + +} // namespace blender::gpu::debug
\ No newline at end of file diff --git a/source/blender/gpu/opengl/gl_debug.hh b/source/blender/gpu/opengl/gl_debug.hh new file mode 100644 index 00000000000..44cd98b72f3 --- /dev/null +++ b/source/blender/gpu/opengl/gl_debug.hh @@ -0,0 +1,31 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +/** \file + * \ingroup gpu + */ + +#pragma once + +namespace blender { +namespace gpu { +namespace debug { + +void init_gl_callbacks(void); + +} // namespace debug +} // namespace gpu +} // namespace blender |