diff --git a/src/xenia/gpu/gpu_flags.cc b/src/xenia/gpu/gpu_flags.cc index ce7ac9bcc..112b5c04d 100644 --- a/src/xenia/gpu/gpu_flags.cc +++ b/src/xenia/gpu/gpu_flags.cc @@ -20,8 +20,7 @@ DEFINE_path( DEFINE_bool(vsync, true, "Enable VSYNC.", "GPU"); -DEFINE_uint64(vsync_interval, 16, - "VSYNC interval. Value is frametime in milliseconds.", "GPU"); +DEFINE_uint64(vsync_fps, 60, "VSYNC frames per second", "GPU"); DEFINE_bool( gpu_allow_invalid_fetch_constants, false, diff --git a/src/xenia/gpu/gpu_flags.h b/src/xenia/gpu/gpu_flags.h index 9a6ef3343..c5ba7fcdd 100644 --- a/src/xenia/gpu/gpu_flags.h +++ b/src/xenia/gpu/gpu_flags.h @@ -18,7 +18,7 @@ DECLARE_path(dump_shaders); DECLARE_bool(vsync); -DECLARE_uint64(vsync_interval); +DECLARE_uint64(vsync_fps); DECLARE_bool(gpu_allow_invalid_fetch_constants); diff --git a/src/xenia/gpu/graphics_system.cc b/src/xenia/gpu/graphics_system.cc index f378015a9..6e8c19268 100644 --- a/src/xenia/gpu/graphics_system.cc +++ b/src/xenia/gpu/graphics_system.cc @@ -104,18 +104,26 @@ X_STATUS GraphicsSystem::Setup(cpu::Processor* processor, vsync_worker_running_ = true; vsync_worker_thread_ = kernel::object_ref( new kernel::XHostThread(kernel_state_, 128 * 1024, 0, [this]() { - uint64_t vsync_duration = - cvars::vsync ? std::max(5, cvars::vsync_interval) : 1; + double vsync_duration_d = + cvars::vsync + ? std::max( + 5.0, 1000.0 / static_cast(cvars::vsync_fps)) + : 1.0; uint64_t last_frame_time = Clock::QueryGuestTickCount(); while (vsync_worker_running_) { uint64_t current_time = Clock::QueryGuestTickCount(); - uint64_t elapsed = (current_time - last_frame_time) / - (Clock::guest_tick_frequency() / 1000); - if (elapsed >= vsync_duration) { + + uint64_t tick_freq = Clock::guest_tick_frequency(); + uint64_t time_delta = current_time - last_frame_time; + double elapsed_d = static_cast(time_delta) / + (static_cast(tick_freq) / 1000.0); + if (elapsed_d >= vsync_duration_d) { MarkVblank(); last_frame_time = current_time; } - xe::threading::Sleep(std::chrono::milliseconds(1)); + if (!cvars::vsync) { + xe::threading::Sleep(std::chrono::milliseconds(1)); + } } return 0; })); @@ -123,7 +131,7 @@ X_STATUS GraphicsSystem::Setup(cpu::Processor* processor, vsync_worker_thread_->set_can_debugger_suspend(true); vsync_worker_thread_->set_name("GPU VSync"); vsync_worker_thread_->Create(); - + vsync_worker_thread_->thread()->set_priority(threading::ThreadPriority::kLowest); if (cvars::trace_gpu_stream) { BeginTracing(); }