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:
parent
936f22d2aa
commit
5d8ae8f988
@ -43,6 +43,7 @@ namespace dxvk::hud {
|
||||
addItem<HudDrawCallStatsItem>("drawcalls", device);
|
||||
addItem<HudPipelineStatsItem>("pipelines", device);
|
||||
addItem<HudMemoryStatsItem>("memory", device);
|
||||
addItem<HudGpuLoadItem>("gpuload", device);
|
||||
}
|
||||
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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();
|
||||
|
||||
};
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user