summaryrefslogtreecommitdiffstats
path: root/src/video_core
diff options
context:
space:
mode:
authorReinUsesLisp <reinuseslisp@airmail.cc>2021-01-23 21:59:32 +0100
committerReinUsesLisp <reinuseslisp@airmail.cc>2021-02-13 06:18:38 +0100
commit025fe458aef87d28c68dc0d4c0f2c43492b62c18 (patch)
treefbd93f27fb86a5230fae6168a6ee791f52009856 /src/video_core
parentvk_buffer_cache: Add support for null index buffers (diff)
downloadyuzu-025fe458aef87d28c68dc0d4c0f2c43492b62c18.tar
yuzu-025fe458aef87d28c68dc0d4c0f2c43492b62c18.tar.gz
yuzu-025fe458aef87d28c68dc0d4c0f2c43492b62c18.tar.bz2
yuzu-025fe458aef87d28c68dc0d4c0f2c43492b62c18.tar.lz
yuzu-025fe458aef87d28c68dc0d4c0f2c43492b62c18.tar.xz
yuzu-025fe458aef87d28c68dc0d4c0f2c43492b62c18.tar.zst
yuzu-025fe458aef87d28c68dc0d4c0f2c43492b62c18.zip
Diffstat (limited to 'src/video_core')
-rw-r--r--src/video_core/renderer_vulkan/vk_staging_buffer_pool.cpp37
-rw-r--r--src/video_core/renderer_vulkan/vk_staging_buffer_pool.h2
2 files changed, 20 insertions, 19 deletions
diff --git a/src/video_core/renderer_vulkan/vk_staging_buffer_pool.cpp b/src/video_core/renderer_vulkan/vk_staging_buffer_pool.cpp
index 4baf791d4..dfd8c8e5a 100644
--- a/src/video_core/renderer_vulkan/vk_staging_buffer_pool.cpp
+++ b/src/video_core/renderer_vulkan/vk_staging_buffer_pool.cpp
@@ -142,33 +142,27 @@ void StagingBufferPool::TickFrame() {
}
StagingBufferRef StagingBufferPool::GetStreamBuffer(size_t size) {
- for (size_t region = Region(free_iterator) + 1,
- region_end = std::min(Region(iterator + size) + 1, NUM_SYNCS);
- region < region_end; ++region) {
- // If we'd have to wait, get a staging buffer to avoid waiting
- if (!scheduler.IsFree(sync_ticks[region])) {
- return GetStagingBuffer(size, MemoryUsage::Upload);
- }
- }
- for (size_t region = Region(used_iterator), region_end = Region(iterator); region < region_end;
- ++region) {
- sync_ticks[region] = scheduler.CurrentTick();
+ if (AreRegionsActive(Region(free_iterator) + 1,
+ std::min(Region(iterator + size) + 1, NUM_SYNCS))) {
+ // Avoid waiting for the previous usages to be free
+ return GetStagingBuffer(size, MemoryUsage::Upload);
}
+ const u64 current_tick = scheduler.CurrentTick();
+ std::fill(sync_ticks.begin() + Region(used_iterator), sync_ticks.begin() + Region(iterator),
+ current_tick);
used_iterator = iterator;
+ free_iterator = std::max(free_iterator, iterator + size);
- if (iterator + size > free_iterator) {
- free_iterator = iterator + size;
- }
if (iterator + size > STREAM_BUFFER_SIZE) {
- for (size_t region = Region(used_iterator); region < NUM_SYNCS; ++region) {
- sync_ticks[region] = scheduler.CurrentTick();
- }
+ std::fill(sync_ticks.begin() + Region(used_iterator), sync_ticks.begin() + NUM_SYNCS,
+ current_tick);
used_iterator = 0;
iterator = 0;
free_iterator = size;
- for (size_t region = 0, region_end = Region(size); region <= region_end; ++region) {
- scheduler.Wait(sync_ticks[region]);
+ if (AreRegionsActive(0, Region(size) + 1)) {
+ // Avoid waiting for the previous usages to be free
+ return GetStagingBuffer(size, MemoryUsage::Upload);
}
}
const size_t offset = iterator;
@@ -180,6 +174,11 @@ StagingBufferRef StagingBufferPool::GetStreamBuffer(size_t size) {
};
}
+bool StagingBufferPool::AreRegionsActive(size_t region_begin, size_t region_end) const {
+ return std::any_of(sync_ticks.begin() + region_begin, sync_ticks.begin() + region_end,
+ [this](u64 sync_tick) { return !scheduler.IsFree(sync_tick); });
+};
+
StagingBufferRef StagingBufferPool::GetStagingBuffer(size_t size, MemoryUsage usage) {
if (const std::optional<StagingBufferRef> ref = TryGetReservedBuffer(size, usage)) {
return *ref;
diff --git a/src/video_core/renderer_vulkan/vk_staging_buffer_pool.h b/src/video_core/renderer_vulkan/vk_staging_buffer_pool.h
index 8e4cadf9b..69f7618de 100644
--- a/src/video_core/renderer_vulkan/vk_staging_buffer_pool.h
+++ b/src/video_core/renderer_vulkan/vk_staging_buffer_pool.h
@@ -67,6 +67,8 @@ private:
StagingBufferRef GetStreamBuffer(size_t size);
+ bool AreRegionsActive(size_t region_begin, size_t region_end) const;
+
StagingBufferRef GetStagingBuffer(size_t size, MemoryUsage usage);
std::optional<StagingBufferRef> TryGetReservedBuffer(size_t size, MemoryUsage usage);