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

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

Issue 12278025: Shrink QueryTracker when freeing everything (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Restore buckets Created 7 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 | Annotate | Revision Log
« no previous file with comments | « gpu/command_buffer/client/query_tracker.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include <GLES2/gl2.h> 5 #include <GLES2/gl2.h>
6 #include <GLES2/gl2ext.h> 6 #include <GLES2/gl2ext.h>
7 #include <GLES2/gl2extchromium.h> 7 #include <GLES2/gl2extchromium.h>
8 8
9 #include "../client/query_tracker.h" 9 #include "../client/query_tracker.h"
10 10
11 #include "../client/atomicops.h" 11 #include "../client/atomicops.h"
12 #include "../client/gles2_cmd_helper.h" 12 #include "../client/gles2_cmd_helper.h"
13 #include "../client/gles2_implementation.h" 13 #include "../client/gles2_implementation.h"
14 #include "../client/mapped_memory.h" 14 #include "../client/mapped_memory.h"
15 #include "../common/time.h" 15 #include "../common/time.h"
16 16
17 namespace gpu { 17 namespace gpu {
18 namespace gles2 { 18 namespace gles2 {
19 19
20 QuerySyncManager::QuerySyncManager(MappedMemoryManager* manager) 20 QuerySyncManager::QuerySyncManager(MappedMemoryManager* manager)
21 : mapped_memory_(manager) { 21 : mapped_memory_(manager) {
22 GPU_DCHECK(manager); 22 GPU_DCHECK(manager);
23 } 23 }
24 24
25 QuerySyncManager::~QuerySyncManager() { 25 QuerySyncManager::~QuerySyncManager() {
26 while (!buckets_.empty()) { 26 while (!buckets_.empty()) {
27 mapped_memory_->Free(buckets_.front()); 27 mapped_memory_->Free(buckets_.front()->syncs);
28 buckets_.pop(); 28 delete buckets_.front();
29 buckets_.pop_front();
29 } 30 }
30 } 31 }
31 32
32 bool QuerySyncManager::Alloc(QuerySyncManager::QueryInfo* info) { 33 bool QuerySyncManager::Alloc(QuerySyncManager::QueryInfo* info) {
33 GPU_DCHECK(info); 34 GPU_DCHECK(info);
34 if (free_queries_.empty()) { 35 if (free_queries_.empty()) {
35 int32 shm_id; 36 int32 shm_id;
36 unsigned int shm_offset; 37 unsigned int shm_offset;
37 void* mem = mapped_memory_->Alloc( 38 void* mem = mapped_memory_->Alloc(
38 kSyncsPerBucket * sizeof(QuerySync), &shm_id, &shm_offset); 39 kSyncsPerBucket * sizeof(QuerySync), &shm_id, &shm_offset);
39 if (!mem) { 40 if (!mem) {
40 return false; 41 return false;
41 } 42 }
42 QuerySync* syncs = static_cast<QuerySync*>(mem); 43 QuerySync* syncs = static_cast<QuerySync*>(mem);
43 buckets_.push(syncs); 44 Bucket* bucket = new Bucket(syncs);
45 buckets_.push_back(bucket);
44 for (size_t ii = 0; ii < kSyncsPerBucket; ++ii) { 46 for (size_t ii = 0; ii < kSyncsPerBucket; ++ii) {
45 free_queries_.push(QueryInfo(shm_id, shm_offset, syncs)); 47 free_queries_.push_back(QueryInfo(bucket, shm_id, shm_offset, syncs));
46 ++syncs; 48 ++syncs;
47 shm_offset += sizeof(*syncs); 49 shm_offset += sizeof(*syncs);
48 } 50 }
49 } 51 }
50 *info = free_queries_.front(); 52 *info = free_queries_.front();
53 ++(info->bucket->used_query_count);
51 info->sync->Reset(); 54 info->sync->Reset();
52 free_queries_.pop(); 55 free_queries_.pop_front();
53 return true; 56 return true;
54 } 57 }
55 58
56 void QuerySyncManager::Free(const QuerySyncManager::QueryInfo& info) { 59 void QuerySyncManager::Free(const QuerySyncManager::QueryInfo& info) {
57 free_queries_.push(info); 60 DCHECK_GT(info.bucket->used_query_count, 0u);
61 --(info.bucket->used_query_count);
62 free_queries_.push_back(info);
63 }
64
65 void QuerySyncManager::Shrink() {
66 std::deque<QueryInfo> new_queue;
67 while (!free_queries_.empty()) {
68 if (free_queries_.front().bucket->used_query_count)
69 new_queue.push_back(free_queries_.front());
70 free_queries_.pop_front();
71 }
72 free_queries_.swap(new_queue);
73
74 std::deque<Bucket*> new_buckets;
75 while (!buckets_.empty()) {
76 Bucket* bucket = buckets_.front();
77 if (bucket->used_query_count) {
78 new_buckets.push_back(bucket);
79 } else {
80 mapped_memory_->Free(bucket->syncs);
81 delete bucket;
82 }
83 buckets_.pop_front();
84 }
85 buckets_.swap(new_buckets);
58 } 86 }
59 87
60 QueryTracker::Query::Query(GLuint id, GLenum target, 88 QueryTracker::Query::Query(GLuint id, GLenum target,
61 const QuerySyncManager::QueryInfo& info) 89 const QuerySyncManager::QueryInfo& info)
62 : id_(id), 90 : id_(id),
63 target_(target), 91 target_(target),
64 info_(info), 92 info_(info),
65 state_(kUninitialized), 93 state_(kUninitialized),
66 submit_count_(0), 94 submit_count_(0),
67 token_(0), 95 token_(0),
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 QueryMap::iterator it = queries_.find(client_id); 226 QueryMap::iterator it = queries_.find(client_id);
199 if (it != queries_.end()) { 227 if (it != queries_.end()) {
200 Query* query = it->second; 228 Query* query = it->second;
201 GPU_DCHECK(context_lost || !query->Pending()); 229 GPU_DCHECK(context_lost || !query->Pending());
202 query_sync_manager_.Free(query->info_); 230 query_sync_manager_.Free(query->info_);
203 queries_.erase(it); 231 queries_.erase(it);
204 delete query; 232 delete query;
205 } 233 }
206 } 234 }
207 235
236 void QueryTracker::Shrink() {
237 query_sync_manager_.Shrink();
238 }
239
208 } // namespace gles2 240 } // namespace gles2
209 } // namespace gpu 241 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/client/query_tracker.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698