From 61e22684af32e460b8161f3686dbe1f128646576 Mon Sep 17 00:00:00 2001 From: KJ16609 Date: Thu, 8 Aug 2024 15:39:15 -0400 Subject: [PATCH] Add in profiling counters --- src/editor/src/gui/drawStats.cpp | 22 ++++++++++++ src/engine/EngineContext.cpp | 4 +-- src/engine/profiling/counters.cpp | 40 +++++++++++++++++++++ src/engine/profiling/counters.hpp | 24 +++++++++++++ src/engine/systems/EntityRendererSystem.cpp | 3 ++ 5 files changed, 91 insertions(+), 2 deletions(-) create mode 100644 src/engine/profiling/counters.cpp create mode 100644 src/engine/profiling/counters.hpp diff --git a/src/editor/src/gui/drawStats.cpp b/src/editor/src/gui/drawStats.cpp index 67cfa55..6da54cc 100644 --- a/src/editor/src/gui/drawStats.cpp +++ b/src/editor/src/gui/drawStats.cpp @@ -4,6 +4,7 @@ #include "core.hpp" #include "engine/buffers/Buffer.hpp" #include "engine/literals/size.hpp" +#include "engine/profiling/counters.hpp" #include "safe_include.hpp" namespace fgl::engine::gui @@ -75,6 +76,21 @@ namespace fgl::engine::gui ImGui::Text( "|- %s Unused", to_string( host.free() ).c_str() ); ImGui::Text( "|- %s Available in most allocated buffer", to_string( host.m_largest_free_block ).c_str() ); ImGui::Separator(); + + if ( ImGui::CollapsingHeader( "Buffers" ) ) + { + for ( const auto* buffer : memory::getActiveBuffers() ) + { + ImGui::Text( "Name: %s", "FIXME" ); + ImGui::Text( + "Allocated: %s/%s (%2.1f\%)", + to_string( buffer->used() ).c_str(), + to_string( buffer->size() ).c_str(), + ( static_cast< float >( buffer->used() ) / static_cast< float >( buffer->size() ) * 100.0f ) ); + ImGui::Text( "Largest block: %s", to_string( buffer->largestBlock() ).c_str() ); + ImGui::Separator(); + } + } } void drawStats( const FrameInfo& info ) @@ -82,6 +98,12 @@ namespace fgl::engine::gui ImGui::Begin( "Stats" ); ImGui::Text( "FPS: %0.1f", ImGui::GetIO().Framerate ); + const auto& counters { profiling::getCounters() }; + ImGui::Text( "Models drawn: %zu", counters.models_draw ); + ImGui::Text( "Verts drawn: %zu", counters.verts_drawn ); + + //TODO: This should likely be moved to the just before we start rendering again. + profiling::resetCounters(); if ( ImGui::CollapsingHeader( "Memory" ) ) { diff --git a/src/engine/EngineContext.cpp b/src/engine/EngineContext.cpp index d13c64d..1bd2d12 100644 --- a/src/engine/EngineContext.cpp +++ b/src/engine/EngineContext.cpp @@ -28,11 +28,11 @@ namespace fgl::engine EngineContext::EngineContext() : m_ubo_buffer_pool( 512_KiB, vk::BufferUsageFlagBits::eUniformBuffer, vk::MemoryPropertyFlagBits::eHostVisible ), m_matrix_info_pool( - 512_KiB, + 2_MiB, vk::BufferUsageFlagBits::eVertexBuffer, vk::MemoryPropertyFlagBits::eDeviceLocal | vk::MemoryPropertyFlagBits::eHostVisible ), m_draw_parameter_pool( - 16_KiB, + 1_MiB, vk::BufferUsageFlagBits::eIndirectBuffer, vk::MemoryPropertyFlagBits::eDeviceLocal | vk::MemoryPropertyFlagBits::eHostVisible ), m_delta_time( 0.0 ) diff --git a/src/engine/profiling/counters.cpp b/src/engine/profiling/counters.cpp new file mode 100644 index 0000000..a834e1f --- /dev/null +++ b/src/engine/profiling/counters.cpp @@ -0,0 +1,40 @@ +// +// Created by kj16609 on 8/8/24. +// + +#include "counters.hpp" + +#include +#include + +namespace fgl::engine::profiling +{ + inline static Counters counters; + + Counters& getCounters() + { + return counters; + } + + void addModelDrawn( std::size_t n ) + { + counters.models_draw += n; + } + + void addVertexDrawn( std::size_t n ) + { + counters.verts_drawn += n; + } + + void resetCounters() + { + counters.verts_drawn = 0; + counters.models_draw = 0; + } + + // In order for resetCounters to work we need to ensure we can just zero the struct. + // It being trivially copyable fits this requirement + static_assert( std::is_trivially_copyable_v< Counters > ); + static_assert( std::is_trivially_default_constructible_v< Counters > ); + +} // namespace fgl::engine::profiling diff --git a/src/engine/profiling/counters.hpp b/src/engine/profiling/counters.hpp new file mode 100644 index 0000000..d567c20 --- /dev/null +++ b/src/engine/profiling/counters.hpp @@ -0,0 +1,24 @@ +// +// Created by kj16609 on 8/8/24. +// + +#pragma once + +#include + +namespace fgl::engine::profiling +{ + struct Counters + { + std::size_t verts_drawn; + std::size_t models_draw; + }; + + Counters& getCounters(); + + void addModelDrawn( std::size_t n = 1 ); + void addVertexDrawn( std::size_t n ); + + void resetCounters(); + +} // namespace fgl::engine::profiling diff --git a/src/engine/systems/EntityRendererSystem.cpp b/src/engine/systems/EntityRendererSystem.cpp index b762c95..7140b06 100644 --- a/src/engine/systems/EntityRendererSystem.cpp +++ b/src/engine/systems/EntityRendererSystem.cpp @@ -10,6 +10,7 @@ #include "DrawPair.hpp" #include "engine/camera/Camera.hpp" #include "engine/literals/size.hpp" +#include "engine/profiling/counters.hpp" #include "engine/tree/octtree/OctTreeNode.hpp" namespace fgl::engine @@ -132,6 +133,8 @@ namespace fgl::engine if ( draw_commands.empty() ) return; + profiling::addModelDrawn( model_matricies.size() ); + auto& model_matrix_info_buffer { m_textured_model_matrix_info_buffers[ info.frame_idx ] }; model_matrix_info_buffer = std::make_unique< ModelMatrixInfoBufferSuballocation >( info.model_matrix_info_buffer, model_matricies );