Introduce hack to ignore frequently read-back textures

Readback can be especially slow on mobile due to the varying load pattern it creates which often prevents the CPU/GPU from clocking up. Since some games perform texture readback but don't actually use it for anything significant implement a hack to skip it and significantly improve performance in such cases.
This commit is contained in:
Billy Laws
2022-10-21 21:53:26 +01:00
parent e45e7546c8
commit 6c0f084aae
8 changed files with 31 additions and 1 deletions

View File

@ -167,8 +167,15 @@ namespace skyline::gpu {
// If this mutex would cause other callbacks to be blocked then we should block on this mutex in advance
std::shared_ptr<FenceCycle> waitCycle{};
do {
if (waitCycle)
// We need to do a loop here since we can't wait with the texture locked but not doing so means that the texture could have it's cycle changed which we wouldn't wait on, loop until we are sure the cycle hasn't changed to avoid that
if (waitCycle) {
i64 startNs{texture->accumulatedGuestWaitCounter > SkipReadbackHackWaitCountThreshold ? util::GetTimeNs() : 0};
waitCycle->Wait();
if (startNs)
texture->accumulatedGuestWaitTime += std::chrono::nanoseconds(util::GetTimeNs() - startNs);
texture->accumulatedGuestWaitCounter++;
}
std::scoped_lock lock{*texture};
if (waitCycle && texture->cycle == waitCycle) {
@ -218,6 +225,11 @@ namespace skyline::gpu {
return true; // If the texture is already CPU dirty or we can transition it to being CPU dirty then we don't need to do anything
}
if (texture->accumulatedGuestWaitTime > SkipReadbackHackWaitTimeThreshold && *texture->gpu.state.settings->enableTextureReadbackHack) {
texture->dirtyState = DirtyState::Clean;
return true;
}
std::unique_lock lock{*texture, std::try_to_lock};
if (!lock)
return false;