From 52756deac9258cb7775feb5ff0d42a141a36479a Mon Sep 17 00:00:00 2001 From: Luke Street Date: Mon, 2 May 2022 23:31:14 -0400 Subject: [PATCH] aurora: Reduce buffer sizes; add buffer size debug overlay --- Runtime/ImGuiConsole.cpp | 25 +++++++++++++++++++++++++ aurora/lib/gfx/common.cpp | 23 +++++++++++++++-------- 2 files changed, 40 insertions(+), 8 deletions(-) diff --git a/Runtime/ImGuiConsole.cpp b/Runtime/ImGuiConsole.cpp index 249b996e0..0011db84d 100644 --- a/Runtime/ImGuiConsole.cpp +++ b/Runtime/ImGuiConsole.cpp @@ -740,6 +740,20 @@ std::optional ImGuiConsole::ShowAboutWindow(bool canClose, std::str return result; } +static std::string BytesToString(size_t bytes) { + constexpr std::array suffixes{"B"sv, "KB"sv, "MB"sv, "GB"sv, "TB"sv, "PB"sv, "EB"sv}; + u32 s = 0; + auto count = static_cast(bytes); + while (count >= 1024.0 && s < 7) { + s++; + count /= 1024.0; + } + if (count - floor(count) == 0.0) { + return fmt::format("{}{}", static_cast(count), suffixes[s]); + } + return fmt::format("{:.1f}{}", count, suffixes[s]); +} + void ImGuiConsole::ShowDebugOverlay() { if (!m_frameCounter && !m_frameRate && !m_inGameTime && !m_roomTimer && !m_playerInfo && !m_areaInfo && !m_worldInfo && !m_randomStats && !m_resourceStats && !m_pipelineInfo) { @@ -907,6 +921,17 @@ void ImGuiConsole::ShowDebugOverlay() { ImGuiStringViewText(fmt::format(FMT_STRING("Queued pipelines: {}\n"), aurora::gfx::queuedPipelines)); ImGuiStringViewText(fmt::format(FMT_STRING("Done pipelines: {}\n"), aurora::gfx::createdPipelines)); + ImGuiStringViewText( + fmt::format(FMT_STRING("Vertex size: {}\n"), BytesToString(aurora::gfx::g_lastVertSize))); + ImGuiStringViewText( + fmt::format(FMT_STRING("Uniform size: {}\n"), BytesToString(aurora::gfx::g_lastUniformSize))); + ImGuiStringViewText( + fmt::format(FMT_STRING("Index size: {}\n"), BytesToString(aurora::gfx::g_lastIndexSize))); + ImGuiStringViewText( + fmt::format(FMT_STRING("Storage size: {}\n"), BytesToString(aurora::gfx::g_lastStorageSize))); + ImGuiStringViewText(fmt::format(FMT_STRING("Total: {}\n"), + BytesToString(aurora::gfx::g_lastVertSize + aurora::gfx::g_lastUniformSize + + aurora::gfx::g_lastIndexSize + aurora::gfx::g_lastStorageSize))); } ShowCornerContextMenu(m_debugOverlayCorner, m_inputOverlayCorner); } diff --git a/aurora/lib/gfx/common.cpp b/aurora/lib/gfx/common.cpp index 528af39dd..73caa2679 100644 --- a/aurora/lib/gfx/common.cpp +++ b/aurora/lib/gfx/common.cpp @@ -21,10 +21,10 @@ using gpu::g_queue; std::vector g_debugGroupStack; #endif -constexpr uint64_t UniformBufferSize = 5242880; // 5mb -constexpr uint64_t VertexBufferSize = 5242880; // 5mb -constexpr uint64_t IndexBufferSize = 2097152; // 2mb -constexpr uint64_t StorageBufferSize = 134217728; // 128mb +constexpr uint64_t UniformBufferSize = 3145728; // 3mb +constexpr uint64_t VertexBufferSize = 3145728; // 3mb +constexpr uint64_t IndexBufferSize = 1048576; // 1mb +constexpr uint64_t StorageBufferSize = 8388608; // 8mb constexpr uint64_t StagingBufferSize = UniformBufferSize + VertexBufferSize + IndexBufferSize + StorageBufferSize; @@ -358,6 +358,12 @@ void begin_frame() { mapBuffer(g_storage, StorageBufferSize); } +// for imgui debug +size_t g_lastVertSize; +size_t g_lastUniformSize; +size_t g_lastIndexSize; +size_t g_lastStorageSize; + void end_frame(const wgpu::CommandEncoder& cmd) { uint64_t bufferOffset = 0; const auto writeBuffer = [&](ByteBuffer& buf, wgpu::Buffer& out, uint64_t size, std::string_view label) { @@ -367,12 +373,13 @@ void end_frame(const wgpu::CommandEncoder& cmd) { buf.clear(); } bufferOffset += size; + return writeSize; }; g_stagingBuffers[currentStagingBuffer].Unmap(); - writeBuffer(g_verts, g_vertexBuffer, VertexBufferSize, "Vertex"); - writeBuffer(g_uniforms, g_uniformBuffer, UniformBufferSize, "Uniform"); - writeBuffer(g_indices, g_indexBuffer, IndexBufferSize, "Index"); - writeBuffer(g_storage, g_storageBuffer, StorageBufferSize, "Storage"); + g_lastVertSize = writeBuffer(g_verts, g_vertexBuffer, VertexBufferSize, "Vertex"); + g_lastUniformSize = writeBuffer(g_uniforms, g_uniformBuffer, UniformBufferSize, "Uniform"); + g_lastIndexSize = writeBuffer(g_indices, g_indexBuffer, IndexBufferSize, "Index"); + g_lastStorageSize = writeBuffer(g_storage, g_storageBuffer, StorageBufferSize, "Storage"); currentStagingBuffer = (currentStagingBuffer + 1) % g_stagingBuffers.size(); map_staging_buffer(); }