skyline/app/src/main/cpp/skyline/soc/host1x/syncpoint.cpp
PixelyIon 216e5cee81 Separate Guest and Host Presentation + AChoreographer V-Sync Event
We had issues when combining host and guest presentation since certain configurations in guest presentation such as double buffering were very unoptimal for the host and would significantly affect the FPS. As a result of this, we've now made host presentation have its own presentation textures which are copied into from the guest at presentation time, allowing us to change parameters of the host presentation independently of the guest.

We've implemented the infrastructure for this which includes being able to create images from host GPU memory using VMA, an optimized linear texture sync and a method to do on-GPU texture-to-texture copies.

We've also moved to driving the V-Sync event using AChoreographer on its on thread in this PR, which more accurately encapsulates HOS behavior and allows games such as ARMS to boot as they depend on the V-Sync event being signalled even when the game isn't presenting.
2021-07-12 21:27:49 +05:30

68 lines
1.8 KiB
C++

// SPDX-License-Identifier: MPL-2.0
// Copyright © 2020 Skyline Team and Contributors (https://github.com/skyline-emu/)
// Copyright © 2020 Ryujinx Team and Contributors
#include "syncpoint.h"
namespace skyline::soc::host1x {
u64 Syncpoint::RegisterWaiter(u32 threshold, const std::function<void()> &callback) {
if (value >= threshold) {
callback();
return 0;
}
std::lock_guard guard(waiterLock);
waiterMap.emplace(nextWaiterId, Waiter{threshold, callback});
return nextWaiterId++;
}
void Syncpoint::DeregisterWaiter(u64 id) {
std::lock_guard guard(waiterLock);
waiterMap.erase(id);
}
u32 Syncpoint::Increment() {
value++;
std::lock_guard guard(waiterLock);
std::erase_if(waiterMap, [this](const auto &entry) {
if (value >= entry.second.threshold) {
entry.second.callback();
return true;
} else {
return false;
}
});
return value;
}
bool Syncpoint::Wait(u32 threshold, std::chrono::steady_clock::duration timeout) {
if (value >= threshold)
return true;
std::mutex mtx;
std::condition_variable cv;
bool flag{};
if (!RegisterWaiter(threshold, [&cv, &mtx, &flag] {
std::unique_lock lock(mtx);
flag = true;
lock.unlock();
cv.notify_all();
})) {
return true;
}
std::unique_lock lock(mtx);
if (timeout == std::chrono::steady_clock::duration::max()) {
cv.wait(lock, [&flag] { return flag; });
return true;
} else {
return cv.wait_for(lock, timeout, [&flag] { return flag; });
}
}
}