diff options
author | piman@google.com <piman@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-23 00:57:35 +0000 |
---|---|---|
committer | piman@google.com <piman@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-23 00:57:35 +0000 |
commit | 6b7a63f77940d7746e85b1165073cb1c1cc13deb (patch) | |
tree | d2a63c42e07a53641bc19a3191f612a8665619c8 /gpu | |
parent | 1a6273b7545c8413208cd1831862870827645f1e (diff) | |
download | chromium_src-6b7a63f77940d7746e85b1165073cb1c1cc13deb.zip chromium_src-6b7a63f77940d7746e85b1165073cb1c1cc13deb.tar.gz chromium_src-6b7a63f77940d7746e85b1165073cb1c1cc13deb.tar.bz2 |
Add a yield command to the command buffer.
This allows more graceful scheduling so that waiting on the previous frame's swapbuffers doesn't end up being a Finish.
BUG=none
TEST=check in about:gpu and verify that SwapBuffers in the renderer process actually only waits for the previous SwapBuffers in the gpu process.
Review URL: http://codereview.chromium.org/6899037
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@82759 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'gpu')
-rw-r--r-- | gpu/command_buffer/client/cmd_buffer_helper.cc | 5 | ||||
-rw-r--r-- | gpu/command_buffer/client/cmd_buffer_helper.h | 7 | ||||
-rw-r--r-- | gpu/command_buffer/client/gles2_implementation.cc | 1 | ||||
-rw-r--r-- | gpu/command_buffer/common/cmd_buffer_common.h | 29 | ||||
-rw-r--r-- | gpu/command_buffer/common/constants.h | 15 | ||||
-rw-r--r-- | gpu/command_buffer/service/cmd_buffer_engine.h | 2 | ||||
-rw-r--r-- | gpu/command_buffer/service/common_decoder.cc | 8 | ||||
-rw-r--r-- | gpu/command_buffer/service/common_decoder_unittest.cc | 6 | ||||
-rw-r--r-- | gpu/command_buffer/service/gpu_scheduler.cc | 11 |
9 files changed, 73 insertions, 11 deletions
diff --git a/gpu/command_buffer/client/cmd_buffer_helper.cc b/gpu/command_buffer/client/cmd_buffer_helper.cc index 3f7d94e..8da55b69 100644 --- a/gpu/command_buffer/client/cmd_buffer_helper.cc +++ b/gpu/command_buffer/client/cmd_buffer_helper.cc @@ -112,6 +112,11 @@ void CommandBufferHelper::WaitForToken(int32 token) { } } +void CommandBufferHelper::YieldScheduler() { + cmd::YieldScheduler& cmd = GetCmdSpace<cmd::YieldScheduler>(); + cmd.Init(); +} + // Waits for available entries, basically waiting until get >= put + count + 1. // It actually waits for contiguous entries, so it may need to wrap the buffer // around, adding a jump. Thus this function may change the value of put_. The diff --git a/gpu/command_buffer/client/cmd_buffer_helper.h b/gpu/command_buffer/client/cmd_buffer_helper.h index c28333a..0f41b9b 100644 --- a/gpu/command_buffer/client/cmd_buffer_helper.h +++ b/gpu/command_buffer/client/cmd_buffer_helper.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -82,6 +82,11 @@ class CommandBufferHelper { // the value of the token to wait for. void WaitForToken(int32 token); + // Inserts a yield command, signaling the scheduler that this is a good point + // to update the state and schedule other command buffers. This is + // 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. CommandBufferEntry* GetSpace(uint32 entries); diff --git a/gpu/command_buffer/client/gles2_implementation.cc b/gpu/command_buffer/client/gles2_implementation.cc index 86b3bc4..aa94fbb 100644 --- a/gpu/command_buffer/client/gles2_implementation.cc +++ b/gpu/command_buffer/client/gles2_implementation.cc @@ -691,6 +691,7 @@ void GLES2Implementation::SwapBuffers() { } helper_->SwapBuffers(); swap_buffers_tokens_.push(helper_->InsertToken()); + helper_->YieldScheduler(); Flush(); } diff --git a/gpu/command_buffer/common/cmd_buffer_common.h b/gpu/command_buffer/common/cmd_buffer_common.h index e8bcd43..80d1e28 100644 --- a/gpu/command_buffer/common/cmd_buffer_common.h +++ b/gpu/command_buffer/common/cmd_buffer_common.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -157,6 +157,7 @@ namespace cmd { OP(SetBucketDataImmediate) /* 9 */ \ OP(GetBucketSize) /* 10 */ \ OP(GetBucketData) /* 11 */ \ + OP(YieldScheduler) /* 12 */ \ // Common commands. enum CommandId { @@ -641,6 +642,32 @@ COMPILE_ASSERT(offsetof(GetBucketData, shared_memory_id) == 16, COMPILE_ASSERT(offsetof(GetBucketData, shared_memory_offset) == 20, Offsetof_GetBucketData_shared_memory_offset_not_20); +// A Yield command. Hints the scheduler that this is a good point to update the +// state and schedule other command buffers. +struct YieldScheduler { + typedef YieldScheduler ValueType; + static const CommandId kCmdId = kYieldScheduler; + static const cmd::ArgFlags kArgFlags = cmd::kFixed; + + void SetHeader() { + header.SetCmd<ValueType>(); + } + + void Init() { + SetHeader(); + } + static void* Set(void* cmd) { + static_cast<ValueType*>(cmd)->Init(); + return NextCmdAddress<ValueType>(cmd); + } + + CommandHeader header; +}; + +COMPILE_ASSERT(sizeof(YieldScheduler) == 4, Sizeof_YieldScheduler_is_not_4); +COMPILE_ASSERT(offsetof(YieldScheduler, header) == 0, + Offsetof_YieldScheduler_header_not_0); + } // namespace cmd #pragma pack(pop) diff --git a/gpu/command_buffer/common/constants.h b/gpu/command_buffer/common/constants.h index ca1d5a8..3b06cad 100644 --- a/gpu/command_buffer/common/constants.h +++ b/gpu/command_buffer/common/constants.h @@ -26,12 +26,23 @@ namespace error { // This is not an error. It is returned by WaitLatch when it is blocked. // When blocked, the context will not reschedule itself until another // context executes a SetLatch command. - kWaiting + kWaiting, + + // This is not an error either. It just hints the scheduler that it can exit + // its loop, update state, and schedule other command buffers. + kYield }; // Return true if the given error code is an actual error. inline bool IsError(Error error) { - return (error != kNoError && error != kWaiting); + switch (error) { + case kNoError: + case kWaiting: + case kYield: + return false; + default: + return true; + } } } diff --git a/gpu/command_buffer/service/cmd_buffer_engine.h b/gpu/command_buffer/service/cmd_buffer_engine.h index 964944d..59e99ab 100644 --- a/gpu/command_buffer/service/cmd_buffer_engine.h +++ b/gpu/command_buffer/service/cmd_buffer_engine.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/gpu/command_buffer/service/common_decoder.cc b/gpu/command_buffer/service/common_decoder.cc index a116d04..35eaf66 100644 --- a/gpu/command_buffer/service/common_decoder.cc +++ b/gpu/command_buffer/service/common_decoder.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -330,4 +330,10 @@ error::Error CommonDecoder::HandleGetBucketData( return error::kNoError; } +error::Error CommonDecoder::HandleYieldScheduler( + uint32 immediate_data_size, + const cmd::YieldScheduler& args) { + return error::kYield; +} + } // namespace gpu diff --git a/gpu/command_buffer/service/common_decoder_unittest.cc b/gpu/command_buffer/service/common_decoder_unittest.cc index 8f88398..9b53a56 100644 --- a/gpu/command_buffer/service/common_decoder_unittest.cc +++ b/gpu/command_buffer/service/common_decoder_unittest.cc @@ -556,5 +556,11 @@ TEST_F(CommonDecoderTest, GetBucketData) { EXPECT_NE(error::kNoError, ExecuteCmd(cmd)); } +TEST_F(CommonDecoderTest, YieldScheduler) { + cmd::YieldScheduler cmd; + cmd.Init(); + EXPECT_EQ(error::kYield, ExecuteCmd(cmd)); +} + } // namespace gpu diff --git a/gpu/command_buffer/service/gpu_scheduler.cc b/gpu/command_buffer/service/gpu_scheduler.cc index 1782dec..408d56d 100644 --- a/gpu/command_buffer/service/gpu_scheduler.cc +++ b/gpu/command_buffer/service/gpu_scheduler.cc @@ -146,16 +146,17 @@ void GpuScheduler::ProcessCommands() { error::Error error = error::kNoError; int commands_processed = 0; - while (commands_processed < commands_per_update_ && !parser_->IsEmpty()) { + while (commands_processed < commands_per_update_ && + !parser_->IsEmpty()) { error = parser_->ProcessCommand(); - if (error == error::kWaiting) { - break; - } - if (error::IsError(error)) { + if (error == error::kWaiting || error == error::kYield) { + break; + } else if (error::IsError(error)) { command_buffer_->SetParseError(error); return; } + ++commands_processed; if (command_processed_callback_.get()) { command_processed_callback_->Run(); |