Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(142)

Unified Diff: gpu/command_buffer/client/cmd_buffer_helper.cc

Issue 6316002: Make CommandBuffer::Flush asynchronous, and add CommandBuffer::FlushSync with former semantics. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: gpu/command_buffer/client/cmd_buffer_helper.cc
diff --git a/gpu/command_buffer/client/cmd_buffer_helper.cc b/gpu/command_buffer/client/cmd_buffer_helper.cc
index b666e83dc5dc18134cbe8acfdd677ae5fdde7df6..b525021da424bf11d2b357adc860f5f3b2f3a66e 100644
--- a/gpu/command_buffer/client/cmd_buffer_helper.cc
+++ b/gpu/command_buffer/client/cmd_buffer_helper.cc
@@ -17,7 +17,8 @@ CommandBufferHelper::CommandBufferHelper(CommandBuffer* command_buffer)
token_(0),
last_token_read_(-1),
get_(0),
- put_(0) {
+ put_(0),
+ last_put_sent_(0) {
}
bool CommandBufferHelper::Initialize(int32 ring_buffer_size) {
@@ -45,19 +46,25 @@ bool CommandBufferHelper::Initialize(int32 ring_buffer_size) {
CommandBufferHelper::~CommandBufferHelper() {
}
-bool CommandBufferHelper::Flush() {
- CommandBuffer::State state = command_buffer_->Flush(put_);
+bool CommandBufferHelper::FlushSync() {
+ last_put_sent_ = put_;
+ CommandBuffer::State state = command_buffer_->FlushSync(put_);
SynchronizeState(state);
return state.error == error::kNoError;
}
+void CommandBufferHelper::Flush() {
+ last_put_sent_ = put_;
+ command_buffer_->Flush(put_);
+}
+
// Calls Flush() and then waits until the buffer is empty. Break early if the
// error is set.
bool CommandBufferHelper::Finish() {
do {
// Do not loop forever if the flush fails, meaning the command buffer reader
// has shutdown.
- if (!Flush())
+ if (!FlushSync())
return false;
} while (put_ != get_);
@@ -88,9 +95,7 @@ void CommandBufferHelper::WaitForToken(int32 token) {
// Return immediately if corresponding InsertToken failed.
if (token < 0)
return;
- if (last_token_read_ >= token) return; // fast path.
if (token > token_) return; // we wrapped
- Flush();
while (last_token_read_ < token) {
if (get_ == put_) {
GPU_LOG(FATAL) << "Empty command buffer while waiting on a token.";
@@ -98,7 +103,7 @@ void CommandBufferHelper::WaitForToken(int32 token) {
}
// Do not loop forever if the flush fails, meaning the command buffer reader
// has shutdown.
- if (!Flush())
+ if (!FlushSync())
return;
}
}
@@ -116,27 +121,30 @@ void CommandBufferHelper::WaitForAvailableEntries(int32 count) {
// need to make sure get wraps first, actually that get is 1 or more (since
// put will wrap to 0 after we add the jump).
GPU_DCHECK_LE(1, put_);
- Flush();
while (get_ > put_ || get_ == 0) {
// Do not loop forever if the flush fails, meaning the command buffer
// reader has shutdown.
- if (!Flush())
+ if (!FlushSync())
return;
}
// Insert a jump back to the beginning.
cmd::Jump::Set(&entries_[put_], 0);
put_ = 0;
}
- // If we have enough room, return immediatly.
- if (count <= AvailableEntries()) return;
- // Otherwise flush, and wait until we do have enough room.
- Flush();
while (AvailableEntries() < count) {
// Do not loop forever if the flush fails, meaning the command buffer reader
// has shutdown.
- if (!Flush())
+ if (!FlushSync())
return;
}
+ // Force a flush if the buffer is getting half full, or even earlier if the
+ // reader is known to be idle.
+ int32 pending =
+ (put_ + usable_entry_count_ - last_put_sent_) % usable_entry_count_;
+ int32 limit = usable_entry_count_ / ((get_ == last_put_sent_) ? 16 : 2);
+ if (pending > limit) {
+ Flush();
+ }
}
CommandBufferEntry* CommandBufferHelper::GetSpace(uint32 entries) {
« no previous file with comments | « gpu/command_buffer/client/cmd_buffer_helper.h ('k') | gpu/command_buffer/client/gles2_implementation_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698