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