mirror of https://git.suyu.dev/suyu/suyu
Merge pull request #5919 from ReinUsesLisp/stream-buffer-tragic
gl_stream_buffer/vk_staging_buffer_pool: Fix size check
This commit is contained in:
commit
83227ad981
|
@ -40,7 +40,7 @@ std::pair<std::span<u8>, size_t> StreamBuffer::Request(size_t size) noexcept {
|
||||||
glClientWaitSync(fences[region].handle, 0, GL_TIMEOUT_IGNORED);
|
glClientWaitSync(fences[region].handle, 0, GL_TIMEOUT_IGNORED);
|
||||||
fences[region].Release();
|
fences[region].Release();
|
||||||
}
|
}
|
||||||
if (iterator + size > free_iterator) {
|
if (iterator + size >= free_iterator) {
|
||||||
free_iterator = iterator + size;
|
free_iterator = iterator + size;
|
||||||
}
|
}
|
||||||
if (iterator + size > STREAM_BUFFER_SIZE) {
|
if (iterator + size > STREAM_BUFFER_SIZE) {
|
||||||
|
|
|
@ -21,7 +21,12 @@ public:
|
||||||
|
|
||||||
/// Returns the current logical tick.
|
/// Returns the current logical tick.
|
||||||
[[nodiscard]] u64 CurrentTick() const noexcept {
|
[[nodiscard]] u64 CurrentTick() const noexcept {
|
||||||
return current_tick;
|
return current_tick.load(std::memory_order_relaxed);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns the last known GPU tick.
|
||||||
|
[[nodiscard]] u64 KnownGpuTick() const noexcept {
|
||||||
|
return gpu_tick.load(std::memory_order_relaxed);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the timeline semaphore handle.
|
/// Returns the timeline semaphore handle.
|
||||||
|
@ -31,7 +36,7 @@ public:
|
||||||
|
|
||||||
/// Returns true when a tick has been hit by the GPU.
|
/// Returns true when a tick has been hit by the GPU.
|
||||||
[[nodiscard]] bool IsFree(u64 tick) {
|
[[nodiscard]] bool IsFree(u64 tick) {
|
||||||
return gpu_tick >= tick;
|
return gpu_tick.load(std::memory_order_relaxed) >= tick;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Advance to the logical tick.
|
/// Advance to the logical tick.
|
||||||
|
@ -41,7 +46,7 @@ public:
|
||||||
|
|
||||||
/// Refresh the known GPU tick
|
/// Refresh the known GPU tick
|
||||||
void Refresh() {
|
void Refresh() {
|
||||||
gpu_tick = semaphore.GetCounter();
|
gpu_tick.store(semaphore.GetCounter(), std::memory_order_relaxed);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Waits for a tick to be hit on the GPU
|
/// Waits for a tick to be hit on the GPU
|
||||||
|
|
|
@ -153,7 +153,7 @@ StagingBufferRef StagingBufferPool::GetStreamBuffer(size_t size) {
|
||||||
used_iterator = iterator;
|
used_iterator = iterator;
|
||||||
free_iterator = std::max(free_iterator, iterator + size);
|
free_iterator = std::max(free_iterator, iterator + size);
|
||||||
|
|
||||||
if (iterator + size > STREAM_BUFFER_SIZE) {
|
if (iterator + size >= STREAM_BUFFER_SIZE) {
|
||||||
std::fill(sync_ticks.begin() + Region(used_iterator), sync_ticks.begin() + NUM_SYNCS,
|
std::fill(sync_ticks.begin() + Region(used_iterator), sync_ticks.begin() + NUM_SYNCS,
|
||||||
current_tick);
|
current_tick);
|
||||||
used_iterator = 0;
|
used_iterator = 0;
|
||||||
|
@ -175,8 +175,9 @@ StagingBufferRef StagingBufferPool::GetStreamBuffer(size_t size) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StagingBufferPool::AreRegionsActive(size_t region_begin, size_t region_end) const {
|
bool StagingBufferPool::AreRegionsActive(size_t region_begin, size_t region_end) const {
|
||||||
|
const u64 gpu_tick = scheduler.GetMasterSemaphore().KnownGpuTick();
|
||||||
return std::any_of(sync_ticks.begin() + region_begin, sync_ticks.begin() + region_end,
|
return std::any_of(sync_ticks.begin() + region_begin, sync_ticks.begin() + region_end,
|
||||||
[this](u64 sync_tick) { return !scheduler.IsFree(sync_tick); });
|
[gpu_tick](u64 sync_tick) { return gpu_tick < sync_tick; });
|
||||||
};
|
};
|
||||||
|
|
||||||
StagingBufferRef StagingBufferPool::GetStagingBuffer(size_t size, MemoryUsage usage) {
|
StagingBufferRef StagingBufferPool::GetStagingBuffer(size_t size, MemoryUsage usage) {
|
||||||
|
|
Loading…
Reference in New Issue