CircularBuffer remove Discard functionality and allow rotation

This commit is contained in:
Dr. Chat 2016-04-01 21:53:46 -05:00
parent 50f72b4e42
commit f9a634ad25
2 changed files with 10 additions and 19 deletions

View File

@ -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();
}
}

View File

@ -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> fence);
void Discard(Allocation* allocation);
void Flush(Allocation* allocation);
// Clears all allocations, regardless of whether they've been consumed or not.