Skip to content

Commit

Permalink
rsx: Fix zcull time to not time travel to the future
Browse files Browse the repository at this point in the history
  • Loading branch information
elad335 authored and Nekotekina committed Apr 28, 2020
1 parent e095eaf commit 833ace1
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions rpcs3/Emu/RSX/RSXThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ rsx::frame_capture_data frame_capture;

extern CellGcmOffsetTable offsetTable;
extern thread_local std::string(*g_tls_log_prefix)();
extern u64 sys_time_get_timebase_frequency();
extern u64 get_timebased_time();

namespace rsx
{
Expand Down Expand Up @@ -811,16 +813,39 @@ namespace rsx

u64 thread::timestamp()
{
// Get timestamp, and convert it from microseconds to nanoseconds
const u64 t = get_guest_system_time() * 1000;
const u64 freq = sys_time_get_timebase_frequency();

auto get_time_ns = [freq]()
{
const u64 t = get_timebased_time();
return (t / freq * 1'000'000'000 + t % freq * 1'000'000'000 / freq);
};

const u64 t = get_time_ns();
if (t != timestamp_ctrl)
{
timestamp_ctrl = t;
timestamp_subvalue = 0;
return t;
}

timestamp_subvalue += 10;
// Check if we passed the limit of what fixed increments is legal for
// Wait for the next time value reported if we passed the limit
if ((1'000'000'000 / freq) - timestamp_subvalue <= 2)
{
u64 now = get_time_ns();

for (; t == now; now = get_time_ns())
{
_mm_pause();
}

timestamp_ctrl = now;
timestamp_subvalue = 0;
return now;
}

timestamp_subvalue += 2;
return t + timestamp_subvalue;
}

Expand Down

0 comments on commit 833ace1

Please sign in to comment.