Blender V4.3
mtl_debug.mm
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2022-2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
11#include "BLI_compiler_attrs.h"
12#include "BLI_string.h"
13#include "BLI_system.h"
14#include "BLI_utildefines.h"
15
16#include "BKE_global.hh"
17
18#include "GPU_debug.hh"
19#include "GPU_platform.hh"
20
21#include "mtl_context.hh"
22#include "mtl_debug.hh"
23
24#include "CLG_log.h"
25
26#include <utility>
27
28namespace blender::gpu::debug {
29
30CLG_LogRef LOG = {"gpu.debug.metal"};
31
33{
35}
36
37} // namespace blender::gpu::debug
38
39namespace blender::gpu {
40
41/* -------------------------------------------------------------------- */
48void MTLContext::debug_group_begin(const char *name, int index)
49{
50 if (G.debug & G_DEBUG_GPU) {
51 this->main_command_buffer.push_debug_group(name, index);
52 }
53}
54
56{
57 if (G.debug & G_DEBUG_GPU) {
59 }
60}
61
62bool MTLContext::debug_capture_begin(const char * /*title*/)
63{
64 MTLCaptureManager *capture_manager = [MTLCaptureManager sharedCaptureManager];
65 if (!capture_manager) {
66 /* Early exit if frame capture is disabled. */
67 return false;
68 }
69 MTLCaptureDescriptor *capture_descriptor = [[MTLCaptureDescriptor alloc] init];
70 capture_descriptor.captureObject = this->device;
71 NSError *error;
72 if (![capture_manager startCaptureWithDescriptor:capture_descriptor error:&error]) {
73 NSLog(@"Failed to start Metal frame capture, error %@", error);
74 return false;
75 }
76 return true;
77}
78
80{
81 MTLCaptureManager *capture_manager = [MTLCaptureManager sharedCaptureManager];
82 if (!capture_manager) {
83 /* Early exit if frame capture is disabled. */
84 return;
85 }
86 [capture_manager stopCapture];
87}
88
90{
91 /* Create a capture scope visible to xCode Metal Frame capture utility. */
92 MTLCaptureManager *capture_manager = [MTLCaptureManager sharedCaptureManager];
93 if (!capture_manager) {
94 /* Early exit if frame capture is disabled. */
95 return nullptr;
96 }
97 id<MTLCaptureScope> capture_scope = [capture_manager newCaptureScopeWithDevice:this->device];
98 capture_scope.label = [NSString stringWithUTF8String:name];
99 [capture_scope retain];
100
101 return reinterpret_cast<void *>(capture_scope);
102}
103
105{
106 /* Declare opening boundary of scope.
107 * When scope is selected for capture, GPU commands between begin/end scope will be captured. */
108 [(id<MTLCaptureScope>)scope beginScope];
109
110 MTLCaptureManager *capture_manager = [MTLCaptureManager sharedCaptureManager];
111 return [capture_manager isCapturing];
112}
113
115{
116 [(id<MTLCaptureScope>)scope endScope];
117}
118
121} // namespace blender::gpu
@ G_DEBUG_GPU
#define CLOG_ENSURE(clg_ref)
Definition CLG_log.h:150
void init()
void push_debug_group(const char *name, int index)
bool debug_capture_begin(const char *title) override
Definition mtl_debug.mm:62
void * debug_capture_scope_create(const char *name) override
Definition mtl_debug.mm:89
void debug_capture_scope_end(void *scope) override
Definition mtl_debug.mm:114
void debug_group_begin(const char *name, int index) override
Definition mtl_debug.mm:48
bool debug_capture_scope_begin(void *scope) override
Definition mtl_debug.mm:104
MTLCommandBufferManager main_command_buffer
void debug_group_end() override
Definition mtl_debug.mm:55
void debug_capture_end() override
Definition mtl_debug.mm:79
#define G(x, y, z)
static void error(const char *str)