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

Side by Side Diff: gpu/command_buffer/service/query_manager.cc

Issue 16831004: Perform glReadPixels with PBOs in the gpu, if PBOs are available. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: use webglid where approperiate Created 7 years, 6 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/service/query_manager.h" 5 #include "gpu/command_buffer/service/query_manager.h"
6 6
7 #include "base/atomicops.h" 7 #include "base/atomicops.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/shared_memory.h" 10 #include "base/shared_memory.h"
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 DCHECK(mem_params.shared_memory->memory()); 188 DCHECK(mem_params.shared_memory->memory());
189 void *data = static_cast<int8*>(mem_params.shared_memory->memory()) + 189 void *data = static_cast<int8*>(mem_params.shared_memory->memory()) +
190 mem_params.shm_data_offset; 190 mem_params.shm_data_offset;
191 QuerySync* sync = static_cast<QuerySync*>(data); 191 QuerySync* sync = static_cast<QuerySync*>(data);
192 192
193 // Need a MemoryBarrier here to ensure that upload completed before 193 // Need a MemoryBarrier here to ensure that upload completed before
194 // submit_count was written to sync->process_count. 194 // submit_count was written to sync->process_count.
195 base::subtle::MemoryBarrier(); 195 base::subtle::MemoryBarrier();
196 sync->process_count = submit_count; 196 sync->process_count = submit_count;
197 } 197 }
198 void MarkAsCompletedStage1(
199 uint32 submit_count, const AsyncMemoryParams& mem_params);
198 }; 200 };
199 201
200 AsyncPixelTransfersCompletedQuery::AsyncPixelTransfersCompletedQuery( 202 AsyncPixelTransfersCompletedQuery::AsyncPixelTransfersCompletedQuery(
201 QueryManager* manager, GLenum target, int32 shm_id, uint32 shm_offset) 203 QueryManager* manager, GLenum target, int32 shm_id, uint32 shm_offset)
202 : Query(manager, target, shm_id, shm_offset) { 204 : Query(manager, target, shm_id, shm_offset) {
203 } 205 }
204 206
205 bool AsyncPixelTransfersCompletedQuery::Begin() { 207 bool AsyncPixelTransfersCompletedQuery::Begin() {
206 return true; 208 return true;
207 } 209 }
208 210
209 bool AsyncPixelTransfersCompletedQuery::End(uint32 submit_count) { 211 bool AsyncPixelTransfersCompletedQuery::End(uint32 submit_count) {
210 AsyncMemoryParams mem_params; 212 AsyncMemoryParams mem_params;
211 // Get the real shared memory since it might need to be duped to prevent 213 // Get the real shared memory since it might need to be duped to prevent
212 // use-after-free of the memory. 214 // use-after-free of the memory.
213 Buffer buffer = manager()->decoder()->GetSharedMemoryBuffer(shm_id()); 215 Buffer buffer = manager()->decoder()->GetSharedMemoryBuffer(shm_id());
214 if (!buffer.shared_memory) 216 if (!buffer.shared_memory)
215 return false; 217 return false;
216 mem_params.shared_memory = buffer.shared_memory; 218 mem_params.shared_memory = buffer.shared_memory;
217 mem_params.shm_size = buffer.size; 219 mem_params.shm_size = buffer.size;
218 mem_params.shm_data_offset = shm_offset(); 220 mem_params.shm_data_offset = shm_offset();
219 mem_params.shm_data_size = sizeof(QuerySync); 221 mem_params.shm_data_size = sizeof(QuerySync);
220 222
223 manager()->decoder()->WaitForReadPixels(
224 base::Bind(&AsyncPixelTransfersCompletedQuery::MarkAsCompletedStage1,
225 this, submit_count, mem_params));
piman 2013/06/17 19:55:06 The problem here is that for async texture upload,
hubbe 2013/06/25 20:02:51 I changed this so that WaitForReadPixels doesn't a
piman 2013/06/26 22:17:08 So as I read it, and please explain to me if I mis
hubbe 2013/06/28 22:17:49 Fixed by implementing a new query type.
226
227 return AddToPendingTransferQueue(submit_count);
228 }
229
230 void AsyncPixelTransfersCompletedQuery::MarkAsCompletedStage1(
231 uint32 submit_count,
232 const AsyncMemoryParams& mem_params) {
233
221 // Ask AsyncPixelTransferDelegate to run completion callback after all 234 // Ask AsyncPixelTransferDelegate to run completion callback after all
222 // previous async transfers are done. No guarantee that callback is run 235 // previous async transfers are done. No guarantee that callback is run
223 // on the current thread. 236 // on the current thread.
224 manager()->decoder()->GetAsyncPixelTransferManager()->AsyncNotifyCompletion( 237 manager()->decoder()->GetAsyncPixelTransferManager()->AsyncNotifyCompletion(
225 mem_params, 238 mem_params,
226 base::Bind(AsyncPixelTransfersCompletedQuery::MarkAsCompletedThreadSafe, 239 base::Bind(AsyncPixelTransfersCompletedQuery::MarkAsCompletedThreadSafe,
227 submit_count)); 240 submit_count));
228 241
229 return AddToPendingTransferQueue(submit_count); 242
230 } 243 }
231 244
232 bool AsyncPixelTransfersCompletedQuery::Process() { 245 bool AsyncPixelTransfersCompletedQuery::Process() {
233 QuerySync* sync = manager()->decoder()->GetSharedMemoryAs<QuerySync*>( 246 QuerySync* sync = manager()->decoder()->GetSharedMemoryAs<QuerySync*>(
234 shm_id(), shm_offset(), sizeof(*sync)); 247 shm_id(), shm_offset(), sizeof(*sync));
235 if (!sync) 248 if (!sync)
236 return false; 249 return false;
237 250
238 // Check if completion callback has been run. sync->process_count atomicity 251 // Check if completion callback has been run. sync->process_count atomicity
239 // is guaranteed as this is already used to notify client of a completed 252 // is guaranteed as this is already used to notify client of a completed
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 target_(target), 438 target_(target),
426 shm_id_(shm_id), 439 shm_id_(shm_id),
427 shm_offset_(shm_offset), 440 shm_offset_(shm_offset),
428 submit_count_(0), 441 submit_count_(0),
429 pending_(false), 442 pending_(false),
430 deleted_(false) { 443 deleted_(false) {
431 DCHECK(manager); 444 DCHECK(manager);
432 manager_->StartTracking(this); 445 manager_->StartTracking(this);
433 } 446 }
434 447
448 void QueryManager::Query::RunCallbacks() {
449 for (size_t i = 0; i < callbacks_.size(); i++) {
450 callbacks_[i].Run();
451 }
452 callbacks_.clear();
453 }
454
455 void QueryManager::Query::AddCallback(base::Closure callback) {
456 callbacks_.push_back(callback);
piman 2013/06/17 19:55:06 This should call the callback if the query is not
hubbe 2013/06/25 20:02:51 Done. (In other CL)
457 }
458
435 QueryManager::Query::~Query() { 459 QueryManager::Query::~Query() {
460 // Seems like this channel is shutting down with some callbacks
piman 2013/06/17 19:55:06 note: this could also happen if the query is destr
hubbe 2013/06/25 20:02:51 Handled in other CL.
461 // still active. Call the queries now to avoid leaks.
462 RunCallbacks();
436 if (manager_) { 463 if (manager_) {
437 manager_->StopTracking(this); 464 manager_->StopTracking(this);
438 manager_ = NULL; 465 manager_ = NULL;
439 } 466 }
440 } 467 }
441 468
442 bool QueryManager::Query::MarkAsCompleted(uint64 result) { 469 bool QueryManager::Query::MarkAsCompleted(uint64 result) {
443 DCHECK(pending_); 470 DCHECK(pending_);
444 QuerySync* sync = manager_->decoder_->GetSharedMemoryAs<QuerySync*>( 471 QuerySync* sync = manager_->decoder_->GetSharedMemoryAs<QuerySync*>(
445 shm_id_, shm_offset_, sizeof(*sync)); 472 shm_id_, shm_offset_, sizeof(*sync));
(...skipping 13 matching lines...) Expand all
459 486
460 bool QueryManager::ProcessPendingQueries() { 487 bool QueryManager::ProcessPendingQueries() {
461 while (!pending_queries_.empty()) { 488 while (!pending_queries_.empty()) {
462 Query* query = pending_queries_.front().get(); 489 Query* query = pending_queries_.front().get();
463 if (!query->Process()) { 490 if (!query->Process()) {
464 return false; 491 return false;
465 } 492 }
466 if (query->pending()) { 493 if (query->pending()) {
467 break; 494 break;
468 } 495 }
496 query->RunCallbacks();
469 pending_queries_.pop_front(); 497 pending_queries_.pop_front();
470 } 498 }
471 499
472 return true; 500 return true;
473 } 501 }
474 502
475 bool QueryManager::HavePendingQueries() { 503 bool QueryManager::HavePendingQueries() {
476 return !pending_queries_.empty(); 504 return !pending_queries_.empty();
477 } 505 }
478 506
479 bool QueryManager::ProcessPendingTransferQueries() { 507 bool QueryManager::ProcessPendingTransferQueries() {
480 while (!pending_transfer_queries_.empty()) { 508 while (!pending_transfer_queries_.empty()) {
481 Query* query = pending_transfer_queries_.front().get(); 509 Query* query = pending_transfer_queries_.front().get();
482 if (!query->Process()) { 510 if (!query->Process()) {
483 return false; 511 return false;
484 } 512 }
485 if (query->pending()) { 513 if (query->pending()) {
486 break; 514 break;
487 } 515 }
516 query->RunCallbacks();
488 pending_transfer_queries_.pop_front(); 517 pending_transfer_queries_.pop_front();
489 } 518 }
490 519
491 return true; 520 return true;
492 } 521 }
493 522
494 bool QueryManager::HavePendingTransferQueries() { 523 bool QueryManager::HavePendingTransferQueries() {
495 return !pending_transfer_queries_.empty(); 524 return !pending_transfer_queries_.empty();
496 } 525 }
497 526
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 bool QueryManager::EndQuery(Query* query, uint32 submit_count) { 584 bool QueryManager::EndQuery(Query* query, uint32 submit_count) {
556 DCHECK(query); 585 DCHECK(query);
557 if (!RemovePendingQuery(query)) { 586 if (!RemovePendingQuery(query)) {
558 return false; 587 return false;
559 } 588 }
560 return query->End(submit_count); 589 return query->End(submit_count);
561 } 590 }
562 591
563 } // namespace gles2 592 } // namespace gles2
564 } // namespace gpu 593 } // namespace gpu
565
566
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698