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

Side by Side Diff: gpu/command_buffer/client/fenced_allocator.h

Issue 116863003: gpu: Reuse transfer buffers more aggresively (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: [WIP] Review comments follow-up Created 6 years, 11 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
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 // This file contains the definition of the FencedAllocator class. 5 // This file contains the definition of the FencedAllocator class.
6 6
7 #ifndef GPU_COMMAND_BUFFER_CLIENT_FENCED_ALLOCATOR_H_ 7 #ifndef GPU_COMMAND_BUFFER_CLIENT_FENCED_ALLOCATOR_H_
8 #define GPU_COMMAND_BUFFER_CLIENT_FENCED_ALLOCATOR_H_ 8 #define GPU_COMMAND_BUFFER_CLIENT_FENCED_ALLOCATOR_H_
9 9
10 #include <vector> 10 #include <vector>
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 void Free(Offset offset); 58 void Free(Offset offset);
59 59
60 // Frees a block of memory, pending the passage of a token. That memory won't 60 // Frees a block of memory, pending the passage of a token. That memory won't
61 // be re-allocated until the token has passed through the command stream. 61 // be re-allocated until the token has passed through the command stream.
62 // 62 //
63 // Parameters: 63 // Parameters:
64 // offset: the offset of the memory block to free. 64 // offset: the offset of the memory block to free.
65 // token: the token value to wait for before re-using the memory. 65 // token: the token value to wait for before re-using the memory.
66 void FreePendingToken(Offset offset, int32 token); 66 void FreePendingToken(Offset offset, int32 token);
67 67
68 void FreePendingSerial(Offset offset, uint32 token);
69
68 // Frees any blocks pending a token for which the token has been read. 70 // Frees any blocks pending a token for which the token has been read.
69 void FreeUnused(); 71 void FreeUnused();
70 72
71 // Gets the size of the largest free block that is available without waiting. 73 // Gets the size of the largest free block that is available without waiting.
72 unsigned int GetLargestFreeSize(); 74 unsigned int GetLargestFreeSize();
73 75
74 // Gets the size of the largest free block that can be allocated if the 76 // Gets the size of the largest free block that can be allocated if the
75 // caller can wait. Allocating a block of this size will succeed, but may 77 // caller can wait. Allocating a block of this size will succeed, but may
76 // block. 78 // block.
77 unsigned int GetLargestFreeOrPendingSize(); 79 unsigned int GetLargestFreeOrPendingSize();
78 80
79 // Checks for consistency inside the book-keeping structures. Used for 81 // Checks for consistency inside the book-keeping structures. Used for
80 // testing. 82 // testing.
81 bool CheckConsistency(); 83 bool CheckConsistency();
82 84
83 // True if any memory is allocated. 85 // True if any memory is allocated.
84 bool InUse(); 86 bool InUse();
85 87
86 // Return bytes of memory that is IN_USE 88 // Return bytes of memory that is IN_USE
87 size_t bytes_in_use() const { return bytes_in_use_; } 89 size_t bytes_in_use() const { return bytes_in_use_; }
88 90
89 private: 91 private:
90 // Status of a block of memory, for book-keeping. 92 // Status of a block of memory, for book-keeping.
91 enum State { 93 enum State {
92 IN_USE, 94 IN_USE,
93 FREE, 95 FREE,
94 FREE_PENDING_TOKEN 96 FREE_PENDING_TOKEN,
97 FREE_PENDING_SERIAL
95 }; 98 };
96 99
97 // Book-keeping sturcture that describes a block of memory. 100 // Book-keeping sturcture that describes a block of memory.
98 struct Block { 101 struct Block {
99 State state; 102 State state;
100 Offset offset; 103 Offset offset;
101 unsigned int size; 104 unsigned int size;
102 int32 token; // token to wait for in the FREE_PENDING_TOKEN case. 105 int32 token; // token to wait for in the FREE_PENDING_TOKEN case.
106 uint32 serial;
103 }; 107 };
104 108
105 // Comparison functor for memory block sorting. 109 // Comparison functor for memory block sorting.
106 class OffsetCmp { 110 class OffsetCmp {
107 public: 111 public:
108 bool operator() (const Block &left, const Block &right) { 112 bool operator() (const Block &left, const Block &right) {
109 return left.offset < right.offset; 113 return left.offset < right.offset;
110 } 114 }
111 }; 115 };
112 116
113 typedef std::vector<Block> Container; 117 typedef std::vector<Block> Container;
114 typedef unsigned int BlockIndex; 118 typedef unsigned int BlockIndex;
115 119
116 static const int32 kUnusedToken = 0; 120 static const int32 kUnusedToken = 0;
121 static const uint32 kUnusedSerial = 0;
117 122
118 // Gets the index of a memory block, given its offset. 123 // Gets the index of a memory block, given its offset.
119 BlockIndex GetBlockByOffset(Offset offset); 124 BlockIndex GetBlockByOffset(Offset offset);
120 125
121 // Collapse a free block with its neighbours if they are free. Returns the 126 // Collapse a free block with its neighbours if they are free. Returns the
122 // index of the collapsed block. 127 // index of the collapsed block.
123 // NOTE: this will invalidate block indices. 128 // NOTE: this will invalidate block indices.
124 BlockIndex CollapseFreeBlock(BlockIndex index); 129 BlockIndex CollapseFreeBlock(BlockIndex index);
125 130
126 // Waits for a FREE_PENDING_TOKEN block to be usable, and free it. Returns 131 // Waits for a FREE_PENDING_TOKEN block to be usable, and free it. Returns
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 // be re-allocated until the token has passed through the command stream. 200 // be re-allocated until the token has passed through the command stream.
196 // 201 //
197 // Parameters: 202 // Parameters:
198 // pointer: the pointer to the memory block to free. 203 // pointer: the pointer to the memory block to free.
199 // token: the token value to wait for before re-using the memory. 204 // token: the token value to wait for before re-using the memory.
200 void FreePendingToken(void *pointer, int32 token) { 205 void FreePendingToken(void *pointer, int32 token) {
201 DCHECK(pointer); 206 DCHECK(pointer);
202 allocator_.FreePendingToken(GetOffset(pointer), token); 207 allocator_.FreePendingToken(GetOffset(pointer), token);
203 } 208 }
204 209
210 void FreePendingSerial(void *pointer, uint32 serial) {
211 DCHECK(pointer);
212 allocator_.FreePendingSerial(GetOffset(pointer), serial);
213 }
214
205 // Frees any blocks pending a token for which the token has been read. 215 // Frees any blocks pending a token for which the token has been read.
206 void FreeUnused() { 216 void FreeUnused() {
207 allocator_.FreeUnused(); 217 allocator_.FreeUnused();
208 } 218 }
209 219
210 // Gets a pointer to a memory block given the base memory and the offset. 220 // Gets a pointer to a memory block given the base memory and the offset.
211 // It translates FencedAllocator::kInvalidOffset to NULL. 221 // It translates FencedAllocator::kInvalidOffset to NULL.
212 void *GetPointer(FencedAllocator::Offset offset) { 222 void *GetPointer(FencedAllocator::Offset offset) {
213 return (offset == FencedAllocator::kInvalidOffset) ? 223 return (offset == FencedAllocator::kInvalidOffset) ?
214 NULL : static_cast<char *>(base_) + offset; 224 NULL : static_cast<char *>(base_) + offset;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 261
252 private: 262 private:
253 FencedAllocator allocator_; 263 FencedAllocator allocator_;
254 void* base_; 264 void* base_;
255 DISALLOW_IMPLICIT_CONSTRUCTORS(FencedAllocatorWrapper); 265 DISALLOW_IMPLICIT_CONSTRUCTORS(FencedAllocatorWrapper);
256 }; 266 };
257 267
258 } // namespace gpu 268 } // namespace gpu
259 269
260 #endif // GPU_COMMAND_BUFFER_CLIENT_FENCED_ALLOCATOR_H_ 270 #endif // GPU_COMMAND_BUFFER_CLIENT_FENCED_ALLOCATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698