From f9a634ad25c1b05679a94d87885cda8beb2c31b8 Mon Sep 17 00:00:00 2001 From: "Dr. Chat" Date: Fri, 1 Apr 2016 21:53:46 -0500 Subject: [PATCH] CircularBuffer remove Discard functionality and allow rotation --- src/xenia/ui/vulkan/circular_buffer.cc | 25 +++++++------------------ src/xenia/ui/vulkan/circular_buffer.h | 4 +++- 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/src/xenia/ui/vulkan/circular_buffer.cc b/src/xenia/ui/vulkan/circular_buffer.cc index 4cc22366f..110cd6c36 100644 --- a/src/xenia/ui/vulkan/circular_buffer.cc +++ b/src/xenia/ui/vulkan/circular_buffer.cc @@ -139,7 +139,6 @@ CircularBuffer::Allocation* CircularBuffer::Acquire( assert(read_head_ == write_head_); assert(capacity_ > aligned_length); - read_head_ = 0; write_head_ = length; auto alloc = new Allocation(); @@ -200,19 +199,6 @@ CircularBuffer::Allocation* CircularBuffer::Acquire( return nullptr; } -void CircularBuffer::Discard(Allocation* allocation) { - // TODO: Revert write_head_ (only if this is the last alloc though) - // Or maybe just disallow discards. - for (auto it = allocations_.begin(); it != allocations_.end(); ++it) { - if (*it == allocation) { - allocations_.erase(it); - break; - } - } - - delete allocation; -} - void CircularBuffer::Flush(Allocation* allocation) { VkMappedMemoryRange range; range.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE; @@ -239,7 +225,13 @@ void CircularBuffer::Scavenge() { break; } - read_head_ = (read_head_ + (*it)->aligned_length) % capacity_; + if (capacity_ - read_head_ < (*it)->aligned_length) { + // This allocation is stored at the beginning of the buffer. + read_head_ = (*it)->aligned_length; + } else { + read_head_ += (*it)->aligned_length; + } + delete *it; it = allocations_.erase(it); } @@ -247,9 +239,6 @@ void CircularBuffer::Scavenge() { if (allocations_.empty()) { // Reset R/W heads. read_head_ = write_head_ = 0; - } else { - // FIXME: Haven't verified this works correctly when actually rotating :P - assert_always(); } } diff --git a/src/xenia/ui/vulkan/circular_buffer.h b/src/xenia/ui/vulkan/circular_buffer.h index 2c036c685..6f0ec2f82 100644 --- a/src/xenia/ui/vulkan/circular_buffer.h +++ b/src/xenia/ui/vulkan/circular_buffer.h @@ -52,8 +52,10 @@ class CircularBuffer { uint8_t* host_base() const { return host_base_; } bool CanAcquire(VkDeviceSize length); + + // Acquires space to hold memory. This allocation is only freed when the fence + // reaches the signaled state. Allocation* Acquire(VkDeviceSize length, std::shared_ptr fence); - void Discard(Allocation* allocation); void Flush(Allocation* allocation); // Clears all allocations, regardless of whether they've been consumed or not.