Preventing (one of likely many) race condition with ringbuffer.

This was causing acks for commands not executed if the CPU ran faster
than the GPU.
This commit is contained in:
Ben Vanik 2013-10-13 12:17:07 -07:00
parent 41a652dd03
commit e0af361d74
2 changed files with 15 additions and 11 deletions

View File

@ -75,7 +75,11 @@ void RingBufferWorker::Pump() {
return;
}
}
if (read_ptr_index_ == write_ptr_index_) {
// Bring local so we don't have to worry about them changing out from under
// us.
uint32_t write_ptr_index = write_ptr_index_;
if (read_ptr_index_ == write_ptr_index) {
return;
}
@ -84,11 +88,11 @@ void RingBufferWorker::Pump() {
// TODO(benvanik): handle wrapping around
// read_ptr_index_ = (read_ptr_index_ + 1) % (primary_buffer_size_ / 4);
XEASSERT(write_ptr_index_ > read_ptr_index_);
uint32_t length = write_ptr_index_ - read_ptr_index_;
XEASSERT(write_ptr_index > read_ptr_index_);
uint32_t length = write_ptr_index - read_ptr_index_;
if (length) {
ExecuteSegment(primary_buffer_ptr_ + read_ptr_index_ * 4, length);
read_ptr_index_ = write_ptr_index_;
read_ptr_index_ = write_ptr_index;
}
// TODO(benvanik): use read_ptr_update_freq_ and only issue after moving

View File

@ -43,15 +43,15 @@ protected:
GraphicsDriver* driver_;
uint32_t primary_buffer_ptr_;
uint32_t primary_buffer_size_;
uint32_t primary_buffer_ptr_;
uint32_t primary_buffer_size_;
uint32_t read_ptr_index_;
uint32_t read_ptr_update_freq_;
uint32_t read_ptr_writeback_ptr_;
uint32_t read_ptr_index_;
uint32_t read_ptr_update_freq_;
uint32_t read_ptr_writeback_ptr_;
HANDLE write_ptr_index_event_;
uint32_t write_ptr_index_;
HANDLE write_ptr_index_event_;
volatile uint32_t write_ptr_index_;
};