diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2020-09-14 20:52:49 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2020-09-14 21:53:34 +0300 |
commit | 2da4e2be0a445052e6b984e93c6d232b157d1436 (patch) | |
tree | b04bfc20d6a7ab6b204de0f5ab568aee6a01cabf /source/blender/gpu | |
parent | 59a9cf46b485a00e42fcf93851ff3ed0ba6fe24d (diff) |
Cleanup: GPUDebug: Use Vector instead of custom stack
Diffstat (limited to 'source/blender/gpu')
-rw-r--r-- | source/blender/gpu/intern/gpu_debug.cc | 37 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_debug_private.hh | 11 | ||||
-rw-r--r-- | source/blender/gpu/opengl/gl_context.hh | 4 |
3 files changed, 17 insertions, 35 deletions
diff --git a/source/blender/gpu/intern/gpu_debug.cc b/source/blender/gpu/intern/gpu_debug.cc index 2c9b58f0f96..d4b55d7e758 100644 --- a/source/blender/gpu/intern/gpu_debug.cc +++ b/source/blender/gpu/intern/gpu_debug.cc @@ -31,6 +31,7 @@ #include "GPU_debug.h" +using namespace blender; using namespace blender::gpu; void GPU_debug_group_begin(const char *name) @@ -38,17 +39,10 @@ void GPU_debug_group_begin(const char *name) if (!(G.debug & G_DEBUG_GPU)) { return; } - - DebugStack &stack = Context::get()->debug_stack; - - if (stack.index >= DEBUG_STACK_LEN) { - stack.index = DEBUG_STACK_LEN - 1; - BLI_assert(!"GPUDebug: Debug group stack overflow!"); - } - - BLI_strncpy(stack.names[stack.index++], name, sizeof(stack.names[stack.index++])); - - Context::get()->debug_group_begin(name, stack.index); + Context *ctx = Context::get(); + DebugStack &stack = ctx->debug_stack; + stack.append(StringRef(name)); + ctx->debug_group_begin(name, stack.size()); } void GPU_debug_group_end(void) @@ -56,17 +50,9 @@ void GPU_debug_group_end(void) if (!(G.debug & G_DEBUG_GPU)) { return; } - - DebugStack &stack = Context::get()->debug_stack; - - if (stack.index < 0) { - stack.index = 0; - BLI_assert(!"GPUDebug: Debug group stack underflow!"); - } - - stack.index--; - - Context::get()->debug_group_end(); + Context *ctx = Context::get(); + ctx->debug_stack.pop_last(); + ctx->debug_group_end(); } /* Return a formated string showing the current group hierarchy in this format: @@ -77,15 +63,14 @@ void GPU_debug_get_groups_names(int name_buf_len, char *r_name_buf) if (ctx == nullptr) { return; } - DebugStack &stack = ctx->debug_stack; - if (stack.index == 0) { + if (stack.size() == 0) { r_name_buf[0] = '\0'; return; } size_t sz = 0; - for (int i = 0; i < stack.index; i++) { - sz += BLI_snprintf_rlen(r_name_buf + sz, name_buf_len - sz, "%s > ", stack.names[0]); + for (StringRef &name : stack) { + sz += BLI_snprintf_rlen(r_name_buf + sz, name_buf_len - sz, "%s > ", name.data()); } r_name_buf[sz - 2] = ':'; }
\ No newline at end of file diff --git a/source/blender/gpu/intern/gpu_debug_private.hh b/source/blender/gpu/intern/gpu_debug_private.hh index 7432b02541e..1887e7c698a 100644 --- a/source/blender/gpu/intern/gpu_debug_private.hh +++ b/source/blender/gpu/intern/gpu_debug_private.hh @@ -25,14 +25,11 @@ #pragma once -namespace blender::gpu { +#include "BLI_string_ref.hh" +#include "BLI_vector.hh" -#define DEBUG_STACK_LEN 64 -#define DEBUG_STACK_NAME_LEN 128 +namespace blender::gpu { -struct DebugStack { - char names[DEBUG_STACK_LEN][DEBUG_STACK_NAME_LEN]; - int index = 0; -}; +typedef Vector<StringRef> DebugStack; } // namespace blender::gpu
\ No newline at end of file diff --git a/source/blender/gpu/opengl/gl_context.hh b/source/blender/gpu/opengl/gl_context.hh index 5cebc2a3f3e..66a3fdd3355 100644 --- a/source/blender/gpu/opengl/gl_context.hh +++ b/source/blender/gpu/opengl/gl_context.hh @@ -135,8 +135,8 @@ class GLContext : public Context { void vao_cache_register(GLVaoCache *cache); void vao_cache_unregister(GLVaoCache *cache); - void debug_group_begin(const char *name, int index); - void debug_group_end(void); + void debug_group_begin(const char *name, int index) override; + void debug_group_end(void) override; private: static void orphans_add(Vector<GLuint> &orphan_list, std::mutex &list_mutex, GLuint id); |