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

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: Unset texture and texture_ref after deleting Created 6 years, 9 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>
11 11
12 #include "base/bind.h"
12 #include "base/logging.h" 13 #include "base/logging.h"
13 #include "gpu/command_buffer/common/types.h" 14 #include "gpu/command_buffer/common/types.h"
14 #include "gpu/gpu_export.h" 15 #include "gpu/gpu_export.h"
15 16
16 namespace gpu { 17 namespace gpu {
17 class CommandBufferHelper; 18 class CommandBufferHelper;
18 19
19 // FencedAllocator provides a mechanism to manage allocations within a fixed 20 // FencedAllocator provides a mechanism to manage allocations within a fixed
20 // block of memory (storing the book-keeping externally). Furthermore this 21 // block of memory (storing the book-keeping externally). Furthermore this
21 // class allows to free data "pending" the passage of a command buffer token, 22 // class allows to free data "pending" the passage of a command buffer token,
22 // that is, the memory won't be reused until the command buffer has processed 23 // that is, the memory won't be reused until the command buffer has processed
23 // that token. 24 // that token.
24 // 25 //
25 // NOTE: Although this class is intended to be used in the command buffer 26 // NOTE: Although this class is intended to be used in the command buffer
26 // environment which is multi-process, this class isn't "thread safe", because 27 // environment which is multi-process, this class isn't "thread safe", because
27 // it isn't meant to be shared across modules. It is thread-compatible though 28 // it isn't meant to be shared across modules. It is thread-compatible though
28 // (see http://www.corp.google.com/eng/doc/cpp_primer.html#thread_safety). 29 // (see http://www.corp.google.com/eng/doc/cpp_primer.html#thread_safety).
29 class GPU_EXPORT FencedAllocator { 30 class GPU_EXPORT FencedAllocator {
30 public: 31 public:
31 typedef unsigned int Offset; 32 typedef unsigned int Offset;
32 // Invalid offset, returned by Alloc in case of failure. 33 // Invalid offset, returned by Alloc in case of failure.
33 static const Offset kInvalidOffset = 0xffffffffU; 34 static const Offset kInvalidOffset = 0xffffffffU;
34 35
35 // Creates a FencedAllocator. Note that the size of the buffer is passed, but 36 // 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. 37 // not its base address: everything is handled as offsets into the buffer.
37 FencedAllocator(unsigned int size, 38 FencedAllocator(unsigned int size,
38 CommandBufferHelper *helper); 39 CommandBufferHelper *helper,
40 const base::Closure& poll_callback);
39 41
40 ~FencedAllocator(); 42 ~FencedAllocator();
41 43
42 // Allocates a block of memory. If the buffer is out of directly available 44 // 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 45 // memory, this function may wait until memory that was freed "pending a
44 // token" can be re-used. 46 // token" can be re-used.
45 // 47 //
46 // Parameters: 48 // Parameters:
47 // size: the size of the memory block to allocate. 49 // size: the size of the memory block to allocate.
48 // 50 //
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 BlockIndex WaitForTokenAndFreeBlock(BlockIndex index); 131 BlockIndex WaitForTokenAndFreeBlock(BlockIndex index);
130 132
131 // Allocates a block of memory inside a given block, splitting it in two 133 // Allocates a block of memory inside a given block, splitting it in two
132 // (unless that block is of the exact requested size). 134 // (unless that block is of the exact requested size).
133 // NOTE: this will invalidate block indices. 135 // NOTE: this will invalidate block indices.
134 // Returns the offset of the allocated block (NOTE: this is different from 136 // Returns the offset of the allocated block (NOTE: this is different from
135 // the other functions that return a block index). 137 // the other functions that return a block index).
136 Offset AllocInBlock(BlockIndex index, unsigned int size); 138 Offset AllocInBlock(BlockIndex index, unsigned int size);
137 139
138 CommandBufferHelper *helper_; 140 CommandBufferHelper *helper_;
141 base::Closure poll_callback_;
139 Container blocks_; 142 Container blocks_;
140 size_t bytes_in_use_; 143 size_t bytes_in_use_;
141 144
142 DISALLOW_IMPLICIT_CONSTRUCTORS(FencedAllocator); 145 DISALLOW_IMPLICIT_CONSTRUCTORS(FencedAllocator);
143 }; 146 };
144 147
145 // This class functions just like FencedAllocator, but its API uses pointers 148 // This class functions just like FencedAllocator, but its API uses pointers
146 // instead of offsets. 149 // instead of offsets.
147 class FencedAllocatorWrapper { 150 class FencedAllocatorWrapper {
148 public: 151 public:
149 FencedAllocatorWrapper(unsigned int size, 152 FencedAllocatorWrapper(unsigned int size,
150 CommandBufferHelper* helper, 153 CommandBufferHelper* helper,
154 const base::Closure& poll_callback,
151 void* base) 155 void* base)
152 : allocator_(size, helper), 156 : allocator_(size, helper, poll_callback),
153 base_(base) { } 157 base_(base) { }
154 158
155 // Allocates a block of memory. If the buffer is out of directly available 159 // 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 160 // memory, this function may wait until memory that was freed "pending a
157 // token" can be re-used. 161 // token" can be re-used.
158 // 162 //
159 // Parameters: 163 // Parameters:
160 // size: the size of the memory block to allocate. 164 // size: the size of the memory block to allocate.
161 // 165 //
162 // Returns: 166 // Returns:
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 255
252 private: 256 private:
253 FencedAllocator allocator_; 257 FencedAllocator allocator_;
254 void* base_; 258 void* base_;
255 DISALLOW_IMPLICIT_CONSTRUCTORS(FencedAllocatorWrapper); 259 DISALLOW_IMPLICIT_CONSTRUCTORS(FencedAllocatorWrapper);
256 }; 260 };
257 261
258 } // namespace gpu 262 } // namespace gpu
259 263
260 #endif // GPU_COMMAND_BUFFER_CLIENT_FENCED_ALLOCATOR_H_ 264 #endif // GPU_COMMAND_BUFFER_CLIENT_FENCED_ALLOCATOR_H_
OLDNEW
« no previous file with comments | « gpu/command_buffer/client/cmd_buffer_helper.h ('k') | gpu/command_buffer/client/fenced_allocator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698