Only reallocate MegaBuffer on usage

Certain submissions might not utilize megabuffering but reserve a `MegaBuffer` regardless, this is not optimal since it can inflate the allocations and waste memory. This commit addresses the issue by eliding the allocation given the current submission doesn't utilize them.
This commit is contained in:
PixelyIon 2022-07-07 17:21:09 +05:30
parent 2366f81443
commit 7b209c54a2
No known key found for this signature in database
GPG Key ID: 11BC6C3201BC2C05
3 changed files with 23 additions and 1 deletions

View File

@ -119,6 +119,14 @@ namespace skyline::gpu {
return *this;
}
bool MegaBuffer::WasUsed() {
return freeRegion != slot->backing.subspan(PAGE_SIZE);
}
void MegaBuffer::ReplaceCycle(const std::shared_ptr<FenceCycle> &cycle) {
slot->cycle = cycle;
}
void MegaBuffer::Reset() {
freeRegion = slot->backing.subspan(PAGE_SIZE);
}

View File

@ -91,6 +91,17 @@ namespace skyline::gpu {
MegaBuffer &operator=(MegaBuffer &&other);
/**
* @return If any allocations into the megabuffer were done at the time of the call
*/
bool WasUsed();
/**
* @brief Replaces the cycle associated with the underlying megabuffer with the supplied cycle
* @note The megabuffer must **NOT** have any dependencies that aren't conveyed by the supplied cycle
*/
void ReplaceCycle(const std::shared_ptr<FenceCycle> &cycle);
/**
* @brief Resets the free region of the megabuffer to its initial state, data is left intact but may be overwritten
*/

View File

@ -321,7 +321,10 @@ namespace skyline::gpu::interconnect {
SubmitInternal();
activeCommandBuffer = gpu.scheduler.AllocateCommandBuffer();
cycle = activeCommandBuffer.GetFenceCycle();
megaBuffer = gpu.buffer.AcquireMegaBuffer(cycle);
if (megaBuffer.WasUsed())
megaBuffer = gpu.buffer.AcquireMegaBuffer(cycle);
else
megaBuffer.ReplaceCycle(cycle);
}
ResetInternal();
}