diff options
author | Falk David <falkdavid@gmx.de> | 2020-09-12 13:14:15 +0300 |
---|---|---|
committer | Falk David <falkdavid@gmx.de> | 2020-09-12 13:14:15 +0300 |
commit | 269ceb666b01b8cddbfb5babddf38546a41eba39 (patch) | |
tree | b08a26134ad7bd91a328b8ad441143b498ae2b2d /source/blender/gpu/opengl/gl_debug.cc | |
parent | 91066cd0c3b9737feb85ea72abc7e021124639aa (diff) | |
parent | 29af082e4a0f46659f9c54b435ade36f999baa4b (diff) |
Merge branch 'master' into greasepencil-edit-curve
Diffstat (limited to 'source/blender/gpu/opengl/gl_debug.cc')
-rw-r--r-- | source/blender/gpu/opengl/gl_debug.cc | 75 |
1 files changed, 68 insertions, 7 deletions
diff --git a/source/blender/gpu/opengl/gl_debug.cc b/source/blender/gpu/opengl/gl_debug.cc index 468d1514d60..db99e90d0ec 100644 --- a/source/blender/gpu/opengl/gl_debug.cc +++ b/source/blender/gpu/opengl/gl_debug.cc @@ -112,17 +112,13 @@ static void APIENTRY debug_callback(GLenum UNUSED(source), #undef APIENTRY +/* This function needs to be called once per context. */ 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 (GLContext::debug_layer_support) { + 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); @@ -148,7 +144,8 @@ void init_gl_callbacks(void) msg); } else { - fprintf(stderr, "GPUDebug: Failed to hook OpenGL debug callback\n"); + fprintf(stderr, "GPUDebug: Failed to hook OpenGL debug callback. Use fallback debug layer.\n"); + init_debug_layer(); } } @@ -243,4 +240,68 @@ void raise_gl_error(const char *info) /** \} */ +/* -------------------------------------------------------------------- */ +/** \name Object Label + * + * Useful for debugging through render-doc. Only defined if using `--debug-gpu`. + * Make sure to bind the object first so that it gets defined by the GL implementation. + * \{ */ + +static const char *to_str_prefix(GLenum type) +{ + switch (type) { + case GL_FRAGMENT_SHADER: + case GL_GEOMETRY_SHADER: + case GL_VERTEX_SHADER: + case GL_SHADER: + case GL_PROGRAM: + return "SHD-"; + case GL_SAMPLER: + return "SAM-"; + case GL_TEXTURE: + return "TEX-"; + case GL_FRAMEBUFFER: + return "FBO-"; + case GL_VERTEX_ARRAY: + return "VAO-"; + case GL_UNIFORM_BUFFER: + return "UBO-"; + case GL_BUFFER: + return "BUF-"; + default: + return ""; + } +} +static const char *to_str_suffix(GLenum type) +{ + switch (type) { + case GL_FRAGMENT_SHADER: + return "-Frag"; + case GL_GEOMETRY_SHADER: + return "-Geom"; + case GL_VERTEX_SHADER: + return "-Vert"; + default: + return ""; + } +} + +void object_label(GLenum type, GLuint object, const char *name) +{ + if ((G.debug & G_DEBUG_GPU) && (GLEW_VERSION_4_3 || GLEW_KHR_debug)) { + char label[64]; + SNPRINTF(label, "%s%s%s", to_str_prefix(type), name, to_str_suffix(type)); + /* Small convenience for caller. */ + if (ELEM(type, GL_FRAGMENT_SHADER, GL_GEOMETRY_SHADER, GL_VERTEX_SHADER)) { + type = GL_SHADER; + } + if (ELEM(type, GL_UNIFORM_BUFFER)) { + type = GL_BUFFER; + } + glObjectLabel(type, object, -1, label); + } +} + +/** \} */ + } // namespace blender::gpu::debug |