summaryrefslogtreecommitdiffstats
path: root/gpu/command_buffer/client
diff options
context:
space:
mode:
Diffstat (limited to 'gpu/command_buffer/client')
-rw-r--r--gpu/command_buffer/client/cmd_buffer_helper.cc22
-rw-r--r--gpu/command_buffer/client/cmd_buffer_helper.h2
2 files changed, 16 insertions, 8 deletions
diff --git a/gpu/command_buffer/client/cmd_buffer_helper.cc b/gpu/command_buffer/client/cmd_buffer_helper.cc
index bd44431..6328923 100644
--- a/gpu/command_buffer/client/cmd_buffer_helper.cc
+++ b/gpu/command_buffer/client/cmd_buffer_helper.cc
@@ -52,14 +52,14 @@ CommandBufferHelper::~CommandBufferHelper() {
}
bool CommandBufferHelper::FlushSync() {
- time(&last_flush_time_);
+ last_flush_time_ = clock();
last_put_sent_ = put_;
CommandBuffer::State state = command_buffer_->FlushSync(put_, get_offset());
return state.error == error::kNoError;
}
void CommandBufferHelper::Flush() {
- time(&last_flush_time_);
+ last_flush_time_ = clock();
last_put_sent_ = put_;
command_buffer_->Flush(put_);
}
@@ -152,11 +152,19 @@ void CommandBufferHelper::WaitForAvailableEntries(int32 count) {
return;
}
}
- // Allow this command buffer to be pre-empted by another if a "reasonable"
- // amount of work has been done.
- if (commands_issued_ % kCommandsPerFlushCheck == 0) {
- clock_t current_time = time(NULL);
- if (difftime(current_time, last_flush_time_) > kFlushDelay)
+ // 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_offset() == last_put_sent_) ? 16 : 2);
+ if (pending > limit) {
+ Flush();
+ } else if (commands_issued_ % kCommandsPerFlushCheck == 0) {
+ // Allow this command buffer to be pre-empted by another if a "reasonable"
+ // amount of work has been done.
+ clock_t current_time = clock();
+ if (current_time - last_flush_time_ > kFlushDelay * CLOCKS_PER_SEC)
Flush();
}
}
diff --git a/gpu/command_buffer/client/cmd_buffer_helper.h b/gpu/command_buffer/client/cmd_buffer_helper.h
index a7c17ef..b6f45e2 100644
--- a/gpu/command_buffer/client/cmd_buffer_helper.h
+++ b/gpu/command_buffer/client/cmd_buffer_helper.h
@@ -235,7 +235,7 @@ class CommandBufferHelper {
int commands_issued_;
// Using C runtime instead of base because this file cannot depend on base.
- time_t last_flush_time_;
+ clock_t last_flush_time_;
friend class CommandBufferHelperTest;
DISALLOW_COPY_AND_ASSIGN(CommandBufferHelper);