mirror of
https://github.com/Takiiiiiiii/strato.git
synced 2025-07-17 08:46:39 +00:00
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:
@ -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;
|
||||
|
@ -440,6 +440,11 @@ namespace skyline::gpu {
|
||||
static constexpr size_t FrequentlyLockedThreshold{2}; //!< Threshold for the number of times a texture can be locked (not from context locks, only normal) before it should be considered frequently locked
|
||||
size_t accumulatedCpuLockCounter{};
|
||||
|
||||
static constexpr size_t SkipReadbackHackWaitCountThreshold{8}; //!< Threshold for the number of times a texture can be waited on before it should be considered for the readback hack
|
||||
static constexpr std::chrono::nanoseconds SkipReadbackHackWaitTimeThreshold{constant::NsInSecond / 2}; //!< Threshold for the amount of time a texture can be waited on before it should be considered for the readback hack, `SkipReadbackHackWaitCountThreshold` needs to be hit before this
|
||||
size_t accumulatedGuestWaitCounter{}; //!< Total number of times the texture has been waited on
|
||||
std::chrono::nanoseconds accumulatedGuestWaitTime{}; //!< Amount of time the texture has been waited on for since the `SkipReadbackHackWaitCountThreshold`th wait on it by the guest
|
||||
|
||||
public:
|
||||
std::shared_ptr<FenceCycle> cycle; //!< A fence cycle for when any host operation mutating the texture has completed, it must be waited on prior to any mutations to the backing
|
||||
std::optional<GuestTexture> guest;
|
||||
|
Reference in New Issue
Block a user