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 statistics #2014

Closed doitsujin closed 1 week ago

doitsujin commented 3 weeks ago

Implements necessary functionality for IDXGISwapChain::GetFrameStatistics to return somewhat meaningful data. Without it, we pretend that a present operation completes immediately, which is bad in case the app uses this for frame pacing purposes, and worse if it makes assumptions on whether or not it is safe to free GPU resources. There are a couple of games using this (albeit for unknown purposes), most notably Nixxes ports.

TL;DR is that the API quite literally counts successful presents, and we happen to have an internal timeline doing exactly that in a robust manner already so we can just expose that to the app. Some refactoring was needed since this requires us to always have the waiter thread active, even if present wait is not used for a given present.

Additionally, this adds a frame rate limiter. The main motivation for this interface on the DXVK side of things was to support games that disable their own built-in limiter when running in full-screen with a 60 Hz display mode, but we can do the same here. This is less important for D3D12, but works in games that allow changing the refresh rate, e.g. Horizon Zero Dawn. If this functionality isn't desired, I can drop the commit.

Currently untested on environments where present wait is unsupported. There's no rush to land this either, it's probably a good idea to tackle this after 2.13 and do some broad testing on whether it affects (or breaks) any existing games.