From 7ac9918b393788aa0d18da39dcc066357c4d6dae Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Wed, 25 Sep 2024 00:11:24 +0200 Subject: [PATCH] [hud] Add cache statistics to detailed memory item --- src/dxvk/hud/dxvk_hud_item.cpp | 24 +++++++++++++++++++++++- src/dxvk/hud/dxvk_hud_item.h | 7 ++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/dxvk/hud/dxvk_hud_item.cpp b/src/dxvk/hud/dxvk_hud_item.cpp index ece35086f..2032cf18d 100644 --- a/src/dxvk/hud/dxvk_hud_item.cpp +++ b/src/dxvk/hud/dxvk_hud_item.cpp @@ -652,7 +652,14 @@ namespace dxvk::hud { void HudMemoryDetailsItem::update(dxvk::high_resolution_clock::time_point time) { - m_device->getMemoryAllocationStats(m_stats); + uint64_t ticks = std::chrono::duration_cast(time - m_lastUpdate).count(); + + if (ticks >= UpdateInterval) { + m_cacheStats = m_device->getMemoryAllocationStats(m_stats); + m_displayCacheStats |= m_cacheStats.requestCount != 0u; + + m_lastUpdate = time; + } } @@ -702,6 +709,9 @@ namespace dxvk::hud { pos.y -= 30.0f + 4.0f; } + if (m_displayCacheStats) + pos.y -= 20.0f; + // Actually render the thing for (uint32_t i = 0; i < m_stats.memoryTypes.size(); i++) { const auto& type = m_stats.memoryTypes.at(i); @@ -747,6 +757,18 @@ namespace dxvk::hud { pos.y += 46.0f; } + if (m_displayCacheStats) { + uint32_t hitCount = m_cacheStats.requestCount - m_cacheStats.missCount; + uint32_t hitRate = (100 * hitCount) / std::max(m_cacheStats.requestCount, 1u); + + std::string cacheStr = str::format("Cache: ", m_cacheStats.size >> 10, " kB (", hitRate, "% hit)"); + + renderer.drawText(14.0f, + { pos.x, pos.y }, + { 1.0f, 1.0f, 1.0f, 1.0f }, + cacheStr); + } + return position; } diff --git a/src/dxvk/hud/dxvk_hud_item.h b/src/dxvk/hud/dxvk_hud_item.h index b5fef160b..9516629b8 100644 --- a/src/dxvk/hud/dxvk_hud_item.h +++ b/src/dxvk/hud/dxvk_hud_item.h @@ -394,7 +394,7 @@ namespace dxvk::hud { * \brief HUD item to display detailed memory allocation info */ class HudMemoryDetailsItem : public HudItem { - + constexpr static int64_t UpdateInterval = 500'000; public: HudMemoryDetailsItem(const Rc& device); @@ -421,6 +421,11 @@ namespace dxvk::hud { Rc m_device; DxvkMemoryAllocationStats m_stats; + DxvkSharedAllocationCacheStats m_cacheStats; + + high_resolution_clock::time_point m_lastUpdate = { }; + + bool m_displayCacheStats = false; Rc m_vs; Rc m_fsBackground;