Improve ContextLock semantics

`ContextLock` had unoptimal semantics in the form of direct access to the `isFirst` member which wasn't clearly defined, it's now been broken up into function calls `IsFirstUsage` and `OwnsLock` with explicit move semantics and a function for releasing the lock.

Co-authored-by: PixelyIon <pixelyion@protonmail.com>
This commit is contained in:
Billy Laws
2022-07-16 22:30:57 +05:30
committed by PixelyIon
parent 561103d3da
commit 58174f255f
8 changed files with 57 additions and 33 deletions

View File

@ -24,7 +24,7 @@ namespace skyline::gpu {
return mutex.try_lock();
}
BufferView BufferManager::FindOrCreate(GuestBuffer guestMapping, ContextTag tag, const std::function<void(std::shared_ptr<Buffer>, ContextLock<Buffer> &)> &attachBuffer) {
BufferView BufferManager::FindOrCreate(GuestBuffer guestMapping, ContextTag tag, const std::function<void(std::shared_ptr<Buffer>, ContextLock<Buffer> &&)> &attachBuffer) {
/*
* We align the buffer to the page boundary to ensure that:
* 1) Any buffer view has the same alignment guarantees as on the guest, this is required for UBOs, SSBOs and Texel buffers
@ -65,7 +65,7 @@ namespace skyline::gpu {
for (auto &overlap : overlaps) {
ContextLock overlapLock{tag, *overlap};
if (!overlapLock.isFirst)
if (!overlapLock.IsFirstUsage())
hasAlreadyAttached = true;
buffers.erase(std::find(buffers.begin(), buffers.end(), overlap));
@ -101,7 +101,7 @@ namespace skyline::gpu {
if (hasAlreadyAttached)
// We need to reattach the buffer if any overlapping views were already attached to the current context
attachBuffer(newBuffer, newLock);
attachBuffer(newBuffer, std::move(newLock));
buffers.insert(std::lower_bound(buffers.begin(), buffers.end(), newBuffer->guest->end().base(), BufferLessThan), newBuffer);