Skip to content

Commit

Permalink
rsx: Allow to configure vblank rate
Browse files Browse the repository at this point in the history
  • Loading branch information
elad335 committed Jul 11, 2019
1 parent 537d3f2 commit 096f656
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 18 deletions.
48 changes: 32 additions & 16 deletions rpcs3/Emu/RSX/RSXThread.cpp
Expand Up @@ -456,37 +456,53 @@ namespace rsx

last_flip_time = get_system_time() - 1000000;

vblank_count = 0;

thread_ctrl::spawn("VBlank Thread", [this]()
{
const u64 start_time = get_system_time();
// See sys_timer_usleep for details
#ifdef __linux__
constexpr u32 host_min_quantum = 50;
#else
constexpr u32 host_min_quantum = 500;
#endif
u64 start_time = get_system_time();

vblank_count = 0;
const u64 period_time = 1000000 / g_cfg.video.vblank_rate;
const u64 s_p = period_time - u64{period_time >= host_min_quantum} * host_min_quantum;

// TODO: exit condition
while (!Emu.IsStopped() && !m_rsx_thread_exiting)
{
if (get_system_time() - start_time > vblank_count * 1000000 / 60)
if (get_system_time() - start_time >= period_time)
{
vblank_count++;
sys_rsx_context_attribute(0x55555555, 0xFED, 1, 0, 0, 0);
if (vblank_handler)
do
{
intr_thread->cmd_list
({
{ ppu_cmd::set_args, 1 }, u64{1},
{ ppu_cmd::lle_call, vblank_handler },
{ ppu_cmd::sleep, 0 }
});

thread_ctrl::notify(*intr_thread);
start_time += period_time;

sys_rsx_context_attribute(0x55555555, 0xFED, 1, 0, 0, 0);
if (vblank_handler)
{
vblank_count.release(vblank_count.load() + 1);

intr_thread->cmd_list
({
{ ppu_cmd::set_args, 1 }, u64{1},
{ ppu_cmd::lle_call, vblank_handler },
{ ppu_cmd::sleep, 0 }
});

thread_ctrl::notify(*intr_thread);
}
}
while (get_system_time() - start_time >= period_time);

std::this_thread::sleep_for(16ms);
thread_ctrl::wait_for(s_p);
continue;
}

while (Emu.IsPaused() && !m_rsx_thread_exiting)
std::this_thread::sleep_for(16ms);
thread_ctrl::wait_for(s_p);

thread_ctrl::wait_for(100); // Hack
}
Expand Down
4 changes: 2 additions & 2 deletions rpcs3/Emu/RSX/RSXThread.h
@@ -1,4 +1,4 @@
#pragma once
#pragma once

#include <deque>
#include <variant>
Expand Down Expand Up @@ -549,7 +549,7 @@ namespace rsx
vm::ptr<void(u32)> flip_handler = vm::null;
vm::ptr<void(u32)> user_handler = vm::null;
vm::ptr<void(u32)> vblank_handler = vm::null;
u64 vblank_count;
atomic_t<u64> vblank_count;

public:
bool invalid_command_interrupt_raised = false;
Expand Down
1 change: 1 addition & 0 deletions rpcs3/Emu/System.h
Expand Up @@ -468,6 +468,7 @@ struct cfg_root : cfg::node
cfg::_int<0, 16> anisotropic_level_override{this, "Anisotropic Filter Override", 0};
cfg::_int<1, 1024> min_scalable_dimension{this, "Minimum Scalable Dimension", 16};
cfg::_int<0, 30000000> driver_recovery_timeout{this, "Driver Recovery Timeout", 1000000};
cfg::_int<1, 1000> vblank_rate{this, "Vblank rate", 60};

struct node_d3d12 : cfg::node
{
Expand Down

0 comments on commit 096f656

Please sign in to comment.