diff options
author | apatrick@chromium.org <apatrick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-12 18:04:10 +0000 |
---|---|---|
committer | apatrick@chromium.org <apatrick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-12 18:04:10 +0000 |
commit | b36897c196ab3bcd6eea471d0701e2bf47945e0e (patch) | |
tree | 76c08c2ad47147d5caf44903a41eb720e91b985e /gpu | |
parent | 417d2d1f242f7a5256ab7c7437f7ed6e060b95f3 (diff) | |
download | chromium_src-b36897c196ab3bcd6eea471d0701e2bf47945e0e.zip chromium_src-b36897c196ab3bcd6eea471d0701e2bf47945e0e.tar.gz chromium_src-b36897c196ab3bcd6eea471d0701e2bf47945e0e.tar.bz2 |
Cooperatively round robin GPU command buffers.
The renderer processes asynchronously flush every n milliseconds. This prevents one renderer process from starving the others by issuing excessive amounts of GL calls without flushing.
Also has the advantage that the GPU process more evenly spreads its work out over the course of the frame.
Follows: http://codereview.chromium.org/7253052/
Review URL: http://codereview.chromium.org/7313032
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@92197 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'gpu')
-rw-r--r-- | gpu/command_buffer/client/cmd_buffer_helper.cc | 25 | ||||
-rw-r--r-- | gpu/command_buffer/client/cmd_buffer_helper.h | 9 |
2 files changed, 24 insertions, 10 deletions
diff --git a/gpu/command_buffer/client/cmd_buffer_helper.cc b/gpu/command_buffer/client/cmd_buffer_helper.cc index b012b1a..354d563 100644 --- a/gpu/command_buffer/client/cmd_buffer_helper.cc +++ b/gpu/command_buffer/client/cmd_buffer_helper.cc @@ -10,6 +10,11 @@ namespace gpu { +namespace { +const int kCommandsPerFlushCheck = 100; +const double kFlushDelay = 1.0 / (5.0 * 60.0); +} + CommandBufferHelper::CommandBufferHelper(CommandBuffer* command_buffer) : command_buffer_(command_buffer), entries_(NULL), @@ -19,7 +24,9 @@ CommandBufferHelper::CommandBufferHelper(CommandBuffer* command_buffer) last_token_read_(-1), get_(0), put_(0), - last_put_sent_(0) { + last_put_sent_(0), + commands_issued_(0), + last_flush_time_(0) { } bool CommandBufferHelper::Initialize(int32 ring_buffer_size) { @@ -48,6 +55,7 @@ CommandBufferHelper::~CommandBufferHelper() { } bool CommandBufferHelper::FlushSync() { + time(&last_flush_time_); last_put_sent_ = put_; CommandBuffer::State state = command_buffer_->FlushSync(put_, get_); SynchronizeState(state); @@ -55,6 +63,7 @@ bool CommandBufferHelper::FlushSync() { } void CommandBufferHelper::Flush() { + time(&last_flush_time_); last_put_sent_ = put_; command_buffer_->Flush(put_); } @@ -152,17 +161,17 @@ void CommandBufferHelper::WaitForAvailableEntries(int32 count) { 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(); + // 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) + Flush(); } } CommandBufferEntry* CommandBufferHelper::GetSpace(uint32 entries) { + ++commands_issued_; WaitForAvailableEntries(entries); CommandBufferEntry* space = &entries_[put_]; put_ += entries; diff --git a/gpu/command_buffer/client/cmd_buffer_helper.h b/gpu/command_buffer/client/cmd_buffer_helper.h index 94653a7..c7413ca 100644 --- a/gpu/command_buffer/client/cmd_buffer_helper.h +++ b/gpu/command_buffer/client/cmd_buffer_helper.h @@ -8,6 +8,7 @@ #define GPU_COMMAND_BUFFER_CLIENT_CMD_BUFFER_HELPER_H_ #include <string.h> +#include <time.h> #include "../common/logging.h" #include "../common/constants.h" @@ -87,8 +88,8 @@ class CommandBufferHelper { // particularly useful after inserting a token that will be waited on. void YieldScheduler(); - // Waits for a certain amount of space to be available. Returns address - // of space. + // Called prior to each command being issued. Waits for a certain amount of + // space to be available. Returns address of space. CommandBufferEntry* GetSpace(uint32 entries); // Typed version of GetSpace. Gets enough room for the given type and returns @@ -236,6 +237,10 @@ class CommandBufferHelper { int32 get_; int32 put_; int32 last_put_sent_; + int commands_issued_; + + // Using C runtime instead of base because this file cannot depend on base. + time_t last_flush_time_; friend class CommandBufferHelperTest; DISALLOW_COPY_AND_ASSIGN(CommandBufferHelper); |