From e641ea69fe2ebf3837be36edee831ee459132d84 Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Tue, 9 Oct 2018 08:55:10 -0700 Subject: Improve memory usage stats reporting in Vk backend --- .../include/VulkanDynamicHeap.h | 6 ++-- .../GraphicsEngineVulkan/src/VulkanDynamicHeap.cpp | 36 ++++++++++++++-------- .../GraphicsEngineVulkan/src/VulkanUploadHeap.cpp | 4 ++- .../src/VulkanUtilities/VulkanMemoryManager.cpp | 17 ++++++---- 4 files changed, 41 insertions(+), 22 deletions(-) (limited to 'Graphics/GraphicsEngineVulkan') diff --git a/Graphics/GraphicsEngineVulkan/include/VulkanDynamicHeap.h b/Graphics/GraphicsEngineVulkan/include/VulkanDynamicHeap.h index 4c162aea..b76d0d6c 100644 --- a/Graphics/GraphicsEngineVulkan/include/VulkanDynamicHeap.h +++ b/Graphics/GraphicsEngineVulkan/include/VulkanDynamicHeap.h @@ -213,10 +213,12 @@ private: const Uint32 m_MasterBlockSize; Uint32 m_AvailableSize = 0; - Uint32 m_CurrAllocatedSize = 0; + Uint32 m_CurrAlignedSize = 0; Uint32 m_CurrUsedSize = 0; - Uint32 m_PeakAllocatedSize = 0; + Uint32 m_PeakAlignedSize = 0; Uint32 m_PeakUsedSize = 0; + Uint32 m_CurrAllocatedSize = 0; + Uint32 m_PeakAllocatedSize = 0; }; } diff --git a/Graphics/GraphicsEngineVulkan/src/VulkanDynamicHeap.cpp b/Graphics/GraphicsEngineVulkan/src/VulkanDynamicHeap.cpp index d14d3fb4..2d28141a 100644 --- a/Graphics/GraphicsEngineVulkan/src/VulkanDynamicHeap.cpp +++ b/Graphics/GraphicsEngineVulkan/src/VulkanDynamicHeap.cpp @@ -208,8 +208,9 @@ VulkanDynamicAllocation VulkanDynamicHeap::Allocate(Uint32 SizeInBytes, Uint32 A if (MasterBlock.IsValid()) { AlignedOffset = Align(MasterBlock.UnalignedOffset, size_t{Alignment}); - AlignedSize = MasterBlock.Size; + AlignedSize = MasterBlock.Size; VERIFY_EXPR(MasterBlock.Size >= SizeInBytes + (AlignedOffset - MasterBlock.UnalignedOffset)); + m_CurrAllocatedSize += static_cast(MasterBlock.Size); m_MasterBlocks.emplace_back(MasterBlock); } } @@ -220,9 +221,10 @@ VulkanDynamicAllocation VulkanDynamicHeap::Allocate(Uint32 SizeInBytes, Uint32 A auto MasterBlock = m_GlobalDynamicMemMgr.AllocateMasterBlock(m_MasterBlockSize, 0); if (MasterBlock.IsValid()) { - m_CurrOffset = MasterBlock.UnalignedOffset; + m_CurrOffset = MasterBlock.UnalignedOffset; + m_CurrAllocatedSize += static_cast(MasterBlock.Size); + m_AvailableSize = static_cast(MasterBlock.Size); m_MasterBlocks.emplace_back(MasterBlock); - m_AvailableSize = m_MasterBlockSize; } } @@ -243,10 +245,11 @@ VulkanDynamicAllocation VulkanDynamicHeap::Allocate(Uint32 SizeInBytes, Uint32 A // Every device context uses its own dynamic heap, so there is no need to lock if(AlignedOffset != InvalidOffset) { - m_CurrAllocatedSize += static_cast(AlignedSize); - m_CurrUsedSize += SizeInBytes; - m_PeakAllocatedSize = std::max(m_PeakAllocatedSize, m_CurrAllocatedSize); - m_PeakUsedSize = std::max(m_PeakUsedSize, m_CurrUsedSize); + m_CurrAlignedSize += static_cast(AlignedSize); + m_CurrUsedSize += SizeInBytes; + m_PeakAlignedSize = std::max(m_PeakAlignedSize, m_CurrAlignedSize); + m_PeakUsedSize = std::max(m_PeakUsedSize, m_CurrUsedSize); + m_PeakAllocatedSize = std::max(m_PeakAllocatedSize, m_CurrAllocatedSize); VERIFY_EXPR((AlignedOffset & (Alignment-1)) == 0); return VulkanDynamicAllocation{ m_GlobalDynamicMemMgr, AlignedOffset, SizeInBytes }; @@ -260,20 +263,27 @@ void VulkanDynamicHeap::ReleaseMasterBlocks(RenderDeviceVkImpl& DeviceVkImpl, Ui m_GlobalDynamicMemMgr.ReleaseMasterBlocks(m_MasterBlocks, DeviceVkImpl, CmdQueueMask); m_MasterBlocks.clear(); - m_CurrOffset = InvalidOffset; - m_AvailableSize = 0; + m_CurrOffset = InvalidOffset; + m_AvailableSize = 0; - m_CurrAllocatedSize = 0; - m_CurrUsedSize = 0; + m_CurrUsedSize = 0; + m_CurrAlignedSize = 0; + m_CurrAllocatedSize = 0; } VulkanDynamicHeap::~VulkanDynamicHeap() { DEV_CHECK_ERR(m_MasterBlocks.empty(), m_MasterBlocks.size(), " master block(s) have not been returned to dynamic memory manager"); + auto PeakAllocatedPages = m_PeakAllocatedSize / m_MasterBlockSize; LOG_INFO_MESSAGE(m_HeapName, " usage stats:\n" - " Peak used/peak allocated size: ", FormatMemorySize(m_PeakUsedSize, 2, m_PeakAllocatedSize), '/', FormatMemorySize(m_PeakAllocatedSize, 2, m_PeakAllocatedSize), - ". Peak utilization: ", std::fixed, std::setprecision(1), static_cast(m_PeakUsedSize) / static_cast(std::max(m_PeakAllocatedSize, 1U)) * 100.0, '%'); + " Peak used/aligned/allocated size: ", FormatMemorySize(m_PeakUsedSize, 2, m_PeakAllocatedSize), " / ", + FormatMemorySize(m_PeakAlignedSize, 2, m_PeakAllocatedSize), " / ", + FormatMemorySize(m_PeakAllocatedSize, 2, m_PeakAllocatedSize), + " (", PeakAllocatedPages, (PeakAllocatedPages == 1 ? " page)" : " pages)"), + ". Peak efficiency (used/aligned): ", std::fixed, std::setprecision(1), static_cast(m_PeakUsedSize) / static_cast(std::max(m_PeakAlignedSize, 1U)) * 100.0, '%', + ". Peak utilization (used/allocated): ", std::fixed, std::setprecision(1), static_cast(m_PeakUsedSize) / static_cast(std::max(m_PeakAllocatedSize, 1U)) * 100.0, '%' + ); } } diff --git a/Graphics/GraphicsEngineVulkan/src/VulkanUploadHeap.cpp b/Graphics/GraphicsEngineVulkan/src/VulkanUploadHeap.cpp index 040a2942..90c0c16d 100644 --- a/Graphics/GraphicsEngineVulkan/src/VulkanUploadHeap.cpp +++ b/Graphics/GraphicsEngineVulkan/src/VulkanUploadHeap.cpp @@ -40,7 +40,9 @@ VulkanUploadHeap::VulkanUploadHeap(RenderDeviceVkImpl& RenderDevice, VulkanUploadHeap::~VulkanUploadHeap() { DEV_CHECK_ERR(m_Pages.empty(), "Upload heap '", m_HeapName, "' not all pages are released"); - LOG_INFO_MESSAGE(m_HeapName, " peak used/peak allocated frame size: ", FormatMemorySize(m_PeakFrameSize, 2, m_PeakAllocatedSize), '/', FormatMemorySize(m_PeakAllocatedSize, 2)); + auto PeakAllocatedPages = m_PeakAllocatedSize / m_PageSize; + LOG_INFO_MESSAGE(m_HeapName, " peak used/allocated frame size: ", FormatMemorySize(m_PeakFrameSize, 2, m_PeakAllocatedSize), " / ", FormatMemorySize(m_PeakAllocatedSize, 2), + " (", PeakAllocatedPages, (PeakAllocatedPages == 1 ? " page)" : " pages)") ); } VulkanUploadHeap::UploadPageInfo VulkanUploadHeap::CreateNewPage(VkDeviceSize SizeInBytes)const diff --git a/Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanMemoryManager.cpp b/Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanMemoryManager.cpp index 5f531c9a..54249e59 100644 --- a/Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanMemoryManager.cpp +++ b/Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanMemoryManager.cpp @@ -208,13 +208,18 @@ void VulkanMemoryManager::OnFreeAllocation(VkDeviceSize Size, bool IsHostVisble) VulkanMemoryManager::~VulkanMemoryManager() { + auto PeakDeviceLocalPages = m_PeakAllocatedSize[0] / m_DeviceLocalPageSize; + auto PeakHostVisisblePages = m_PeakAllocatedSize[1] / m_HostVisiblePageSize; LOG_INFO_MESSAGE("VulkanMemoryManager '", m_MgrName, "' stats:\n" - " Peak used/peak allocated device-local memory size: ", - Diligent::FormatMemorySize(m_PeakUsedSize[0], 2, m_PeakAllocatedSize[0]), "/", - Diligent::FormatMemorySize( m_PeakAllocatedSize[0], 2, m_PeakAllocatedSize[0]), - "\n Peak used/peak allocated host-visible memory size: ", - Diligent::FormatMemorySize(m_PeakUsedSize[1], 2, m_PeakAllocatedSize[1]), "/", - Diligent::FormatMemorySize(m_PeakAllocatedSize[1], 2, m_PeakAllocatedSize[1])); + " Peak used/allocated device-local memory size: ", + Diligent::FormatMemorySize(m_PeakUsedSize[0], 2, m_PeakAllocatedSize[0]), " / ", + Diligent::FormatMemorySize(m_PeakAllocatedSize[0], 2, m_PeakAllocatedSize[0]), + " (", PeakDeviceLocalPages, (PeakDeviceLocalPages == 1 ? " page)" : " pages)"), + "\n Peak used/allocated host-visible memory size: ", + Diligent::FormatMemorySize(m_PeakUsedSize[1], 2, m_PeakAllocatedSize[1]), " / ", + Diligent::FormatMemorySize(m_PeakAllocatedSize[1], 2, m_PeakAllocatedSize[1]), + " (", PeakHostVisisblePages, (PeakHostVisisblePages == 1 ? " page)" : " pages)") + ); for(auto it=m_Pages.begin(); it != m_Pages.end(); ++it ) VERIFY(it->second.IsEmpty(), "The page contains outstanding allocations"); -- cgit v1.2.3