From ac9ed964571932ecce83948da1ddb71b95f33dc7 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Sat, 12 Feb 2022 20:24:02 +0100 Subject: [PATCH] [hud] Add HUD item to show CS thread stats --- src/dxvk/hud/dxvk_hud.cpp | 1 + src/dxvk/hud/dxvk_hud_item.cpp | 79 ++++++++++++++++++++++++++++++++++ src/dxvk/hud/dxvk_hud_item.h | 39 +++++++++++++++++ 3 files changed, 119 insertions(+) diff --git a/src/dxvk/hud/dxvk_hud.cpp b/src/dxvk/hud/dxvk_hud.cpp index c4c3b549..003c1915 100644 --- a/src/dxvk/hud/dxvk_hud.cpp +++ b/src/dxvk/hud/dxvk_hud.cpp @@ -43,6 +43,7 @@ namespace dxvk::hud { addItem("drawcalls", -1, device); addItem("pipelines", -1, device); addItem("memory", -1, device); + addItem("cs", -1, device); addItem("gpuload", -1, device); addItem("compiler", -1, device); } diff --git a/src/dxvk/hud/dxvk_hud_item.cpp b/src/dxvk/hud/dxvk_hud_item.cpp index 716dddda..9cdcbdbb 100644 --- a/src/dxvk/hud/dxvk_hud_item.cpp +++ b/src/dxvk/hud/dxvk_hud_item.cpp @@ -513,6 +513,85 @@ namespace dxvk::hud { } + HudCsThreadItem::HudCsThreadItem(const Rc& device) + : m_device(device) { + + } + + + HudCsThreadItem::~HudCsThreadItem() { + + } + + + void HudCsThreadItem::update(dxvk::high_resolution_clock::time_point time) { + uint64_t ticks = std::chrono::duration_cast(time - m_lastUpdate).count(); + + // Capture the maximum here since it's more useful to + // identify stutters than using any sort of average + DxvkStatCounters counters = m_device->getStatCounters(); + uint64_t currCsSyncCount = counters.getCtr(DxvkStatCounter::CsSyncCount); + uint64_t currCsSyncTicks = counters.getCtr(DxvkStatCounter::CsSyncTicks); + + m_maxCsSyncCount = std::max(m_maxCsSyncCount, currCsSyncCount - m_prevCsSyncCount); + m_maxCsSyncTicks = std::max(m_maxCsSyncTicks, currCsSyncTicks - m_prevCsSyncTicks); + + m_prevCsSyncCount = currCsSyncCount; + m_prevCsSyncTicks = currCsSyncTicks; + + m_updateCount++; + + if (ticks >= UpdateInterval) { + uint64_t currCsChunks = counters.getCtr(DxvkStatCounter::CsChunkCount); + uint64_t diffCsChunks = (currCsChunks - m_prevCsChunks) / m_updateCount; + m_prevCsChunks = currCsChunks; + + uint64_t syncTicks = m_maxCsSyncTicks / 100; + + m_csChunkString = str::format(diffCsChunks); + m_csSyncString = m_maxCsSyncCount + ? str::format(m_maxCsSyncCount, " (", (syncTicks / 10), ".", (syncTicks % 10), " ms)") + : str::format(m_maxCsSyncCount); + + m_maxCsSyncCount = 0; + m_maxCsSyncTicks = 0; + + m_updateCount = 0; + m_lastUpdate = time; + } + } + + + HudPos HudCsThreadItem::render( + HudRenderer& renderer, + HudPos position) { + position.y += 16.0f; + renderer.drawText(16.0f, + { position.x, position.y }, + { 0.25f, 1.0f, 0.25f, 1.0f }, + "CS chunks:"); + + renderer.drawText(16.0f, + { position.x + 132.0f, position.y }, + { 1.0f, 1.0f, 1.0f, 1.0f }, + m_csChunkString); + + position.y += 20.0f; + renderer.drawText(16.0f, + { position.x, position.y }, + { 0.25f, 1.0f, 0.25f, 1.0f }, + "CS syncs:"); + + renderer.drawText(16.0f, + { position.x + 132.0f, position.y }, + { 1.0f, 1.0f, 1.0f, 1.0f }, + m_csSyncString); + + position.y += 8.0f; + return position; + } + + HudGpuLoadItem::HudGpuLoadItem(const Rc& device) : m_device(device) { diff --git a/src/dxvk/hud/dxvk_hud_item.h b/src/dxvk/hud/dxvk_hud_item.h index 84fe5ccd..45ef43b0 100644 --- a/src/dxvk/hud/dxvk_hud_item.h +++ b/src/dxvk/hud/dxvk_hud_item.h @@ -354,6 +354,45 @@ namespace dxvk::hud { }; + /** + * \brief HUD item to display CS thread statistics + */ + class HudCsThreadItem : public HudItem { + constexpr static int64_t UpdateInterval = 500'000; + public: + + HudCsThreadItem(const Rc& device); + + ~HudCsThreadItem(); + + void update(dxvk::high_resolution_clock::time_point time); + + HudPos render( + HudRenderer& renderer, + HudPos position); + + private: + + Rc m_device; + + uint64_t m_prevCsSyncCount = 0; + uint64_t m_prevCsSyncTicks = 0; + uint64_t m_prevCsChunks = 0; + + uint64_t m_maxCsSyncCount = 0; + uint64_t m_maxCsSyncTicks = 0; + + uint64_t m_updateCount = 0; + + std::string m_csSyncString; + std::string m_csChunkString; + + dxvk::high_resolution_clock::time_point m_lastUpdate + = dxvk::high_resolution_clock::now(); + + }; + + /** * \brief HUD item to display GPU load */