Blender  V3.3
gpu_debug.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2020 Blender Foundation. All rights reserved. */
3 
10 #include "BKE_global.h"
11 
12 #include "BLI_string.h"
13 
14 #include "gpu_context_private.hh"
15 
16 #include "GPU_debug.h"
17 
18 using namespace blender;
19 using namespace blender::gpu;
20 
21 void GPU_debug_group_begin(const char *name)
22 {
23  if (!(G.debug & G_DEBUG_GPU)) {
24  return;
25  }
26  Context *ctx = Context::get();
27  DebugStack &stack = ctx->debug_stack;
28  stack.append(StringRef(name));
29  ctx->debug_group_begin(name, stack.size());
30 }
31 
33 {
34  if (!(G.debug & G_DEBUG_GPU)) {
35  return;
36  }
37  Context *ctx = Context::get();
38  ctx->debug_stack.pop_last();
39  ctx->debug_group_end();
40 }
41 
42 void GPU_debug_get_groups_names(int name_buf_len, char *r_name_buf)
43 {
44  Context *ctx = Context::get();
45  if (ctx == nullptr) {
46  return;
47  }
48  DebugStack &stack = ctx->debug_stack;
49  if (stack.size() == 0) {
50  r_name_buf[0] = '\0';
51  return;
52  }
53  size_t len = 0;
54  for (StringRef &name : stack) {
55  len += BLI_snprintf_rlen(r_name_buf + len, name_buf_len - len, "%s > ", name.data());
56  }
57  r_name_buf[len - 3] = '\0';
58 }
59 
60 bool GPU_debug_group_match(const char *ref)
61 {
62  /* Otherwise there will be no names. */
63  BLI_assert(G.debug & G_DEBUG_GPU);
64  Context *ctx = Context::get();
65  if (ctx == nullptr) {
66  return false;
67  }
68  const DebugStack &stack = ctx->debug_stack;
69  for (const StringRef &name : stack) {
70  if (name == ref) {
71  return true;
72  }
73  }
74  return false;
75 }
@ G_DEBUG_GPU
Definition: BKE_global.h:193
#define BLI_assert(a)
Definition: BLI_assert.h:46
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:694
void append(const T &value)
Definition: BLI_vector.hh:433
virtual void debug_group_begin(const char *, int)
static Context * get()
Definition: gpu_context.cc:82
virtual void debug_group_end()
int len
Definition: draw_manager.c:108
void GPU_debug_group_end()
Definition: gpu_debug.cc:32
bool GPU_debug_group_match(const char *ref)
Definition: gpu_debug.cc:60
void GPU_debug_group_begin(const char *name)
Definition: gpu_debug.cc:21
void GPU_debug_get_groups_names(int name_buf_len, char *r_name_buf)
Definition: gpu_debug.cc:42
#define G(x, y, z)