From e409f05b402db72de7ed44c40ae59922bd324e2d Mon Sep 17 00:00:00 2001 From: Luke Street Date: Sat, 26 Mar 2022 20:23:16 -0400 Subject: [PATCH] aurora: Add graphics debug group stack --- Runtime/Graphics/CCubeRenderer.cpp | 18 ++++++++ Runtime/Graphics/CGraphics.hpp | 20 ++------- Runtime/Particle/CElementGen.cpp | 8 ++++ aurora/include/aurora/gfx.hpp | 10 +++++ aurora/lib/gfx/common.cpp | 71 ++++++++++++++++++++++++++++-- 5 files changed, 108 insertions(+), 19 deletions(-) diff --git a/Runtime/Graphics/CCubeRenderer.cpp b/Runtime/Graphics/CCubeRenderer.cpp index 0c8dae553..6b40cfaf2 100644 --- a/Runtime/Graphics/CCubeRenderer.cpp +++ b/Runtime/Graphics/CCubeRenderer.cpp @@ -287,6 +287,11 @@ void CCubeRenderer::RemoveStaticGeometry(const std::vectorx18_areaIdx), + zeus::skBlue); + CCubeModel* lastModel = nullptr; EDrawableType lastDrawableType = EDrawableType::Invalid; for (u16 idx : Buckets::sBucketIndex) { diff --git a/Runtime/Graphics/CGraphics.hpp b/Runtime/Graphics/CGraphics.hpp index fb2fe0203..04ed49aae 100644 --- a/Runtime/Graphics/CGraphics.hpp +++ b/Runtime/Graphics/CGraphics.hpp @@ -406,22 +406,10 @@ public: // void Draw() const { CGraphics::DrawArray(m_start, m_vec.size() - m_start); } }; -#ifdef BOO_GRAPHICS_DEBUG_GROUPS -class GraphicsDebugGroup { - /* Stack only */ - void* operator new(size_t); - void operator delete(void*); - void* operator new[](size_t); - void operator delete[](void*); - -public: - explicit GraphicsDebugGroup(const char* name, const zeus::CColor& color = zeus::skWhite) { - zeus::simd_floats f(color.mSimd); - CGraphics::g_BooMainCommandQueue->pushDebugGroup(name, f.array()); - } - ~GraphicsDebugGroup() { CGraphics::g_BooMainCommandQueue->popDebugGroup(); } -}; -#define SCOPED_GRAPHICS_DEBUG_GROUP(...) GraphicsDebugGroup _GfxDbg_(__VA_ARGS__); +#ifdef AURORA_GFX_DEBUG_GROUPS +#define SCOPED_GRAPHICS_DEBUG_GROUP(name, ...) \ + OPTICK_EVENT_DYNAMIC(name); \ + aurora::gfx::ScopedDebugGroup _GfxDbg_{name} #else #define SCOPED_GRAPHICS_DEBUG_GROUP(name, ...) OPTICK_EVENT_DYNAMIC(name) #endif diff --git a/Runtime/Particle/CElementGen.cpp b/Runtime/Particle/CElementGen.cpp index 14440fda9..d501328ba 100644 --- a/Runtime/Particle/CElementGen.cpp +++ b/Runtime/Particle/CElementGen.cpp @@ -868,6 +868,8 @@ void CElementGen::Render() { } void CElementGen::RenderModels() { + SCOPED_GRAPHICS_DEBUG_GROUP(fmt::format(FMT_STRING("CElementGen::RenderModels")), zeus::skYellow); + CParticleGlobals::instance()->m_particleAccessParameters = nullptr; if (x26d_26_modelsUseLights) { CGraphics::SetLightState(x274_backupLightActive); @@ -1091,6 +1093,8 @@ void CElementGen::RenderModels() { } void CElementGen::RenderLines() { + SCOPED_GRAPHICS_DEBUG_GROUP(fmt::format(FMT_STRING("CElementGen::RenderLines")), zeus::skYellow); + CGenDescription* desc = x1c_genDesc.GetObj(); CGlobalRandom gr(x27c_randState); @@ -1198,6 +1202,8 @@ void CElementGen::RenderParticles() { return; } + SCOPED_GRAPHICS_DEBUG_GROUP(fmt::format(FMT_STRING("CElementGen::RenderParticles")), zeus::skYellow); + CRealElement* size = desc->x4c_x38_SIZE.get(); if (size && size->IsConstant()) { float sizeVal; @@ -1630,6 +1636,8 @@ void CElementGen::RenderParticles() { } void CElementGen::RenderParticlesIndirectTexture() { + SCOPED_GRAPHICS_DEBUG_GROUP(fmt::format(FMT_STRING("CElementGen::RenderParticlesIndirectTexture")), zeus::skYellow); + CGenDescription* desc = x1c_genDesc.GetObj(); zeus::CTransform systemViewPointMatrix(CGraphics::g_ViewMatrix); diff --git a/aurora/include/aurora/gfx.hpp b/aurora/include/aurora/gfx.hpp index 1334c4cc7..a49365af7 100644 --- a/aurora/include/aurora/gfx.hpp +++ b/aurora/include/aurora/gfx.hpp @@ -132,6 +132,16 @@ struct Light { [[nodiscard]] bool get_dxt_compression_supported() noexcept; +#ifndef NDEBUG +#define AURORA_GFX_DEBUG_GROUPS +#endif +void push_debug_group(zstring_view label) noexcept; +void pop_debug_group() noexcept; +struct ScopedDebugGroup { + inline ScopedDebugGroup(zstring_view label) noexcept { push_debug_group(label); } + inline ~ScopedDebugGroup() noexcept { pop_debug_group(); } +}; + // GX state void bind_texture(GX::TexMapID id, metaforce::EClampMode clamp, const TextureHandle& tex, float lod) noexcept; void unbind_texture(GX::TexMapID id) noexcept; diff --git a/aurora/lib/gfx/common.cpp b/aurora/lib/gfx/common.cpp index 0672b10c6..b13970ccb 100644 --- a/aurora/lib/gfx/common.cpp +++ b/aurora/lib/gfx/common.cpp @@ -19,6 +19,10 @@ static logvisor::Module Log("aurora::gfx"); using gpu::g_device; using gpu::g_queue; +#ifdef AURORA_GFX_DEBUG_GROUPS +std::vector g_debugGroupStack; +#endif + constexpr uint64_t UniformBufferSize = 5242880; // 5mb constexpr uint64_t VertexBufferSize = 5242880; // 5mb constexpr uint64_t IndexBufferSize = 2097152; // 2mb @@ -60,6 +64,9 @@ enum class CommandType { }; struct Command { CommandType type; +#ifdef AURORA_GFX_DEBUG_GROUPS + std::vector debugGroupStack; +#endif union Data { struct SetViewportCommand { float left; @@ -248,7 +255,15 @@ static PipelineRef find_pipeline(PipelineCreateCommand command, NewPipelineCallb return hash; } -static void push_draw_command(ShaderDrawCommand data) { g_commands.push_back({CommandType::Draw, {.draw = data}}); } +static void push_draw_command(ShaderDrawCommand data) { + g_commands.push_back({ + .type = CommandType::Draw, +#ifdef AURORA_GFX_DEBUG_GROUPS + .debugGroupStack = g_debugGroupStack, +#endif + .data = {.draw = data}, + }); +} bool get_dxt_compression_supported() noexcept { return g_device.HasFeature(wgpu::FeatureName::TextureCompressionBC); } @@ -256,7 +271,13 @@ static Command::Data::SetViewportCommand g_cachedViewport; void set_viewport(float left, float top, float width, float height, float znear, float zfar) noexcept { Command::Data::SetViewportCommand cmd{left, top, width, height, znear, zfar}; if (cmd != g_cachedViewport) { - g_commands.push_back({CommandType::SetViewport, {.setViewport = cmd}}); + g_commands.push_back({ + .type = CommandType::SetViewport, +#ifdef AURORA_GFX_DEBUG_GROUPS + .debugGroupStack = g_debugGroupStack, +#endif + .data = {.setViewport = cmd}, + }); g_cachedViewport = cmd; } } @@ -264,7 +285,13 @@ static Command::Data::SetScissorCommand g_cachedScissor; void set_scissor(uint32_t x, uint32_t y, uint32_t w, uint32_t h) noexcept { Command::Data::SetScissorCommand cmd{x, y, w, h}; if (cmd != g_cachedScissor) { - g_commands.push_back({CommandType::SetScissor, {.setScissor = cmd}}); + g_commands.push_back({ + .type = CommandType::SetScissor, +#ifdef AURORA_GFX_DEBUG_GROUPS + .debugGroupStack = g_debugGroupStack, +#endif + .data = {.setScissor = cmd}, + }); g_cachedScissor = cmd; } } @@ -504,8 +531,29 @@ void end_frame(const wgpu::CommandEncoder& cmd) { void render(const wgpu::RenderPassEncoder& pass) { g_currentPipeline = UINT64_MAX; +#ifdef AURORA_GFX_DEBUG_GROUPS + std::vector lastDebugGroupStack; +#endif for (const auto& cmd : g_commands) { +#ifdef AURORA_GFX_DEBUG_GROUPS + { + size_t firstDiff = lastDebugGroupStack.size(); + for (size_t i = 0; i < lastDebugGroupStack.size(); ++i) { + if (i >= cmd.debugGroupStack.size() || cmd.debugGroupStack[i] != lastDebugGroupStack[i]) { + firstDiff = i; + break; + } + } + for (size_t i = firstDiff; i < lastDebugGroupStack.size(); ++i) { + pass.PopDebugGroup(); + } + for (size_t i = firstDiff; i < cmd.debugGroupStack.size(); ++i) { + pass.PushDebugGroup(cmd.debugGroupStack[i].c_str()); + } + lastDebugGroupStack = cmd.debugGroupStack; + } +#endif switch (cmd.type) { case CommandType::SetViewport: { const auto& vp = cmd.data.setViewport; @@ -541,6 +589,12 @@ void render(const wgpu::RenderPassEncoder& pass) { } } +#ifdef AURORA_GFX_DEBUG_GROUPS + for (size_t i = 0; i < lastDebugGroupStack.size(); ++i) { + pass.PopDebugGroup(); + } +#endif + g_commands.clear(); } @@ -659,4 +713,15 @@ uint32_t align_uniform(uint32_t value) { const auto uniform_alignment = limits.limits.minUniformBufferOffsetAlignment; return ALIGN(value, uniform_alignment); } + +void push_debug_group(zstring_view label) noexcept { +#ifdef AURORA_GFX_DEBUG_GROUPS + g_debugGroupStack.emplace_back(label); +#endif +} +void pop_debug_group() noexcept { +#ifdef AURORA_GFX_DEBUG_GROUPS + g_debugGroupStack.pop_back(); +#endif +} } // namespace aurora::gfx