Avoid calling SynchronizeGuest when attempting to megabuffer unless necessary

This commit is contained in:
Billy Laws 2022-09-18 15:26:49 +01:00
parent e5919e84a1
commit 4b2b6fc6e9

View File

@ -275,10 +275,6 @@ namespace skyline::gpu {
BufferBinding Buffer::TryMegaBufferView(const std::shared_ptr<FenceCycle> &pCycle, MegaBufferAllocator &allocator, size_t executionNumber, BufferBinding Buffer::TryMegaBufferView(const std::shared_ptr<FenceCycle> &pCycle, MegaBufferAllocator &allocator, size_t executionNumber,
vk::DeviceSize offset, vk::DeviceSize size) { vk::DeviceSize offset, vk::DeviceSize size) {
if (!SynchronizeGuest(false, true))
// Bail out if buffer cannot be synced, we don't know the contents ahead of time so the sequence is indeterminate
return {};
if (!everHadInlineUpdate && sequenceNumber < FrequentlySyncedThreshold) if (!everHadInlineUpdate && sequenceNumber < FrequentlySyncedThreshold)
// Don't megabuffer buffers that have never had inline updates and are not frequently synced since performance is only going to be harmed as a result of the constant copying and there wont be any benefit since there are no GPU inline updates that would be avoided // Don't megabuffer buffers that have never had inline updates and are not frequently synced since performance is only going to be harmed as a result of the constant copying and there wont be any benefit since there are no GPU inline updates that would be avoided
return {}; return {};
@ -286,6 +282,11 @@ namespace skyline::gpu {
if (size > MegaBufferingDisableThreshold) if (size > MegaBufferingDisableThreshold)
return {}; return {};
// We are safe to check dirty state here since it will only ever be set GPU dirty with the buffer locked and from the active GPFIFO thread. This helps with perf since the lock ends up being slightly expensive
if (dirtyState == DirtyState::GpuDirty && !SynchronizeGuest(false, true))
// Bail out if buffer cannot be synced, we don't know the contents ahead of time so the sequence is indeterminate
return {};
size_t entryIdx{offset >> megaBufferTableShift}; size_t entryIdx{offset >> megaBufferTableShift};
size_t bufferEntryOffset{entryIdx << megaBufferTableShift}; size_t bufferEntryOffset{entryIdx << megaBufferTableShift};
size_t entryViewOffset{offset - bufferEntryOffset}; size_t entryViewOffset{offset - bufferEntryOffset};