[Bf-blender-cvs] [fed61d5] master: Debug GPU functionality from soc-viewport_fx by Jason Wilkins

Antony Riakiotakis noreply at git.blender.org
Mon Feb 23 13:49:31 CET 2015


Commit: fed61d50c77130bc59849b067d9f7a502908003f
Author: Antony Riakiotakis
Date:   Mon Feb 16 21:19:12 2015 +0100
Branches: master
https://developer.blender.org/rBfed61d50c77130bc59849b067d9f7a502908003f

Debug GPU functionality from soc-viewport_fx by Jason Wilkins

patch number D706 with changes:

- WITH_GPU_DEBUG just creates a debug context (and enables the debug messaging
system functions) but leaves the checks we had intact. Old patch
added the debug functionality only if we had the flag on to save some
performance.

Rationale here is that we might not want to recompile blender just to get
the extra information, and having users start blender with a -d flag to
get the extra information is also useful for bug reports. Those checks already
existed and most expensive ones are hidden behind a debug mode check
so performance should not be that bad.

- Did some cleanup of existing functionality:
When things go wrong blender side, just print the error,
don't check for GL errors first.

- Did not port changes needed for GLES to regular glew.h

- Got rid of duplicate or very similar new functionality.

Generally, code is more moving things around/cleanup and should work exactly
as before apart from the debug context, so it's safe to add even now.

It also provides a nice substitute function for glu error descriptions

===================================================================

M	CMakeLists.txt
M	intern/ghost/intern/GHOST_ContextGLX.h
M	intern/ghost/intern/GHOST_ContextSDL.h
M	intern/ghost/intern/GHOST_ContextWGL.h
M	source/blender/gpu/CMakeLists.txt
A	source/blender/gpu/GPU_debug.h
M	source/blender/gpu/GPU_draw.h
M	source/blender/gpu/GPU_extensions.h
M	source/blender/gpu/intern/gpu_codegen.c
A	source/blender/gpu/intern/gpu_debug.c
M	source/blender/gpu/intern/gpu_draw.c
M	source/blender/gpu/intern/gpu_extensions.c
D	source/blender/gpu/intern/gpu_extensions_private.h
M	source/blender/gpu/intern/gpu_init_exit.c
A	source/blender/gpu/intern/gpu_private.h
M	source/blender/windowmanager/intern/wm_event_system.c

