Avoid waiting on mutex in PresentationEngine::Present

We want to block on the host thread during presentation while the host surface isn't present to implicitly pause the game, this can end up being fairly costly as it involves locking the `PresentationEngine` mutex which can lead to a lot of contention with the presentation thread. This fixes the issue by polling if there is a surface and only if there isn't then doing the wait as it isn't mandatory to wait always, we'll eventually run into the guest thread stalling.
This commit is contained in:
PixelyIon 2022-06-26 15:26:18 +05:30
parent 30475ffc43
commit d7399e33c1
No known key found for this signature in database
GPG Key ID: 11BC6C3201BC2C05

View File

@ -374,8 +374,11 @@ namespace skyline::gpu {
} }
u64 PresentationEngine::Present(const std::shared_ptr<Texture> &texture, i64 timestamp, i64 swapInterval, AndroidRect crop, NativeWindowScalingMode scalingMode, NativeWindowTransform transform, skyline::service::hosbinder::AndroidFence fence, const std::function<void()>& presentCallback) { u64 PresentationEngine::Present(const std::shared_ptr<Texture> &texture, i64 timestamp, i64 swapInterval, AndroidRect crop, NativeWindowScalingMode scalingMode, NativeWindowTransform transform, skyline::service::hosbinder::AndroidFence fence, const std::function<void()>& presentCallback) {
std::unique_lock lock(mutex); if (!vkSurface.has_value()) {
surfaceCondition.wait(lock, [this]() { return vkSurface.has_value(); }); // We want this function to generally (not necessarily always) block when a surface is not present to implicitly pause the game
std::unique_lock lock(mutex);
surfaceCondition.wait(lock, [this]() { return vkSurface.has_value(); });
}
presentQueue.Push(PresentableFrame{ presentQueue.Push(PresentableFrame{
texture, texture,