1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2025-02-18 04:54:15 +01:00

[hud] Implement GPU load display as a HUD item

This commit is contained in:
Philip Rebohle 2019-12-13 11:45:02 +01:00
parent 936f22d2aa
commit 5d8ae8f988
No known key found for this signature in database
GPG Key ID: C8CC613427A31C99
3 changed files with 79 additions and 0 deletions

View File

@ -43,6 +43,7 @@ namespace dxvk::hud {
addItem<HudDrawCallStatsItem>("drawcalls", device);
addItem<HudPipelineStatsItem>("pipelines", device);
addItem<HudMemoryStatsItem>("memory", device);
addItem<HudGpuLoadItem>("gpuload", device);
}

View File

@ -431,4 +431,50 @@ namespace dxvk::hud {
return position;
}
HudGpuLoadItem::HudGpuLoadItem(const Rc<DxvkDevice>& device)
: m_device(device) {
}
HudGpuLoadItem::~HudGpuLoadItem() {
}
void HudGpuLoadItem::update(dxvk::high_resolution_clock::time_point time) {
uint64_t ticks = std::chrono::duration_cast<std::chrono::microseconds>(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;
}
}

View File

@ -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<DxvkDevice>& device);
~HudGpuLoadItem();
void update(dxvk::high_resolution_clock::time_point time);
HudPos render(
HudRenderer& renderer,
HudPos position);
private:
Rc<DxvkDevice> 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();
};
}