diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2020-09-09 23:28:39 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2020-09-09 23:28:39 +0300 |
commit | 96a62d094f16df970788e13a35f1f22dc349b564 (patch) | |
tree | 482a1b40708bb69c9e7f66253a2e323e40f68100 | |
parent | 59467d8c94a96de48364eec5f2a4c37389434cbf (diff) |
Wrap glObjectLabel and shorten object labeltmp-gldebuglayer
-rw-r--r-- | source/blender/gpu/opengl/gl_debug.cc | 64 | ||||
-rw-r--r-- | source/blender/gpu/opengl/gl_debug.hh | 10 | ||||
-rw-r--r-- | source/blender/gpu/opengl/gl_framebuffer.cc | 17 | ||||
-rw-r--r-- | source/blender/gpu/opengl/gl_immediate.cc | 8 | ||||
-rw-r--r-- | source/blender/gpu/opengl/gl_shader.cc | 23 | ||||
-rw-r--r-- | source/blender/gpu/opengl/gl_texture.cc | 49 | ||||
-rw-r--r-- | source/blender/gpu/opengl/gl_uniform_buffer.cc | 7 |
7 files changed, 102 insertions, 76 deletions
diff --git a/source/blender/gpu/opengl/gl_debug.cc b/source/blender/gpu/opengl/gl_debug.cc index 27b11c8125e..472473fadb3 100644 --- a/source/blender/gpu/opengl/gl_debug.cc +++ b/source/blender/gpu/opengl/gl_debug.cc @@ -240,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 (GLContext::debug_layer_support) { + 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 diff --git a/source/blender/gpu/opengl/gl_debug.hh b/source/blender/gpu/opengl/gl_debug.hh index 8369a46f0e9..892fb1d2ddb 100644 --- a/source/blender/gpu/opengl/gl_debug.hh +++ b/source/blender/gpu/opengl/gl_debug.hh @@ -24,10 +24,6 @@ #include "glew-mx.h" -namespace blender { -namespace gpu { -namespace debug { - /* Manual line breaks for readability. */ /* clang-format off */ #define _VA_ARG_LIST1(t) t @@ -85,6 +81,10 @@ namespace debug { # define GL_CHECK_RESOURCES(info) #endif +namespace blender { +namespace gpu { +namespace debug { + void raise_gl_error(const char *info); void check_gl_error(const char *info); void check_gl_resources(const char *info); @@ -92,6 +92,8 @@ void init_gl_callbacks(void); void init_debug_layer(void); +void object_label(GLenum type, GLuint object, const char *name); + } // namespace debug #define DEBUG_FUNC_OVERRIDE(func, ...) \ diff --git a/source/blender/gpu/opengl/gl_framebuffer.cc b/source/blender/gpu/opengl/gl_framebuffer.cc index 563feacde51..1578c5fa619 100644 --- a/source/blender/gpu/opengl/gl_framebuffer.cc +++ b/source/blender/gpu/opengl/gl_framebuffer.cc @@ -65,10 +65,8 @@ GLFrameBuffer::GLFrameBuffer( viewport_[2] = scissor_[2] = w; viewport_[3] = scissor_[3] = h; - if (fbo_id_ && GLContext::debug_layer_support) { - char sh_name[32]; - SNPRINTF(sh_name, "FrameBuffer-%s", name); - glObjectLabel(GL_FRAMEBUFFER, fbo_id_, -1, sh_name); + if (fbo_id_) { + debug::object_label(GL_FRAMEBUFFER, fbo_id_, name_); } } @@ -99,14 +97,11 @@ void GLFrameBuffer::init(void) context_ = GLContext::get(); state_manager_ = static_cast<GLStateManager *>(context_->state_manager); glGenFramebuffers(1, &fbo_id_); + /* Binding before setting the label is needed on some drivers. + * This is not an issue since we call this function only before binding. */ + glBindFramebuffer(GL_FRAMEBUFFER, fbo_id_); - if (GLContext::debug_layer_support) { - char sh_name[64]; - SNPRINTF(sh_name, "FrameBuffer-%s", name_); - /* Binding before setting the label is needed on some drivers. */ - glBindFramebuffer(GL_FRAMEBUFFER, fbo_id_); - glObjectLabel(GL_FRAMEBUFFER, fbo_id_, -1, sh_name); - } + debug::object_label(GL_FRAMEBUFFER, fbo_id_, name_); } /** \} */ diff --git a/source/blender/gpu/opengl/gl_immediate.cc b/source/blender/gpu/opengl/gl_immediate.cc index 86d61f02318..fd31d77cc80 100644 --- a/source/blender/gpu/opengl/gl_immediate.cc +++ b/source/blender/gpu/opengl/gl_immediate.cc @@ -60,11 +60,9 @@ GLImmediate::GLImmediate() glBindBuffer(GL_ARRAY_BUFFER, 0); glBindVertexArray(0); - if (GLContext::debug_layer_support) { - glObjectLabel(GL_VERTEX_ARRAY, vao_id_, -1, "VAO-Immediate"); - glObjectLabel(GL_BUFFER, buffer.vbo_id, -1, "VBO-ImmediateBuffer"); - glObjectLabel(GL_BUFFER, buffer_strict.vbo_id, -1, "VBO-ImmediateBufferStrict"); - } + debug::object_label(GL_VERTEX_ARRAY, vao_id_, "Immediate"); + debug::object_label(GL_BUFFER, buffer.vbo_id, "ImmediateVbo"); + debug::object_label(GL_BUFFER, buffer_strict.vbo_id, "ImmediateVboStrict"); } GLImmediate::~GLImmediate() diff --git a/source/blender/gpu/opengl/gl_shader.cc b/source/blender/gpu/opengl/gl_shader.cc index 4314ecfa6be..7b3a071bf63 100644 --- a/source/blender/gpu/opengl/gl_shader.cc +++ b/source/blender/gpu/opengl/gl_shader.cc @@ -28,6 +28,7 @@ #include "GPU_platform.h" #include "gl_backend.hh" +#include "gl_debug.hh" #include "gl_vertex_buffer.hh" #include "gl_shader.hh" @@ -48,11 +49,7 @@ GLShader::GLShader(const char *name) : Shader(name) #endif shader_program_ = glCreateProgram(); - if (GLContext::debug_layer_support) { - char sh_name[64]; - SNPRINTF(sh_name, "ShaderProgram-%s", name); - glObjectLabel(GL_PROGRAM, shader_program_, -1, sh_name); - } + debug::object_label(GL_PROGRAM, shader_program_, name); } GLShader::~GLShader(void) @@ -163,21 +160,7 @@ GLuint GLShader::create_shader_stage(GLenum gl_stage, MutableSpan<const char *> return 0; } - if (GLContext::debug_layer_support) { - char sh_name[64]; - switch (gl_stage) { - case GL_VERTEX_SHADER: - BLI_snprintf(sh_name, sizeof(sh_name), "VertShader-%s", name); - break; - case GL_GEOMETRY_SHADER: - BLI_snprintf(sh_name, sizeof(sh_name), "GeomShader-%s", name); - break; - case GL_FRAGMENT_SHADER: - BLI_snprintf(sh_name, sizeof(sh_name), "FragShader-%s", name); - break; - } - glObjectLabel(GL_SHADER, shader, -1, sh_name); - } + debug::object_label(gl_stage, shader, name); glAttachShader(shader_program_, shader); return shader; diff --git a/source/blender/gpu/opengl/gl_texture.cc b/source/blender/gpu/opengl/gl_texture.cc index cc042b72951..4e279fc47c1 100644 --- a/source/blender/gpu/opengl/gl_texture.cc +++ b/source/blender/gpu/opengl/gl_texture.cc @@ -96,12 +96,7 @@ bool GLTexture::init_internal(void) glTexParameteri(target_, GL_TEXTURE_MIN_FILTER, GL_NEAREST); } - if (GLContext::debug_layer_support) { - char sh_name[64]; - SNPRINTF(sh_name, "Texture-%s", name_); - /* Binding before setting the label is needed on some drivers. */ - glObjectLabel(GL_TEXTURE, tex_id_, -1, sh_name); - } + debug::object_label(GL_TEXTURE, tex_id_, name_); return true; } @@ -123,12 +118,8 @@ bool GLTexture::init_internal(GPUVertBuf *vbo) glTexBuffer(target_, internal_format, gl_vbo->vbo_id_); } - if (GLContext::debug_layer_support) { - char sh_name[64]; - SNPRINTF(sh_name, "Texture-%s", name_); - /* Binding before setting the label is needed on some drivers. */ - glObjectLabel(GL_TEXTURE, tex_id_, -1, sh_name); - } + debug::object_label(GL_TEXTURE, tex_id_, name_); + return true; } @@ -501,22 +492,20 @@ void GLTexture::samplers_init(void) * - GL_TEXTURE_LOD_BIAS is 0.0f. **/ - if (GLContext::debug_layer_support) { - char sampler_name[128]; - SNPRINTF(sampler_name, - "Sampler%s%s%s%s%s%s%s%s%s%s", - (state == GPU_SAMPLER_DEFAULT) ? "_default" : "", - (state & GPU_SAMPLER_FILTER) ? "_filter" : "", - (state & GPU_SAMPLER_MIPMAP) ? "_mipmap" : "", - (state & GPU_SAMPLER_REPEAT) ? "_repeat-" : "", - (state & GPU_SAMPLER_REPEAT_S) ? "S" : "", - (state & GPU_SAMPLER_REPEAT_T) ? "T" : "", - (state & GPU_SAMPLER_REPEAT_R) ? "R" : "", - (state & GPU_SAMPLER_CLAMP_BORDER) ? "_clamp_border" : "", - (state & GPU_SAMPLER_COMPARE) ? "_compare" : "", - (state & GPU_SAMPLER_ANISO) ? "_aniso" : ""); - glObjectLabel(GL_SAMPLER, samplers_[i], -1, sampler_name); - } + char sampler_name[128] = "\0\0"; + SNPRINTF(sampler_name, + "%s%s%s%s%s%s%s%s%s%s", + (state == GPU_SAMPLER_DEFAULT) ? "_default" : "", + (state & GPU_SAMPLER_FILTER) ? "_filter" : "", + (state & GPU_SAMPLER_MIPMAP) ? "_mipmap" : "", + (state & GPU_SAMPLER_REPEAT) ? "_repeat-" : "", + (state & GPU_SAMPLER_REPEAT_S) ? "S" : "", + (state & GPU_SAMPLER_REPEAT_T) ? "T" : "", + (state & GPU_SAMPLER_REPEAT_R) ? "R" : "", + (state & GPU_SAMPLER_CLAMP_BORDER) ? "_clamp_border" : "", + (state & GPU_SAMPLER_COMPARE) ? "_compare" : "", + (state & GPU_SAMPLER_ANISO) ? "_aniso" : ""); + debug::object_label(GL_SAMPLER, samplers_[i], &sampler_name[1]); } samplers_update(); @@ -526,9 +515,7 @@ void GLTexture::samplers_init(void) glSamplerParameteri(icon_sampler, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glSamplerParameterf(icon_sampler, GL_TEXTURE_LOD_BIAS, -0.5f); - if (GLContext::debug_layer_support) { - glObjectLabel(GL_SAMPLER, icon_sampler, -1, "Sampler-icons"); - } + debug::object_label(GL_SAMPLER, icon_sampler, "icons"); } void GLTexture::samplers_update(void) diff --git a/source/blender/gpu/opengl/gl_uniform_buffer.cc b/source/blender/gpu/opengl/gl_uniform_buffer.cc index 74453a08bfe..dd305fca555 100644 --- a/source/blender/gpu/opengl/gl_uniform_buffer.cc +++ b/source/blender/gpu/opengl/gl_uniform_buffer.cc @@ -29,6 +29,7 @@ #include "gpu_context_private.hh" #include "gl_backend.hh" +#include "gl_debug.hh" #include "gl_uniform_buffer.hh" namespace blender::gpu { @@ -62,11 +63,7 @@ void GLUniformBuf::init(void) glBindBuffer(GL_UNIFORM_BUFFER, ubo_id_); glBufferData(GL_UNIFORM_BUFFER, size_in_bytes_, NULL, GL_DYNAMIC_DRAW); - if (GLContext::debug_layer_support) { - char sh_name[64]; - SNPRINTF(sh_name, "UBO-%s", name_); - glObjectLabel(GL_BUFFER, ubo_id_, -1, sh_name); - } + debug::object_label(GL_UNIFORM_BUFFER, ubo_id_, name_); } void GLUniformBuf::update(const void *data) |