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

[hud] Add item to display frame latency sleep

This commit is contained in:
Philip Rebohle 2024-10-25 22:58:16 +02:00
parent dc846fd052
commit 3514580452
3 changed files with 70 additions and 1 deletions

View File

@ -682,8 +682,12 @@ namespace dxvk {
void D3D11SwapChain::CreateHud() {
m_hud = hud::Hud::createHud(m_device);
if (m_hud != nullptr)
if (m_hud) {
m_hud->addItem<hud::HudClientApiItem>("api", 1, GetApiName());
if (m_latencyControl)
m_hud->addItem<hud::HudLatencyControlItem>("latency", -1, m_latencyControl);
}
}

View File

@ -1578,4 +1578,37 @@ namespace dxvk::hud {
/ (uint32_t(m_tasksTotal - m_offset));
}
void HudLatencyControlItem::update(dxvk::high_resolution_clock::time_point time) {
uint64_t ticks = std::chrono::duration_cast<std::chrono::microseconds>(time - m_lastUpdate).count();
m_sleepDuration = std::max(m_sleepDuration, m_latencyControl->getLastSleepDuration());
if (ticks >= UpdateInterval) {
uint64_t duration = m_sleepDuration.count() / 100000;
m_sleepDurationText = str::format(duration / 10u, ".", duration % 10u, " ms");
m_sleepDuration = std::chrono::nanoseconds(0);
m_lastUpdate = time;
}
}
HudPos HudLatencyControlItem::render(
const DxvkContextObjects& ctx,
const HudPipelineKey& key,
const HudOptions& options,
HudRenderer& renderer,
HudPos position) {
position.y += 16;
renderer.drawText(16, position, 0xffc0ff00u, "Latency sleep:");
renderer.drawText(16, { position.x + 180, position.y }, 0xffffffffu, m_sleepDurationText);
position.y += 8;
return position;
}
}

View File

@ -1,10 +1,12 @@
#pragma once
#include <chrono>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include "../../util/util_latency.h"
#include "../../util/util_time.h"
#include "../dxvk_gpu_query.h"
@ -719,4 +721,34 @@ namespace dxvk::hud {
};
/**
* \brief Latency control item
*/
class HudLatencyControlItem : public HudItem {
constexpr static int64_t UpdateInterval = 500'000;
public:
HudLatencyControlItem(Rc<DxvkLatencyControl> latencyControl)
: m_latencyControl(std::move(latencyControl)) { }
void update(dxvk::high_resolution_clock::time_point time);
HudPos render(
const DxvkContextObjects& ctx,
const HudPipelineKey& key,
const HudOptions& options,
HudRenderer& renderer,
HudPos position);
private:
Rc<DxvkLatencyControl> m_latencyControl;
std::chrono::nanoseconds m_sleepDuration = { };
std::string m_sleepDurationText;
dxvk::high_resolution_clock::time_point m_lastUpdate = dxvk::high_resolution_clock::now();
};
}