===================================================================

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 93e34f4..cdef12c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -403,6 +403,7 @@ option(WITH_GL_EGL              "Use the EGL OpenGL system library instead of th
 option(WITH_GL_PROFILE_COMPAT   "Support using the OpenGL 'compatibility' profile. (deprecated)"                                                    ON )
 option(WITH_GL_PROFILE_CORE     "Support using the OpenGL 3.2+ 'core' profile."                                                                     OFF)
 option(WITH_GL_PROFILE_ES20     "Support using OpenGL ES 2.0. (thru either EGL or the AGL/WGL/XGL 'es20' profile)"                                  OFF)
+option(WITH_GPU_DEBUG           "Create a debug OpenGL context (allows inserting custom messages and getting notifications for bad GL use)"         OFF)
 
 mark_as_advanced(
 	WITH_GLEW_MX
@@ -411,6 +412,7 @@ mark_as_advanced(
 	WITH_GL_PROFILE_COMPAT
 	WITH_GL_PROFILE_CORE
 	WITH_GL_PROFILE_ES20
+	WITH_GPU_DEBUG
 )
 
 if(WITH_GL_PROFILE_COMPAT)
@@ -2350,6 +2352,10 @@ if(WITH_GL_EGL)
 	list(APPEND GL_DEFINITIONS -DWITH_EGL)
 endif()
 
+if(WITH_GPU_DEBUG)
+	list(APPEND GL_DEFINITIONS -DWITH_GPU_DEBUG)
+endif()
+
 #-----------------------------------------------------------------------------
 # Configure OpenMP.
 if(WITH_OPENMP)
@@ -2832,6 +2838,7 @@ if(FIRST_RUN)
 	info_cfg_option(WITH_GL_PROFILE_COMPAT)
 	info_cfg_option(WITH_GL_PROFILE_CORE)
 	info_cfg_option(WITH_GL_PROFILE_ES20)
+	info_cfg_option(WITH_GPU_DEBUG)
 	if(WIN32)
 		info_cfg_option(WITH_GL_ANGLE)
 	endif()
diff --git a/intern/ghost/intern/GHOST_ContextGLX.h b/intern/ghost/intern/GHOST_ContextGLX.h
index e2169ac..b33c0b5 100644
--- a/intern/ghost/intern/GHOST_ContextGLX.h
+++ b/intern/ghost/intern/GHOST_ContextGLX.h
@@ -46,7 +46,11 @@ extern "C" GLXEWContext *glxewContext;
 
 
 #ifndef GHOST_OPENGL_GLX_CONTEXT_FLAGS
-#define GHOST_OPENGL_GLX_CONTEXT_FLAGS 0
+#  ifdef WITH_GPU_DEBUG
+#    define GHOST_OPENGL_GLX_CONTEXT_FLAGS GLX_CONTEXT_DEBUG_BIT_ARB
+#  else
+#    define GHOST_OPENGL_GLX_CONTEXT_FLAGS 0
+#  endif
 #endif
 
 #ifndef GHOST_OPENGL_GLX_RESET_NOTIFICATION_STRATEGY
diff --git a/intern/ghost/intern/GHOST_ContextSDL.h b/intern/ghost/intern/GHOST_ContextSDL.h
index c151d8e..61f339c 100644
--- a/intern/ghost/intern/GHOST_ContextSDL.h
+++ b/intern/ghost/intern/GHOST_ContextSDL.h
@@ -40,7 +40,11 @@ extern "C" {
 
 
 #ifndef GHOST_OPENGL_SDL_CONTEXT_FLAGS
-#define GHOST_OPENGL_SDL_CONTEXT_FLAGS 0
+#  ifdef WITH_GPU_DEBUG
+#    define GHOST_OPENGL_SDL_CONTEXT_FLAGS SDL_GL_CONTEXT_DEBUG_FLAG
+#  else
+#    define GHOST_OPENGL_SDL_CONTEXT_FLAGS 0
+# endif
 #endif
 
 #ifndef GHOST_OPENGL_SDL_RESET_NOTIFICATION_STRATEGY
diff --git a/intern/ghost/intern/GHOST_ContextWGL.h b/intern/ghost/intern/GHOST_ContextWGL.h
index 189121d..98a8059 100644
--- a/intern/ghost/intern/GHOST_ContextWGL.h
+++ b/intern/ghost/intern/GHOST_ContextWGL.h
@@ -45,7 +45,11 @@ extern "C" WGLEWContext *wglewContext;
 #endif
 
 #ifndef GHOST_OPENGL_WGL_CONTEXT_FLAGS
-#define GHOST_OPENGL_WGL_CONTEXT_FLAGS 0
+#  ifdef WITH_GPU_DEBUG
+#    define GHOST_OPENGL_WGL_CONTEXT_FLAGS WGL_CONTEXT_DEBUG_BIT_ARB
+#  else
+#    define GHOST_OPENGL_WGL_CONTEXT_FLAGS 0
+#  endif
 #endif
 
 #ifndef GHOST_OPENGL_WGL_RESET_NOTIFICATION_STRATEGY
diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt
index 12b7f86..b5d9028 100644
--- a/source/blender/gpu/CMakeLists.txt
+++ b/source/blender/gpu/CMakeLists.txt
@@ -55,6 +55,7 @@ set(SRC
 	intern/gpu_simple_shader.c
 	intern/gpu_select.c
 	intern/gpu_compositing.c
+	intern/gpu_debug.c
 
 	shaders/gpu_shader_fx_lib.glsl
 	shaders/gpu_shader_fx_ssao_frag.glsl
@@ -73,6 +74,7 @@ set(SRC
 
 	GPU_buffers.h
 	GPU_draw.h
+	GPU_debug.h
 	GPU_extensions.h
 	GPU_glew.h
 	GPU_init_exit.h
@@ -81,7 +83,7 @@ set(SRC
 	GPU_select.h
 	GPU_compositing.h
 	intern/gpu_codegen.h
-	intern/gpu_extensions_private.h
+	intern/gpu_private.h
 )
 
 data_to_c_simple(shaders/gpu_shader_material.glsl SRC)
diff --git a/source/blender/gpu/GPU_debug.h b/source/blender/gpu/GPU_debug.h
new file mode 100644
index 0000000..02c5df0
--- /dev/null
+++ b/source/blender/gpu/GPU_debug.h
@@ -0,0 +1,78 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * 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.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Jason Wilkins.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file source/blender/gpu/GPU_debug.h
+ *  \ingroup gpu
+ */
+
+#ifndef __GPU_DEBUG_H__
+#define __GPU_DEBUG_H__
+
+#include "GPU_glew.h"
+
+#include "BLI_utildefines.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* prints something if debug mode is active only */
+void GPU_print_error_debug(const char *str);
+
+/* replacement for gluErrorString */
+const char *gpuErrorString(GLenum err);
+
+/* prints current OpenGL state */
+void GPU_state_print(void);
+
+void gpu_assert_no_gl_errors(const char *file, int line, const char *str);
+
+#  define GPU_ASSERT_NO_GL_ERRORS(str) gpu_assert_no_gl_errors(__FILE__, __LINE__, (str))
+
+#  define GPU_CHECK_ERRORS_AROUND(glProcCall)                      \
+       (                                             \
+       GPU_ASSERT_NO_GL_ERRORS("Pre: "  #glProcCall), \
+       (glProcCall),                                 \
+       GPU_ASSERT_NO_GL_ERRORS("Post: " #glProcCall)  \
+       )
+
+
+#ifdef WITH_GPU_DEBUG
+/* inserts a debug marker message for the debug context messaging system */
+void gpu_string_marker     (size_t size, const char *str);
+
+#  define GPU_STRING_MARKER(size, str) gpu_string_marker((size), (str))
+#else /* WITH_GPU_DEBUG */
+#  define GPU_STRING_MARKER(len, str)  ((void)(size),(void)(str))
+#endif /* WITH_GPU_DEBUG */
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* __GPU_DEBUG_H__ */
\ No newline at end of file
diff --git a/source/blender/gpu/GPU_draw.h b/source/blender/gpu/GPU_draw.h
index 3ddec15..4329127 100644
--- a/source/blender/gpu/GPU_draw.h
+++ b/source/blender/gpu/GPU_draw.h
@@ -57,10 +57,6 @@ struct SmokeModifierData;
 
 void GPU_state_init(void);
 
-/* Debugging */
-
-void GPU_state_print(void);
-
 /* Material drawing
  * - first the state is initialized by a particular object and
  *   it's materials
diff --git a/source/blender/gpu/GPU_extensions.h b/source/blender/gpu/GPU_extensions.h
index 739d456..186db85 100644
--- a/source/blender/gpu/GPU_extensions.h
+++ b/source/blender/gpu/GPU_extensions.h
@@ -55,7 +55,6 @@ typedef struct GPUShader GPUShader;
 /* GPU extensions support */
 
 void GPU_extensions_disable(void);
-int GPU_print_error(const char *str);
 
 int GPU_glsl_support(void);
 int GPU_non_power_of_two_support(void);
diff --git a/source/blender/gpu/intern/gpu_codegen.c b/source/blender/gpu/intern/gpu_codegen.c
index 9e4d0d5..47d2ac2 100644
--- a/source/blender/gpu/intern/gpu_codegen.c
+++ b/source/blender/gpu/intern/gpu_codegen.c
@@ -31,8 +31,6 @@
  * Convert material node-trees to GLSL.
  */
 
-#include "GPU_glew.h"
-
 #include "MEM_guardedalloc.h"
 
 #include "DNA_customdata_types.h"
@@ -44,6 +42,7 @@
 #include "BLI_dynstr.h"
 #include "BLI_ghash.h"
 
+#include "GPU_glew.h"
 #include "GPU_material.h"
 #include "GPU_extensions.h"
 
diff --git a/source/blender/gpu/intern/gpu_debug.c b/source/blender/gpu/intern/gpu_debug.c
new file mode 100644
index 0000000..fb77274
--- /dev/null
+++ b/source/blender/gpu/intern/gpu_debug.c
@@ -0,0 +1,748 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * 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.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Brecht Van Lommel, Jason Wilkins.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file source/blender/gpu/GPU_debug.h
+ *  \ingroup gpu
+ */
+
+#include "BLI_sys_types.h"
+
+#include "BKE_global.h"
+
+#include "GPU_glew.h"
+#include "GPU_debug.h"
+#include "intern/gpu_private.h"
+
+#include <stdio.h>
+#include <string.h>
+
+#define CASE_CODE_RETURN_STR(code) case code: return #code;
+
+static const char* gpu_gl_error_symbol(GLenum err)
+{
+	switch(err) {
+		CASE_CODE_RETURN_STR(GL_NO_ERROR)
+		CASE_CODE_RETURN_STR(GL_INVALID_ENUM)
+		CASE_CODE_RETURN_STR(GL_INVALID_VALUE)
+		CASE_CODE_RETURN_STR(GL_INVALID_OPERATION)
+		CASE_CODE_RETURN_STR(GL_STACK_OVERFLOW)
+		CASE_CODE_RETURN_STR(GL_STACK_UNDERFLOW)
+		CASE_CODE_RETURN_STR(GL_OUT_OF_MEMORY)
+
+#if GL_ARB_imaging
+		CASE_CODE_RETURN_STR(GL_TABLE_TOO_LARGE)
+#endif
+
+#if defined(WITH_GLU)
+		CASE_CODE_RETURN_STR(GLU_INVALID_ENUM)
+		CASE_CODE_RETURN_STR(GLU_INVALID_VALUE)
+		CASE_CODE_RETURN_STR(GLU_OUT_OF_MEMORY)
+#endif
+
+		default:
+			return "<unknown error>";
+	}
+}
+
+#undef CASE_CODE_RETURN_STR
+
+
+static bool gpu_report_gl_error

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list