summaryrefslogtreecommitdiffstats
path: root/gpu
diff options
context:
space:
mode:
authorqsr@chromium.org <qsr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-10 16:41:14 +0000
committerqsr@chromium.org <qsr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-10 16:41:14 +0000
commit1924a4adffd01dd8bfd3753b41e16aaf9ab086b3 (patch)
treed9a011fc9c295eeb132771741f84cfaf6a6203f2 /gpu
parent8a312e5083d8acf6f14610a9168917a9fb3d74fb (diff)
downloadchromium_src-1924a4adffd01dd8bfd3753b41e16aaf9ab086b3.zip
chromium_src-1924a4adffd01dd8bfd3753b41e16aaf9ab086b3.tar.gz
chromium_src-1924a4adffd01dd8bfd3753b41e16aaf9ab086b3.tar.bz2
In RingBuffer::GetLargestFreeSizeNoWaiting, release until current token.
RingBuffer::GetLargestFreeSizeNoWaiting can release any block for which tokens have already been seen. R=gman@chromium.org Review URL: https://codereview.chromium.org/16226019 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@205224 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'gpu')
-rw-r--r--gpu/command_buffer/client/ring_buffer.cc8
-rw-r--r--gpu/command_buffer/client/ring_buffer_test.cc33
2 files changed, 38 insertions, 3 deletions
diff --git a/gpu/command_buffer/client/ring_buffer.cc b/gpu/command_buffer/client/ring_buffer.cc
index 46a86a2..42e09bd 100644
--- a/gpu/command_buffer/client/ring_buffer.cc
+++ b/gpu/command_buffer/client/ring_buffer.cc
@@ -94,8 +94,12 @@ void RingBuffer::FreePendingToken(RingBuffer::Offset offset,
}
unsigned int RingBuffer::GetLargestFreeSizeNoWaiting() {
- // TODO(gman): Should check what the current token is and free up to that
- // point.
+ unsigned int last_token_read = helper_->last_token_read();
+ while (!blocks_.empty()) {
+ Block& block = blocks_.front();
+ if (block.token > last_token_read || block.state == IN_USE) break;
+ FreeOldestBlock();
+ }
if (free_offset_ == in_use_offset_) {
if (blocks_.empty()) {
// The entire buffer is free.
diff --git a/gpu/command_buffer/client/ring_buffer_test.cc b/gpu/command_buffer/client/ring_buffer_test.cc
index ceeb2ed..921cf39 100644
--- a/gpu/command_buffer/client/ring_buffer_test.cc
+++ b/gpu/command_buffer/client/ring_buffer_test.cc
@@ -35,7 +35,29 @@ class BaseRingBufferTest : public testing::Test {
static const unsigned int kBaseOffset = 128;
static const unsigned int kBufferSize = 1024;
+ void RunPendingSetToken() {
+ for (std::vector<const void*>::iterator it = set_token_arguments_.begin();
+ it != set_token_arguments_.end();
+ ++it) {
+ api_mock_->SetToken(cmd::kSetToken, 1, *it);
+ }
+ set_token_arguments_.clear();
+ delay_set_token_ = false;
+ }
+
+ void SetToken(unsigned int command,
+ unsigned int arg_count,
+ const void* _args) {
+ EXPECT_EQ(cmd::kSetToken, command);
+ EXPECT_EQ(1u, arg_count);
+ if (delay_set_token_)
+ set_token_arguments_.push_back(_args);
+ else
+ api_mock_->SetToken(cmd::kSetToken, 1, _args);
+ }
+
virtual void SetUp() {
+ delay_set_token_ = false;
api_mock_.reset(new AsyncAPIMock);
// ignore noops in the mock - we don't want to inspect the internals of the
// helper.
@@ -43,7 +65,7 @@ class BaseRingBufferTest : public testing::Test {
.WillRepeatedly(Return(error::kNoError));
// Forward the SetToken calls to the engine
EXPECT_CALL(*api_mock_.get(), DoCommand(cmd::kSetToken, 1, _))
- .WillRepeatedly(DoAll(Invoke(api_mock_.get(), &AsyncAPIMock::SetToken),
+ .WillRepeatedly(DoAll(Invoke(this, &BaseRingBufferTest::SetToken),
Return(error::kNoError)));
{
@@ -81,6 +103,9 @@ class BaseRingBufferTest : public testing::Test {
scoped_ptr<CommandBufferService> command_buffer_;
scoped_ptr<GpuScheduler> gpu_scheduler_;
scoped_ptr<CommandBufferHelper> helper_;
+ std::vector<const void*> set_token_arguments_;
+ bool delay_set_token_;
+
};
#ifndef _MSC_VER
@@ -128,6 +153,7 @@ TEST_F(RingBufferTest, TestFreePendingToken) {
const unsigned int kAllocCount = kBufferSize / kSize;
CHECK(kAllocCount * kSize == kBufferSize);
+ delay_set_token_ = true;
// Allocate several buffers to fill in the memory.
int32 tokens[kAllocCount];
for (unsigned int ii = 0; ii < kAllocCount; ++ii) {
@@ -140,6 +166,8 @@ TEST_F(RingBufferTest, TestFreePendingToken) {
EXPECT_EQ(kBufferSize - (kSize * kAllocCount),
allocator_->GetLargestFreeSizeNoWaiting());
+ RunPendingSetToken();
+
// This allocation will need to reclaim the space freed above, so that should
// process the commands until a token is passed.
RingBuffer::Offset offset1 = allocator_->Alloc(kSize);
@@ -242,6 +270,7 @@ TEST_F(RingBufferWrapperTest, TestFreePendingToken) {
const unsigned int kAllocCount = kBufferSize / kSize;
CHECK(kAllocCount * kSize == kBufferSize);
+ delay_set_token_ = true;
// Allocate several buffers to fill in the memory.
int32 tokens[kAllocCount];
for (unsigned int ii = 0; ii < kAllocCount; ++ii) {
@@ -254,6 +283,8 @@ TEST_F(RingBufferWrapperTest, TestFreePendingToken) {
EXPECT_EQ(kBufferSize - (kSize * kAllocCount),
allocator_->GetLargestFreeSizeNoWaiting());
+ RunPendingSetToken();
+
// This allocation will need to reclaim the space freed above, so that should
// process the commands until the token is passed.
void* pointer1 = allocator_->Alloc(kSize);