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

Side by Side Diff: trunk/src/gpu/command_buffer/client/fenced_allocator.cc

Issue 216673006: Revert 260177 "By keeping track of transfer buffer usage (both s..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 years, 8 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 implementation of the FencedAllocator class. 5 // This file contains the implementation of the FencedAllocator class.
6 6
7 #include "gpu/command_buffer/client/fenced_allocator.h" 7 #include "gpu/command_buffer/client/fenced_allocator.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
(...skipping 16 matching lines...) Expand all
27 return (size + (kAllocAlignment - 1)) & ~(kAllocAlignment - 1); 27 return (size + (kAllocAlignment - 1)) & ~(kAllocAlignment - 1);
28 } 28 }
29 29
30 } // namespace 30 } // namespace
31 31
32 #ifndef _MSC_VER 32 #ifndef _MSC_VER
33 const FencedAllocator::Offset FencedAllocator::kInvalidOffset; 33 const FencedAllocator::Offset FencedAllocator::kInvalidOffset;
34 #endif 34 #endif
35 35
36 FencedAllocator::FencedAllocator(unsigned int size, 36 FencedAllocator::FencedAllocator(unsigned int size,
37 CommandBufferHelper* helper, 37 CommandBufferHelper *helper)
38 const base::Closure& poll_callback)
39 : helper_(helper), 38 : helper_(helper),
40 poll_callback_(poll_callback),
41 bytes_in_use_(0) { 39 bytes_in_use_(0) {
42 Block block = { FREE, 0, RoundDown(size), kUnusedToken }; 40 Block block = { FREE, 0, RoundDown(size), kUnusedToken };
43 blocks_.push_back(block); 41 blocks_.push_back(block);
44 } 42 }
45 43
46 FencedAllocator::~FencedAllocator() { 44 FencedAllocator::~FencedAllocator() {
47 // Free blocks pending tokens. 45 // Free blocks pending tokens.
48 for (unsigned int i = 0; i < blocks_.size(); ++i) { 46 for (unsigned int i = 0; i < blocks_.size(); ++i) {
49 if (blocks_[i].state == FREE_PENDING_TOKEN) { 47 if (blocks_[i].state == FREE_PENDING_TOKEN) {
50 i = WaitForTokenAndFreeBlock(i); 48 i = WaitForTokenAndFreeBlock(i);
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 BlockIndex index) { 196 BlockIndex index) {
199 Block &block = blocks_[index]; 197 Block &block = blocks_[index];
200 DCHECK_EQ(block.state, FREE_PENDING_TOKEN); 198 DCHECK_EQ(block.state, FREE_PENDING_TOKEN);
201 helper_->WaitForToken(block.token); 199 helper_->WaitForToken(block.token);
202 block.state = FREE; 200 block.state = FREE;
203 return CollapseFreeBlock(index); 201 return CollapseFreeBlock(index);
204 } 202 }
205 203
206 // Frees any blocks pending a token for which the token has been read. 204 // Frees any blocks pending a token for which the token has been read.
207 void FencedAllocator::FreeUnused() { 205 void FencedAllocator::FreeUnused() {
208 // Free any potential blocks that has its lifetime handled outside. 206 int32 last_token_read = helper_->last_token_read();
209 poll_callback_.Run();
210
211 for (unsigned int i = 0; i < blocks_.size();) { 207 for (unsigned int i = 0; i < blocks_.size();) {
212 Block& block = blocks_[i]; 208 Block& block = blocks_[i];
213 if (block.state == FREE_PENDING_TOKEN && 209 if (block.state == FREE_PENDING_TOKEN && block.token <= last_token_read) {
214 helper_->HasTokenPassed(block.token)) {
215 block.state = FREE; 210 block.state = FREE;
216 i = CollapseFreeBlock(i); 211 i = CollapseFreeBlock(i);
217 } else { 212 } else {
218 ++i; 213 ++i;
219 } 214 }
220 } 215 }
221 } 216 }
222 217
223 // If the block is exactly the requested size, simply mark it IN_USE, otherwise 218 // If the block is exactly the requested size, simply mark it IN_USE, otherwise
224 // split it and mark the first one (of the requested size) IN_USE. 219 // split it and mark the first one (of the requested size) IN_USE.
(...skipping 19 matching lines...) Expand all
244 // The blocks are in offset order, so we can do a binary search. 239 // The blocks are in offset order, so we can do a binary search.
245 FencedAllocator::BlockIndex FencedAllocator::GetBlockByOffset(Offset offset) { 240 FencedAllocator::BlockIndex FencedAllocator::GetBlockByOffset(Offset offset) {
246 Block templ = { IN_USE, offset, 0, kUnusedToken }; 241 Block templ = { IN_USE, offset, 0, kUnusedToken };
247 Container::iterator it = std::lower_bound(blocks_.begin(), blocks_.end(), 242 Container::iterator it = std::lower_bound(blocks_.begin(), blocks_.end(),
248 templ, OffsetCmp()); 243 templ, OffsetCmp());
249 DCHECK(it != blocks_.end() && it->offset == offset); 244 DCHECK(it != blocks_.end() && it->offset == offset);
250 return it-blocks_.begin(); 245 return it-blocks_.begin();
251 } 246 }
252 247
253 } // namespace gpu 248 } // namespace gpu
OLDNEW
« no previous file with comments | « trunk/src/gpu/command_buffer/client/fenced_allocator.h ('k') | trunk/src/gpu/command_buffer/client/fenced_allocator_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698