mirror of
https://github.com/yuzu-emu/yuzu-mainline
synced 2024-11-22 18:44:03 +00:00
vk_resource_pool: Load GPU tick once and compare with it
Other minor style improvements. Rename free_iterator to hint_iterator, to describe better what it does.
This commit is contained in:
parent
95722823b9
commit
b8ffdbb167
2 changed files with 8 additions and 8 deletions
|
@ -17,21 +17,21 @@ ResourcePool::~ResourcePool() = default;
|
||||||
size_t ResourcePool::CommitResource() {
|
size_t ResourcePool::CommitResource() {
|
||||||
// Refresh semaphore to query updated results
|
// Refresh semaphore to query updated results
|
||||||
master_semaphore.Refresh();
|
master_semaphore.Refresh();
|
||||||
|
const u64 gpu_tick = master_semaphore.KnownGpuTick();
|
||||||
const auto search = [this](size_t begin, size_t end) -> std::optional<size_t> {
|
const auto search = [this, gpu_tick](size_t begin, size_t end) -> std::optional<size_t> {
|
||||||
for (size_t iterator = begin; iterator < end; ++iterator) {
|
for (size_t iterator = begin; iterator < end; ++iterator) {
|
||||||
if (master_semaphore.IsFree(ticks[iterator])) {
|
if (gpu_tick >= ticks[iterator]) {
|
||||||
ticks[iterator] = master_semaphore.CurrentTick();
|
ticks[iterator] = master_semaphore.CurrentTick();
|
||||||
return iterator;
|
return iterator;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return {};
|
return std::nullopt;
|
||||||
};
|
};
|
||||||
// Try to find a free resource from the hinted position to the end.
|
// Try to find a free resource from the hinted position to the end.
|
||||||
auto found = search(free_iterator, ticks.size());
|
std::optional<size_t> found = search(hint_iterator, ticks.size());
|
||||||
if (!found) {
|
if (!found) {
|
||||||
// Search from beginning to the hinted position.
|
// Search from beginning to the hinted position.
|
||||||
found = search(0, free_iterator);
|
found = search(0, hint_iterator);
|
||||||
if (!found) {
|
if (!found) {
|
||||||
// Both searches failed, the pool is full; handle it.
|
// Both searches failed, the pool is full; handle it.
|
||||||
const size_t free_resource = ManageOverflow();
|
const size_t free_resource = ManageOverflow();
|
||||||
|
@ -41,7 +41,7 @@ size_t ResourcePool::CommitResource() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Free iterator is hinted to the resource after the one that's been commited.
|
// Free iterator is hinted to the resource after the one that's been commited.
|
||||||
free_iterator = (*found + 1) % ticks.size();
|
hint_iterator = (*found + 1) % ticks.size();
|
||||||
return *found;
|
return *found;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ private:
|
||||||
|
|
||||||
MasterSemaphore& master_semaphore;
|
MasterSemaphore& master_semaphore;
|
||||||
size_t grow_step = 0; ///< Number of new resources created after an overflow
|
size_t grow_step = 0; ///< Number of new resources created after an overflow
|
||||||
size_t free_iterator = 0; ///< Hint to where the next free resources is likely to be found
|
size_t hint_iterator = 0; ///< Hint to where the next free resources is likely to be found
|
||||||
std::vector<u64> ticks; ///< Ticks for each resource
|
std::vector<u64> ticks; ///< Ticks for each resource
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue