Blender V4.3
gpu_debug.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2020 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
11#include "BKE_global.hh"
12
13#include "BLI_string.h"
14
16
17#include "GPU_debug.hh"
18
19using namespace blender;
20using namespace blender::gpu;
21
22void GPU_debug_group_begin(const char *name)
23{
24 if (!(G.debug & G_DEBUG_GPU)) {
25 return;
26 }
27 Context *ctx = Context::get();
28 DebugStack &stack = ctx->debug_stack;
29 stack.append(StringRef(name));
30 ctx->debug_group_begin(name, stack.size());
31}
32
34{
35 if (!(G.debug & G_DEBUG_GPU)) {
36 return;
37 }
38 Context *ctx = Context::get();
39 ctx->debug_stack.pop_last();
40 ctx->debug_group_end();
41}
42
43void GPU_debug_get_groups_names(int name_buf_len, char *r_name_buf)
44{
45 Context *ctx = Context::get();
46 if (ctx == nullptr) {
47 return;
48 }
49 DebugStack &stack = ctx->debug_stack;
50 if (stack.is_empty()) {
51 r_name_buf[0] = '\0';
52 return;
53 }
54 size_t len = 0;
55 for (StringRef &name : stack) {
56 len += BLI_snprintf_rlen(r_name_buf + len, name_buf_len - len, "%s > ", name.data());
57 }
58 r_name_buf[len - 3] = '\0';
59}
60
61bool GPU_debug_group_match(const char *ref)
62{
63 /* Otherwise there will be no names. */
64 BLI_assert(G.debug & G_DEBUG_GPU);
65 Context *ctx = Context::get();
66 if (ctx == nullptr) {
67 return false;
68 }
69 const DebugStack &stack = ctx->debug_stack;
70 for (const StringRef &name : stack) {
71 if (name == ref) {
72 return true;
73 }
74 }
75 return false;
76}
77
78void GPU_debug_capture_begin(const char *title)
79{
80 /* GPU Frame capture is only enabled when --debug-gpu is specified. */
81 if (!(G.debug & G_DEBUG_GPU)) {
82 return;
83 }
84
85 Context *ctx = Context::get();
86 if (ctx && !ctx->debug_is_capturing) {
87 ctx->debug_is_capturing = ctx->debug_capture_begin(title);
88 /* Call GPU_finish to ensure all desired GPU commands occur within the capture boundary. */
89 GPU_finish();
90 }
91}
92
94{
95 /* GPU Frame capture is only enabled when --debug-gpu is specified. */
96 if (!(G.debug & G_DEBUG_GPU)) {
97 return;
98 }
99
100 Context *ctx = Context::get();
101 if (ctx && ctx->debug_is_capturing) {
102 /* Call GPU_finish to ensure all desired GPU commands occur within the capture boundary. */
103 GPU_finish();
104 ctx->debug_capture_end();
105 ctx->debug_is_capturing = false;
106 }
107}
108
109void *GPU_debug_capture_scope_create(const char *name)
110{
111 /* GPU Frame capture is only enabled when --debug-gpu is specified. */
112 if (!(G.debug & G_DEBUG_GPU)) {
113 return nullptr;
114 }
115
116 Context *ctx = Context::get();
117 if (!ctx) {
118 return nullptr;
119 }
120 return ctx->debug_capture_scope_create(name);
121}
122
124{
125 /* Early exit if scope does not exist or not in debug mode. */
126 if (!(G.debug & G_DEBUG_GPU) || !scope) {
127 return false;
128 }
129
130 Context *ctx = Context::get();
131 if (!ctx) {
132 return false;
133 }
134
135 /* Declare beginning of capture scope region. */
136 bool scope_capturing = ctx->debug_capture_scope_begin(scope);
137 if (scope_capturing && !ctx->debug_is_capturing) {
138 /* Call GPU_finish to ensure all desired GPU commands occur within the capture boundary. */
139 GPU_finish();
140 ctx->debug_is_capturing = true;
141 }
142 return ctx->debug_is_capturing;
143}
144
146{
147 /* Early exit if scope does not exist or not in debug mode. */
148 if (!(G.debug & G_DEBUG_GPU) || !scope) {
149 return;
150 }
151
152 Context *ctx = Context::get();
153 if (!ctx) {
154 return;
155 }
156
157 /* If capturing, call GPU_finish to ensure all desired GPU commands occur within the capture
158 * boundary. */
159 if (ctx->debug_is_capturing) {
160 GPU_finish();
161 ctx->debug_is_capturing = false;
162 }
163
164 /* Declare end of capture scope region. */
165 ctx->debug_capture_scope_end(scope);
166}
@ G_DEBUG_GPU
#define BLI_assert(a)
Definition BLI_assert.h:50
size_t BLI_snprintf_rlen(char *__restrict dst, size_t dst_maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
void GPU_finish()
Definition gpu_state.cc:299
int64_t size() const
void append(const T &value)
bool is_empty() const
virtual void debug_group_begin(const char *, int)
static Context * get()
virtual void debug_capture_scope_end(void *scope)=0
virtual bool debug_capture_scope_begin(void *scope)=0
virtual void * debug_capture_scope_create(const char *name)=0
virtual void debug_capture_end()=0
virtual bool debug_capture_begin(const char *title)=0
int len
void GPU_debug_group_end()
Definition gpu_debug.cc:33
void GPU_debug_capture_end()
Definition gpu_debug.cc:93
void GPU_debug_capture_scope_end(void *scope)
Definition gpu_debug.cc:145
void GPU_debug_capture_begin(const char *title)
Definition gpu_debug.cc:78
bool GPU_debug_group_match(const char *ref)
Definition gpu_debug.cc:61
bool GPU_debug_capture_scope_begin(void *scope)
Definition gpu_debug.cc:123
void GPU_debug_group_begin(const char *name)
Definition gpu_debug.cc:22
void GPU_debug_get_groups_names(int name_buf_len, char *r_name_buf)
Definition gpu_debug.cc:43
void * GPU_debug_capture_scope_create(const char *name)
Definition gpu_debug.cc:109
#define G(x, y, z)