Put GetTimestamp into Utils

This commit is contained in:
FakeMichau committed 2026-09-25 20:30:05 +02:00
1 parent 20d9d147a4
commit 1875b8a99b
10 files changed
+51 -61

No files matched your search

+10
View File
@@ -933,3 +933,13 @@ std::map<Util::Luid, std::filesystem::path> Util::GetDriverStore()
return result;
}
uint64_t Util::GetTimestamp()
{
FILETIME fileTime;
GetSystemTimePreciseAsFileTime(&fileTime);
uint64_t time = (static_cast<uint64_t>(fileTime.dwHighDateTime) << 32) | fileTime.dwLowDateTime;
return time * 100;
}
+1
View File
@@ -57,6 +57,7 @@ void LoadProxyLibrary(const std::wstring& name, const std::wstring& optiPath, co
HMODULE* memoryModule, HMODULE* loadedModule);
std::map<Luid, std::filesystem::path> GetDriverStore();
uint64_t GetTimestamp();
template <typename T> void DelayedDestroy(std::unique_ptr<T> ptr)
{
@@ -250,7 +250,7 @@ bool InputCommon::update_low_latency_tech(IUnknown* pDevice, std::optional<LowLa
void InputCommon::add_marker_to_report(const MarkerParams& marker_params)
{
auto current_timestamp = get_timestamp() / 1000;
auto current_timestamp = Util::GetTimestamp() / 1000;
static auto last_sim_start = current_timestamp;
static auto _2nd_last_sim_start = current_timestamp;
auto current_report = &frame_reports[marker_params.frame_id % FRAME_REPORTS_BUFFER_SIZE];
@@ -273,26 +273,26 @@ void InputCommon::add_marker_to_report(const MarkerParams& marker_params)
{
case MarkerType::SIMULATION_START:
_2nd_last_sim_start = last_sim_start;
last_sim_start = get_timestamp() / 1000;
last_sim_start = Util::GetTimestamp() / 1000;
current_report->simStartTime = last_sim_start;
break;
case MarkerType::SIMULATION_END:
current_report->simEndTime = get_timestamp() / 1000;
current_report->simEndTime = Util::GetTimestamp() / 1000;
break;
case MarkerType::RENDERSUBMIT_START:
current_report->renderSubmitStartTime = get_timestamp() / 1000;
current_report->renderSubmitStartTime = Util::GetTimestamp() / 1000;
break;
case MarkerType::RENDERSUBMIT_END:
current_report->renderSubmitEndTime = get_timestamp() / 1000;
current_report->renderSubmitEndTime = Util::GetTimestamp() / 1000;
break;
case MarkerType::PRESENT_START:
current_report->presentStartTime = get_timestamp() / 1000;
current_report->presentStartTime = Util::GetTimestamp() / 1000;
break;
case MarkerType::PRESENT_END:
current_report->presentEndTime = get_timestamp() / 1000;
current_report->presentEndTime = Util::GetTimestamp() / 1000;
break;
case MarkerType::INPUT_SAMPLE:
current_report->inputSampleTime = get_timestamp() / 1000;
current_report->inputSampleTime = Util::GetTimestamp() / 1000;
break;
default:
break;
+4 -14
View File
@@ -56,16 +56,6 @@ void tonvss(NvAPI_ShortString nvss, std::string str);
if (std::string(it->func) == #method) \
return fakenvapi::idToFuncMapping.insert({ id, (void*) nvapi_calls::method }).first->second;
static inline uint64_t get_timestamp()
{
FILETIME fileTime;
GetSystemTimePreciseAsFileTime(&fileTime);
uint64_t time = (static_cast<uint64_t>(fileTime.dwHighDateTime) << 32) | fileTime.dwLowDateTime;
return time * 100;
}
// https://learn.microsoft.com/en-us/windows/win32/sync/using-waitable-timer-objects
inline int timer_sleep(int64_t hundred_ns)
{
@@ -88,11 +78,11 @@ inline int timer_sleep(int64_t hundred_ns)
inline int busywait_sleep(int64_t ns)
{
auto current_time = get_timestamp();
auto current_time = Util::GetTimestamp();
auto wait_until = current_time + ns;
while (current_time < wait_until)
{
current_time = get_timestamp();
current_time = Util::GetTimestamp();
}
return 0;
}
@@ -103,13 +93,13 @@ inline int eepy(int64_t ns)
int status;
auto current_time = get_timestamp();
auto current_time = Util::GetTimestamp();
if (ns <= busywait_threshold)
status = busywait_sleep(ns);
else
status = timer_sleep((ns - busywait_threshold) / 100);
if (int64_t sleep_deviation = ns - (get_timestamp() - current_time); sleep_deviation > 0 && !status)
if (int64_t sleep_deviation = ns - (Util::GetTimestamp() - current_time); sleep_deviation > 0 && !status)
status = busywait_sleep(sleep_deviation);
return status;
@@ -11,13 +11,13 @@ inline HRESULT AntiLag2::al2_sleep()
// if (effective_fg_state && minimum_interval_us != 0) {
// static uint64_t previous_frame_time = 0;
// uint64_t current_time = get_timestamp();
// uint64_t current_time = Util::GetTimestamp();
// uint64_t frame_time = current_time - previous_frame_time;
// if (frame_time < 1000 * minimum_interval_us) {
// if (auto res = eepy(minimum_interval_us * 1000 - frame_time); res)
// LOG_ERROR("Sleep command failed: {}", res);
// }
// previous_frame_time = get_timestamp();
// previous_frame_time = Util::GetTimestamp();
// } else {
// max_fps = minimum_interval_us > 0 ? (int) std::round(1000000.0f / minimum_interval_us) : 0;
// }
@@ -25,14 +25,14 @@ inline HRESULT AntiLag2::al2_sleep()
HRESULT result = {};
// auto pre_sleep = get_timestamp();
// auto pre_sleep = Util::GetTimestamp();
if (dx12_ctx.m_pAntiLagAPI)
result = AMD::AntiLag2DX12::Update(&dx12_ctx, is_enabled(), max_fps);
else if (dx11_ctx.m_pAntiLagAPI)
result = AMD::AntiLag2DX11::Update(&dx11_ctx, is_enabled(), max_fps);
// log_event("al2_sleep", "{}", get_timestamp() - pre_sleep);
// log_event("al2_sleep", "{}", Util::GetTimestamp() - pre_sleep);
LOG_TRACE_LOWLATENCY("FSR Anti-Lag 2.0 Call Spot: {}",
current_call_spot == CallSpot::SimulationStart ? "SimulationStart" : "SleepCall");
@@ -29,7 +29,7 @@ void LatencyFlex::lfx_sleep(uint64_t reflex_frame_id)
ctx->Reset();
}
uint64_t current_timestamp = get_timestamp();
uint64_t current_timestamp = Util::GetTimestamp();
uint64_t timestamp;
// Set FPS Limiter
@@ -85,7 +85,7 @@ void LatencyFlex::lfx_sleep(uint64_t reflex_frame_id)
void LatencyFlex::lfx_end_frame(uint64_t reflex_frame_id)
{
auto current_timestamp = get_timestamp();
auto current_timestamp = Util::GetTimestamp();
mutex.lock();
auto frame_id = (LFXMode) Config::Instance()->FN_LatencyFlexMode.value_or_default() == LFXMode::ReflexIDs
? reflex_frame_id
+6 -16
View File
@@ -4,16 +4,6 @@
#include "Config.h"
// #include "hooks/D3D11Hooks.h"
inline uint64_t FrameLimit::get_timestamp()
{
FILETIME fileTime;
GetSystemTimePreciseAsFileTime(&fileTime);
uint64_t time = (static_cast<uint64_t>(fileTime.dwHighDateTime) << 32) | fileTime.dwLowDateTime;
return time * 100;
}
// https://learn.microsoft.com/en-us/windows/win32/sync/using-waitable-timer-objects
inline int FrameLimit::timer_sleep(int64_t hundred_ns)
{
@@ -36,11 +26,11 @@ inline int FrameLimit::timer_sleep(int64_t hundred_ns)
inline int FrameLimit::busywait_sleep(int64_t ns)
{
auto current_time = get_timestamp();
auto current_time = Util::GetTimestamp();
auto wait_until = current_time + ns;
while (current_time < wait_until)
{
current_time = get_timestamp();
current_time = Util::GetTimestamp();
}
return 0;
}
@@ -49,13 +39,13 @@ inline int FrameLimit::combined_sleep(int64_t ns)
{
constexpr int64_t busywait_threshold = 2'000'000; // 2ms
int status {};
auto current_time = get_timestamp();
auto current_time = Util::GetTimestamp();
if (ns <= busywait_threshold)
status = busywait_sleep(ns);
else
status = timer_sleep((ns - busywait_threshold) / 100);
if (int64_t sleep_deviation = ns - (get_timestamp() - current_time); sleep_deviation > 0 && !status)
if (int64_t sleep_deviation = ns - (Util::GetTimestamp() - current_time); sleep_deviation > 0 && !status)
status = busywait_sleep(sleep_deviation);
return status;
@@ -71,13 +61,13 @@ void FrameLimit::sleep(bool fgActive)
min_interval_us *= 2;
static uint64_t previous_frame_time = 0;
uint64_t current_time = get_timestamp();
uint64_t current_time = Util::GetTimestamp();
uint64_t frame_time = current_time - previous_frame_time;
if (frame_time < 1000 * min_interval_us)
{
if (auto res = combined_sleep(min_interval_us * 1000 - frame_time); res)
LOG_ERROR("Sleep command failed: {}", res);
}
previous_frame_time = get_timestamp();
previous_frame_time = Util::GetTimestamp();
}
}
-1
View File
@@ -3,7 +3,6 @@
class FrameLimit
{
static uint64_t get_timestamp();
static int timer_sleep(int64_t hundred_ns);
static int busywait_sleep(int64_t ns);
static int combined_sleep(int64_t ns);
@@ -174,7 +174,7 @@ void LowLatency::get_latency_result(NV_LATENCY_RESULT_PARAMS* pGetLatencyParams)
void LowLatency::add_marker_to_report(NV_LATENCY_MARKER_PARAMS* pSetLatencyMarkerParams)
{
auto current_timestamp = get_timestamp() / 1000;
auto current_timestamp = Util::GetTimestamp() / 1000;
static auto last_sim_start = current_timestamp;
static auto _2nd_last_sim_start = current_timestamp;
auto current_report = &frame_reports[pSetLatencyMarkerParams->frameID % FRAME_REPORTS_BUFFER_SIZE];
@@ -197,26 +197,26 @@ void LowLatency::add_marker_to_report(NV_LATENCY_MARKER_PARAMS* pSetLatencyMarke
{
case SIMULATION_START:
_2nd_last_sim_start = last_sim_start;
last_sim_start = get_timestamp() / 1000;
last_sim_start = Util::GetTimestamp() / 1000;
current_report->simStartTime = last_sim_start;
break;
case SIMULATION_END:
current_report->simEndTime = get_timestamp() / 1000;
current_report->simEndTime = Util::GetTimestamp() / 1000;
break;
case RENDERSUBMIT_START:
current_report->renderSubmitStartTime = get_timestamp() / 1000;
current_report->renderSubmitStartTime = Util::GetTimestamp() / 1000;
break;
case RENDERSUBMIT_END:
current_report->renderSubmitEndTime = get_timestamp() / 1000;
current_report->renderSubmitEndTime = Util::GetTimestamp() / 1000;
break;
case PRESENT_START:
current_report->presentStartTime = get_timestamp() / 1000;
current_report->presentStartTime = Util::GetTimestamp() / 1000;
break;
case PRESENT_END:
current_report->presentEndTime = get_timestamp() / 1000;
current_report->presentEndTime = Util::GetTimestamp() / 1000;
break;
case INPUT_SAMPLE:
current_report->inputSampleTime = get_timestamp() / 1000;
current_report->inputSampleTime = Util::GetTimestamp() / 1000;
break;
default:
break;
@@ -108,7 +108,7 @@ void LowLatency::get_latency_result(NV_VULKAN_LATENCY_RESULT_PARAMS* pGetLatency
void LowLatency::add_marker_to_report(NV_VULKAN_LATENCY_MARKER_PARAMS* pSetLatencyMarkerParams)
{
auto current_timestamp = get_timestamp() / 1000;
auto current_timestamp = Util::GetTimestamp() / 1000;
static auto last_sim_start = current_timestamp;
static auto _2nd_last_sim_start = current_timestamp;
auto current_report = &frame_reports[pSetLatencyMarkerParams->frameID % FRAME_REPORTS_BUFFER_SIZE];
@@ -131,26 +131,26 @@ void LowLatency::add_marker_to_report(NV_VULKAN_LATENCY_MARKER_PARAMS* pSetLaten
{
case VULKAN_SIMULATION_START:
_2nd_last_sim_start = last_sim_start;
last_sim_start = get_timestamp() / 1000;
last_sim_start = Util::GetTimestamp() / 1000;
current_report->simStartTime = last_sim_start;
break;
case VULKAN_SIMULATION_END:
current_report->simEndTime = get_timestamp() / 1000;
current_report->simEndTime = Util::GetTimestamp() / 1000;
break;
case VULKAN_RENDERSUBMIT_START:
current_report->renderSubmitStartTime = get_timestamp() / 1000;
current_report->renderSubmitStartTime = Util::GetTimestamp() / 1000;
break;
case VULKAN_RENDERSUBMIT_END:
current_report->renderSubmitEndTime = get_timestamp() / 1000;
current_report->renderSubmitEndTime = Util::GetTimestamp() / 1000;
break;
case VULKAN_PRESENT_START:
current_report->presentStartTime = get_timestamp() / 1000;
current_report->presentStartTime = Util::GetTimestamp() / 1000;
break;
case VULKAN_PRESENT_END:
current_report->presentEndTime = get_timestamp() / 1000;
current_report->presentEndTime = Util::GetTimestamp() / 1000;
break;
case VULKAN_INPUT_SAMPLE:
current_report->inputSampleTime = get_timestamp() / 1000;
current_report->inputSampleTime = Util::GetTimestamp() / 1000;
break;
default:
break;