From 3de849969712f56eb8aebff00a967f1d5591fd72 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Fri, 13 Dec 2019 10:56:46 +0100 Subject: [PATCH] [hud] Implement draw call stats display as a HUD item --- src/dxvk/hud/dxvk_hud.cpp | 1 + src/dxvk/hud/dxvk_hud_item.cpp | 53 ++++++++++++++++++++++++++++++++++ src/dxvk/hud/dxvk_hud_item.h | 27 +++++++++++++++++ 3 files changed, 81 insertions(+) diff --git a/src/dxvk/hud/dxvk_hud.cpp b/src/dxvk/hud/dxvk_hud.cpp index 0af4fec6..9cbb4ed9 100644 --- a/src/dxvk/hud/dxvk_hud.cpp +++ b/src/dxvk/hud/dxvk_hud.cpp @@ -40,6 +40,7 @@ namespace dxvk::hud { addItem("fps"); addItem("frametimes"); addItem("submissions", device); + addItem("drawcalls", device); } diff --git a/src/dxvk/hud/dxvk_hud_item.cpp b/src/dxvk/hud/dxvk_hud_item.cpp index b803670b..ef742900 100644 --- a/src/dxvk/hud/dxvk_hud_item.cpp +++ b/src/dxvk/hud/dxvk_hud_item.cpp @@ -293,4 +293,57 @@ namespace dxvk::hud { return position; } + + HudDrawCallStatsItem::HudDrawCallStatsItem(const Rc& device) + : m_device(device) { + + } + + + HudDrawCallStatsItem::~HudDrawCallStatsItem() { + + } + + + void HudDrawCallStatsItem::update(dxvk::high_resolution_clock::time_point time) { + DxvkStatCounters counters = m_device->getStatCounters(); + + m_diffCounters = counters.diff(m_prevCounters); + m_prevCounters = counters; + } + + + HudPos HudDrawCallStatsItem::render( + HudRenderer& renderer, + HudPos position) { + uint64_t gpCalls = m_diffCounters.getCtr(DxvkStatCounter::CmdDrawCalls); + uint64_t cpCalls = m_diffCounters.getCtr(DxvkStatCounter::CmdDispatchCalls); + uint64_t rpCalls = m_diffCounters.getCtr(DxvkStatCounter::CmdRenderPassCount); + + std::string strDrawCalls = str::format("Draw calls: ", gpCalls); + std::string strDispatchCalls = str::format("Dispatch calls: ", cpCalls); + std::string strRenderPasses = str::format("Render passes: ", rpCalls); + + position.y += 16.0f; + renderer.drawText(16.0f, + { position.x, position.y }, + { 1.0f, 1.0f, 1.0f, 1.0f }, + strDrawCalls); + + position.y += 20.0f; + renderer.drawText(16.0f, + { position.x, position.y }, + { 1.0f, 1.0f, 1.0f, 1.0f }, + strDispatchCalls); + + position.y += 20.0f; + renderer.drawText(16.0f, + { position.x, position.y }, + { 1.0f, 1.0f, 1.0f, 1.0f }, + strRenderPasses); + + position.y += 8.0f; + return position; + } + } diff --git a/src/dxvk/hud/dxvk_hud_item.h b/src/dxvk/hud/dxvk_hud_item.h index 1d327fe8..5924614c 100644 --- a/src/dxvk/hud/dxvk_hud_item.h +++ b/src/dxvk/hud/dxvk_hud_item.h @@ -242,4 +242,31 @@ namespace dxvk::hud { }; + + /** + * \brief HUD item to display draw call counts + */ + class HudDrawCallStatsItem : public HudItem { + + public: + + HudDrawCallStatsItem(const Rc& device); + + ~HudDrawCallStatsItem(); + + void update(dxvk::high_resolution_clock::time_point time); + + HudPos render( + HudRenderer& renderer, + HudPos position); + + private: + + Rc m_device; + + DxvkStatCounters m_prevCounters; + DxvkStatCounters m_diffCounters; + + }; + } \ No newline at end of file