From bf5c7f67ea418d4ae22925c16052646f6fe31efa Mon Sep 17 00:00:00 2001 From: Mateusz Dukat Date: Sun, 10 Mar 2024 16:24:17 +0100 Subject: [PATCH] [GPU] Add hard FPS limit without vsync --- src/xenia/gpu/gpu_flags.cc | 7 +++++++ src/xenia/gpu/gpu_flags.h | 3 +++ src/xenia/gpu/graphics_system.cc | 8 +++++++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/xenia/gpu/gpu_flags.cc b/src/xenia/gpu/gpu_flags.cc index e6ae0ad69..810d9f5ee 100644 --- a/src/xenia/gpu/gpu_flags.cc +++ b/src/xenia/gpu/gpu_flags.cc @@ -22,6 +22,13 @@ DEFINE_bool(vsync, true, "Enable VSYNC.", "GPU"); DEFINE_uint64(vsync_fps, 60, "VSYNC frames per second", "GPU"); +DEFINE_uint64(hard_fps, 60, + "Hard FPS lock, ignored when vsync is used. " + "Game will never exceed this value", "GPU"); + +DEFINE_bool(hard_fps_enable, false, + "Enable hard FPS lock, ignored if vsync is enabled", "GPU"); + DEFINE_bool( gpu_allow_invalid_fetch_constants, true, "Allow texture and vertex fetch constants with invalid type - generally " diff --git a/src/xenia/gpu/gpu_flags.h b/src/xenia/gpu/gpu_flags.h index c5ba7fcdd..e0f97a348 100644 --- a/src/xenia/gpu/gpu_flags.h +++ b/src/xenia/gpu/gpu_flags.h @@ -20,6 +20,9 @@ DECLARE_bool(vsync); DECLARE_uint64(vsync_fps); +DECLARE_uint64(hard_fps); +DECLARE_bool(hard_fps_enable); + DECLARE_bool(gpu_allow_invalid_fetch_constants); DECLARE_bool(half_pixel_offset); diff --git a/src/xenia/gpu/graphics_system.cc b/src/xenia/gpu/graphics_system.cc index cc06c1390..91c3a3139 100644 --- a/src/xenia/gpu/graphics_system.cc +++ b/src/xenia/gpu/graphics_system.cc @@ -133,8 +133,14 @@ X_STATUS GraphicsSystem::Setup(cpu::Processor* processor, threading::NanoSleep(estimated_nanoseconds); } } + if (!cvars::vsync) { - xe::threading::Sleep(std::chrono::milliseconds(1)); + if (cvars::hard_fps_enable) { + uint64_t hard_frame_sleep_time = 1000000000 / cvars::hard_fps; + xe::threading::NanoSleep(hard_frame_sleep_time); + } else { + xe::threading::Sleep(std::chrono::milliseconds(1)); + } } } return 0;