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

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

Issue 2956005: Adds MapBufferSubData and MapTexSubImage2D.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 5 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
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 // This file contains the tests for the FencedAllocator class. 5 // This file contains the tests for the FencedAllocator class.
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/scoped_nsautorelease_pool.h" 9 #include "base/scoped_nsautorelease_pool.h"
10 #include "gpu/command_buffer/client/cmd_buffer_helper.h" 10 #include "gpu/command_buffer/client/cmd_buffer_helper.h"
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 // Check that the token has indeed passed. 199 // Check that the token has indeed passed.
200 EXPECT_LE(token, GetToken()); 200 EXPECT_LE(token, GetToken());
201 201
202 // Free up everything. 202 // Free up everything.
203 for (unsigned int i = 0; i < kAllocCount; ++i) { 203 for (unsigned int i = 0; i < kAllocCount; ++i) {
204 allocator_->Free(offsets[i]); 204 allocator_->Free(offsets[i]);
205 EXPECT_TRUE(allocator_->CheckConsistency()); 205 EXPECT_TRUE(allocator_->CheckConsistency());
206 } 206 }
207 } 207 }
208 208
209 // Checks the free-pending-token mechanism using FreeUnused
210 TEST_F(FencedAllocatorTest, FreeUnused) {
211 EXPECT_TRUE(allocator_->CheckConsistency());
212
213 const unsigned int kSize = 16;
214 const unsigned int kAllocCount = kBufferSize / kSize;
215 CHECK(kAllocCount * kSize == kBufferSize);
216
217 // Allocate several buffers to fill in the memory.
218 FencedAllocator::Offset offsets[kAllocCount];
219 for (unsigned int i = 0; i < kAllocCount; ++i) {
220 offsets[i] = allocator_->Alloc(kSize);
221 EXPECT_NE(FencedAllocator::kInvalidOffset, offsets[i]);
222 EXPECT_GE(kBufferSize, offsets[i]+kSize);
223 EXPECT_TRUE(allocator_->CheckConsistency());
224 }
225
226 // No memory should be available.
227 EXPECT_EQ(0u, allocator_->GetLargestFreeSize());
228
229 // Free one successful allocation, pending fence.
230 int32 token = helper_.get()->InsertToken();
231 allocator_->FreePendingToken(offsets[0], token);
232 EXPECT_TRUE(allocator_->CheckConsistency());
233
234 // Force the command buffer to process the token.
235 helper_->Finish();
236
237 // Tell the allocator to update what's available based on the current token.
238 allocator_->FreeUnused();
239
240 // Check that the new largest free size takes into account the unused block.
241 EXPECT_EQ(kSize, allocator_->GetLargestFreeSize());
242
243 // Free two more.
244 token = helper_.get()->InsertToken();
245 allocator_->FreePendingToken(offsets[1], token);
246 token = helper_.get()->InsertToken();
247 allocator_->FreePendingToken(offsets[2], token);
248 EXPECT_TRUE(allocator_->CheckConsistency());
249
250 // Check that nothing has changed.
251 EXPECT_EQ(kSize, allocator_->GetLargestFreeSize());
252
253 // Force the command buffer to process the token.
254 helper_->Finish();
255
256 // Tell the allocator to update what's available based on the current token.
257 allocator_->FreeUnused();
258
259 // Check that the new largest free size takes into account the unused blocks.
260 EXPECT_EQ(kSize * 3, allocator_->GetLargestFreeSize());
261
262 // Free up everything.
263 for (unsigned int i = 3; i < kAllocCount; ++i) {
264 allocator_->Free(offsets[i]);
265 EXPECT_TRUE(allocator_->CheckConsistency());
266 }
267 }
268
209 // Tests GetLargestFreeSize 269 // Tests GetLargestFreeSize
210 TEST_F(FencedAllocatorTest, TestGetLargestFreeSize) { 270 TEST_F(FencedAllocatorTest, TestGetLargestFreeSize) {
211 EXPECT_TRUE(allocator_->CheckConsistency()); 271 EXPECT_TRUE(allocator_->CheckConsistency());
212 EXPECT_EQ(kBufferSize, allocator_->GetLargestFreeSize()); 272 EXPECT_EQ(kBufferSize, allocator_->GetLargestFreeSize());
213 273
214 FencedAllocator::Offset offset = allocator_->Alloc(kBufferSize); 274 FencedAllocator::Offset offset = allocator_->Alloc(kBufferSize);
215 ASSERT_NE(FencedAllocator::kInvalidOffset, offset); 275 ASSERT_NE(FencedAllocator::kInvalidOffset, offset);
216 EXPECT_EQ(0u, allocator_->GetLargestFreeSize()); 276 EXPECT_EQ(0u, allocator_->GetLargestFreeSize());
217 allocator_->Free(offset); 277 allocator_->Free(offset);
218 EXPECT_EQ(kBufferSize, allocator_->GetLargestFreeSize()); 278 EXPECT_EQ(kBufferSize, allocator_->GetLargestFreeSize());
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 EXPECT_LE(token, GetToken()); 513 EXPECT_LE(token, GetToken());
454 514
455 // Free up everything. 515 // Free up everything.
456 for (unsigned int i = 0; i < kAllocCount; ++i) { 516 for (unsigned int i = 0; i < kAllocCount; ++i) {
457 allocator_->Free(pointers[i]); 517 allocator_->Free(pointers[i]);
458 EXPECT_TRUE(allocator_->CheckConsistency()); 518 EXPECT_TRUE(allocator_->CheckConsistency());
459 } 519 }
460 } 520 }
461 521
462 } // namespace gpu 522 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/client/fenced_allocator.cc ('k') | gpu/command_buffer/client/gles2_c_lib_autogen.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698