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

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

Issue 116863003: gpu: Reuse transfer buffers more aggresively (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Added AsyncUploadSync test, FencedAllocator test, addressed review issues 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) 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 #include "gpu/command_buffer/client/mapped_memory.h" 5 #include "gpu/command_buffer/client/mapped_memory.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <functional> 8 #include <functional>
9 9
10 #include "base/debug/trace_event.h" 10 #include "base/debug/trace_event.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "gpu/command_buffer/client/cmd_buffer_helper.h" 12 #include "gpu/command_buffer/client/cmd_buffer_helper.h"
13 13
14 namespace gpu { 14 namespace gpu {
15 15
16 MemoryChunk::MemoryChunk( 16 MemoryChunk::MemoryChunk(int32 shm_id,
17 int32 shm_id, gpu::Buffer shm, CommandBufferHelper* helper) 17 gpu::Buffer shm,
18 CommandBufferHelper* helper,
19 const base::Closure& poll_callback)
18 : shm_id_(shm_id), 20 : shm_id_(shm_id),
19 shm_(shm), 21 shm_(shm),
20 allocator_(shm.size, helper, shm.ptr) { 22 allocator_(shm.size, helper, poll_callback, shm.ptr) {
21 } 23 }
22 24
23 MappedMemoryManager::MappedMemoryManager(CommandBufferHelper* helper, 25 MappedMemoryManager::MappedMemoryManager(CommandBufferHelper* helper,
26 const base::Closure& poll_callback,
24 size_t unused_memory_reclaim_limit) 27 size_t unused_memory_reclaim_limit)
25 : chunk_size_multiple_(1), 28 : chunk_size_multiple_(1),
26 helper_(helper), 29 helper_(helper),
30 poll_callback_(poll_callback),
27 allocated_memory_(0), 31 allocated_memory_(0),
28 max_free_bytes_(unused_memory_reclaim_limit) { 32 max_free_bytes_(unused_memory_reclaim_limit) {
29 } 33 }
30 34
31 MappedMemoryManager::~MappedMemoryManager() { 35 MappedMemoryManager::~MappedMemoryManager() {
32 CommandBuffer* cmd_buf = helper_->command_buffer(); 36 CommandBuffer* cmd_buf = helper_->command_buffer();
33 for (MemoryChunkVector::iterator iter = chunks_.begin(); 37 for (MemoryChunkVector::iterator iter = chunks_.begin();
34 iter != chunks_.end(); ++iter) { 38 iter != chunks_.end(); ++iter) {
35 MemoryChunk* chunk = *iter; 39 MemoryChunk* chunk = *iter;
36 cmd_buf->DestroyTransferBuffer(chunk->shm_id()); 40 cmd_buf->DestroyTransferBuffer(chunk->shm_id());
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 82
79 // Make a new chunk to satisfy the request. 83 // Make a new chunk to satisfy the request.
80 CommandBuffer* cmd_buf = helper_->command_buffer(); 84 CommandBuffer* cmd_buf = helper_->command_buffer();
81 unsigned int chunk_size = 85 unsigned int chunk_size =
82 ((size + chunk_size_multiple_ - 1) / chunk_size_multiple_) * 86 ((size + chunk_size_multiple_ - 1) / chunk_size_multiple_) *
83 chunk_size_multiple_; 87 chunk_size_multiple_;
84 int32 id = -1; 88 int32 id = -1;
85 gpu::Buffer shm = cmd_buf->CreateTransferBuffer(chunk_size, &id); 89 gpu::Buffer shm = cmd_buf->CreateTransferBuffer(chunk_size, &id);
86 if (id < 0) 90 if (id < 0)
87 return NULL; 91 return NULL;
88 MemoryChunk* mc = new MemoryChunk(id, shm, helper_); 92 MemoryChunk* mc = new MemoryChunk(id, shm, helper_, poll_callback_);
89 allocated_memory_ += mc->GetSize(); 93 allocated_memory_ += mc->GetSize();
90 chunks_.push_back(mc); 94 chunks_.push_back(mc);
91 void* mem = mc->Alloc(size); 95 void* mem = mc->Alloc(size);
92 DCHECK(mem); 96 DCHECK(mem);
93 *shm_id = mc->shm_id(); 97 *shm_id = mc->shm_id();
94 *shm_offset = mc->GetOffset(mem); 98 *shm_offset = mc->GetOffset(mem);
95 return mem; 99 return mem;
96 } 100 }
97 101
98 void MappedMemoryManager::Free(void* pointer) { 102 void MappedMemoryManager::Free(void* pointer) {
(...skipping 28 matching lines...) Expand all
127 cmd_buf->DestroyTransferBuffer(chunk->shm_id()); 131 cmd_buf->DestroyTransferBuffer(chunk->shm_id());
128 allocated_memory_ -= chunk->GetSize(); 132 allocated_memory_ -= chunk->GetSize();
129 iter = chunks_.erase(iter); 133 iter = chunks_.erase(iter);
130 } else { 134 } else {
131 ++iter; 135 ++iter;
132 } 136 }
133 } 137 }
134 } 138 }
135 139
136 } // namespace gpu 140 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698