Blender  V3.3
gl_debug_layer.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2005 Blender Foundation. All rights reserved. */
3 
11 #include "BLI_utildefines.h"
12 
13 #include "gl_debug.hh"
14 
15 using GPUvoidptr = void *;
16 
17 #define GPUvoidptr_set void *ret =
18 #define GPUvoidptr_ret return ret
19 
20 #define GLboolean_set GLboolean ret =
21 #define GLboolean_ret return ret
22 
23 #define void_set
24 #define void_ret
25 
26 #define DEBUG_FUNC_DECLARE(pfn, rtn_type, fn, ...) \
27  static pfn real_##fn; \
28  static rtn_type GLAPIENTRY debug_##fn(ARG_LIST(__VA_ARGS__)) \
29  { \
30  debug::check_gl_error("generated before " #fn); \
31  rtn_type##_set real_##fn(ARG_LIST_CALL(__VA_ARGS__)); \
32  debug::check_gl_error("" #fn); \
33  rtn_type##_ret; \
34  }
35 
36 namespace blender::gpu::debug {
37 
38 /* List of wrapped functions. We don't have to support all of them.
39  * Some functions might be declared as `extern` in GLEW. We cannot override them in this case.
40  * Keep the list in alphabetical order. */
41 
42 /* Avoid very long declarations. */
43 /* clang-format off */
44 DEBUG_FUNC_DECLARE(PFNGLBEGINQUERYPROC, void, glBeginQuery, GLenum, target, GLuint, id);
45 DEBUG_FUNC_DECLARE(PFNGLBEGINTRANSFORMFEEDBACKPROC, void, glBeginTransformFeedback, GLenum, primitiveMode);
46 DEBUG_FUNC_DECLARE(PFNGLBINDBUFFERBASEPROC, void, glBindBufferBase, GLenum, target, GLuint, index, GLuint, buffer);
47 DEBUG_FUNC_DECLARE(PFNGLBINDBUFFERPROC, void, glBindBuffer, GLenum, target, GLuint, buffer);
48 DEBUG_FUNC_DECLARE(PFNGLBINDFRAMEBUFFERPROC, void, glBindFramebuffer, GLenum, target, GLuint, framebuffer);
49 DEBUG_FUNC_DECLARE(PFNGLBINDSAMPLERPROC, void, glBindSampler, GLuint, unit, GLuint, sampler);
50 DEBUG_FUNC_DECLARE(PFNGLBINDVERTEXARRAYPROC, void, glBindVertexArray, GLuint, array);
51 DEBUG_FUNC_DECLARE(PFNGLBLITFRAMEBUFFERPROC, void, glBlitFramebuffer, GLint, srcX0, GLint, srcY0, GLint, srcX1, GLint, srcY1, GLint, dstX0, GLint, dstY0, GLint, dstX1, GLint, dstY1, GLbitfield, mask, GLenum, filter);
52 DEBUG_FUNC_DECLARE(PFNGLBUFFERDATAPROC, void, glBufferData, GLenum, target, GLsizeiptr, size, const void *, data, GLenum, usage);
53 DEBUG_FUNC_DECLARE(PFNGLBUFFERSUBDATAPROC, void, glBufferSubData, GLenum, target, GLintptr, offset, GLsizeiptr, size, const void *, data);
54 DEBUG_FUNC_DECLARE(PFNGLDELETEBUFFERSPROC, void, glDeleteBuffers, GLsizei, n, const GLuint *, buffers);
55 DEBUG_FUNC_DECLARE(PFNGLDELETEFRAMEBUFFERSPROC, void, glDeleteFramebuffers, GLsizei, n, const GLuint*, framebuffers);
56 DEBUG_FUNC_DECLARE(PFNGLDELETEPROGRAMPROC, void, glDeleteProgram, GLuint, program);
57 DEBUG_FUNC_DECLARE(PFNGLDELETEQUERIESPROC, void, glDeleteQueries, GLsizei, n, const GLuint *, ids);
58 DEBUG_FUNC_DECLARE(PFNGLDELETESAMPLERSPROC, void, glDeleteSamplers, GLsizei, count, const GLuint *, samplers);
59 DEBUG_FUNC_DECLARE(PFNGLDELETESHADERPROC, void, glDeleteShader, GLuint, shader);
60 DEBUG_FUNC_DECLARE(PFNGLDELETEVERTEXARRAYSPROC, void, glDeleteVertexArrays, GLsizei, n, const GLuint *, arrays);
61 DEBUG_FUNC_DECLARE(PFNGLDRAWARRAYSINSTANCEDBASEINSTANCEPROC, void, glDrawArraysInstancedBaseInstance, GLenum, mode, GLint, first, GLsizei, count, GLsizei, primcount, GLuint, baseinstance);
62 DEBUG_FUNC_DECLARE(PFNGLDRAWARRAYSINSTANCEDPROC, void, glDrawArraysInstanced, GLenum, mode, GLint, first, GLsizei, count, GLsizei, primcount);
63 DEBUG_FUNC_DECLARE(PFNGLDRAWBUFFERSPROC, void, glDrawBuffers, GLsizei, n, const GLenum*, bufs);
64 DEBUG_FUNC_DECLARE(PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXBASEINSTANCEPROC, void, glDrawElementsInstancedBaseVertexBaseInstance, GLenum, mode, GLsizei, count, GLenum, type, const void *, indices, GLsizei, primcount, GLint, basevertex, GLuint, baseinstance);
65 DEBUG_FUNC_DECLARE(PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXPROC, void, glDrawElementsInstancedBaseVertex, GLenum, mode, GLsizei, count, GLenum, type, const void *, indices, GLsizei, instancecount, GLint, basevertex);
66 DEBUG_FUNC_DECLARE(PFNGLENDQUERYPROC, void, glEndQuery, GLenum, target);
67 DEBUG_FUNC_DECLARE(PFNGLDISPATCHCOMPUTEPROC, void, glDispatchCompute, GLuint, num_groups_x, GLuint, num_groups_y, GLuint, num_groups_z);
68 DEBUG_FUNC_DECLARE(PFNGLDISPATCHCOMPUTEINDIRECTPROC, void, glDispatchComputeIndirect, GLintptr, indirect);
69 DEBUG_FUNC_DECLARE(PFNGLENDTRANSFORMFEEDBACKPROC, void, glEndTransformFeedback, void);
70 DEBUG_FUNC_DECLARE(PFNGLFRAMEBUFFERTEXTURE2DPROC, void, glFramebufferTexture2D, GLenum, target, GLenum, attachment, GLenum, textarget, GLuint, texture, GLint, level);
71 DEBUG_FUNC_DECLARE(PFNGLFRAMEBUFFERTEXTURELAYERPROC, void, glFramebufferTextureLayer, GLenum, target, GLenum, attachment, GLuint, texture, GLint, level, GLint, layer);
72 DEBUG_FUNC_DECLARE(PFNGLFRAMEBUFFERTEXTUREPROC, void, glFramebufferTexture, GLenum, target, GLenum, attachment, GLuint, texture, GLint, level);
73 DEBUG_FUNC_DECLARE(PFNGLGENBUFFERSPROC, void, glGenBuffers, GLsizei, n, GLuint *, buffers);
74 DEBUG_FUNC_DECLARE(PFNGLGENERATEMIPMAPPROC, void, glGenerateMipmap, GLenum, target);
75 DEBUG_FUNC_DECLARE(PFNGLGENERATETEXTUREMIPMAPPROC, void, glGenerateTextureMipmap, GLuint, texture);
76 DEBUG_FUNC_DECLARE(PFNGLGENFRAMEBUFFERSPROC, void, glGenFramebuffers, GLsizei, n, GLuint *, framebuffers);
77 DEBUG_FUNC_DECLARE(PFNGLGENQUERIESPROC, void, glGenQueries, GLsizei, n, GLuint *, ids);
78 DEBUG_FUNC_DECLARE(PFNGLGENSAMPLERSPROC, void, glGenSamplers, GLsizei, n, GLuint *, samplers);
79 DEBUG_FUNC_DECLARE(PFNGLGENVERTEXARRAYSPROC, void, glGenVertexArrays, GLsizei, n, GLuint *, arrays);
80 DEBUG_FUNC_DECLARE(PFNGLLINKPROGRAMPROC, void, glLinkProgram, GLuint, program);
81 DEBUG_FUNC_DECLARE(PFNGLMAPBUFFERRANGEPROC, GPUvoidptr, glMapBufferRange, GLenum, target, GLintptr, offset, GLsizeiptr, length, GLbitfield, access);
82 DEBUG_FUNC_DECLARE(PFNGLTEXBUFFERPROC, void, glTexBuffer, GLenum, target, GLenum, internalFormat, GLuint, buffer);
83 DEBUG_FUNC_DECLARE(PFNGLTEXIMAGE3DPROC, void, glTexImage3D, GLenum, target, GLint, level, GLint, internalFormat, GLsizei, width, GLsizei, height, GLsizei, depth, GLint, border, GLenum, format, GLenum, type, const GLvoid *,pixels);
84 DEBUG_FUNC_DECLARE(PFNGLTEXSUBIMAGE3DPROC, void, glTexSubImage3D, GLenum, target, GLint, level, GLint, xoffset, GLint, yoffset, GLint, zoffset, GLsizei, width, GLsizei, height, GLsizei, depth, GLenum, format, GLenum, type, const GLvoid *, pixels);
85 DEBUG_FUNC_DECLARE(PFNGLTEXTUREBUFFERPROC, void, glTextureBuffer, GLuint, texture, GLenum, internalformat, GLuint, buffer);
86 DEBUG_FUNC_DECLARE(PFNGLUNMAPBUFFERPROC, GLboolean, glUnmapBuffer, GLenum, target);
87 DEBUG_FUNC_DECLARE(PFNGLUSEPROGRAMPROC, void, glUseProgram, GLuint, program);
88 /* clang-format on */
89 
90 #undef DEBUG_FUNC_DECLARE
91 
93 {
94 #define DEBUG_WRAP(function) \
95  do { \
96  real_##function = ::function; \
97  ::function = &debug_##function; \
98  } while (0)
99 
100  DEBUG_WRAP(glBeginQuery);
101  DEBUG_WRAP(glBeginTransformFeedback);
102  DEBUG_WRAP(glBindBuffer);
103  DEBUG_WRAP(glBindBufferBase);
104  DEBUG_WRAP(glBindFramebuffer);
105  DEBUG_WRAP(glBindSampler);
106  DEBUG_WRAP(glBindVertexArray);
107  DEBUG_WRAP(glBlitFramebuffer);
108  DEBUG_WRAP(glBufferData);
109  DEBUG_WRAP(glBufferSubData);
110  DEBUG_WRAP(glDeleteBuffers);
111  DEBUG_WRAP(glDeleteFramebuffers);
112  DEBUG_WRAP(glDeleteProgram);
113  DEBUG_WRAP(glDeleteQueries);
114  DEBUG_WRAP(glDeleteSamplers);
115  DEBUG_WRAP(glDeleteShader);
116  DEBUG_WRAP(glDeleteVertexArrays);
117  DEBUG_WRAP(glDispatchCompute);
118  DEBUG_WRAP(glDispatchComputeIndirect);
119  DEBUG_WRAP(glDrawArraysInstanced);
120  DEBUG_WRAP(glDrawArraysInstancedBaseInstance);
121  DEBUG_WRAP(glDrawBuffers);
122  DEBUG_WRAP(glDrawElementsInstancedBaseVertex);
123  DEBUG_WRAP(glDrawElementsInstancedBaseVertexBaseInstance);
124  DEBUG_WRAP(glEndQuery);
125  DEBUG_WRAP(glEndTransformFeedback);
126  DEBUG_WRAP(glFramebufferTexture);
127  DEBUG_WRAP(glFramebufferTexture2D);
128  DEBUG_WRAP(glFramebufferTextureLayer);
129  DEBUG_WRAP(glGenBuffers);
130  DEBUG_WRAP(glGenerateMipmap);
131  DEBUG_WRAP(glGenerateTextureMipmap);
132  DEBUG_WRAP(glGenFramebuffers);
133  DEBUG_WRAP(glGenQueries);
134  DEBUG_WRAP(glGenSamplers);
135  DEBUG_WRAP(glGenVertexArrays);
136  DEBUG_WRAP(glLinkProgram);
137  DEBUG_WRAP(glMapBufferRange);
138  DEBUG_WRAP(glTexBuffer);
139  DEBUG_WRAP(glTexImage3D);
140  DEBUG_WRAP(glTexSubImage3D);
141  DEBUG_WRAP(glTextureBuffer);
142  DEBUG_WRAP(glUnmapBuffer);
143  DEBUG_WRAP(glUseProgram);
144 
145 #undef DEBUG_WRAP
146 }
147 
148 } // namespace blender::gpu::debug
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei height
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei width
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
depth_tx sampler(1, ImageType::FLOAT_2D, "combined_tx") .sampler(2
#define DEBUG_WRAP(function)
void * GPUvoidptr
GPUFrameBuffer * framebuffers[FRAMEBUFFER_STACK_DEPTH]
DO_INLINE void filter(lfVector *V, fmatrix3x3 *S)
IconTextureDrawCall border
int count
ccl_global float * buffer
ccl_gpu_kernel_postfix ccl_global float int int int int float bool int offset
ccl_gpu_kernel_postfix int ccl_global int * indices
format
Definition: logImageCore.h:38
ccl_device_inline float4 mask(const int4 &mask, const float4 &a)
Definition: math_float4.h:513
DEBUG_FUNC_DECLARE(PFNGLBEGINQUERYPROC, void, glBeginQuery, GLenum, target, GLuint, id)
T length(const vec_base< T, Size > &a)
static RawVector< RawArray< int64_t, 0 > > arrays