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

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

Issue 849103002: Share SyncPointManager implementation in in-process cmd buffer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: private Created 5 years, 10 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 | « no previous file | gpu/command_buffer/service/sync_point_manager.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/command_buffer/service/in_process_command_buffer.h" 5 #include "gpu/command_buffer/service/in_process_command_buffer.h"
6 6
7 #include <queue> 7 #include <queue>
8 #include <set> 8 #include <set>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 13 matching lines...) Expand all
24 #include "gpu/command_buffer/service/context_group.h" 24 #include "gpu/command_buffer/service/context_group.h"
25 #include "gpu/command_buffer/service/gl_context_virtual.h" 25 #include "gpu/command_buffer/service/gl_context_virtual.h"
26 #include "gpu/command_buffer/service/gpu_scheduler.h" 26 #include "gpu/command_buffer/service/gpu_scheduler.h"
27 #include "gpu/command_buffer/service/gpu_switches.h" 27 #include "gpu/command_buffer/service/gpu_switches.h"
28 #include "gpu/command_buffer/service/image_factory.h" 28 #include "gpu/command_buffer/service/image_factory.h"
29 #include "gpu/command_buffer/service/image_manager.h" 29 #include "gpu/command_buffer/service/image_manager.h"
30 #include "gpu/command_buffer/service/mailbox_manager_impl.h" 30 #include "gpu/command_buffer/service/mailbox_manager_impl.h"
31 #include "gpu/command_buffer/service/mailbox_manager_sync.h" 31 #include "gpu/command_buffer/service/mailbox_manager_sync.h"
32 #include "gpu/command_buffer/service/memory_tracking.h" 32 #include "gpu/command_buffer/service/memory_tracking.h"
33 #include "gpu/command_buffer/service/query_manager.h" 33 #include "gpu/command_buffer/service/query_manager.h"
34 #include "gpu/command_buffer/service/sync_point_manager.h"
34 #include "gpu/command_buffer/service/transfer_buffer_manager.h" 35 #include "gpu/command_buffer/service/transfer_buffer_manager.h"
35 #include "gpu/command_buffer/service/valuebuffer_manager.h" 36 #include "gpu/command_buffer/service/valuebuffer_manager.h"
36 #include "ui/gfx/geometry/size.h" 37 #include "ui/gfx/geometry/size.h"
37 #include "ui/gl/gl_context.h" 38 #include "ui/gl/gl_context.h"
38 #include "ui/gl/gl_image.h" 39 #include "ui/gl/gl_image.h"
39 #include "ui/gl/gl_share_group.h" 40 #include "ui/gl/gl_share_group.h"
40 41
41 #if defined(OS_ANDROID) 42 #if defined(OS_ANDROID)
42 #include "gpu/command_buffer/service/stream_texture_manager_in_process_android.h " 43 #include "gpu/command_buffer/service/stream_texture_manager_in_process_android.h "
43 #include "ui/gl/android/surface_texture.h" 44 #include "ui/gl/android/surface_texture.h"
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 124
124 class ScopedEvent { 125 class ScopedEvent {
125 public: 126 public:
126 ScopedEvent(base::WaitableEvent* event) : event_(event) {} 127 ScopedEvent(base::WaitableEvent* event) : event_(event) {}
127 ~ScopedEvent() { event_->Signal(); } 128 ~ScopedEvent() { event_->Signal(); }
128 129
129 private: 130 private:
130 base::WaitableEvent* event_; 131 base::WaitableEvent* event_;
131 }; 132 };
132 133
133 class SyncPointManager { 134 class SyncPointManagerWrapper {
134 public: 135 public:
135 SyncPointManager(); 136 SyncPointManagerWrapper();
136 ~SyncPointManager();
137 137
138 uint32 GenerateSyncPoint(); 138 uint32 GenerateSyncPoint();
139 void RetireSyncPoint(uint32 sync_point); 139 void RetireSyncPoint(uint32 sync_point);
140 void AddSyncPointCallback(uint32 sync_point, const base::Closure& callback);
140 141
141 bool IsSyncPointPassed(uint32 sync_point);
142 void WaitSyncPoint(uint32 sync_point); 142 void WaitSyncPoint(uint32 sync_point);
143 143
144 private: 144 private:
145 // This lock protects access to pending_sync_points_ and next_sync_point_ and 145 void SyncPointRetired();
146 // is used with the ConditionVariable to signal when a sync point is retired. 146
147 base::Lock lock_; 147 const scoped_refptr<SyncPointManager> manager_;
148 std::set<uint32> pending_sync_points_; 148 base::Lock retire_lock_;
149 uint32 next_sync_point_; 149 base::ConditionVariable retire_cond_var_;
150 base::ConditionVariable cond_var_; 150
151 DISALLOW_COPY_AND_ASSIGN(SyncPointManagerWrapper);
151 }; 152 };
152 153
153 SyncPointManager::SyncPointManager() : next_sync_point_(1), cond_var_(&lock_) {} 154 SyncPointManagerWrapper::SyncPointManagerWrapper()
154 155 : manager_(new SyncPointManager), retire_cond_var_(&retire_lock_) {
155 SyncPointManager::~SyncPointManager() {
156 DCHECK_EQ(pending_sync_points_.size(), 0U);
157 } 156 }
158 157
159 uint32 SyncPointManager::GenerateSyncPoint() { 158 uint32 SyncPointManagerWrapper::GenerateSyncPoint() {
160 base::AutoLock lock(lock_); 159 uint32 sync_point = manager_->GenerateSyncPoint();
161 uint32 sync_point = next_sync_point_++; 160 manager_->AddSyncPointCallback(
162 DCHECK_EQ(pending_sync_points_.count(sync_point), 0U); 161 sync_point, base::Bind(&SyncPointManagerWrapper::SyncPointRetired,
163 pending_sync_points_.insert(sync_point); 162 base::Unretained(this)));
164 return sync_point; 163 return sync_point;
165 } 164 }
166 165
167 void SyncPointManager::RetireSyncPoint(uint32 sync_point) { 166 void SyncPointManagerWrapper::RetireSyncPoint(uint32 sync_point) {
168 base::AutoLock lock(lock_); 167 manager_->RetireSyncPoint(sync_point);
169 DCHECK(pending_sync_points_.count(sync_point));
170 pending_sync_points_.erase(sync_point);
171 cond_var_.Broadcast();
172 } 168 }
173 169
174 bool SyncPointManager::IsSyncPointPassed(uint32 sync_point) { 170 void SyncPointManagerWrapper::AddSyncPointCallback(
175 base::AutoLock lock(lock_); 171 uint32 sync_point,
176 return pending_sync_points_.count(sync_point) == 0; 172 const base::Closure& callback) {
173 manager_->AddSyncPointCallback(sync_point, callback);
177 } 174 }
178 175
179 void SyncPointManager::WaitSyncPoint(uint32 sync_point) { 176 void SyncPointManagerWrapper::WaitSyncPoint(uint32 sync_point) {
180 base::AutoLock lock(lock_); 177 base::AutoLock lock(retire_lock_);
181 while (pending_sync_points_.count(sync_point)) { 178 while (!manager_->IsSyncPointRetired(sync_point)) {
182 cond_var_.Wait(); 179 retire_cond_var_.Wait();
183 } 180 }
184 } 181 }
185 182
186 base::LazyInstance<SyncPointManager> g_sync_point_manager = 183 void SyncPointManagerWrapper::SyncPointRetired() {
184 base::AutoLock lock(retire_lock_);
185 retire_cond_var_.Broadcast();
186 }
187
188 base::LazyInstance<SyncPointManagerWrapper> g_sync_point_manager =
187 LAZY_INSTANCE_INITIALIZER; 189 LAZY_INSTANCE_INITIALIZER;
188 190
189 base::SharedMemoryHandle ShareToGpuThread( 191 base::SharedMemoryHandle ShareToGpuThread(
190 base::SharedMemoryHandle source_handle) { 192 base::SharedMemoryHandle source_handle) {
191 #if defined(OS_WIN) 193 #if defined(OS_WIN)
192 // Windows needs to explicitly duplicate the handle to current process. 194 // Windows needs to explicitly duplicate the handle to current process.
193 base::SharedMemoryHandle target_handle; 195 base::SharedMemoryHandle target_handle;
194 if (!DuplicateHandle(GetCurrentProcess(), 196 if (!DuplicateHandle(GetCurrentProcess(),
195 source_handle, 197 source_handle,
196 GetCurrentProcess(), 198 GetCurrentProcess(),
(...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after
824 decoder_->GetContextGroup()->mailbox_manager(); 826 decoder_->GetContextGroup()->mailbox_manager();
825 if (mailbox_manager->UsesSync()) { 827 if (mailbox_manager->UsesSync()) {
826 bool make_current_success = false; 828 bool make_current_success = false;
827 { 829 {
828 base::AutoLock lock(command_buffer_lock_); 830 base::AutoLock lock(command_buffer_lock_);
829 make_current_success = MakeCurrent(); 831 make_current_success = MakeCurrent();
830 } 832 }
831 if (make_current_success) 833 if (make_current_success)
832 mailbox_manager->PushTextureUpdates(sync_point); 834 mailbox_manager->PushTextureUpdates(sync_point);
833 } 835 }
836
834 g_sync_point_manager.Get().RetireSyncPoint(sync_point); 837 g_sync_point_manager.Get().RetireSyncPoint(sync_point);
835 } 838 }
836 839
837 void InProcessCommandBuffer::SignalSyncPoint(unsigned sync_point, 840 void InProcessCommandBuffer::SignalSyncPoint(unsigned sync_point,
838 const base::Closure& callback) { 841 const base::Closure& callback) {
839 CheckSequencedThread(); 842 CheckSequencedThread();
840 QueueTask(base::Bind(&InProcessCommandBuffer::SignalSyncPointOnGpuThread, 843 QueueTask(base::Bind(&InProcessCommandBuffer::SignalSyncPointOnGpuThread,
841 base::Unretained(this), 844 base::Unretained(this),
842 sync_point, 845 sync_point,
843 WrapCallback(callback))); 846 WrapCallback(callback)));
844 } 847 }
845 848
846 bool InProcessCommandBuffer::WaitSyncPointOnGpuThread(unsigned sync_point) { 849 bool InProcessCommandBuffer::WaitSyncPointOnGpuThread(unsigned sync_point) {
847 g_sync_point_manager.Get().WaitSyncPoint(sync_point); 850 g_sync_point_manager.Get().WaitSyncPoint(sync_point);
851
848 gles2::MailboxManager* mailbox_manager = 852 gles2::MailboxManager* mailbox_manager =
849 decoder_->GetContextGroup()->mailbox_manager(); 853 decoder_->GetContextGroup()->mailbox_manager();
850 mailbox_manager->PullTextureUpdates(sync_point); 854 mailbox_manager->PullTextureUpdates(sync_point);
851 return true; 855 return true;
852 } 856 }
853 857
854 void InProcessCommandBuffer::SignalSyncPointOnGpuThread( 858 void InProcessCommandBuffer::SignalSyncPointOnGpuThread(
855 unsigned sync_point, 859 unsigned sync_point,
856 const base::Closure& callback) { 860 const base::Closure& callback) {
857 if (g_sync_point_manager.Get().IsSyncPointPassed(sync_point)) { 861 g_sync_point_manager.Get().AddSyncPointCallback(sync_point, callback);
boliu 2015/01/28 00:49:03 Question. The callback is no longer guaranteed to
boliu 2015/01/28 17:48:17 I think it should be posted back to this gpu threa
boliu 2015/01/28 17:53:50 Wait, can the sync point be retired on another gpu
858 callback.Run();
859 } else {
860 service_->ScheduleIdleWork(
861 base::Bind(&InProcessCommandBuffer::SignalSyncPointOnGpuThread,
862 gpu_thread_weak_ptr_,
863 sync_point,
864 callback));
865 }
866 } 862 }
867 863
868 void InProcessCommandBuffer::SignalQuery(unsigned query_id, 864 void InProcessCommandBuffer::SignalQuery(unsigned query_id,
869 const base::Closure& callback) { 865 const base::Closure& callback) {
870 CheckSequencedThread(); 866 CheckSequencedThread();
871 QueueTask(base::Bind(&InProcessCommandBuffer::SignalQueryOnGpuThread, 867 QueueTask(base::Bind(&InProcessCommandBuffer::SignalQueryOnGpuThread,
872 base::Unretained(this), 868 base::Unretained(this),
873 query_id, 869 query_id,
874 WrapCallback(callback))); 870 WrapCallback(callback)));
875 } 871 }
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
957 953
958 #if defined(OS_ANDROID) 954 #if defined(OS_ANDROID)
959 scoped_refptr<gfx::SurfaceTexture> 955 scoped_refptr<gfx::SurfaceTexture>
960 InProcessCommandBuffer::GetSurfaceTexture(uint32 stream_id) { 956 InProcessCommandBuffer::GetSurfaceTexture(uint32 stream_id) {
961 DCHECK(stream_texture_manager_); 957 DCHECK(stream_texture_manager_);
962 return stream_texture_manager_->GetSurfaceTexture(stream_id); 958 return stream_texture_manager_->GetSurfaceTexture(stream_id);
963 } 959 }
964 #endif 960 #endif
965 961
966 } // namespace gpu 962 } // namespace gpu
OLDNEW
« no previous file with comments | « no previous file | gpu/command_buffer/service/sync_point_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698