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

Side by Side Diff: gpu/command_buffer/client/transfer_buffer_unittest.cc

Issue 9387014: Add AsyncFlush when transferbuffer is > a certain size (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 10 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « gpu/command_buffer/client/transfer_buffer.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Tests for the Command Buffer Helper. 5 // Tests for the Command Buffer Helper.
6 6
7 #include "gpu/command_buffer/client/transfer_buffer.h" 7 #include "gpu/command_buffer/client/transfer_buffer.h"
8 8
9 #include "gpu/command_buffer/client/client_test_helper.h" 9 #include "gpu/command_buffer/client/client_test_helper.h"
10 #include "gpu/command_buffer/client/cmd_buffer_helper.h" 10 #include "gpu/command_buffer/client/cmd_buffer_helper.h"
11 #include "gpu/command_buffer/common/command_buffer.h" 11 #include "gpu/command_buffer/common/command_buffer.h"
12 #include "gpu/command_buffer/common/compiler_specific.h" 12 #include "gpu/command_buffer/common/compiler_specific.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "testing/gmock/include/gmock/gmock.h" 14 #include "testing/gmock/include/gmock/gmock.h"
15 15
16 using ::testing::_; 16 using ::testing::_;
17 using ::testing::Invoke; 17 using ::testing::Invoke;
18 using ::testing::Return; 18 using ::testing::Return;
19 using ::testing::StrictMock; 19 using ::testing::StrictMock;
20 20
21 namespace gpu { 21 namespace gpu {
22 22
23
23 class TransferBufferTest : public testing::Test { 24 class TransferBufferTest : public testing::Test {
24 protected: 25 protected:
25 static const int32 kNumCommandEntries = 400; 26 static const int32 kNumCommandEntries = 400;
26 static const int32 kCommandBufferSizeBytes = 27 static const int32 kCommandBufferSizeBytes =
27 kNumCommandEntries * sizeof(CommandBufferEntry); 28 kNumCommandEntries * sizeof(CommandBufferEntry);
28 static const unsigned int kStartingOffset = 64; 29 static const unsigned int kStartingOffset = 64;
29 static const unsigned int kAlignment = 4; 30 static const unsigned int kAlignment = 4;
30 static const size_t kTransferBufferSize = 256; 31 static const size_t kTransferBufferSize = 256;
31 32
32 TransferBufferTest() 33 TransferBufferTest()
33 : transfer_buffer_id_(0) { 34 : transfer_buffer_id_(0) {
34 } 35 }
35 36
36 virtual void SetUp() OVERRIDE; 37 virtual void SetUp() OVERRIDE;
37 virtual void TearDown() OVERRIDE; 38 virtual void TearDown() OVERRIDE;
38 39
39 MockClientCommandBuffer* command_buffer() const { 40 virtual void Initialize(unsigned int size_to_flush) {
41 ASSERT_TRUE(transfer_buffer_->Initialize(
42 kTransferBufferSize,
43 kStartingOffset,
44 kTransferBufferSize,
45 kTransferBufferSize,
46 kAlignment,
47 size_to_flush));
48 }
49
50 MockClientCommandBufferMockFlush* command_buffer() const {
40 return command_buffer_.get(); 51 return command_buffer_.get();
41 } 52 }
42 53
43 scoped_ptr<MockClientCommandBuffer> command_buffer_; 54 scoped_ptr<MockClientCommandBufferMockFlush> command_buffer_;
44 scoped_ptr<CommandBufferHelper> helper_; 55 scoped_ptr<CommandBufferHelper> helper_;
45 scoped_ptr<TransferBuffer> transfer_buffer_; 56 scoped_ptr<TransferBuffer> transfer_buffer_;
46 int32 transfer_buffer_id_; 57 int32 transfer_buffer_id_;
47 }; 58 };
48 59
49 void TransferBufferTest::SetUp() { 60 void TransferBufferTest::SetUp() {
50 command_buffer_.reset(new StrictMock<MockClientCommandBuffer>()); 61 command_buffer_.reset(new StrictMock<MockClientCommandBufferMockFlush>());
51 ASSERT_TRUE(command_buffer_->Initialize()); 62 ASSERT_TRUE(command_buffer_->Initialize());
52 63
53 helper_.reset(new CommandBufferHelper(command_buffer())); 64 helper_.reset(new CommandBufferHelper(command_buffer()));
54 ASSERT_TRUE(helper_->Initialize(kCommandBufferSizeBytes)); 65 ASSERT_TRUE(helper_->Initialize(kCommandBufferSizeBytes));
55 66
56 transfer_buffer_id_ = command_buffer()->GetNextFreeTransferBufferId(); 67 transfer_buffer_id_ = command_buffer()->GetNextFreeTransferBufferId();
57 68
58 transfer_buffer_.reset(new TransferBuffer(helper_.get())); 69 transfer_buffer_.reset(new TransferBuffer(helper_.get()));
59 ASSERT_TRUE(transfer_buffer_->Initialize(
60 kTransferBufferSize,
61 kStartingOffset,
62 kTransferBufferSize,
63 kTransferBufferSize,
64 kAlignment));
65 } 70 }
66 71
67 void TransferBufferTest::TearDown() { 72 void TransferBufferTest::TearDown() {
68 if (transfer_buffer_->HaveBuffer()) { 73 if (transfer_buffer_->HaveBuffer()) {
69 EXPECT_CALL(*command_buffer(), OnFlush()) 74 EXPECT_CALL(*command_buffer(), OnFlush())
70 .Times(1) 75 .Times(1)
71 .RetiresOnSaturation(); 76 .RetiresOnSaturation();
72 EXPECT_CALL(*command_buffer(), DestroyTransferBuffer(_)) 77 EXPECT_CALL(*command_buffer(), DestroyTransferBuffer(_))
73 .Times(1) 78 .Times(1)
74 .RetiresOnSaturation(); 79 .RetiresOnSaturation();
75 } 80 }
76 transfer_buffer_.reset(); 81 transfer_buffer_.reset();
77 } 82 }
78 83
79 // GCC requires these declarations, but MSVC requires they not be present 84 // GCC requires these declarations, but MSVC requires they not be present
80 #ifndef _MSC_VER 85 #ifndef _MSC_VER
81 const int32 TransferBufferTest::kNumCommandEntries; 86 const int32 TransferBufferTest::kNumCommandEntries;
82 const int32 TransferBufferTest::kCommandBufferSizeBytes; 87 const int32 TransferBufferTest::kCommandBufferSizeBytes;
83 const unsigned int TransferBufferTest::kStartingOffset; 88 const unsigned int TransferBufferTest::kStartingOffset;
84 const unsigned int TransferBufferTest::kAlignment; 89 const unsigned int TransferBufferTest::kAlignment;
85 const size_t TransferBufferTest::kTransferBufferSize; 90 const size_t TransferBufferTest::kTransferBufferSize;
86 #endif 91 #endif
87 92
88 TEST_F(TransferBufferTest, Basic) { 93 TEST_F(TransferBufferTest, Basic) {
94 Initialize(0);
89 EXPECT_TRUE(transfer_buffer_->HaveBuffer()); 95 EXPECT_TRUE(transfer_buffer_->HaveBuffer());
90 EXPECT_EQ(transfer_buffer_id_, transfer_buffer_->GetShmId()); 96 EXPECT_EQ(transfer_buffer_id_, transfer_buffer_->GetShmId());
91 EXPECT_EQ( 97 EXPECT_EQ(
92 kTransferBufferSize - kStartingOffset, 98 kTransferBufferSize - kStartingOffset,
93 transfer_buffer_->GetCurrentMaxAllocationWithoutRealloc()); 99 transfer_buffer_->GetCurrentMaxAllocationWithoutRealloc());
94 } 100 }
95 101
96 TEST_F(TransferBufferTest, Free) { 102 TEST_F(TransferBufferTest, Free) {
103 Initialize(0);
97 EXPECT_TRUE(transfer_buffer_->HaveBuffer()); 104 EXPECT_TRUE(transfer_buffer_->HaveBuffer());
98 EXPECT_EQ(transfer_buffer_id_, transfer_buffer_->GetShmId()); 105 EXPECT_EQ(transfer_buffer_id_, transfer_buffer_->GetShmId());
99 106
100 // Free buffer. 107 // Free buffer.
101 EXPECT_CALL(*command_buffer(), OnFlush()) 108 EXPECT_CALL(*command_buffer(), OnFlush())
102 .Times(1) 109 .Times(1)
103 .RetiresOnSaturation(); 110 .RetiresOnSaturation();
104 EXPECT_CALL(*command_buffer(), DestroyTransferBuffer(_)) 111 EXPECT_CALL(*command_buffer(), DestroyTransferBuffer(_))
105 .Times(1) 112 .Times(1)
106 .RetiresOnSaturation(); 113 .RetiresOnSaturation();
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 .Times(1) 172 .Times(1)
166 .RetiresOnSaturation(); 173 .RetiresOnSaturation();
167 EXPECT_CALL(*command_buffer(), DestroyTransferBuffer(_)) 174 EXPECT_CALL(*command_buffer(), DestroyTransferBuffer(_))
168 .Times(1) 175 .Times(1)
169 .RetiresOnSaturation(); 176 .RetiresOnSaturation();
170 transfer_buffer_->Free(); 177 transfer_buffer_->Free();
171 transfer_buffer_->Free(); 178 transfer_buffer_->Free();
172 } 179 }
173 180
174 TEST_F(TransferBufferTest, TooLargeAllocation) { 181 TEST_F(TransferBufferTest, TooLargeAllocation) {
182 Initialize(0);
175 // Check that we can't allocate large than max size. 183 // Check that we can't allocate large than max size.
176 void* ptr = transfer_buffer_->Alloc(kTransferBufferSize + 1); 184 void* ptr = transfer_buffer_->Alloc(kTransferBufferSize + 1);
177 EXPECT_TRUE(ptr == NULL); 185 EXPECT_TRUE(ptr == NULL);
178 // Check we if we try to allocate larger than max we get max. 186 // Check we if we try to allocate larger than max we get max.
179 unsigned int size_allocated = 0; 187 unsigned int size_allocated = 0;
180 ptr = transfer_buffer_->AllocUpTo( 188 ptr = transfer_buffer_->AllocUpTo(
181 kTransferBufferSize + 1, &size_allocated); 189 kTransferBufferSize + 1, &size_allocated);
182 ASSERT_TRUE(ptr != NULL); 190 ASSERT_TRUE(ptr != NULL);
183 EXPECT_EQ(kTransferBufferSize - kStartingOffset, size_allocated); 191 EXPECT_EQ(kTransferBufferSize - kStartingOffset, size_allocated);
184 transfer_buffer_->FreePendingToken(ptr, 1); 192 transfer_buffer_->FreePendingToken(ptr, 1);
185 } 193 }
186 194
187 class MockClientCommandBufferCanFail : public MockClientCommandBuffer { 195 TEST_F(TransferBufferTest, Flush) {
196 Initialize(16u);
197 unsigned int size_allocated = 0;
198 for (int i = 0; i < 8; ++i) {
199 void* ptr = transfer_buffer_->AllocUpTo(8u, &size_allocated);
200 ASSERT_TRUE(ptr != NULL);
201 EXPECT_EQ(8u, size_allocated);
202 if (i % 2) {
203 EXPECT_CALL(*command_buffer(), Flush(_))
204 .Times(1)
205 .RetiresOnSaturation();
206 }
207 transfer_buffer_->FreePendingToken(ptr, 1);
208 }
209 for (int i = 0; i < 8; ++i) {
210 void* ptr = transfer_buffer_->Alloc(8u);
211 ASSERT_TRUE(ptr != NULL);
212 if (i % 2) {
213 EXPECT_CALL(*command_buffer(), Flush(_))
214 .Times(1)
215 .RetiresOnSaturation();
216 }
217 transfer_buffer_->FreePendingToken(ptr, 1);
218 }
219 }
220
221 class MockClientCommandBufferCanFail : public MockClientCommandBufferMockFlush {
188 public: 222 public:
189 MockClientCommandBufferCanFail() { 223 MockClientCommandBufferCanFail() {
190 } 224 }
191 virtual ~MockClientCommandBufferCanFail() { 225 virtual ~MockClientCommandBufferCanFail() {
192 } 226 }
193 227
194 MOCK_METHOD2(CreateTransferBuffer, int32(size_t size, int32 id_request)); 228 MOCK_METHOD2(CreateTransferBuffer, int32(size_t size, int32 id_request));
195 229
196 int32 RealCreateTransferBuffer(size_t size, int32 id_request) { 230 int32 RealCreateTransferBuffer(size_t size, int32 id_request) {
197 return MockCommandBufferBase::CreateTransferBuffer(size, id_request); 231 return MockCommandBufferBase::CreateTransferBuffer(size, id_request);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 command_buffer(), 282 command_buffer(),
249 &MockClientCommandBufferCanFail::RealCreateTransferBuffer)) 283 &MockClientCommandBufferCanFail::RealCreateTransferBuffer))
250 .RetiresOnSaturation(); 284 .RetiresOnSaturation();
251 285
252 transfer_buffer_.reset(new TransferBuffer(helper_.get())); 286 transfer_buffer_.reset(new TransferBuffer(helper_.get()));
253 ASSERT_TRUE(transfer_buffer_->Initialize( 287 ASSERT_TRUE(transfer_buffer_->Initialize(
254 kStartTransferBufferSize, 288 kStartTransferBufferSize,
255 kStartingOffset, 289 kStartingOffset,
256 kMinTransferBufferSize, 290 kMinTransferBufferSize,
257 kMaxTransferBufferSize, 291 kMaxTransferBufferSize,
258 kAlignment)); 292 kAlignment,
293 0));
259 } 294 }
260 295
261 void TransferBufferExpandContractTest::TearDown() { 296 void TransferBufferExpandContractTest::TearDown() {
262 if (transfer_buffer_->HaveBuffer()) { 297 if (transfer_buffer_->HaveBuffer()) {
263 EXPECT_CALL(*command_buffer(), OnFlush()) 298 EXPECT_CALL(*command_buffer(), OnFlush())
264 .Times(1) 299 .Times(1)
265 .RetiresOnSaturation(); 300 .RetiresOnSaturation();
266 EXPECT_CALL(*command_buffer(), DestroyTransferBuffer(_)) 301 EXPECT_CALL(*command_buffer(), DestroyTransferBuffer(_))
267 .Times(1) 302 .Times(1)
268 .RetiresOnSaturation(); 303 .RetiresOnSaturation();
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 .WillOnce(Return(-1)) 457 .WillOnce(Return(-1))
423 .RetiresOnSaturation(); 458 .RetiresOnSaturation();
424 459
425 const size_t kSize1 = 512 - kStartingOffset; 460 const size_t kSize1 = 512 - kStartingOffset;
426 unsigned int size_allocated = 0; 461 unsigned int size_allocated = 0;
427 void* ptr = transfer_buffer_->AllocUpTo(kSize1, &size_allocated); 462 void* ptr = transfer_buffer_->AllocUpTo(kSize1, &size_allocated);
428 ASSERT_TRUE(ptr == NULL); 463 ASSERT_TRUE(ptr == NULL);
429 EXPECT_FALSE(transfer_buffer_->HaveBuffer()); 464 EXPECT_FALSE(transfer_buffer_->HaveBuffer());
430 } 465 }
431 466
467
432 } // namespace gpu 468 } // namespace gpu
433 469
434 470
OLDNEW
« no previous file with comments | « gpu/command_buffer/client/transfer_buffer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698