Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 17 matching lines...) Expand all Loading... | |
| 28 // (see http://www.corp.google.com/eng/doc/cpp_primer.html#thread_safety). | 28 // (see http://www.corp.google.com/eng/doc/cpp_primer.html#thread_safety). |
| 29 class GPU_EXPORT FencedAllocator { | 29 class GPU_EXPORT FencedAllocator { |
| 30 public: | 30 public: |
| 31 typedef unsigned int Offset; | 31 typedef unsigned int Offset; |
| 32 // Invalid offset, returned by Alloc in case of failure. | 32 // Invalid offset, returned by Alloc in case of failure. |
| 33 static const Offset kInvalidOffset = 0xffffffffU; | 33 static const Offset kInvalidOffset = 0xffffffffU; |
| 34 | 34 |
| 35 // Creates a FencedAllocator. Note that the size of the buffer is passed, but | 35 // Creates a FencedAllocator. Note that the size of the buffer is passed, but |
| 36 // not its base address: everything is handled as offsets into the buffer. | 36 // not its base address: everything is handled as offsets into the buffer. |
| 37 FencedAllocator(unsigned int size, | 37 FencedAllocator(unsigned int size, |
| 38 bool aggressive_reuse, | |
|
epennerAtGoogle
2013/12/18 19:21:15
Rather than a separate allocator, do you think it
| |
| 38 CommandBufferHelper *helper); | 39 CommandBufferHelper *helper); |
| 39 | 40 |
| 40 ~FencedAllocator(); | 41 ~FencedAllocator(); |
| 41 | 42 |
| 42 // Allocates a block of memory. If the buffer is out of directly available | 43 // Allocates a block of memory. If the buffer is out of directly available |
| 43 // memory, this function may wait until memory that was freed "pending a | 44 // memory, this function may wait until memory that was freed "pending a |
| 44 // token" can be re-used. | 45 // token" can be re-used. |
| 45 // | 46 // |
| 46 // Parameters: | 47 // Parameters: |
| 47 // size: the size of the memory block to allocate. | 48 // size: the size of the memory block to allocate. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 80 // testing. | 81 // testing. |
| 81 bool CheckConsistency(); | 82 bool CheckConsistency(); |
| 82 | 83 |
| 83 // True if any memory is allocated. | 84 // True if any memory is allocated. |
| 84 bool InUse(); | 85 bool InUse(); |
| 85 | 86 |
| 86 // Return bytes of memory that is IN_USE | 87 // Return bytes of memory that is IN_USE |
| 87 size_t bytes_in_use() const { return bytes_in_use_; } | 88 size_t bytes_in_use() const { return bytes_in_use_; } |
| 88 | 89 |
| 89 private: | 90 private: |
| 91 Offset AggressiveAlloc(unsigned int size); | |
| 92 | |
| 90 // Status of a block of memory, for book-keeping. | 93 // Status of a block of memory, for book-keeping. |
| 91 enum State { | 94 enum State { |
| 92 IN_USE, | 95 IN_USE, |
| 93 FREE, | 96 FREE, |
| 94 FREE_PENDING_TOKEN | 97 FREE_PENDING_TOKEN |
| 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; |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 130 | 133 |
| 131 // Allocates a block of memory inside a given block, splitting it in two | 134 // Allocates a block of memory inside a given block, splitting it in two |
| 132 // (unless that block is of the exact requested size). | 135 // (unless that block is of the exact requested size). |
| 133 // NOTE: this will invalidate block indices. | 136 // NOTE: this will invalidate block indices. |
| 134 // Returns the offset of the allocated block (NOTE: this is different from | 137 // Returns the offset of the allocated block (NOTE: this is different from |
| 135 // the other functions that return a block index). | 138 // the other functions that return a block index). |
| 136 Offset AllocInBlock(BlockIndex index, unsigned int size); | 139 Offset AllocInBlock(BlockIndex index, unsigned int size); |
| 137 | 140 |
| 138 CommandBufferHelper *helper_; | 141 CommandBufferHelper *helper_; |
| 139 Container blocks_; | 142 Container blocks_; |
| 143 bool aggressive_reuse_; | |
| 140 size_t bytes_in_use_; | 144 size_t bytes_in_use_; |
| 141 | 145 |
| 142 DISALLOW_IMPLICIT_CONSTRUCTORS(FencedAllocator); | 146 DISALLOW_IMPLICIT_CONSTRUCTORS(FencedAllocator); |
| 143 }; | 147 }; |
| 144 | 148 |
| 145 // This class functions just like FencedAllocator, but its API uses pointers | 149 // This class functions just like FencedAllocator, but its API uses pointers |
| 146 // instead of offsets. | 150 // instead of offsets. |
| 147 class FencedAllocatorWrapper { | 151 class FencedAllocatorWrapper { |
| 148 public: | 152 public: |
| 149 FencedAllocatorWrapper(unsigned int size, | 153 FencedAllocatorWrapper(unsigned int size, |
| 154 bool aggressive_reuse, | |
| 150 CommandBufferHelper* helper, | 155 CommandBufferHelper* helper, |
| 151 void* base) | 156 void* base) |
| 152 : allocator_(size, helper), | 157 : allocator_(size, aggressive_reuse, helper), |
| 153 base_(base) { } | 158 base_(base) { } |
| 154 | 159 |
| 155 // Allocates a block of memory. If the buffer is out of directly available | 160 // Allocates a block of memory. If the buffer is out of directly available |
| 156 // memory, this function may wait until memory that was freed "pending a | 161 // memory, this function may wait until memory that was freed "pending a |
| 157 // token" can be re-used. | 162 // token" can be re-used. |
| 158 // | 163 // |
| 159 // Parameters: | 164 // Parameters: |
| 160 // size: the size of the memory block to allocate. | 165 // size: the size of the memory block to allocate. |
| 161 // | 166 // |
| 162 // Returns: | 167 // Returns: |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 251 | 256 |
| 252 private: | 257 private: |
| 253 FencedAllocator allocator_; | 258 FencedAllocator allocator_; |
| 254 void* base_; | 259 void* base_; |
| 255 DISALLOW_IMPLICIT_CONSTRUCTORS(FencedAllocatorWrapper); | 260 DISALLOW_IMPLICIT_CONSTRUCTORS(FencedAllocatorWrapper); |
| 256 }; | 261 }; |
| 257 | 262 |
| 258 } // namespace gpu | 263 } // namespace gpu |
| 259 | 264 |
| 260 #endif // GPU_COMMAND_BUFFER_CLIENT_FENCED_ALLOCATOR_H_ | 265 #endif // GPU_COMMAND_BUFFER_CLIENT_FENCED_ALLOCATOR_H_ |
| OLD | NEW |