Vulkan: Colored debug groups #124108

Open
Jeroen Bakker wants to merge 2 commits from Jeroen-Bakker/blender:vulkan/debug-group-colors into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
29 changed files with 58 additions and 22 deletions

View File

@ -269,6 +269,7 @@ DrawEngineType draw_engine_basic_type = {
/*next*/ nullptr,
/*prev*/ nullptr,
/*idname*/ N_("Basic"),
/*debug_color*/ GPU_DEBUG_GROUP_COLOR_DEFAULT,
/*vedata_size*/ &basic_data_size,
/*engine_init*/ nullptr,
/*engine_free*/ &basic_engine_free,

View File

@ -319,6 +319,7 @@ DrawEngineType draw_engine_compositor_type = {
/*next*/ nullptr,
/*prev*/ nullptr,
/*idname*/ N_("Compositor"),
/*debug_color*/ GPU_DEBUG_GROUP_COLOR_DEFAULT,
/*vedata_size*/ &compositor_data_size,
/*engine_init*/ &compositor_engine_init,
/*engine_free*/ nullptr,

View File

@ -196,6 +196,7 @@ DrawEngineType draw_engine_eevee_next_type = {
/*next*/ nullptr,
/*prev*/ nullptr,
/*idname*/ N_("EEVEE"),
/*debug_color*/ ColorTheme4f(1.0, 0.5, 0.0, 1.0),
/*vedata_size*/ &eevee_data_size,
/*engine_init*/ &eevee_engine_init,
/*engine_free*/ &eevee_engine_free,

View File

@ -443,6 +443,7 @@ DrawEngineType draw_engine_external_type = {
/*next*/ nullptr,
/*prev*/ nullptr,
/*idname*/ N_("External"),
/*debug_color*/ blender::ColorTheme4f(0.0, 0.0, 1.0, 1.0),
/*vedata_size*/ &external_data_size,
/*engine_init*/ &external_engine_init,
/*engine_free*/ &external_engine_free,

View File

@ -1278,6 +1278,7 @@ DrawEngineType draw_engine_gpencil_type = {
/*next*/ nullptr,
/*prev*/ nullptr,
/*idname*/ N_("GpencilMode"),
/*debug_color*/ blender::ColorTheme4f(1.0, 1.0, 0.0, 1.0),
/*vedata_size*/ &GPENCIL_data_size,
/*engine_init*/ &GPENCIL_engine_init,
/*engine_free*/ &GPENCIL_engine_free,

View File

@ -191,6 +191,7 @@ DrawEngineType draw_engine_image_type = {
/*next*/ nullptr,
/*prev*/ nullptr,
/*idname*/ N_("UV/Image"),
/*debug_color*/ blender::ColorTheme4f(0.0, 1.0, 1.0, 1.0),
/*vedata_size*/ &IMAGE_data_size,
/*engine_init*/ &IMAGE_engine_init,
/*engine_free*/ &IMAGE_engine_free,

View File

@ -800,6 +800,7 @@ DrawEngineType draw_engine_overlay_type = {
/*next*/ nullptr,
/*prev*/ nullptr,
/*idname*/ N_("Overlay"),
/*debug_color*/ blender::ColorTheme4f(0.0, 1.0, 0.5, 1.0),
/*vedata_size*/ &overlay_data_size,
/*engine_init*/ &OVERLAY_engine_init,
/*engine_free*/ &OVERLAY_engine_free,

View File

@ -97,6 +97,7 @@ DrawEngineType draw_engine_overlay_next_type = {
/*next*/ nullptr,
/*prev*/ nullptr,
/*idname*/ N_("Overlay"),
/*debug_color*/ blender::ColorTheme4f(0.0, 1.0, 0.5, 1.0),
/*vedata_size*/ &overlay_data_size,
/*engine_init*/ &OVERLAY_next_engine_init,
/*engine_free*/ nullptr,

View File

@ -103,6 +103,7 @@ DrawEngineType draw_engine_debug_select_type = {
/*next*/ nullptr,
/*prev*/ nullptr,
/*idname*/ N_("Select ID Debug"),
/*debug_color*/ GPU_DEBUG_GROUP_COLOR_DEFAULT,
/*vedata_size*/ &select_debug_data_size,
/*engine_init*/ &select_debug_engine_init,
/*engine_free*/ &select_debug_engine_free,

View File

@ -304,6 +304,7 @@ DrawEngineType draw_engine_select_type = {
/*next*/ nullptr,
/*prev*/ nullptr,
/*idname*/ N_("Select ID"),
/*debug_color*/ GPU_DEBUG_GROUP_COLOR_DEFAULT,
/*vedata_size*/ &select_data_size,
/*engine_init*/ &select_engine_init,
/*engine_free*/ &select_engine_free,

View File

@ -85,6 +85,7 @@ DrawEngineType draw_engine_select_next_type = {
/*next*/ nullptr,
/*prev*/ nullptr,
/*idname*/ N_("Select-Next"),
/*debug_color*/ GPU_DEBUG_GROUP_COLOR_DEFAULT,
/*vedata_size*/ &SELECT_next_data_size,
/*engine_init*/ &SELECT_next_engine_init,
/*engine_free*/ nullptr,

View File

@ -794,6 +794,7 @@ DrawEngineType draw_engine_workbench = {
/*next*/ nullptr,
/*prev*/ nullptr,
/*idname*/ N_("Workbench"),
/*debug_color*/ ColorTheme4f(0.5, 1.0, 0.0, 1.0),
/*vedata_size*/ &workbench_data_size,
/*engine_init*/ &workbench_engine_init,
/*engine_free*/ &workbench_engine_free,

View File

@ -119,6 +119,8 @@ struct DrawEngineType {
char idname[32];
blender::ColorTheme4f debug_color;
const DrawEngineDataSize *vedata_size;
void (*engine_init)(void *vedata);

View File

@ -1118,7 +1118,7 @@ static void drw_engines_draw_scene()
DRW_ENABLED_ENGINE_ITER (DST.view_data_active, engine, data) {
PROFILE_START(stime);
if (engine->draw_scene) {
DRW_stats_group_start(engine->idname);
DRW_stats_group_start(engine->idname, engine->debug_color);
engine->draw_scene(data);
/* Restore for next engine */
if (DRW_state_is_fbo()) {

View File

@ -119,11 +119,11 @@ static void drw_stats_timer_start_ex(const char *name, const bool is_query)
}
}
void DRW_stats_group_start(const char *name)
void DRW_stats_group_start(const char *name, const blender::ColorTheme4f &debug_color)
{
drw_stats_timer_start_ex(name, false);
GPU_debug_group_begin(name);
GPU_debug_group_begin(name, debug_color);
}
void DRW_stats_group_end()

View File

@ -8,6 +8,8 @@
#pragma once
#include "GPU_debug.hh"
struct rcti;
void DRW_stats_free();
@ -18,7 +20,8 @@ void DRW_stats_reset();
* Use this to group the queries. It does NOT keep track
* of the time, it only sum what the queries inside it.
*/
void DRW_stats_group_start(const char *name);
void DRW_stats_group_start(
const char *name, const blender::ColorTheme4f &debug_color = GPU_DEBUG_GROUP_COLOR_DEFAULT);
void DRW_stats_group_end();
/**

View File

@ -44,11 +44,15 @@
#pragma once
#include "BLI_color.hh"
#include "BLI_sys_types.h"
#define GPU_DEBUG_SHADER_COMPILATION_GROUP "Shader Compilation"
void GPU_debug_group_begin(const char *name);
static blender::ColorTheme4f GPU_DEBUG_GROUP_COLOR_DEFAULT = {};
void GPU_debug_group_begin(const char *name,
const blender::ColorTheme4f &color = GPU_DEBUG_GROUP_COLOR_DEFAULT);
void GPU_debug_group_end();
/**
* Return a formatted string showing the current group hierarchy in this format:

View File

@ -30,7 +30,7 @@ class DummyContext : public Context {
void memory_statistics_get(int * /*r_total_mem*/, int * /*r_free_mem*/) override {}
void debug_group_begin(const char *, int) override {}
void debug_group_begin(const char *, const ColorTheme4f & /*color*/, int) override {}
void debug_group_end() override {}
bool debug_capture_begin(const char * /*title*/) override
{

View File

@ -12,6 +12,8 @@
#include "MEM_guardedalloc.h"
#include "BLI_color.hh"
#include "GPU_context.hh"
#include "gpu_debug_private.hh"
@ -85,7 +87,7 @@ class Context {
virtual void memory_statistics_get(int *r_total_mem, int *r_free_mem) = 0;
virtual void debug_group_begin(const char *, int){};
virtual void debug_group_begin(const char *, const ColorTheme4f & /*color*/, int){};
virtual void debug_group_end(){};
/* Returns true if capture successfully started. */

View File

@ -19,7 +19,7 @@
using namespace blender;
using namespace blender::gpu;
void GPU_debug_group_begin(const char *name)
void GPU_debug_group_begin(const char *name, const ColorTheme4f &color)
{
if (!(G.debug & G_DEBUG_GPU)) {
return;
@ -27,7 +27,7 @@ void GPU_debug_group_begin(const char *name)
Context *ctx = Context::get();
DebugStack &stack = ctx->debug_stack;
stack.append(StringRef(name));
ctx->debug_group_begin(name, stack.size());
ctx->debug_group_begin(name, color, stack.size());
}
void GPU_debug_group_end()

View File

@ -775,7 +775,7 @@ class MTLContext : public Context {
return static_cast<MTLContext *>(Context::get());
}
void debug_group_begin(const char *name, int index) override;
void debug_group_begin(const char *name, const ColorTheme4f &color, int index) override;
void debug_group_end() override;
bool debug_capture_begin(const char *title) override;
void debug_capture_end() override;

View File

@ -45,7 +45,7 @@ namespace blender::gpu {
* "passes".
* \{ */
void MTLContext::debug_group_begin(const char *name, int index)
void MTLContext::debug_group_begin(const char *name, const ColorTheme4f & /*color*/, int index)
{
if (G.debug & G_DEBUG_GPU) {
this->main_command_buffer.push_debug_group(name, index);

View File

@ -128,7 +128,7 @@ class GLContext : public Context {
void vao_cache_register(GLVaoCache *cache);
void vao_cache_unregister(GLVaoCache *cache);
void debug_group_begin(const char *name, int index) override;
void debug_group_begin(const char *name, const ColorTheme4f &color, int index) override;
void debug_group_end() override;
bool debug_capture_begin(const char *title) override;
void debug_capture_end() override;

View File

@ -381,7 +381,7 @@ namespace blender::gpu {
* Useful for debugging through render-doc. This makes all the API calls grouped into "passes".
* \{ */
void GLContext::debug_group_begin(const char *name, int index)
void GLContext::debug_group_begin(const char *name, const ColorTheme4f & /*color*/, int index)
{
if ((G.debug & G_DEBUG_GPU) &&
(epoxy_gl_version() >= 43 || epoxy_has_gl_extension("GL_KHR_debug")))

View File

@ -190,8 +190,9 @@ void VKCommandBuilder::activate_debug_group(VKRenderGraph &render_graph,
VkDebugUtilsLabelEXT debug_utils_label = {};
debug_utils_label.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_LABEL_EXT;
for (int index : IndexRange(state_.debug_level, num_begins)) {
std::string group_name = render_graph.debug_.group_names[to_group[index]];
debug_utils_label.pLabelName = group_name.c_str();
const VKRenderGraph::DebugGroup &debug_group = render_graph.debug_.groups[to_group[index]];
debug_utils_label.pLabelName = debug_group.name.c_str();
copy_v4_v4(debug_utils_label.color, debug_group.color);
command_buffer.begin_debug_utils_label(&debug_utils_label);
}
}

View File

@ -96,9 +96,9 @@ void VKRenderGraph::submit()
/** \name Debug
* \{ */
void VKRenderGraph::debug_group_begin(const char *name)
void VKRenderGraph::debug_group_begin(const char *name, const ColorTheme4f &color)
{
DebugGroupNameID name_id = debug_.group_names.index_of_or_add(std::string(name));
DebugGroupNameID name_id = debug_.groups.index_of_or_add({std::string(name), color});
debug_.group_stack.append(name_id);
debug_.group_used = false;
}

View File

@ -42,6 +42,7 @@
#include "BKE_global.hh"
#include "BLI_color.hh"
#include "BLI_map.hh"
#include "BLI_utility_mixins.hh"
#include "BLI_vector.hh"
@ -96,8 +97,19 @@ class VKRenderGraph : public NonCopyable {
*/
VKResourceStateTracker &resources_;
struct DebugGroup {
std::string name;
ColorTheme4f color;
BLI_STRUCT_EQUALITY_OPERATORS_2(DebugGroup, name, color)
uint64_t hash() const
{
return get_default_hash<std::string, ColorTheme4f>(name, color);
}
};
struct {
VectorSet<std::string> group_names;
VectorSet<DebugGroup> groups;
/** Current stack of debug group names. */
Vector<DebugGroupNameID> group_stack;
@ -241,7 +253,7 @@ class VKRenderGraph : public NonCopyable {
*
* New nodes added to the render graph will be associated with this debug group.
*/
void debug_group_begin(const char *name);
void debug_group_begin(const char *name, const ColorTheme4f &color);
/**
* Pop the top of the debugging group stack.

View File

@ -58,7 +58,7 @@ class VKContext : public Context, NonCopyable {
void memory_statistics_get(int *r_total_mem_kb, int *r_free_mem_kb) override;
void debug_group_begin(const char *, int) override;
void debug_group_begin(const char *, const ColorTheme4f &color, int) override;
void debug_group_end() override;
bool debug_capture_begin(const char *title) override;
void debug_capture_end() override;

View File

@ -19,9 +19,9 @@
static CLG_LogRef LOG = {"gpu.vulkan"};
namespace blender::gpu {
void VKContext::debug_group_begin(const char *name, int)
void VKContext::debug_group_begin(const char *name, const ColorTheme4f &color, int)
{
render_graph.debug_group_begin(name);
render_graph.debug_group_begin(name, color);
}
void VKContext::debug_group_end()