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

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

Issue 116863003: gpu: Reuse transfer buffers more aggresively (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Async upload token part of existing Async command; use separate shared memory to sync async upload … Created 6 years, 10 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 #ifndef GPU_COMMAND_BUFFER_CLIENT_MAPPED_MEMORY_H_ 5 #ifndef GPU_COMMAND_BUFFER_CLIENT_MAPPED_MEMORY_H_
6 #define GPU_COMMAND_BUFFER_CLIENT_MAPPED_MEMORY_H_ 6 #define GPU_COMMAND_BUFFER_CLIENT_MAPPED_MEMORY_H_
7 7
8 #include "base/bind.h"
8 #include "base/memory/scoped_vector.h" 9 #include "base/memory/scoped_vector.h"
9 #include "gpu/command_buffer/client/fenced_allocator.h" 10 #include "gpu/command_buffer/client/fenced_allocator.h"
10 #include "gpu/command_buffer/common/buffer.h" 11 #include "gpu/command_buffer/common/buffer.h"
11 #include "gpu/command_buffer/common/types.h" 12 #include "gpu/command_buffer/common/types.h"
12 #include "gpu/gpu_export.h" 13 #include "gpu/gpu_export.h"
13 14
14 namespace gpu { 15 namespace gpu {
15 16
16 class CommandBufferHelper; 17 class CommandBufferHelper;
17 18
18 // Manages a shared memory segment. 19 // Manages a shared memory segment.
19 class GPU_EXPORT MemoryChunk { 20 class GPU_EXPORT MemoryChunk {
20 public: 21 public:
21 MemoryChunk(int32 shm_id, gpu::Buffer shm, CommandBufferHelper* helper); 22 MemoryChunk(int32 shm_id,
23 gpu::Buffer shm,
24 CommandBufferHelper* helper,
25 const base::Closure& poll_callback);
22 26
23 // Gets the size of the largest free block that is available without waiting. 27 // Gets the size of the largest free block that is available without waiting.
24 unsigned int GetLargestFreeSizeWithoutWaiting() { 28 unsigned int GetLargestFreeSizeWithoutWaiting() {
25 return allocator_.GetLargestFreeSize(); 29 return allocator_.GetLargestFreeSize();
26 } 30 }
27 31
28 // Gets the size of the largest free block that can be allocated if the 32 // Gets the size of the largest free block that can be allocated if the
29 // caller can wait. 33 // caller can wait.
30 unsigned int GetLargestFreeSizeWithWaiting() { 34 unsigned int GetLargestFreeSizeWithWaiting() {
31 return allocator_.GetLargestFreeOrPendingSize(); 35 return allocator_.GetLargestFreeOrPendingSize();
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 // Manages MemoryChunks. 114 // Manages MemoryChunks.
111 class GPU_EXPORT MappedMemoryManager { 115 class GPU_EXPORT MappedMemoryManager {
112 public: 116 public:
113 enum MemoryLimit { 117 enum MemoryLimit {
114 kNoLimit = 0, 118 kNoLimit = 0,
115 }; 119 };
116 120
117 // |unused_memory_reclaim_limit|: When exceeded this causes pending memory 121 // |unused_memory_reclaim_limit|: When exceeded this causes pending memory
118 // to be reclaimed before allocating more memory. 122 // to be reclaimed before allocating more memory.
119 MappedMemoryManager(CommandBufferHelper* helper, 123 MappedMemoryManager(CommandBufferHelper* helper,
124 const base::Closure& poll_callback,
120 size_t unused_memory_reclaim_limit); 125 size_t unused_memory_reclaim_limit);
121 126
122 ~MappedMemoryManager(); 127 ~MappedMemoryManager();
123 128
124 unsigned int chunk_size_multiple() const { 129 unsigned int chunk_size_multiple() const {
125 return chunk_size_multiple_; 130 return chunk_size_multiple_;
126 } 131 }
127 132
128 void set_chunk_size_multiple(unsigned int multiple) { 133 void set_chunk_size_multiple(unsigned int multiple) {
129 chunk_size_multiple_ = multiple; 134 chunk_size_multiple_ = multiple;
(...skipping 24 matching lines...) Expand all
154 void FreePendingToken(void* pointer, int32 token); 159 void FreePendingToken(void* pointer, int32 token);
155 160
156 // Free Any Shared memory that is not in use. 161 // Free Any Shared memory that is not in use.
157 void FreeUnused(); 162 void FreeUnused();
158 163
159 // Used for testing 164 // Used for testing
160 size_t num_chunks() const { 165 size_t num_chunks() const {
161 return chunks_.size(); 166 return chunks_.size();
162 } 167 }
163 168
169 size_t bytes_in_use() const {
170 size_t bytes_in_use = 0;
171 for (size_t ii = 0; ii < chunks_.size(); ++ii) {
172 MemoryChunk* chunk = chunks_[ii];
173 bytes_in_use += chunk->bytes_in_use();
174 }
175 return bytes_in_use;
176 }
177
164 // Used for testing 178 // Used for testing
165 size_t allocated_memory() const { 179 size_t allocated_memory() const {
166 return allocated_memory_; 180 return allocated_memory_;
167 } 181 }
168 182
169 private: 183 private:
170 typedef ScopedVector<MemoryChunk> MemoryChunkVector; 184 typedef ScopedVector<MemoryChunk> MemoryChunkVector;
171 185
172 // size a chunk is rounded up to. 186 // size a chunk is rounded up to.
173 unsigned int chunk_size_multiple_; 187 unsigned int chunk_size_multiple_;
174 CommandBufferHelper* helper_; 188 CommandBufferHelper* helper_;
189 base::Closure poll_callback_;
175 MemoryChunkVector chunks_; 190 MemoryChunkVector chunks_;
176 size_t allocated_memory_; 191 size_t allocated_memory_;
177 size_t max_free_bytes_; 192 size_t max_free_bytes_;
178 193
179 DISALLOW_COPY_AND_ASSIGN(MappedMemoryManager); 194 DISALLOW_COPY_AND_ASSIGN(MappedMemoryManager);
180 }; 195 };
181 196
182 } // namespace gpu 197 } // namespace gpu
183 198
184 #endif // GPU_COMMAND_BUFFER_CLIENT_MAPPED_MEMORY_H_ 199 #endif // GPU_COMMAND_BUFFER_CLIENT_MAPPED_MEMORY_H_
185 200
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698