aurora: Add graphics debug group stack

This commit is contained in:
Luke Street 2022-03-26 20:23:16 -04:00
parent 67818aaabc
commit e409f05b40
5 changed files with 108 additions and 19 deletions

View File

@ -287,6 +287,11 @@ void CCubeRenderer::RemoveStaticGeometry(const std::vector<CMetroidModelInstance
}
void CCubeRenderer::DrawUnsortedGeometry(s32 areaIdx, s32 mask, s32 targetMask, bool shadowRender) {
SCOPED_GRAPHICS_DEBUG_GROUP(
fmt::format(FMT_STRING("CCubeRenderer::DrawUnsortedGeometry areaIdx={} mask={} targetMask={} shadowRender={}"),
areaIdx, mask, targetMask, shadowRender),
zeus::skBlue);
SetupRendererStates(true);
CModelFlags flags;
CAreaListItem* lastOctreeItem = nullptr;
@ -359,6 +364,11 @@ void CCubeRenderer::DrawUnsortedGeometry(s32 areaIdx, s32 mask, s32 targetMask,
}
void CCubeRenderer::DrawSortedGeometry(s32 areaIdx, s32 mask, s32 targetMask) {
SCOPED_GRAPHICS_DEBUG_GROUP(
fmt::format(FMT_STRING("CCubeRenderer::DrawSortedGeometry areaIdx={} mask={} targetMask={}"), areaIdx, mask,
targetMask),
zeus::skBlue);
SetupRendererStates(true);
const CAreaListItem* item = nullptr;
for (const auto& areaListItem : x1c_areaListItems) {
@ -387,6 +397,11 @@ void CCubeRenderer::DrawStaticGeometry(s32 areaIdx, s32 mask, s32 targetMask) {
}
void CCubeRenderer::DrawAreaGeometry(s32 areaIdx, s32 mask, s32 targetMask) {
SCOPED_GRAPHICS_DEBUG_GROUP(
fmt::format(FMT_STRING("CCubeRenderer::DrawAreaGeometry areaIdx={} mask={} targetMask={}"), areaIdx, mask,
targetMask),
zeus::skBlue);
x318_30_inAreaDraw = true;
SetupRendererStates(true);
constexpr CModelFlags flags{0, 0, 3, zeus::skWhite};
@ -427,6 +442,9 @@ void CCubeRenderer::DrawAreaGeometry(s32 areaIdx, s32 mask, s32 targetMask) {
}
void CCubeRenderer::RenderBucketItems(const CAreaListItem* item) {
SCOPED_GRAPHICS_DEBUG_GROUP(fmt::format(FMT_STRING("CCubeRenderer::RenderBucketItems areaIdx={}"), item->x18_areaIdx),
zeus::skBlue);
CCubeModel* lastModel = nullptr;
EDrawableType lastDrawableType = EDrawableType::Invalid;
for (u16 idx : Buckets::sBucketIndex) {

View File

@ -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

View File

@ -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);

View File

@ -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;

View File

@ -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<std::string> 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<std::string> 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<std::string> 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