From 5698fb2049b916a19ba8f5cbca7836509d4a1b91 Mon Sep 17 00:00:00 2001 From: Jeroen Bakker Date: Fri, 23 Feb 2024 10:57:37 +0100 Subject: [PATCH] RenderDoc: Set Capture Title Adds an option to set the capture title when using renderdoc `GPU_debug_capture_begin` has an optional `title` parameter to set the title of the renderdoc capture. Pull Request: https://projects.blender.org/blender/blender/pulls/118649 --- intern/renderdoc_dynload/include/renderdoc_api.hh | 3 ++- intern/renderdoc_dynload/intern/renderdoc_api.cc | 10 +++++++++- source/blender/gpu/GPU_debug.h | 6 ++++-- source/blender/gpu/dummy/dummy_context.hh | 2 +- source/blender/gpu/intern/gpu_context_private.hh | 2 +- source/blender/gpu/intern/gpu_debug.cc | 4 ++-- source/blender/gpu/metal/mtl_context.hh | 2 +- source/blender/gpu/metal/mtl_debug.mm | 2 +- source/blender/gpu/opengl/gl_backend.hh | 2 +- source/blender/gpu/opengl/gl_context.hh | 2 +- source/blender/gpu/opengl/gl_debug.cc | 13 +++++++++---- source/blender/gpu/tests/gpu_testing.cc | 2 +- source/blender/gpu/vulkan/vk_backend.hh | 2 +- source/blender/gpu/vulkan/vk_context.hh | 2 +- source/blender/gpu/vulkan/vk_debug.cc | 13 +++++++++---- 15 files changed, 44 insertions(+), 23 deletions(-) diff --git a/intern/renderdoc_dynload/include/renderdoc_api.hh b/intern/renderdoc_dynload/include/renderdoc_api.hh index 264938d41d6..e1fcab6aa54 100644 --- a/intern/renderdoc_dynload/include/renderdoc_api.hh +++ b/intern/renderdoc_dynload/include/renderdoc_api.hh @@ -34,6 +34,7 @@ class Renderdoc { RENDERDOC_WindowHandle window_handle); void end_frame_capture(RENDERDOC_DevicePointer device_handle, RENDERDOC_WindowHandle window_handle); + void set_frame_capture_title(const char *capture_title); private: /** @@ -44,4 +45,4 @@ class Renderdoc { bool check_loaded(); void load(); }; -} // namespace renderdoc::api \ No newline at end of file +} // namespace renderdoc::api diff --git a/intern/renderdoc_dynload/intern/renderdoc_api.cc b/intern/renderdoc_dynload/intern/renderdoc_api.cc index 09906e6bdd4..d0f5019fad1 100644 --- a/intern/renderdoc_dynload/intern/renderdoc_api.cc +++ b/intern/renderdoc_dynload/intern/renderdoc_api.cc @@ -33,6 +33,14 @@ void Renderdoc::end_frame_capture(RENDERDOC_DevicePointer device_handle, renderdoc_api_->EndFrameCapture(device_handle, window_handle); } +void Renderdoc::set_frame_capture_title(const char *title) +{ + if (!check_loaded()) { + return; + } + renderdoc_api_->SetCaptureTitle(title); +} + bool Renderdoc::check_loaded() { switch (state_) { @@ -64,4 +72,4 @@ void Renderdoc::load() #endif } -} // namespace renderdoc::api \ No newline at end of file +} // namespace renderdoc::api diff --git a/source/blender/gpu/GPU_debug.h b/source/blender/gpu/GPU_debug.h index b5def134367..04da14ff595 100644 --- a/source/blender/gpu/GPU_debug.h +++ b/source/blender/gpu/GPU_debug.h @@ -16,7 +16,7 @@ * #include "GPU_debug.h" * static void do_render_engine(Render *re) * { - * GPU_debug_capture_begin(); + * GPU_debug_capture_begin(__func__); * RE_engine_render(re, false); * GPU_debug_capture_end(); * } @@ -68,8 +68,10 @@ bool GPU_debug_group_match(const char *ref); * GPU Frame capture support. * * Allows instantaneous frame capture of GPU calls between begin/end. + * + * \param title: Optional title to set for the frame capture. */ -void GPU_debug_capture_begin(void); +void GPU_debug_capture_begin(const char *title); void GPU_debug_capture_end(void); /** diff --git a/source/blender/gpu/dummy/dummy_context.hh b/source/blender/gpu/dummy/dummy_context.hh index 73d8bbe2084..f9e2cc0a3bf 100644 --- a/source/blender/gpu/dummy/dummy_context.hh +++ b/source/blender/gpu/dummy/dummy_context.hh @@ -32,7 +32,7 @@ class DummyContext : public Context { void debug_group_begin(const char *, int) override {} void debug_group_end() override {} - bool debug_capture_begin() override + bool debug_capture_begin(const char * /*title*/) override { return false; } diff --git a/source/blender/gpu/intern/gpu_context_private.hh b/source/blender/gpu/intern/gpu_context_private.hh index e05c62742b8..0ca2fc42fb2 100644 --- a/source/blender/gpu/intern/gpu_context_private.hh +++ b/source/blender/gpu/intern/gpu_context_private.hh @@ -87,7 +87,7 @@ class Context { virtual void debug_group_end(){}; /* Returns true if capture successfully started. */ - virtual bool debug_capture_begin() = 0; + virtual bool debug_capture_begin(const char *title) = 0; virtual void debug_capture_end() = 0; virtual void *debug_capture_scope_create(const char *name) = 0; virtual bool debug_capture_scope_begin(void *scope) = 0; diff --git a/source/blender/gpu/intern/gpu_debug.cc b/source/blender/gpu/intern/gpu_debug.cc index 5c2d25b292e..21f806a07f5 100644 --- a/source/blender/gpu/intern/gpu_debug.cc +++ b/source/blender/gpu/intern/gpu_debug.cc @@ -75,7 +75,7 @@ bool GPU_debug_group_match(const char *ref) return false; } -void GPU_debug_capture_begin() +void GPU_debug_capture_begin(const char *title) { /* GPU Frame capture is only enabled when --debug-gpu is specified. */ if (!(G.debug & G_DEBUG_GPU)) { @@ -84,7 +84,7 @@ void GPU_debug_capture_begin() Context *ctx = Context::get(); if (ctx && !ctx->debug_is_capturing) { - ctx->debug_is_capturing = ctx->debug_capture_begin(); + ctx->debug_is_capturing = ctx->debug_capture_begin(title); if (!ctx->debug_is_capturing) { printf("Failed to start GPU frame capture!\n"); } diff --git a/source/blender/gpu/metal/mtl_context.hh b/source/blender/gpu/metal/mtl_context.hh index 9ca913d9347..9e65088fd2c 100644 --- a/source/blender/gpu/metal/mtl_context.hh +++ b/source/blender/gpu/metal/mtl_context.hh @@ -780,7 +780,7 @@ class MTLContext : public Context { void debug_group_begin(const char *name, int index) override; void debug_group_end() override; - bool debug_capture_begin() override; + bool debug_capture_begin(const char *title) override; void debug_capture_end() override; void *debug_capture_scope_create(const char *name) override; bool debug_capture_scope_begin(void *scope) override; diff --git a/source/blender/gpu/metal/mtl_debug.mm b/source/blender/gpu/metal/mtl_debug.mm index 66804bffb99..f522c2ae17c 100644 --- a/source/blender/gpu/metal/mtl_debug.mm +++ b/source/blender/gpu/metal/mtl_debug.mm @@ -59,7 +59,7 @@ void MTLContext::debug_group_end() } } -bool MTLContext::debug_capture_begin() +bool MTLContext::debug_capture_begin(const char * /*title*/) { MTLCaptureManager *capture_manager = [MTLCaptureManager sharedCaptureManager]; if (!capture_manager) { diff --git a/source/blender/gpu/opengl/gl_backend.hh b/source/blender/gpu/opengl/gl_backend.hh index efae977d01b..5d7f1189b44 100644 --- a/source/blender/gpu/opengl/gl_backend.hh +++ b/source/blender/gpu/opengl/gl_backend.hh @@ -163,7 +163,7 @@ class GLBackend : public GPUBackend { void render_end() override{}; void render_step() override{}; - bool debug_capture_begin(); + bool debug_capture_begin(const char *title); void debug_capture_end(); private: diff --git a/source/blender/gpu/opengl/gl_context.hh b/source/blender/gpu/opengl/gl_context.hh index 10e76d2f977..ab15d19d25c 100644 --- a/source/blender/gpu/opengl/gl_context.hh +++ b/source/blender/gpu/opengl/gl_context.hh @@ -129,7 +129,7 @@ class GLContext : public Context { void debug_group_begin(const char *name, int index) override; void debug_group_end() override; - bool debug_capture_begin() override; + bool debug_capture_begin(const char *title) override; void debug_capture_end() override; void *debug_capture_scope_create(const char *name) override; bool debug_capture_scope_begin(void *scope) override; diff --git a/source/blender/gpu/opengl/gl_debug.cc b/source/blender/gpu/opengl/gl_debug.cc index ce5d1a3e63f..3a150cae13e 100644 --- a/source/blender/gpu/opengl/gl_debug.cc +++ b/source/blender/gpu/opengl/gl_debug.cc @@ -386,18 +386,23 @@ void GLContext::debug_group_end() } } -bool GLContext::debug_capture_begin() +bool GLContext::debug_capture_begin(const char *title) { - return GLBackend::get()->debug_capture_begin(); + return GLBackend::get()->debug_capture_begin(title); } -bool GLBackend::debug_capture_begin() +bool GLBackend::debug_capture_begin(const char *title) { #ifdef WITH_RENDERDOC if (G.debug & G_DEBUG_GPU_RENDERDOC) { - return renderdoc_.start_frame_capture(nullptr, nullptr); + bool result = renderdoc_.start_frame_capture(nullptr, nullptr); + if (result && title) { + renderdoc_.set_frame_capture_title(title); + } + return result; } #endif + UNUSED_VARS(title); return false; } diff --git a/source/blender/gpu/tests/gpu_testing.cc b/source/blender/gpu/tests/gpu_testing.cc index f61573c4522..c5d03638160 100644 --- a/source/blender/gpu/tests/gpu_testing.cc +++ b/source/blender/gpu/tests/gpu_testing.cc @@ -37,7 +37,7 @@ void GPUTest::SetUp() GPU_render_begin(); GPU_context_begin_frame(context); - GPU_debug_capture_begin(); + GPU_debug_capture_begin(nullptr); } void GPUTest::TearDown() diff --git a/source/blender/gpu/vulkan/vk_backend.hh b/source/blender/gpu/vulkan/vk_backend.hh index e5e35c03583..107af4c77ed 100644 --- a/source/blender/gpu/vulkan/vk_backend.hh +++ b/source/blender/gpu/vulkan/vk_backend.hh @@ -72,7 +72,7 @@ class VKBackend : public GPUBackend { void render_end() override; void render_step() override; - bool debug_capture_begin(); + bool debug_capture_begin(const char *title); void debug_capture_end(); shaderc::Compiler &get_shaderc_compiler(); diff --git a/source/blender/gpu/vulkan/vk_context.hh b/source/blender/gpu/vulkan/vk_context.hh index 5e797aa5c98..fe7884b180e 100644 --- a/source/blender/gpu/vulkan/vk_context.hh +++ b/source/blender/gpu/vulkan/vk_context.hh @@ -50,7 +50,7 @@ class VKContext : public Context, NonCopyable { void debug_group_begin(const char *, int) override; void debug_group_end() override; - bool debug_capture_begin() override; + bool debug_capture_begin(const char *title) override; void debug_capture_end() override; void *debug_capture_scope_create(const char *name) override; bool debug_capture_scope_begin(void *scope) override; diff --git a/source/blender/gpu/vulkan/vk_debug.cc b/source/blender/gpu/vulkan/vk_debug.cc index 4cf4f51b861..d9eb97765f0 100644 --- a/source/blender/gpu/vulkan/vk_debug.cc +++ b/source/blender/gpu/vulkan/vk_debug.cc @@ -30,16 +30,21 @@ void VKContext::debug_group_end() debug::pop_marker(device); } -bool VKContext::debug_capture_begin() +bool VKContext::debug_capture_begin(const char *title) { - return VKBackend::get().debug_capture_begin(); + return VKBackend::get().debug_capture_begin(title); } -bool VKBackend::debug_capture_begin() +bool VKBackend::debug_capture_begin(const char *title) { #ifdef WITH_RENDERDOC - return renderdoc_api_.start_frame_capture(device_get().instance_get(), nullptr); + bool result = renderdoc_api_.start_frame_capture(device_get().instance_get(), nullptr); + if (result && title) { + renderdoc_api_.set_frame_capture_title(title); + } + return result; #else + UNUSED_VARS(title); return false; #endif }