[Bf-blender-cvs] [2da4e2be0a4] master: Cleanup: GPUDebug: Use Vector instead of custom stack

Clément Foucault noreply at git.blender.org
Mon Sep 14 20:53:55 CEST 2020


Commit: 2da4e2be0a445052e6b984e93c6d232b157d1436
Author: Clément Foucault
Date:   Mon Sep 14 19:52:49 2020 +0200
Branches: master
https://developer.blender.org/rB2da4e2be0a445052e6b984e93c6d232b157d1436

Cleanup: GPUDebug: Use Vector instead of custom stack

===================================================================

M	source/blender/gpu/intern/gpu_debug.cc
M	source/blender/gpu/intern/gpu_debug_private.hh
M	source/blender/gpu/opengl/gl_context.hh

===================================================================

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);



More information about the Bf-blender-cvs mailing list