HansKristian-Work / vkd3d-proton

Fork of VKD3D. Development branches for Proton's Direct3D 12 implementation.
GNU Lesser General Public License v2.1
1.75k stars 183 forks source link

Implement frame rate limiter #2024

Closed doitsujin closed 1 week ago

doitsujin commented 1 week ago

Fallout from #2014. Implementation matches that of DXVK.

The SetTargetFrameRate function is called with:

The algorithm itself is fairly simple and intends to roughly emulate the behaviour of running on a lower refresh rate display:

Sleeping needs to be reasonably accurate to not mess up frame pacing, which is why we intentionally ask to be woken up a few milliseconds early and busy-wait for the remainder of the duration time. The downside here is power consumption, but the only way to really improve on that would be to do the SpecialK thing of abusing the monitorx / mwaitx instruction on Ryzen CPUs, which isn't trivial since they require cpuid checks and operate in units of TSC ticks.