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

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

Issue 238933003: Re-land: gpu: Add CHROMIUM_sync_query extension. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 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/memory/shared_memory.h" 10 #include "base/memory/shared_memory.h"
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 382
383 void GetErrorQuery::Destroy(bool /* have_context */) { 383 void GetErrorQuery::Destroy(bool /* have_context */) {
384 if (!IsDeleted()) { 384 if (!IsDeleted()) {
385 MarkAsDeleted(); 385 MarkAsDeleted();
386 } 386 }
387 } 387 }
388 388
389 GetErrorQuery::~GetErrorQuery() { 389 GetErrorQuery::~GetErrorQuery() {
390 } 390 }
391 391
392 class CommandsCompletedQuery : public QueryManager::Query {
393 public:
394 CommandsCompletedQuery(QueryManager* manager,
395 GLenum target,
396 int32 shm_id,
397 uint32 shm_offset,
398 bool use_arb_sync);
399
400 // Overridden from QueryManager::Query:
401 virtual bool Begin() OVERRIDE;
402 virtual bool End(base::subtle::Atomic32 submit_count) OVERRIDE;
403 virtual bool Process() OVERRIDE;
404 virtual void Destroy(bool have_context) OVERRIDE;
405
406 protected:
407 virtual ~CommandsCompletedQuery();
408
409 private:
410 bool use_arb_sync_;
411 GLsync sync_;
412 };
413
414 CommandsCompletedQuery::CommandsCompletedQuery(QueryManager* manager,
415 GLenum target,
416 int32 shm_id,
417 uint32 shm_offset,
418 bool use_arb_sync)
419 : Query(manager, target, shm_id, shm_offset),
420 use_arb_sync_(use_arb_sync),
421 sync_(NULL) {}
422
423 bool CommandsCompletedQuery::Begin() {
424 if (sync_) {
425 glDeleteSync(sync_);
426 sync_ = NULL;
427 }
428 return true;
429 }
430
431 bool CommandsCompletedQuery::End(base::subtle::Atomic32 submit_count) {
432 if (use_arb_sync_) {
433 sync_ = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
no sievers 2014/04/15 18:41:15 You have to glFlush() somewhere or the commands mi
no sievers 2014/04/15 18:48:44 "Querying the GL_QUERY_RESULT implicitly flushes t
reveman 2014/04/15 22:29:28 As I mentioned above, the idea is to make the clie
434 DCHECK(sync_);
435 } else {
436 TRACE_EVENT0("gpu", "CommandsCompletedQuery::End");
437 glFinish(); // Poor man's GPU fence.
no sievers 2014/04/15 18:41:15 Do we need this fallback, or can we not support th
reveman 2014/04/15 22:29:28 We'll need a fall-back somewhere but maybe it shou
438 }
439 return AddToPendingQueue(submit_count);
440 }
441
442 bool CommandsCompletedQuery::Process() {
443 if (sync_) {
444 int value = GL_UNSIGNALED;
445 glGetSynciv(sync_, GL_SYNC_STATUS, 1, NULL, &value);
no sievers 2014/04/15 18:41:15 See comment in gl_fence.cc that this does not work
reveman 2014/04/15 22:29:28 Ok, makes sense to use GLFence and handle these ty
446 if (value == GL_UNSIGNALED)
447 return true;
448 }
449 return MarkAsCompleted(0);
450 }
451
452 void CommandsCompletedQuery::Destroy(bool have_context) {
453 if (have_context && !IsDeleted()) {
454 if (sync_)
455 glDeleteSync(sync_);
456 MarkAsDeleted();
457 }
458 }
459
460 CommandsCompletedQuery::~CommandsCompletedQuery() {}
461
392 QueryManager::QueryManager( 462 QueryManager::QueryManager(
393 GLES2Decoder* decoder, 463 GLES2Decoder* decoder,
394 FeatureInfo* feature_info) 464 FeatureInfo* feature_info)
395 : decoder_(decoder), 465 : decoder_(decoder),
396 use_arb_occlusion_query2_for_occlusion_query_boolean_( 466 use_arb_occlusion_query2_for_occlusion_query_boolean_(
397 feature_info->feature_flags( 467 feature_info->feature_flags(
398 ).use_arb_occlusion_query2_for_occlusion_query_boolean), 468 ).use_arb_occlusion_query2_for_occlusion_query_boolean),
399 use_arb_occlusion_query_for_occlusion_query_boolean_( 469 use_arb_occlusion_query_for_occlusion_query_boolean_(
400 feature_info->feature_flags( 470 feature_info->feature_flags(
401 ).use_arb_occlusion_query_for_occlusion_query_boolean), 471 ).use_arb_occlusion_query_for_occlusion_query_boolean),
472 use_arb_sync_(feature_info->feature_flags().arb_sync),
402 query_count_(0) { 473 query_count_(0) {
403 DCHECK(!(use_arb_occlusion_query_for_occlusion_query_boolean_ && 474 DCHECK(!(use_arb_occlusion_query_for_occlusion_query_boolean_ &&
404 use_arb_occlusion_query2_for_occlusion_query_boolean_)); 475 use_arb_occlusion_query2_for_occlusion_query_boolean_));
405 } 476 }
406 477
407 QueryManager::~QueryManager() { 478 QueryManager::~QueryManager() {
408 DCHECK(queries_.empty()); 479 DCHECK(queries_.empty());
409 480
410 // If this triggers, that means something is keeping a reference to 481 // If this triggers, that means something is keeping a reference to
411 // a Query belonging to this. 482 // a Query belonging to this.
(...skipping 25 matching lines...) Expand all
437 query = new AsyncPixelTransfersCompletedQuery( 508 query = new AsyncPixelTransfersCompletedQuery(
438 this, target, shm_id, shm_offset); 509 this, target, shm_id, shm_offset);
439 break; 510 break;
440 case GL_ASYNC_PIXEL_PACK_COMPLETED_CHROMIUM: 511 case GL_ASYNC_PIXEL_PACK_COMPLETED_CHROMIUM:
441 query = new AsyncReadPixelsCompletedQuery( 512 query = new AsyncReadPixelsCompletedQuery(
442 this, target, shm_id, shm_offset); 513 this, target, shm_id, shm_offset);
443 break; 514 break;
444 case GL_GET_ERROR_QUERY_CHROMIUM: 515 case GL_GET_ERROR_QUERY_CHROMIUM:
445 query = new GetErrorQuery(this, target, shm_id, shm_offset); 516 query = new GetErrorQuery(this, target, shm_id, shm_offset);
446 break; 517 break;
518 case GL_COMMANDS_COMPLETED_CHROMIUM:
519 query = new CommandsCompletedQuery(
520 this, target, shm_id, shm_offset, use_arb_sync_);
521 break;
447 default: { 522 default: {
448 GLuint service_id = 0; 523 GLuint service_id = 0;
449 glGenQueriesARB(1, &service_id); 524 glGenQueriesARB(1, &service_id);
450 DCHECK_NE(0u, service_id); 525 DCHECK_NE(0u, service_id);
451 query = new AllSamplesPassedQuery( 526 query = new AllSamplesPassedQuery(
452 this, target, shm_id, shm_offset, service_id); 527 this, target, shm_id, shm_offset, service_id);
453 break; 528 break;
454 } 529 }
455 } 530 }
456 std::pair<QueryMap::iterator, bool> result = 531 std::pair<QueryMap::iterator, bool> result =
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
672 bool QueryManager::EndQuery(Query* query, base::subtle::Atomic32 submit_count) { 747 bool QueryManager::EndQuery(Query* query, base::subtle::Atomic32 submit_count) {
673 DCHECK(query); 748 DCHECK(query);
674 if (!RemovePendingQuery(query)) { 749 if (!RemovePendingQuery(query)) {
675 return false; 750 return false;
676 } 751 }
677 return query->End(submit_count); 752 return query->End(submit_count);
678 } 753 }
679 754
680 } // namespace gles2 755 } // namespace gles2
681 } // namespace gpu 756 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698