From e0bc0d3a97676addce9730645ebe9dd250be420e Mon Sep 17 00:00:00 2001 From: Billy Laws Date: Sun, 6 Nov 2022 20:04:17 +0000 Subject: [PATCH] Avoid megabuffering buffers larger than the chunk size --- app/src/main/cpp/skyline/gpu/buffer.cpp | 4 ++-- app/src/main/cpp/skyline/gpu/megabuffer.cpp | 2 -- app/src/main/cpp/skyline/gpu/megabuffer.h | 2 ++ 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/main/cpp/skyline/gpu/buffer.cpp b/app/src/main/cpp/skyline/gpu/buffer.cpp index 1d35eaca..54fb63dd 100644 --- a/app/src/main/cpp/skyline/gpu/buffer.cpp +++ b/app/src/main/cpp/skyline/gpu/buffer.cpp @@ -330,7 +330,7 @@ namespace skyline::gpu { BufferBinding Buffer::TryMegaBufferView(const std::shared_ptr &pCycle, MegaBufferAllocator &allocator, u32 executionNumber, vk::DeviceSize offset, vk::DeviceSize size) { - if (!everHadInlineUpdate && sequenceNumber < FrequentlySyncedThreshold) + if ((!everHadInlineUpdate && sequenceNumber < FrequentlySyncedThreshold) || size >= MegaBufferChunkSize) // 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 {}; @@ -346,7 +346,7 @@ namespace skyline::gpu { } // If more than half the buffer has been megabuffered in chunks within the same execution assume this will generally be the case for this buffer and just megabuffer the whole thing without chunking - if (unifiedMegaBufferEnabled || megaBufferViewAccumulatedSize > (backing.size() / 2)) { + if (unifiedMegaBufferEnabled || (megaBufferViewAccumulatedSize > (backing.size() / 2) && backing.size() < MegaBufferChunkSize)) { if (!unifiedMegaBuffer) { unifiedMegaBuffer = allocator.Push(pCycle, mirror, true); unifiedMegaBufferEnabled = true; diff --git a/app/src/main/cpp/skyline/gpu/megabuffer.cpp b/app/src/main/cpp/skyline/gpu/megabuffer.cpp index 2e022d50..8e04792a 100644 --- a/app/src/main/cpp/skyline/gpu/megabuffer.cpp +++ b/app/src/main/cpp/skyline/gpu/megabuffer.cpp @@ -5,8 +5,6 @@ #include "megabuffer.h" namespace skyline::gpu { - constexpr static vk::DeviceSize MegaBufferChunkSize{25 * 1024 * 1024}; //!< Size in bytes of a single megabuffer chunk (25MiB) - MegaBufferChunk::MegaBufferChunk(GPU &gpu) : backing{gpu.memory.AllocateBuffer(MegaBufferChunkSize)}, freeRegion{backing.subspan(PAGE_SIZE)} {} bool MegaBufferChunk::TryReset() { diff --git a/app/src/main/cpp/skyline/gpu/megabuffer.h b/app/src/main/cpp/skyline/gpu/megabuffer.h index 74d71a62..3fc3d033 100644 --- a/app/src/main/cpp/skyline/gpu/megabuffer.h +++ b/app/src/main/cpp/skyline/gpu/megabuffer.h @@ -6,6 +6,8 @@ #include "memory_manager.h" namespace skyline::gpu { + constexpr static vk::DeviceSize MegaBufferChunkSize{25 * 1024 * 1024}; //!< Size in bytes of a single megabuffer chunk (25MiB) + /** * @brief A simple linearly allocated GPU-side buffer used to temporarily store buffer modifications allowing them to be replayed in-sequence on the GPU * @note This class is **not** thread-safe and any calls must be externally synchronized