diff --git a/src/dxvk/hud/dxvk_hud.cpp b/src/dxvk/hud/dxvk_hud.cpp index 246a6c4ff..40866d158 100644 --- a/src/dxvk/hud/dxvk_hud.cpp +++ b/src/dxvk/hud/dxvk_hud.cpp @@ -43,6 +43,7 @@ namespace dxvk::hud { addItem("drawcalls", device); addItem("pipelines", device); addItem("memory", device); + addItem("gpuload", device); } diff --git a/src/dxvk/hud/dxvk_hud_item.cpp b/src/dxvk/hud/dxvk_hud_item.cpp index 849b7bcdf..773cae5ae 100644 --- a/src/dxvk/hud/dxvk_hud_item.cpp +++ b/src/dxvk/hud/dxvk_hud_item.cpp @@ -431,4 +431,50 @@ namespace dxvk::hud { return position; } + + HudGpuLoadItem::HudGpuLoadItem(const Rc& device) + : m_device(device) { + + } + + + HudGpuLoadItem::~HudGpuLoadItem() { + + } + + + void HudGpuLoadItem::update(dxvk::high_resolution_clock::time_point time) { + uint64_t ticks = std::chrono::duration_cast(time - m_lastUpdate).count(); + + if (ticks >= UpdateInterval) { + DxvkStatCounters counters = m_device->getStatCounters(); + uint64_t currGpuIdleTicks = counters.getCtr(DxvkStatCounter::GpuIdleTicks); + + m_diffGpuIdleTicks = currGpuIdleTicks - m_prevGpuIdleTicks; + m_prevGpuIdleTicks = currGpuIdleTicks; + + uint64_t busyTicks = ticks > m_diffGpuIdleTicks + ? uint64_t(ticks - m_diffGpuIdleTicks) + : uint64_t(0); + + m_gpuLoadString = str::format("GPU: ", (100 * busyTicks) / ticks, "%"); + m_lastUpdate = time; + } + } + + + HudPos HudGpuLoadItem::render( + HudRenderer& renderer, + HudPos position) { + position.y += 16.0f; + + renderer.drawText(16.0f, + { position.x, position.y }, + { 1.0f, 1.0f, 1.0f, 1.0f }, + m_gpuLoadString); + + 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 c40a2054c..b66ff0684 100644 --- a/src/dxvk/hud/dxvk_hud_item.h +++ b/src/dxvk/hud/dxvk_hud_item.h @@ -322,4 +322,36 @@ namespace dxvk::hud { }; + + /** + * \brief HUD item to display GPU load + */ + class HudGpuLoadItem : public HudItem { + constexpr static int64_t UpdateInterval = 500'000; + public: + + HudGpuLoadItem(const Rc& device); + + ~HudGpuLoadItem(); + + void update(dxvk::high_resolution_clock::time_point time); + + HudPos render( + HudRenderer& renderer, + HudPos position); + + private: + + Rc m_device; + + uint64_t m_prevGpuIdleTicks = 0; + uint64_t m_diffGpuIdleTicks = 0; + + std::string m_gpuLoadString = "GPU: "; + + dxvk::high_resolution_clock::time_point m_lastUpdate + = dxvk::high_resolution_clock::now(); + + }; + } \ No newline at end of file