Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClément Foucault <foucault.clem@gmail.com>2020-09-09 01:47:59 +0300
committerClément Foucault <foucault.clem@gmail.com>2020-09-10 15:19:00 +0300
commit9d5977f5e1fa2eac782278c61c3cc86685cc1b5a (patch)
treed88fad9af66de5ef23c50e12a886cee109342bbf /source/blender/gpu/opengl/gl_debug.cc
parentb8bcbb2cf26f7217099076e17d69088e690c0790 (diff)
GL: Add fallback debug layer
This is to improve debugging on older hardware that may not support 4.3 debug capabilities (like Macs). This avoids sprinkling glGetErrors manually. This might still be needed to find the root cause since not all functions are covered. This overrides the functions pointers that GLEW have already init. This is only enabled if using --debug-gpu option and the debug extension are not available. This also cleanup the usage of GLContext::debug_layer_support and use wrapper to set object labels.
Diffstat (limited to 'source/blender/gpu/opengl/gl_debug.cc')
-rw-r--r--source/blender/gpu/opengl/gl_debug.cc75
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..de88fdc154c 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 renderdoc. 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