OLD | NEW |
---|---|
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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/bind_helpers.h" | 6 #include "base/bind_helpers.h" |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/hash.h" | 8 #include "base/hash.h" |
9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
10 #include "base/memory/shared_memory.h" | 10 #include "base/memory/shared_memory.h" |
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
539 | 539 |
540 gpu::SyncPointManager* sync_point_manager = manager->sync_point_manager(); | 540 gpu::SyncPointManager* sync_point_manager = manager->sync_point_manager(); |
541 DCHECK(sync_point_manager); | 541 DCHECK(sync_point_manager); |
542 | 542 |
543 decoder_.reset(::gpu::gles2::GLES2Decoder::Create(context_group_.get())); | 543 decoder_.reset(::gpu::gles2::GLES2Decoder::Create(context_group_.get())); |
544 scheduler_.reset(new gpu::GpuScheduler(command_buffer_.get(), | 544 scheduler_.reset(new gpu::GpuScheduler(command_buffer_.get(), |
545 decoder_.get(), | 545 decoder_.get(), |
546 decoder_.get())); | 546 decoder_.get())); |
547 sync_point_client_ = | 547 sync_point_client_ = |
548 sync_point_manager->CreateSyncPointClient( | 548 sync_point_manager->CreateSyncPointClient( |
549 channel_->GetSyncPointClientState(), | 549 channel_->GetSyncPointOrderData(), |
550 gpu::CommandBufferNamespace::GPU_IO, | 550 gpu::CommandBufferNamespace::GPU_IO, |
551 command_buffer_id_); | 551 command_buffer_id_); |
552 | 552 |
553 if (preemption_flag_.get()) | 553 if (preemption_flag_.get()) |
554 scheduler_->SetPreemptByFlag(preemption_flag_); | 554 scheduler_->SetPreemptByFlag(preemption_flag_); |
555 | 555 |
556 decoder_->set_engine(scheduler_.get()); | 556 decoder_->set_engine(scheduler_.get()); |
557 | 557 |
558 if (!handle_.is_null()) { | 558 if (!handle_.is_null()) { |
559 surface_ = ImageTransportSurface::CreateSurface( | 559 surface_ = ImageTransportSurface::CreateSurface( |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
646 | 646 |
647 decoder_->GetLogger()->SetMsgCallback( | 647 decoder_->GetLogger()->SetMsgCallback( |
648 base::Bind(&GpuCommandBufferStub::SendConsoleMessage, | 648 base::Bind(&GpuCommandBufferStub::SendConsoleMessage, |
649 base::Unretained(this))); | 649 base::Unretained(this))); |
650 decoder_->SetShaderCacheCallback( | 650 decoder_->SetShaderCacheCallback( |
651 base::Bind(&GpuCommandBufferStub::SendCachedShader, | 651 base::Bind(&GpuCommandBufferStub::SendCachedShader, |
652 base::Unretained(this))); | 652 base::Unretained(this))); |
653 decoder_->SetWaitSyncPointCallback( | 653 decoder_->SetWaitSyncPointCallback( |
654 base::Bind(&GpuCommandBufferStub::OnWaitSyncPoint, | 654 base::Bind(&GpuCommandBufferStub::OnWaitSyncPoint, |
655 base::Unretained(this))); | 655 base::Unretained(this))); |
656 decoder_->SetFenceSyncReleaseCallback(base::Bind( | |
657 &GpuCommandBufferStub::OnFenceSyncRelease, base::Unretained(this))); | |
658 decoder_->SetWaitFenceSyncCallback(base::Bind( | |
659 &GpuCommandBufferStub::OnWaitFenceSync, base::Unretained(this))); | |
656 | 660 |
657 command_buffer_->SetPutOffsetChangeCallback( | 661 command_buffer_->SetPutOffsetChangeCallback( |
658 base::Bind(&GpuCommandBufferStub::PutChanged, base::Unretained(this))); | 662 base::Bind(&GpuCommandBufferStub::PutChanged, base::Unretained(this))); |
659 command_buffer_->SetGetBufferChangeCallback( | 663 command_buffer_->SetGetBufferChangeCallback( |
660 base::Bind(&gpu::GpuScheduler::SetGetBuffer, | 664 base::Bind(&gpu::GpuScheduler::SetGetBuffer, |
661 base::Unretained(scheduler_.get()))); | 665 base::Unretained(scheduler_.get()))); |
662 command_buffer_->SetParseErrorCallback( | 666 command_buffer_->SetParseErrorCallback( |
663 base::Bind(&GpuCommandBufferStub::OnParseError, base::Unretained(this))); | 667 base::Bind(&GpuCommandBufferStub::OnParseError, base::Unretained(this))); |
664 scheduler_->SetSchedulingChangedCallback(base::Bind( | 668 scheduler_->SetSchedulingChangedCallback(base::Bind( |
665 &GpuCommandBufferStub::OnSchedulingChanged, base::Unretained(this))); | 669 &GpuCommandBufferStub::OnSchedulingChanged, base::Unretained(this))); |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
935 if (retire) | 939 if (retire) |
936 OnRetireSyncPoint(sync_point); | 940 OnRetireSyncPoint(sync_point); |
937 } | 941 } |
938 | 942 |
939 void GpuCommandBufferStub::OnRetireSyncPoint(uint32 sync_point) { | 943 void GpuCommandBufferStub::OnRetireSyncPoint(uint32 sync_point) { |
940 DCHECK(!sync_points_.empty() && sync_points_.front() == sync_point); | 944 DCHECK(!sync_points_.empty() && sync_points_.front() == sync_point); |
941 sync_points_.pop_front(); | 945 sync_points_.pop_front(); |
942 | 946 |
943 gpu::gles2::MailboxManager* mailbox_manager = | 947 gpu::gles2::MailboxManager* mailbox_manager = |
944 context_group_->mailbox_manager(); | 948 context_group_->mailbox_manager(); |
945 if (mailbox_manager->UsesSync() && MakeCurrent()) | 949 if (mailbox_manager->UsesSync() && MakeCurrent()) { |
946 mailbox_manager->PushTextureUpdates(sync_point); | 950 // Old sync points are global and do not have a command buffer ID, |
951 // We can simply use the global sync point number as the release count with | |
952 // 0 for the command buffer ID (under normal circumstances 0 is invalid so | |
953 // will not be used) until the old sync points are replaced. | |
954 gpu::gles2::SyncToken sync_token = { | |
955 gpu::CommandBufferNamespace::GPU_IO, | |
956 0, | |
957 sync_point | |
958 }; | |
959 mailbox_manager->PushTextureUpdates(sync_token); | |
960 } | |
947 | 961 |
948 GpuChannelManager* manager = channel_->gpu_channel_manager(); | 962 GpuChannelManager* manager = channel_->gpu_channel_manager(); |
949 manager->sync_point_manager()->RetireSyncPoint(sync_point); | 963 manager->sync_point_manager()->RetireSyncPoint(sync_point); |
950 } | 964 } |
951 | 965 |
952 bool GpuCommandBufferStub::OnWaitSyncPoint(uint32 sync_point) { | 966 bool GpuCommandBufferStub::OnWaitSyncPoint(uint32 sync_point) { |
953 DCHECK(!waiting_for_sync_point_); | 967 DCHECK(!waiting_for_sync_point_); |
954 DCHECK(scheduler_->scheduled()); | 968 DCHECK(scheduler_->scheduled()); |
955 if (!sync_point) | 969 if (!sync_point) |
956 return true; | 970 return true; |
957 GpuChannelManager* manager = channel_->gpu_channel_manager(); | 971 GpuChannelManager* manager = channel_->gpu_channel_manager(); |
958 if (manager->sync_point_manager()->IsSyncPointRetired(sync_point)) { | 972 if (manager->sync_point_manager()->IsSyncPointRetired(sync_point)) { |
959 PullTextureUpdates(sync_point); | 973 // Old sync points are global and do not have a command buffer ID, |
974 // We can simply use the global sync point number as the release count with | |
975 // 0 for the command buffer ID (under normal circumstances 0 is invalid so | |
976 // will not be used) until the old sync points are replaced. | |
977 PullTextureUpdates(gpu::CommandBufferNamespace::GPU_IO, 0, sync_point); | |
960 return true; | 978 return true; |
961 } | 979 } |
962 | 980 |
963 TRACE_EVENT_ASYNC_BEGIN1("gpu", "WaitSyncPoint", this, "GpuCommandBufferStub", | 981 TRACE_EVENT_ASYNC_BEGIN1("gpu", "WaitSyncPoint", this, "GpuCommandBufferStub", |
964 this); | 982 this); |
965 | 983 |
966 scheduler_->SetScheduled(false); | 984 scheduler_->SetScheduled(false); |
967 waiting_for_sync_point_ = true; | 985 waiting_for_sync_point_ = true; |
968 manager->sync_point_manager()->AddSyncPointCallback( | 986 manager->sync_point_manager()->AddSyncPointCallback( |
969 sync_point, | 987 sync_point, |
970 base::Bind(&RunOnThread, task_runner_, | 988 base::Bind(&RunOnThread, task_runner_, |
971 base::Bind(&GpuCommandBufferStub::OnWaitSyncPointCompleted, | 989 base::Bind(&GpuCommandBufferStub::OnWaitSyncPointCompleted, |
972 this->AsWeakPtr(), sync_point))); | 990 this->AsWeakPtr(), sync_point))); |
973 return !waiting_for_sync_point_; | 991 return !waiting_for_sync_point_; |
974 } | 992 } |
975 | 993 |
976 void GpuCommandBufferStub::OnWaitSyncPointCompleted(uint32 sync_point) { | 994 void GpuCommandBufferStub::OnWaitSyncPointCompleted(uint32 sync_point) { |
piman
2015/09/30 22:50:23
nit: At this point, this is equivalent to OnWaitFe
David Yen
2015/09/30 23:55:18
These functions are about to be deleted so it's pr
| |
977 DCHECK(waiting_for_sync_point_); | 995 DCHECK(waiting_for_sync_point_); |
978 DCHECK(!scheduler_->scheduled()); | 996 DCHECK(!scheduler_->scheduled()); |
979 TRACE_EVENT_ASYNC_END1("gpu", "WaitSyncPoint", this, "GpuCommandBufferStub", | 997 TRACE_EVENT_ASYNC_END1("gpu", "WaitSyncPoint", this, "GpuCommandBufferStub", |
980 this); | 998 this); |
981 PullTextureUpdates(sync_point); | 999 // Old sync points are global and do not have a command buffer ID, |
1000 // We can simply use the global sync point number as the release count with | |
1001 // 0 for the command buffer ID (under normal circumstances 0 is invalid so | |
1002 // will not be used) until the old sync points are replaced. | |
1003 PullTextureUpdates(gpu::CommandBufferNamespace::GPU_IO, 0, sync_point); | |
982 waiting_for_sync_point_ = false; | 1004 waiting_for_sync_point_ = false; |
983 scheduler_->SetScheduled(true); | 1005 scheduler_->SetScheduled(true); |
984 } | 1006 } |
985 | 1007 |
986 void GpuCommandBufferStub::PullTextureUpdates(uint32 sync_point) { | 1008 void GpuCommandBufferStub::PullTextureUpdates( |
1009 gpu::CommandBufferNamespace namespace_id, | |
1010 uint64_t command_buffer_id, | |
1011 uint32_t release) { | |
987 gpu::gles2::MailboxManager* mailbox_manager = | 1012 gpu::gles2::MailboxManager* mailbox_manager = |
988 context_group_->mailbox_manager(); | 1013 context_group_->mailbox_manager(); |
989 if (mailbox_manager->UsesSync() && MakeCurrent()) | 1014 if (mailbox_manager->UsesSync() && MakeCurrent()) { |
990 mailbox_manager->PullTextureUpdates(sync_point); | 1015 gpu::gles2::SyncToken sync_token = { |
1016 namespace_id, | |
1017 command_buffer_id, | |
1018 release | |
1019 }; | |
1020 mailbox_manager->PullTextureUpdates(sync_token); | |
1021 } | |
991 } | 1022 } |
992 | 1023 |
993 void GpuCommandBufferStub::OnSignalSyncPoint(uint32 sync_point, uint32 id) { | 1024 void GpuCommandBufferStub::OnSignalSyncPoint(uint32 sync_point, uint32 id) { |
994 GpuChannelManager* manager = channel_->gpu_channel_manager(); | 1025 GpuChannelManager* manager = channel_->gpu_channel_manager(); |
995 manager->sync_point_manager()->AddSyncPointCallback( | 1026 manager->sync_point_manager()->AddSyncPointCallback( |
996 sync_point, | 1027 sync_point, |
997 base::Bind(&RunOnThread, task_runner_, | 1028 base::Bind(&RunOnThread, task_runner_, |
998 base::Bind(&GpuCommandBufferStub::OnSignalSyncPointAck, | 1029 base::Bind(&GpuCommandBufferStub::OnSignalSyncPointAck, |
999 this->AsWeakPtr(), id))); | 1030 this->AsWeakPtr(), id))); |
1000 } | 1031 } |
(...skipping 14 matching lines...) Expand all Loading... | |
1015 this->AsWeakPtr(), | 1046 this->AsWeakPtr(), |
1016 id)); | 1047 id)); |
1017 return; | 1048 return; |
1018 } | 1049 } |
1019 } | 1050 } |
1020 } | 1051 } |
1021 // Something went wrong, run callback immediately. | 1052 // Something went wrong, run callback immediately. |
1022 OnSignalSyncPointAck(id); | 1053 OnSignalSyncPointAck(id); |
1023 } | 1054 } |
1024 | 1055 |
1056 void GpuCommandBufferStub::OnFenceSyncRelease(uint64_t release) { | |
1057 if (!sync_point_client_->client_state()->IsFenceSyncReleased(release)) { | |
piman
2015/09/30 22:50:23
It's worth DLOG(ERROR) if this is false, because i
David Yen
2015/09/30 23:55:18
Done.
| |
1058 gpu::gles2::MailboxManager* mailbox_manager = | |
1059 context_group_->mailbox_manager(); | |
1060 if (mailbox_manager->UsesSync() && MakeCurrent()) { | |
1061 gpu::gles2::SyncToken sync_token = { | |
1062 gpu::CommandBufferNamespace::GPU_IO, | |
1063 command_buffer_id_, | |
1064 release | |
1065 }; | |
1066 mailbox_manager->PushTextureUpdates(sync_token); | |
1067 } | |
1068 | |
1069 sync_point_client_->ReleaseFenceSync(release); | |
1070 } | |
1071 } | |
1072 | |
1073 bool GpuCommandBufferStub::OnWaitFenceSync( | |
1074 gpu::CommandBufferNamespace namespace_id, | |
1075 uint64_t command_buffer_id, | |
1076 uint64_t release) { | |
1077 DCHECK(!waiting_for_sync_point_); | |
1078 DCHECK(scheduler_->scheduled()); | |
1079 | |
1080 GpuChannelManager* manager = channel_->gpu_channel_manager(); | |
1081 DCHECK(manager); | |
1082 | |
1083 gpu::SyncPointManager* sync_point_manager = manager->sync_point_manager(); | |
1084 DCHECK(sync_point_manager); | |
1085 | |
1086 scoped_refptr<gpu::SyncPointClientState> release_state = | |
1087 sync_point_manager->GetSyncPointClientState(namespace_id, | |
1088 command_buffer_id); | |
1089 | |
1090 if (!release_state) | |
1091 return true; | |
1092 | |
1093 if (release_state->IsFenceSyncReleased(release)) { | |
1094 PullTextureUpdates(namespace_id, command_buffer_id, release); | |
1095 return true; | |
1096 } | |
1097 | |
1098 TRACE_EVENT_ASYNC_BEGIN1("gpu", "WaitFenceSync", this, | |
1099 "GpuCommandBufferStub", this); | |
1100 scheduler_->SetScheduled(false); | |
1101 waiting_for_sync_point_ = true; | |
1102 sync_point_client_->WaitNonThreadSafe( | |
1103 release_state, | |
1104 release, | |
1105 task_runner_, | |
1106 base::Bind(&GpuCommandBufferStub::OnWaitFenceSyncCompleted, | |
1107 this->AsWeakPtr(), namespace_id, command_buffer_id, release)); | |
1108 | |
1109 return scheduler_->scheduled(); | |
1110 } | |
1111 | |
1112 void GpuCommandBufferStub::OnWaitFenceSyncCompleted( | |
1113 gpu::CommandBufferNamespace namespace_id, | |
1114 uint64_t command_buffer_id, | |
1115 uint64_t release) { | |
1116 DCHECK(waiting_for_sync_point_); | |
1117 DCHECK(!scheduler_->scheduled()); | |
1118 TRACE_EVENT_ASYNC_END1("gpu", "WaitFenceSync", this, "GpuCommandBufferStub", | |
1119 this); | |
1120 PullTextureUpdates(namespace_id, command_buffer_id, release); | |
piman
2015/09/30 22:50:23
You would want to reset waiting_for_sync_point_ he
David Yen
2015/09/30 23:55:18
Done.
| |
1121 scheduler_->SetScheduled(true); | |
1122 } | |
1025 | 1123 |
1026 void GpuCommandBufferStub::OnSetClientHasMemoryAllocationChangedCallback( | 1124 void GpuCommandBufferStub::OnSetClientHasMemoryAllocationChangedCallback( |
1027 bool has_callback) { | 1125 bool has_callback) { |
1028 TRACE_EVENT0( | 1126 TRACE_EVENT0( |
1029 "gpu", | 1127 "gpu", |
1030 "GpuCommandBufferStub::OnSetClientHasMemoryAllocationChangedCallback"); | 1128 "GpuCommandBufferStub::OnSetClientHasMemoryAllocationChangedCallback"); |
1031 if (has_callback) { | 1129 if (has_callback) { |
1032 if (!memory_manager_client_state_) { | 1130 if (!memory_manager_client_state_) { |
1033 memory_manager_client_state_.reset( | 1131 memory_manager_client_state_.reset( |
1034 GetMemoryManager()->CreateClientState(this, !offscreen_, true)); | 1132 GetMemoryManager()->CreateClientState(this, !offscreen_, true)); |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1218 result)); | 1316 result)); |
1219 } | 1317 } |
1220 | 1318 |
1221 void GpuCommandBufferStub::SendUpdateVSyncParameters(base::TimeTicks timebase, | 1319 void GpuCommandBufferStub::SendUpdateVSyncParameters(base::TimeTicks timebase, |
1222 base::TimeDelta interval) { | 1320 base::TimeDelta interval) { |
1223 Send(new GpuCommandBufferMsg_UpdateVSyncParameters(route_id_, timebase, | 1321 Send(new GpuCommandBufferMsg_UpdateVSyncParameters(route_id_, timebase, |
1224 interval)); | 1322 interval)); |
1225 } | 1323 } |
1226 | 1324 |
1227 } // namespace content | 1325 } // namespace content |
OLD | NEW |