Blender  V2.93
gpu_debug.cc
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2020 Blender Foundation.
17  * All rights reserved.
18  */
19 
26 #include "BKE_global.h"
27 
28 #include "BLI_string.h"
29 
30 #include "gpu_context_private.hh"
31 
32 #include "GPU_debug.h"
33 
34 using namespace blender;
35 using namespace blender::gpu;
36 
37 void GPU_debug_group_begin(const char *name)
38 {
39  if (!(G.debug & G_DEBUG_GPU)) {
40  return;
41  }
42  Context *ctx = Context::get();
43  DebugStack &stack = ctx->debug_stack;
44  stack.append(StringRef(name));
45  ctx->debug_group_begin(name, stack.size());
46 }
47 
49 {
50  if (!(G.debug & G_DEBUG_GPU)) {
51  return;
52  }
53  Context *ctx = Context::get();
54  ctx->debug_stack.pop_last();
55  ctx->debug_group_end();
56 }
57 
62 void GPU_debug_get_groups_names(int name_buf_len, char *r_name_buf)
63 {
64  Context *ctx = Context::get();
65  if (ctx == nullptr) {
66  return;
67  }
68  DebugStack &stack = ctx->debug_stack;
69  if (stack.size() == 0) {
70  r_name_buf[0] = '\0';
71  return;
72  }
73  size_t sz = 0;
74  for (StringRef &name : stack) {
75  sz += BLI_snprintf_rlen(r_name_buf + sz, name_buf_len - sz, "%s > ", name.data());
76  }
77  r_name_buf[sz - 3] = '\0';
78 }
79 
80 /* Return true if inside a debug group with the same name. */
81 bool GPU_debug_group_match(const char *ref)
82 {
83  /* Otherwise there will be no names. */
84  BLI_assert(G.debug & G_DEBUG_GPU);
85  Context *ctx = Context::get();
86  if (ctx == nullptr) {
87  return false;
88  }
89  DebugStack &stack = ctx->debug_stack;
90  for (StringRef &name : stack) {
91  if (name == ref) {
92  return true;
93  }
94  }
95  return false;
96 }
@ G_DEBUG_GPU
Definition: BKE_global.h:151
#define BLI_assert(a)
Definition: BLI_assert.h:58
size_t BLI_snprintf_rlen(char *__restrict dst, size_t maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
int64_t size() const
Definition: BLI_vector.hh:662
void append(const T &value)
Definition: BLI_vector.hh:438
virtual void debug_group_end(void)
virtual void debug_group_begin(const char *, int)
static Context * get(void)
Definition: gpu_context.cc:88
bool GPU_debug_group_match(const char *ref)
Definition: gpu_debug.cc:81
void GPU_debug_group_end(void)
Definition: gpu_debug.cc:48
void GPU_debug_group_begin(const char *name)
Definition: gpu_debug.cc:37
void GPU_debug_get_groups_names(int name_buf_len, char *r_name_buf)
Definition: gpu_debug.cc:62
#define G(x, y, z)