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

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

Issue 18340003: gpu: Fix removal of pending queries. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 5 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
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 "gpu/command_buffer/client/query_tracker.h" 5 #include "gpu/command_buffer/client/query_tracker.h"
6 6
7 #include <GLES2/gl2.h> 7 #include <GLES2/gl2.h>
8 #include <GLES2/gl2ext.h> 8 #include <GLES2/gl2ext.h>
9 #include <GLES2/gl2extchromium.h> 9 #include <GLES2/gl2extchromium.h>
10 10
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 uint32 QueryTracker::Query::GetResult() const { 192 uint32 QueryTracker::Query::GetResult() const {
193 GPU_DCHECK(state_ == kComplete || state_ == kUninitialized); 193 GPU_DCHECK(state_ == kComplete || state_ == kUninitialized);
194 return result_; 194 return result_;
195 } 195 }
196 196
197 QueryTracker::QueryTracker(MappedMemoryManager* manager) 197 QueryTracker::QueryTracker(MappedMemoryManager* manager)
198 : query_sync_manager_(manager) { 198 : query_sync_manager_(manager) {
199 } 199 }
200 200
201 QueryTracker::~QueryTracker() { 201 QueryTracker::~QueryTracker() {
202 queries_.clear(); 202 while (!queries_.empty()) {
203 delete queries_.begin()->second;
204 queries_.erase(queries_.begin());
205 }
206 while (!removed_queries_.empty()) {
207 delete removed_queries_.front();
208 removed_queries_.pop_front();
209 }
203 } 210 }
204 211
205 QueryTracker::Query* QueryTracker::CreateQuery(GLuint id, GLenum target) { 212 QueryTracker::Query* QueryTracker::CreateQuery(GLuint id, GLenum target) {
206 GPU_DCHECK_NE(0u, id); 213 GPU_DCHECK_NE(0u, id);
214 FreeCompletedQueries();
207 QuerySyncManager::QueryInfo info; 215 QuerySyncManager::QueryInfo info;
208 if (!query_sync_manager_.Alloc(&info)) { 216 if (!query_sync_manager_.Alloc(&info)) {
209 return NULL; 217 return NULL;
210 } 218 }
211 Query* query = new Query(id, target, info); 219 Query* query = new Query(id, target, info);
212 std::pair<QueryMap::iterator, bool> result = 220 std::pair<QueryMap::iterator, bool> result =
213 queries_.insert(std::make_pair(id, query)); 221 queries_.insert(std::make_pair(id, query));
214 GPU_DCHECK(result.second); 222 GPU_DCHECK(result.second);
215 return query; 223 return query;
216 } 224 }
217 225
218 QueryTracker::Query* QueryTracker::GetQuery( 226 QueryTracker::Query* QueryTracker::GetQuery(
219 GLuint client_id) { 227 GLuint client_id) {
220 QueryMap::iterator it = queries_.find(client_id); 228 QueryMap::iterator it = queries_.find(client_id);
221 return it != queries_.end() ? it->second : NULL; 229 return it != queries_.end() ? it->second : NULL;
222 } 230 }
223 231
224 void QueryTracker::RemoveQuery(GLuint client_id, bool context_lost) { 232 void QueryTracker::RemoveQuery(GLuint client_id) {
225 (void)context_lost; // stop unused warning
226 QueryMap::iterator it = queries_.find(client_id); 233 QueryMap::iterator it = queries_.find(client_id);
227 if (it != queries_.end()) { 234 if (it != queries_.end()) {
228 Query* query = it->second; 235 Query* query = it->second;
229 GPU_DCHECK(context_lost || !query->Pending()); 236 // When you delete a query you can't mark its memory as unused until it's
237 // completed.
238 // Note: If you don't do this you won't mess up the service but you will
239 // mess up yourself.
240 removed_queries_.push_back(query);
241 queries_.erase(it);
242 FreeCompletedQueries();
243 }
244 }
245
246 void QueryTracker::Shrink() {
247 FreeCompletedQueries();
248 query_sync_manager_.Shrink();
249 }
250
251 void QueryTracker::FreeCompletedQueries() {
252 QueryList::iterator it = removed_queries_.begin();
253 while (it != removed_queries_.end()) {
254 Query* query = *it;
255 if (query->Pending() &&
256 query->info_.sync->process_count != query->submit_count()) {
257 ++it;
258 continue;
259 }
260
230 query_sync_manager_.Free(query->info_); 261 query_sync_manager_.Free(query->info_);
231 queries_.erase(it); 262 it = removed_queries_.erase(it);
232 delete query; 263 delete query;
233 } 264 }
234 } 265 }
235 266
236 void QueryTracker::Shrink() {
237 query_sync_manager_.Shrink();
238 }
239
240 } // namespace gles2 267 } // namespace gles2
241 } // namespace gpu 268 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/client/query_tracker.h ('k') | gpu/command_buffer/client/query_tracker_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698