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

Side by Side Diff: gpu/ipc/in_process_command_buffer.cc

Issue 2752393002: gpu: Add SequenceId for identifying sync point sequences. (Closed)
Patch Set: piman's review 3 Created 3 years, 9 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
« no previous file with comments | « gpu/ipc/in_process_command_buffer.h ('k') | gpu/ipc/service/gpu_channel.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/ipc/in_process_command_buffer.h" 5 #include "gpu/ipc/in_process_command_buffer.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <queue> 10 #include <queue>
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 program_cache_.reset(new gles2::MemoryProgramCache( 173 program_cache_.reset(new gles2::MemoryProgramCache(
174 gpu_preferences_.gpu_program_cache_size, 174 gpu_preferences_.gpu_program_cache_size,
175 disable_disk_cache, 175 disable_disk_cache,
176 workarounds.disable_program_caching_for_transform_feedback)); 176 workarounds.disable_program_caching_for_transform_feedback));
177 } 177 }
178 return program_cache_.get(); 178 return program_cache_.get();
179 } 179 }
180 180
181 InProcessCommandBuffer::InProcessCommandBuffer( 181 InProcessCommandBuffer::InProcessCommandBuffer(
182 const scoped_refptr<Service>& service) 182 const scoped_refptr<Service>& service)
183 : command_buffer_id_( 183 : command_buffer_id_(CommandBufferId::FromUnsafeValue(
184 CommandBufferId::FromUnsafeValue(g_next_command_buffer_id.GetNext())), 184 g_next_command_buffer_id.GetNext() + 1)),
185 delayed_work_pending_(false), 185 delayed_work_pending_(false),
186 image_factory_(nullptr), 186 image_factory_(nullptr),
187 gpu_control_client_(nullptr), 187 gpu_control_client_(nullptr),
188 #if DCHECK_IS_ON() 188 #if DCHECK_IS_ON()
189 context_lost_(false), 189 context_lost_(false),
190 #endif 190 #endif
191 last_put_offset_(-1), 191 last_put_offset_(-1),
192 gpu_memory_buffer_manager_(nullptr), 192 gpu_memory_buffer_manager_(nullptr),
193 next_fence_sync_release_(1), 193 next_fence_sync_release_(1),
194 flushed_fence_sync_release_(0), 194 flushed_fence_sync_release_(0),
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 } 340 }
341 } 341 }
342 } 342 }
343 343
344 if (!surface_.get()) { 344 if (!surface_.get()) {
345 LOG(ERROR) << "Could not create GLSurface."; 345 LOG(ERROR) << "Could not create GLSurface.";
346 DestroyOnGpuThread(); 346 DestroyOnGpuThread();
347 return false; 347 return false;
348 } 348 }
349 349
350 sync_point_order_data_ = SyncPointOrderData::Create(); 350 sync_point_order_data_ =
351 sync_point_client_ = base::MakeUnique<SyncPointClient>( 351 service_->sync_point_manager()->CreateSyncPointOrderData();
352 service_->sync_point_manager(), sync_point_order_data_, GetNamespaceID(), 352 sync_point_client_state_ =
353 GetCommandBufferID()); 353 service_->sync_point_manager()->CreateSyncPointClientState(
354 GetNamespaceID(), GetCommandBufferID(),
355 sync_point_order_data_->sequence_id());
354 356
355 if (service_->UseVirtualizedGLContexts() || 357 if (service_->UseVirtualizedGLContexts() ||
356 decoder_->GetContextGroup() 358 decoder_->GetContextGroup()
357 ->feature_info() 359 ->feature_info()
358 ->workarounds() 360 ->workarounds()
359 .use_virtualized_gl_contexts) { 361 .use_virtualized_gl_contexts) {
360 context_ = gl_share_group_->GetSharedContext(surface_.get()); 362 context_ = gl_share_group_->GetSharedContext(surface_.get());
361 if (!context_.get()) { 363 if (!context_.get()) {
362 context_ = gl::init::CreateGLContext( 364 context_ = gl::init::CreateGLContext(
363 gl_share_group_.get(), surface_.get(), 365 gl_share_group_.get(), surface_.get(),
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 gpu_thread_weak_ptr_factory_.InvalidateWeakPtrs(); 454 gpu_thread_weak_ptr_factory_.InvalidateWeakPtrs();
453 command_buffer_.reset(); 455 command_buffer_.reset();
454 // Clean up GL resources if possible. 456 // Clean up GL resources if possible.
455 bool have_context = context_.get() && context_->MakeCurrent(surface_.get()); 457 bool have_context = context_.get() && context_->MakeCurrent(surface_.get());
456 if (decoder_) { 458 if (decoder_) {
457 decoder_->Destroy(have_context); 459 decoder_->Destroy(have_context);
458 decoder_.reset(); 460 decoder_.reset();
459 } 461 }
460 context_ = nullptr; 462 context_ = nullptr;
461 surface_ = nullptr; 463 surface_ = nullptr;
462 sync_point_client_ = nullptr;
463 if (sync_point_order_data_) { 464 if (sync_point_order_data_) {
464 sync_point_order_data_->Destroy(); 465 sync_point_order_data_->Destroy();
465 sync_point_order_data_ = nullptr; 466 sync_point_order_data_ = nullptr;
466 } 467 }
468 if (sync_point_client_state_) {
469 sync_point_client_state_->Destroy();
470 sync_point_client_state_ = nullptr;
471 }
467 gl_share_group_ = nullptr; 472 gl_share_group_ = nullptr;
468 context_group_ = nullptr; 473 context_group_ = nullptr;
469 474
470 base::AutoLock lock(task_queue_lock_); 475 base::AutoLock lock(task_queue_lock_);
471 std::queue<std::unique_ptr<GpuTask>> empty; 476 std::queue<std::unique_ptr<GpuTask>> empty;
472 task_queue_.swap(empty); 477 task_queue_.swap(empty);
473 478
474 return true; 479 return true;
475 } 480 }
476 481
(...skipping 23 matching lines...) Expand all
500 } 505 }
501 506
502 void InProcessCommandBuffer::QueueTask(bool out_of_order, 507 void InProcessCommandBuffer::QueueTask(bool out_of_order,
503 const base::Closure& task) { 508 const base::Closure& task) {
504 if (out_of_order) { 509 if (out_of_order) {
505 service_->ScheduleTask(task); 510 service_->ScheduleTask(task);
506 return; 511 return;
507 } 512 }
508 // Release the |task_queue_lock_| before calling ScheduleTask because 513 // Release the |task_queue_lock_| before calling ScheduleTask because
509 // the callback may get called immediately and attempt to acquire the lock. 514 // the callback may get called immediately and attempt to acquire the lock.
510 SyncPointManager* sync_manager = service_->sync_point_manager(); 515 uint32_t order_num = sync_point_order_data_->GenerateUnprocessedOrderNumber();
511 uint32_t order_num =
512 sync_point_order_data_->GenerateUnprocessedOrderNumber(sync_manager);
513 { 516 {
514 base::AutoLock lock(task_queue_lock_); 517 base::AutoLock lock(task_queue_lock_);
515 task_queue_.push(base::MakeUnique<GpuTask>(task, order_num)); 518 task_queue_.push(base::MakeUnique<GpuTask>(task, order_num));
516 } 519 }
517 service_->ScheduleTask(base::Bind( 520 service_->ScheduleTask(base::Bind(
518 &InProcessCommandBuffer::ProcessTasksOnGpuThread, gpu_thread_weak_ptr_)); 521 &InProcessCommandBuffer::ProcessTasksOnGpuThread, gpu_thread_weak_ptr_));
519 } 522 }
520 523
521 void InProcessCommandBuffer::ProcessTasksOnGpuThread() { 524 void InProcessCommandBuffer::ProcessTasksOnGpuThread() {
522 while (executor_->scheduled()) { 525 while (executor_->scheduled()) {
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
795 LOG(ERROR) << "Failed to create image for buffer."; 798 LOG(ERROR) << "Failed to create image for buffer.";
796 return; 799 return;
797 } 800 }
798 801
799 image_manager->AddImage(image.get(), id); 802 image_manager->AddImage(image.get(), id);
800 break; 803 break;
801 } 804 }
802 } 805 }
803 806
804 if (fence_sync) 807 if (fence_sync)
805 sync_point_client_->ReleaseFenceSync(fence_sync); 808 sync_point_client_state_->ReleaseFenceSync(fence_sync);
806 } 809 }
807 810
808 void InProcessCommandBuffer::DestroyImage(int32_t id) { 811 void InProcessCommandBuffer::DestroyImage(int32_t id) {
809 CheckSequencedThread(); 812 CheckSequencedThread();
810 813
811 QueueTask(false, base::Bind(&InProcessCommandBuffer::DestroyImageOnGpuThread, 814 QueueTask(false, base::Bind(&InProcessCommandBuffer::DestroyImageOnGpuThread,
812 base::Unretained(this), id)); 815 base::Unretained(this), id));
813 } 816 }
814 817
815 void InProcessCommandBuffer::DestroyImageOnGpuThread(int32_t id) { 818 void InProcessCommandBuffer::DestroyImageOnGpuThread(int32_t id) {
(...skipping 11 matching lines...) Expand all
827 } 830 }
828 831
829 void InProcessCommandBuffer::FenceSyncReleaseOnGpuThread(uint64_t release) { 832 void InProcessCommandBuffer::FenceSyncReleaseOnGpuThread(uint64_t release) {
830 SyncToken sync_token(GetNamespaceID(), GetExtraCommandBufferData(), 833 SyncToken sync_token(GetNamespaceID(), GetExtraCommandBufferData(),
831 GetCommandBufferID(), release); 834 GetCommandBufferID(), release);
832 835
833 gles2::MailboxManager* mailbox_manager = 836 gles2::MailboxManager* mailbox_manager =
834 decoder_->GetContextGroup()->mailbox_manager(); 837 decoder_->GetContextGroup()->mailbox_manager();
835 mailbox_manager->PushTextureUpdates(sync_token); 838 mailbox_manager->PushTextureUpdates(sync_token);
836 839
837 sync_point_client_->ReleaseFenceSync(release); 840 sync_point_client_state_->ReleaseFenceSync(release);
838 } 841 }
839 842
840 bool InProcessCommandBuffer::WaitSyncTokenOnGpuThread( 843 bool InProcessCommandBuffer::WaitSyncTokenOnGpuThread(
841 const SyncToken& sync_token) { 844 const SyncToken& sync_token) {
842 DCHECK(!waiting_for_sync_point_); 845 DCHECK(!waiting_for_sync_point_);
843 gpu::SyncPointManager* sync_point_manager = service_->sync_point_manager(); 846 gpu::SyncPointManager* sync_point_manager = service_->sync_point_manager();
844 DCHECK(sync_point_manager); 847 DCHECK(sync_point_manager);
845 848
846 gles2::MailboxManager* mailbox_manager = 849 gles2::MailboxManager* mailbox_manager =
847 decoder_->GetContextGroup()->mailbox_manager(); 850 decoder_->GetContextGroup()->mailbox_manager();
848 DCHECK(mailbox_manager); 851 DCHECK(mailbox_manager);
849 852
850 if (service_->BlockThreadOnWaitSyncToken()) { 853 if (service_->BlockThreadOnWaitSyncToken()) {
851 // Wait if sync point wait is valid. 854 // Wait if sync point wait is valid.
852 if (sync_point_client_->Wait( 855 if (sync_point_client_state_->Wait(
853 sync_token, 856 sync_token,
854 base::Bind(&base::WaitableEvent::Signal, 857 base::Bind(&base::WaitableEvent::Signal,
855 base::Unretained(&fence_sync_wait_event_)))) { 858 base::Unretained(&fence_sync_wait_event_)))) {
856 fence_sync_wait_event_.Wait(); 859 fence_sync_wait_event_.Wait();
857 } 860 }
858 861
859 mailbox_manager->PullTextureUpdates(sync_token); 862 mailbox_manager->PullTextureUpdates(sync_token);
860 return false; 863 return false;
861 } 864 }
862 865
863 waiting_for_sync_point_ = sync_point_client_->Wait( 866 waiting_for_sync_point_ = sync_point_client_state_->Wait(
864 sync_token, 867 sync_token,
865 base::Bind(&InProcessCommandBuffer::OnWaitSyncTokenCompleted, 868 base::Bind(&InProcessCommandBuffer::OnWaitSyncTokenCompleted,
866 gpu_thread_weak_ptr_factory_.GetWeakPtr(), sync_token)); 869 gpu_thread_weak_ptr_factory_.GetWeakPtr(), sync_token));
867 if (!waiting_for_sync_point_) { 870 if (!waiting_for_sync_point_) {
868 mailbox_manager->PullTextureUpdates(sync_token); 871 mailbox_manager->PullTextureUpdates(sync_token);
869 return false; 872 return false;
870 } 873 }
871 874
872 executor_->SetScheduled(false); 875 executor_->SetScheduled(false);
873 return true; 876 return true;
(...skipping 25 matching lines...) Expand all
899 DCHECK(!executor_->scheduled()); 902 DCHECK(!executor_->scheduled());
900 903
901 executor_->SetScheduled(true); 904 executor_->SetScheduled(true);
902 ProcessTasksOnGpuThread(); 905 ProcessTasksOnGpuThread();
903 } 906 }
904 } 907 }
905 908
906 void InProcessCommandBuffer::SignalSyncTokenOnGpuThread( 909 void InProcessCommandBuffer::SignalSyncTokenOnGpuThread(
907 const SyncToken& sync_token, 910 const SyncToken& sync_token,
908 const base::Closure& callback) { 911 const base::Closure& callback) {
909 if (!sync_point_client_->Wait(sync_token, WrapCallback(callback))) 912 if (!sync_point_client_state_->Wait(sync_token, WrapCallback(callback)))
910 callback.Run(); 913 callback.Run();
911 } 914 }
912 915
913 void InProcessCommandBuffer::SignalQuery(unsigned query_id, 916 void InProcessCommandBuffer::SignalQuery(unsigned query_id,
914 const base::Closure& callback) { 917 const base::Closure& callback) {
915 CheckSequencedThread(); 918 CheckSequencedThread();
916 QueueTask(false, base::Bind(&InProcessCommandBuffer::SignalQueryOnGpuThread, 919 QueueTask(false, base::Bind(&InProcessCommandBuffer::SignalQueryOnGpuThread,
917 base::Unretained(this), query_id, 920 base::Unretained(this), query_id,
918 WrapCallback(callback))); 921 WrapCallback(callback)));
919 } 922 }
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
1121 return wrapped_callback; 1124 return wrapped_callback;
1122 } 1125 }
1123 1126
1124 InProcessCommandBuffer::GpuTask::GpuTask(const base::Closure& callback, 1127 InProcessCommandBuffer::GpuTask::GpuTask(const base::Closure& callback,
1125 uint32_t order_number) 1128 uint32_t order_number)
1126 : callback(callback), order_number(order_number) {} 1129 : callback(callback), order_number(order_number) {}
1127 1130
1128 InProcessCommandBuffer::GpuTask::~GpuTask() {} 1131 InProcessCommandBuffer::GpuTask::~GpuTask() {}
1129 1132
1130 } // namespace gpu 1133 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/ipc/in_process_command_buffer.h ('k') | gpu/ipc/service/gpu_channel.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698