[Bf-blender-cvs] [01d152419ff] tmp-gldebuglayer: Add more debug capabilities for non pointers function

Clément Foucault noreply at git.blender.org
Wed Sep 9 02:57:32 CEST 2020


Commit: 01d152419ff321675faa08c4059f9e7765f1d764
Author: Clément Foucault
Date:   Wed Sep 9 02:56:38 2020 +0200
Branches: tmp-gldebuglayer
https://developer.blender.org/rB01d152419ff321675faa08c4059f9e7765f1d764

Add more debug capabilities for non pointers function

We wrap them inside a function of the same name but not in
the same namespace.

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

M	source/blender/gpu/opengl/gl_debug.hh
M	source/blender/gpu/opengl/gl_debug_layer.cc

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

diff --git a/source/blender/gpu/opengl/gl_debug.hh b/source/blender/gpu/opengl/gl_debug.hh
index d792a0d95c2..c651d0981fb 100644
--- a/source/blender/gpu/opengl/gl_debug.hh
+++ b/source/blender/gpu/opengl/gl_debug.hh
@@ -20,10 +20,59 @@
 
 #pragma once
 
+#include "BKE_global.h"
+
 namespace blender {
 namespace gpu {
 namespace debug {
 
+/* Manual line breaks for readability. */
+/* clang-format off */
+#define _VA_ARG_LIST1(t) t
+#define _VA_ARG_LIST2(t, a) t a
+#define _VA_ARG_LIST4(t, a, b, c) \
+  _VA_ARG_LIST2(t, a), _VA_ARG_LIST2(b, c)
+#define _VA_ARG_LIST6(t, a, b, c, d, e) \
+  _VA_ARG_LIST2(t, a), _VA_ARG_LIST4(b, c, d, e)
+#define _VA_ARG_LIST8(t, a, b, c, d, e, f, g) \
+  _VA_ARG_LIST2(t, a), _VA_ARG_LIST6(b, c, d, e, f, g)
+#define _VA_ARG_LIST10(t, a, b, c, d, e, f, g, h, i) \
+  _VA_ARG_LIST2(t, a), _VA_ARG_LIST8(b, c, d, e, f, g, h, i)
+#define _VA_ARG_LIST12(t, a, b, c, d, e, f, g, h, i, j, k) \
+  _VA_ARG_LIST2(t, a), _VA_ARG_LIST10(b, c, d, e, f, g, h, i, j, k)
+#define _VA_ARG_LIST14(t, a, b, c, d, e, f, g, h, i, j, k, l, m) \
+  _VA_ARG_LIST2(t, a), _VA_ARG_LIST12(b, c, d, e, f, g, h, i, j, k, l, m)
+#define _VA_ARG_LIST16(t, a, b, c, d, e, f, g, h, i, j, k, l, m, o, p) \
+  _VA_ARG_LIST2(t, a), _VA_ARG_LIST14(b, c, d, e, f, g, h, i, j, k, l, m, o, p)
+#define _VA_ARG_LIST18(t, a, b, c, d, e, f, g, h, i, j, k, l, m, o, p, q, r) \
+  _VA_ARG_LIST2(t, a), _VA_ARG_LIST16(b, c, d, e, f, g, h, i, j, k, l, m, o, p, q, r)
+#define _VA_ARG_LIST20(t, a, b, c, d, e, f, g, h, i, j, k, l, m, o, p, q, r, s, u) \
+  _VA_ARG_LIST2(t, a), _VA_ARG_LIST18(b, c, d, e, f, g, h, i, j, k, l, m, o, p, q, r, s, u)
+#define ARG_LIST(...) VA_NARGS_CALL_OVERLOAD(_VA_ARG_LIST, __VA_ARGS__)
+
+#define _VA_ARG_LIST_CALL1(t)
+#define _VA_ARG_LIST_CALL2(t, a) a
+#define _VA_ARG_LIST_CALL4(t, a, b, c) \
+  _VA_ARG_LIST_CALL2(t, a), _VA_ARG_LIST_CALL2(b, c)
+#define _VA_ARG_LIST_CALL6(t, a, b, c, d, e) \
+  _VA_ARG_LIST_CALL2(t, a), _VA_ARG_LIST_CALL4(b, c, d, e)
+#define _VA_ARG_LIST_CALL8(t, a, b, c, d, e, f, g) \
+  _VA_ARG_LIST_CALL2(t, a), _VA_ARG_LIST_CALL6(b, c, d, e, f, g)
+#define _VA_ARG_LIST_CALL10(t, a, b, c, d, e, f, g, h, i) \
+  _VA_ARG_LIST_CALL2(t, a), _VA_ARG_LIST_CALL8(b, c, d, e, f, g, h, i)
+#define _VA_ARG_LIST_CALL12(t, a, b, c, d, e, f, g, h, i, j, k) \
+  _VA_ARG_LIST_CALL2(t, a), _VA_ARG_LIST_CALL10(b, c, d, e, f, g, h, i, j, k)
+#define _VA_ARG_LIST_CALL14(t, a, b, c, d, e, f, g, h, i, j, k, l, m) \
+  _VA_ARG_LIST_CALL2(t, a), _VA_ARG_LIST_CALL12(b, c, d, e, f, g, h, i, j, k, l, m)
+#define _VA_ARG_LIST_CALL16(t, a, b, c, d, e, f, g, h, i, j, k, l, m, o, p) \
+  _VA_ARG_LIST_CALL2(t, a), _VA_ARG_LIST_CALL14(b, c, d, e, f, g, h, i, j, k, l, m, o, p)
+#define _VA_ARG_LIST_CALL18(t, a, b, c, d, e, f, g, h, i, j, k, l, m, o, p, q, r) \
+  _VA_ARG_LIST_CALL2(t, a), _VA_ARG_LIST_CALL16(b, c, d, e, f, g, h, i, j, k, l, m, o, p, q, r)
+#define _VA_ARG_LIST_CALL20(t, a, b, c, d, e, f, g, h, i, j, k, l, m, o, p, q, r, s, u) \
+  _VA_ARG_LIST_CALL2(t, a), _VA_ARG_LIST_CALL18(b, c, d, e, f, g, h, i, j, k, l, m, o, p, q, r, s, u)
+#define ARG_LIST_CALL(...) VA_NARGS_CALL_OVERLOAD(_VA_ARG_LIST_CALL, __VA_ARGS__)
+/* clang-format on */
+
 /* Enabled on MacOS by default since there is no support for debug callbacks. */
 #if defined(DEBUG) && defined(__APPLE__)
 #  define GL_CHECK_ERROR(info) debug::check_gl_error(info)
@@ -45,5 +94,31 @@ void init_gl_callbacks(void);
 void init_debug_layer(void);
 
 }  // namespace debug
+
+#define DEBUG_FUNC_OVERRIDE(func, ...) \
+  inline void func(ARG_LIST(__VA_ARGS__)) \
+  { \
+    if (G.debug & G_DEBUG_GPU) { \
+      debug::check_gl_error("generated before " #func); \
+      ::func(ARG_LIST_CALL(__VA_ARGS__)); \
+      debug::check_gl_error("" #func); \
+    } \
+    else { \
+      ::func(ARG_LIST_CALL(__VA_ARGS__)); \
+    } \
+  }
+
+/* Avoid very long declarations. */
+/* clang-format off */
+DEBUG_FUNC_OVERRIDE(glClear, GLbitfield, mask);
+DEBUG_FUNC_OVERRIDE(glDeleteTextures, GLsizei, n, const GLuint *, textures);
+DEBUG_FUNC_OVERRIDE(glDrawArrays, GLenum, mode, GLint, first, GLsizei, count);
+DEBUG_FUNC_OVERRIDE(glFinish, void);
+DEBUG_FUNC_OVERRIDE(glFlush, void);
+DEBUG_FUNC_OVERRIDE(glGetTexImage, GLenum, target, GLint, level, GLenum, format, GLenum, type, void *, pixels);
+DEBUG_FUNC_OVERRIDE(glReadBuffer, GLenum, mode);
+DEBUG_FUNC_OVERRIDE(glReadPixels, GLint, x, GLint, y, GLsizei, width, GLsizei, height, GLenum, format, GLenum, type, void *, pixels);
+/* clang-format on */
+
 }  // namespace gpu
 }  // namespace blender
diff --git a/source/blender/gpu/opengl/gl_debug_layer.cc b/source/blender/gpu/opengl/gl_debug_layer.cc
index 0b32b3f3bf9..9bb47dbf1e2 100644
--- a/source/blender/gpu/opengl/gl_debug_layer.cc
+++ b/source/blender/gpu/opengl/gl_debug_layer.cc
@@ -30,55 +30,6 @@
 
 #include "gl_debug.hh"
 
-namespace blender::gpu::debug {
-
-/* Manual line breaks for readability. */
-/* clang-format off */
-#define _VA_ARG_LIST1(t) t
-#define _VA_ARG_LIST2(t, a) t a
-#define _VA_ARG_LIST4(t, a, b, c) \
-  _VA_ARG_LIST2(t, a), _VA_ARG_LIST2(b, c)
-#define _VA_ARG_LIST6(t, a, b, c, d, e) \
-  _VA_ARG_LIST2(t, a), _VA_ARG_LIST4(b, c, d, e)
-#define _VA_ARG_LIST8(t, a, b, c, d, e, f, g) \
-  _VA_ARG_LIST2(t, a), _VA_ARG_LIST6(b, c, d, e, f, g)
-#define _VA_ARG_LIST10(t, a, b, c, d, e, f, g, h, i) \
-  _VA_ARG_LIST2(t, a), _VA_ARG_LIST8(b, c, d, e, f, g, h, i)
-#define _VA_ARG_LIST12(t, a, b, c, d, e, f, g, h, i, j, k) \
-  _VA_ARG_LIST2(t, a), _VA_ARG_LIST10(b, c, d, e, f, g, h, i, j, k)
-#define _VA_ARG_LIST14(t, a, b, c, d, e, f, g, h, i, j, k, l, m) \
-  _VA_ARG_LIST2(t, a), _VA_ARG_LIST12(b, c, d, e, f, g, h, i, j, k, l, m)
-#define _VA_ARG_LIST16(t, a, b, c, d, e, f, g, h, i, j, k, l, m, o, p) \
-  _VA_ARG_LIST2(t, a), _VA_ARG_LIST14(b, c, d, e, f, g, h, i, j, k, l, m, o, p)
-#define _VA_ARG_LIST18(t, a, b, c, d, e, f, g, h, i, j, k, l, m, o, p, q, r) \
-  _VA_ARG_LIST2(t, a), _VA_ARG_LIST16(b, c, d, e, f, g, h, i, j, k, l, m, o, p, q, r)
-#define _VA_ARG_LIST20(t, a, b, c, d, e, f, g, h, i, j, k, l, m, o, p, q, r, s, u) \
-  _VA_ARG_LIST2(t, a), _VA_ARG_LIST18(b, c, d, e, f, g, h, i, j, k, l, m, o, p, q, r, s, u)
-#define ARG_LIST(...) VA_NARGS_CALL_OVERLOAD(_VA_ARG_LIST, __VA_ARGS__)
-
-#define _VA_ARG_LIST_CALL1(t)
-#define _VA_ARG_LIST_CALL2(t, a) a
-#define _VA_ARG_LIST_CALL4(t, a, b, c) \
-  _VA_ARG_LIST_CALL2(t, a), _VA_ARG_LIST_CALL2(b, c)
-#define _VA_ARG_LIST_CALL6(t, a, b, c, d, e) \
-  _VA_ARG_LIST_CALL2(t, a), _VA_ARG_LIST_CALL4(b, c, d, e)
-#define _VA_ARG_LIST_CALL8(t, a, b, c, d, e, f, g) \
-  _VA_ARG_LIST_CALL2(t, a), _VA_ARG_LIST_CALL6(b, c, d, e, f, g)
-#define _VA_ARG_LIST_CALL10(t, a, b, c, d, e, f, g, h, i) \
-  _VA_ARG_LIST_CALL2(t, a), _VA_ARG_LIST_CALL8(b, c, d, e, f, g, h, i)
-#define _VA_ARG_LIST_CALL12(t, a, b, c, d, e, f, g, h, i, j, k) \
-  _VA_ARG_LIST_CALL2(t, a), _VA_ARG_LIST_CALL10(b, c, d, e, f, g, h, i, j, k)
-#define _VA_ARG_LIST_CALL14(t, a, b, c, d, e, f, g, h, i, j, k, l, m) \
-  _VA_ARG_LIST_CALL2(t, a), _VA_ARG_LIST_CALL12(b, c, d, e, f, g, h, i, j, k, l, m)
-#define _VA_ARG_LIST_CALL16(t, a, b, c, d, e, f, g, h, i, j, k, l, m, o, p) \
-  _VA_ARG_LIST_CALL2(t, a), _VA_ARG_LIST_CALL14(b, c, d, e, f, g, h, i, j, k, l, m, o, p)
-#define _VA_ARG_LIST_CALL18(t, a, b, c, d, e, f, g, h, i, j, k, l, m, o, p, q, r) \
-  _VA_ARG_LIST_CALL2(t, a), _VA_ARG_LIST_CALL16(b, c, d, e, f, g, h, i, j, k, l, m, o, p, q, r)
-#define _VA_ARG_LIST_CALL20(t, a, b, c, d, e, f, g, h, i, j, k, l, m, o, p, q, r, s, u) \
-  _VA_ARG_LIST_CALL2(t, a), _VA_ARG_LIST_CALL18(b, c, d, e, f, g, h, i, j, k, l, m, o, p, q, r, s, u)
-#define ARG_LIST_CALL(...) VA_NARGS_CALL_OVERLOAD(_VA_ARG_LIST_CALL, __VA_ARGS__)
-/* clang-format on */
-
 typedef void *GPUvoidptr;
 
 #define GPUvoidptr_set void *ret =
@@ -94,9 +45,9 @@ typedef void *GPUvoidptr;
   pfn real_##fn; \
   static rtn_type GLAPIENTRY debug_##fn(ARG_LIST(__VA_ARGS__)) \
   { \
-    check_gl_error("generated before " #fn); \
+    debug::check_gl_error("generated before " #fn); \
     rtn_type##_set real_##fn(ARG_LIST_CALL(__VA_ARGS__)); \
-    check_gl_error("" #fn); \
+    debug::check_gl_error("" #fn); \
     rtn_type##_ret; \
   }
 
@@ -107,6 +58,8 @@ typedef void *GPUvoidptr;
     UNUSED_VARS(ARG_LIST_CALL(__VA_ARGS__)); \
   }
 
+namespace blender::gpu::debug {
+
 /* List of wrapped functions. We dont have to support all of them.
  * Some functions might be declared as extern in GLEW. We cannot override them in this case.
  * Keep the list in alphabetical order. */



More information about the Bf-blender-cvs mailing list