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 "gpu/command_buffer/service/sync_point_manager.h" | 5 #include "gpu/command_buffer/service/sync_point_manager.h" |
6 | 6 |
7 #include <limits.h> | 7 #include <limits.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/location.h" | 12 #include "base/location.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/memory/ptr_util.h" | |
14 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
15 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
16 | 17 |
17 namespace gpu { | 18 namespace gpu { |
18 | 19 |
19 namespace { | 20 namespace { |
20 | 21 |
21 void RunOnThread(scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 22 void RunOnThread(scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
22 const base::Closure& callback) { | 23 const base::Closure& callback) { |
23 if (task_runner->BelongsToCurrentThread()) { | 24 if (task_runner->BelongsToCurrentThread()) { |
24 callback.Run(); | 25 callback.Run(); |
25 } else { | 26 } else { |
26 task_runner->PostTask(FROM_HERE, callback); | 27 task_runner->PostTask(FROM_HERE, callback); |
27 } | 28 } |
28 } | 29 } |
29 | 30 |
30 } // namespace | 31 } // namespace |
31 | 32 |
32 scoped_refptr<SyncPointOrderData> SyncPointOrderData::Create() { | 33 SyncPointOrderData::OrderFence::OrderFence( |
33 return new SyncPointOrderData; | 34 uint32_t order, |
35 uint64_t release, | |
36 const base::Closure& callback, | |
37 scoped_refptr<SyncPointClientState> state) | |
38 : order_num(order), | |
39 fence_release(release), | |
40 release_callback(callback), | |
41 client_state(std::move(state)) {} | |
42 | |
43 SyncPointOrderData::OrderFence::OrderFence(const OrderFence& other) = default; | |
44 | |
45 SyncPointOrderData::OrderFence::~OrderFence() {} | |
46 | |
47 SyncPointOrderData::SyncPointOrderData(SyncPointManager* sync_point_manager, | |
48 SequenceId sequence_id) | |
49 : sync_point_manager_(sync_point_manager), sequence_id_(sequence_id) {} | |
50 | |
51 SyncPointOrderData::~SyncPointOrderData() { | |
52 DCHECK(destroyed_); | |
34 } | 53 } |
35 | 54 |
36 void SyncPointOrderData::Destroy() { | 55 void SyncPointOrderData::Destroy() { |
37 // Because of circular references between the SyncPointOrderData and | 56 // Because of circular references between the SyncPointOrderData and |
38 // SyncPointClientState, we must remove the references on destroy. Releasing | 57 // SyncPointClientState, we must remove the references on destroy. Releasing |
39 // the fence syncs in the order fence queue would be redundant at this point | 58 // the fence syncs in the order fence queue would be redundant at this point |
40 // because they are assumed to be released on the destruction of the | 59 // because they are assumed to be released on the destruction of the |
41 // SyncPointClient. | 60 // SyncPointClientState. |
42 base::AutoLock auto_lock(lock_); | 61 base::AutoLock auto_lock(lock_); |
43 destroyed_ = true; | 62 destroyed_ = true; |
44 while (!order_fence_queue_.empty()) { | 63 while (!order_fence_queue_.empty()) { |
45 order_fence_queue_.pop(); | 64 order_fence_queue_.pop(); |
46 } | 65 } |
66 sync_point_manager_->DestroyedSyncPointOrderData(sequence_id_); | |
47 } | 67 } |
48 | 68 |
49 uint32_t SyncPointOrderData::GenerateUnprocessedOrderNumber( | 69 uint32_t SyncPointOrderData::GenerateUnprocessedOrderNumber() { |
50 SyncPointManager* sync_point_manager) { | |
51 const uint32_t order_num = sync_point_manager->GenerateOrderNumber(); | |
52 base::AutoLock auto_lock(lock_); | 70 base::AutoLock auto_lock(lock_); |
53 unprocessed_order_num_ = order_num; | 71 DCHECK(!destroyed_); |
54 return order_num; | 72 unprocessed_order_num_ = sync_point_manager_->GenerateOrderNumber(); |
73 return unprocessed_order_num_; | |
55 } | 74 } |
56 | 75 |
57 void SyncPointOrderData::BeginProcessingOrderNumber(uint32_t order_num) { | 76 void SyncPointOrderData::BeginProcessingOrderNumber(uint32_t order_num) { |
58 DCHECK(processing_thread_checker_.CalledOnValidThread()); | 77 DCHECK(processing_thread_checker_.CalledOnValidThread()); |
59 DCHECK_GE(order_num, current_order_num_); | 78 DCHECK_GE(order_num, current_order_num_); |
60 // Use thread-safe accessors here because |processed_order_num_| and | 79 // Use thread-safe accessors here because |processed_order_num_| and |
61 // |unprocessed_order_num_| are protected by a lock. | 80 // |unprocessed_order_num_| are protected by a lock. |
62 DCHECK_GT(order_num, processed_order_num()); | 81 DCHECK_GT(order_num, processed_order_num()); |
63 DCHECK_LE(order_num, unprocessed_order_num()); | 82 DCHECK_LE(order_num, unprocessed_order_num()); |
64 current_order_num_ = order_num; | 83 current_order_num_ = order_num; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
120 break; | 139 break; |
121 } | 140 } |
122 } | 141 } |
123 | 142 |
124 for (OrderFence& order_fence : ensure_releases) { | 143 for (OrderFence& order_fence : ensure_releases) { |
125 order_fence.client_state->EnsureWaitReleased(order_fence.fence_release, | 144 order_fence.client_state->EnsureWaitReleased(order_fence.fence_release, |
126 order_fence.release_callback); | 145 order_fence.release_callback); |
127 } | 146 } |
128 } | 147 } |
129 | 148 |
130 SyncPointOrderData::OrderFence::OrderFence( | |
131 uint32_t order, | |
132 uint64_t release, | |
133 const base::Closure& callback, | |
134 scoped_refptr<SyncPointClientState> state) | |
135 : order_num(order), | |
136 fence_release(release), | |
137 release_callback(callback), | |
138 client_state(std::move(state)) {} | |
139 | |
140 SyncPointOrderData::OrderFence::OrderFence(const OrderFence& other) = default; | |
141 | |
142 SyncPointOrderData::OrderFence::~OrderFence() {} | |
143 | |
144 SyncPointOrderData::SyncPointOrderData() {} | |
145 | |
146 SyncPointOrderData::~SyncPointOrderData() {} | |
147 | |
148 bool SyncPointOrderData::ValidateReleaseOrderNumber( | 149 bool SyncPointOrderData::ValidateReleaseOrderNumber( |
149 scoped_refptr<SyncPointClientState> client_state, | 150 scoped_refptr<SyncPointClientState> client_state, |
150 uint32_t wait_order_num, | 151 uint32_t wait_order_num, |
151 uint64_t fence_release, | 152 uint64_t fence_release, |
152 const base::Closure& release_callback) { | 153 const base::Closure& release_callback) { |
153 base::AutoLock auto_lock(lock_); | 154 base::AutoLock auto_lock(lock_); |
154 if (destroyed_) | 155 if (destroyed_) |
155 return false; | 156 return false; |
156 | 157 |
157 // Release should have a possible unprocessed order number lower than the wait | 158 // Release should have a possible unprocessed order number lower than the wait |
(...skipping 19 matching lines...) Expand all Loading... | |
177 uint64_t release, | 178 uint64_t release, |
178 const base::Closure& callback) | 179 const base::Closure& callback) |
179 : release_count(release), callback_closure(callback) {} | 180 : release_count(release), callback_closure(callback) {} |
180 | 181 |
181 SyncPointClientState::ReleaseCallback::ReleaseCallback( | 182 SyncPointClientState::ReleaseCallback::ReleaseCallback( |
182 const ReleaseCallback& other) = default; | 183 const ReleaseCallback& other) = default; |
183 | 184 |
184 SyncPointClientState::ReleaseCallback::~ReleaseCallback() {} | 185 SyncPointClientState::ReleaseCallback::~ReleaseCallback() {} |
185 | 186 |
186 SyncPointClientState::SyncPointClientState( | 187 SyncPointClientState::SyncPointClientState( |
187 scoped_refptr<SyncPointOrderData> order_data) | 188 SyncPointManager* sync_point_manager, |
188 : order_data_(std::move(order_data)) {} | 189 scoped_refptr<SyncPointOrderData> order_data, |
190 CommandBufferNamespace namespace_id, | |
191 CommandBufferId command_buffer_id) | |
192 : sync_point_manager_(sync_point_manager), | |
193 order_data_(std::move(order_data)), | |
194 namespace_id_(namespace_id), | |
195 command_buffer_id_(command_buffer_id) {} | |
189 | 196 |
190 SyncPointClientState::~SyncPointClientState() {} | 197 SyncPointClientState::~SyncPointClientState() { |
198 DCHECK_EQ(UINT64_MAX, fence_sync_release_); | |
199 } | |
200 | |
201 void SyncPointClientState::Destroy() { | |
202 // Release all fences on destruction. | |
203 ReleaseFenceSyncHelper(UINT64_MAX); | |
204 sync_point_manager_->DestroyedSyncPointClientState(namespace_id_, | |
205 command_buffer_id_); | |
piman
2017/03/17 19:12:37
nit: let's reset sync_point_manager_ here, and DCH
sunnyps
2017/03/17 21:48:23
Done.
| |
206 } | |
207 | |
208 bool SyncPointClientState::Wait(const SyncToken& sync_token, | |
209 const base::Closure& callback) { | |
210 // Validate that this Wait call is between BeginProcessingOrderNumber() and | |
211 // FinishProcessingOrderNumber(), or else we may deadlock. | |
212 DCHECK(order_data_->IsProcessingOrderNumber()); | |
213 if (sync_token.namespace_id() == namespace_id_ && | |
214 sync_token.command_buffer_id() == command_buffer_id_) { | |
215 return false; | |
216 } | |
217 uint32_t wait_order_number = order_data_->current_order_num(); | |
218 return sync_point_manager_->Wait(sync_token, wait_order_number, callback); | |
219 } | |
220 | |
221 bool SyncPointClientState::WaitNonThreadSafe( | |
222 const SyncToken& sync_token, | |
223 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | |
224 const base::Closure& callback) { | |
225 return Wait(sync_token, base::Bind(&RunOnThread, task_runner, callback)); | |
226 } | |
191 | 227 |
192 bool SyncPointClientState::IsFenceSyncReleased(uint64_t release) { | 228 bool SyncPointClientState::IsFenceSyncReleased(uint64_t release) { |
193 base::AutoLock lock(fence_sync_lock_); | 229 base::AutoLock lock(fence_sync_lock_); |
194 return release <= fence_sync_release_; | 230 return release <= fence_sync_release_; |
195 } | 231 } |
196 | 232 |
197 bool SyncPointClientState::WaitForRelease(uint64_t release, | 233 bool SyncPointClientState::WaitForRelease(uint64_t release, |
198 uint32_t wait_order_num, | 234 uint32_t wait_order_num, |
199 const base::Closure& callback) { | 235 const base::Closure& callback) { |
200 // Lock must be held the whole time while we validate otherwise it could be | 236 // Lock must be held the whole time while we validate otherwise it could be |
201 // released while we are checking. | 237 // released while we are checking. |
202 { | 238 { |
203 base::AutoLock auto_lock(fence_sync_lock_); | 239 base::AutoLock auto_lock(fence_sync_lock_); |
204 if (release > fence_sync_release_ && | 240 if (release > fence_sync_release_ && |
205 order_data_->ValidateReleaseOrderNumber(this, wait_order_num, release, | 241 order_data_->ValidateReleaseOrderNumber(this, wait_order_num, release, |
206 callback)) { | 242 callback)) { |
207 // Add the callback which will be called upon release. | 243 // Add the callback which will be called upon release. |
208 release_callback_queue_.push(ReleaseCallback(release, callback)); | 244 release_callback_queue_.push(ReleaseCallback(release, callback)); |
209 return true; | 245 return true; |
210 } | 246 } |
211 } | 247 } |
212 // Already released, do not run the callback. | 248 // Already released, do not run the callback. |
213 return false; | 249 return false; |
214 } | 250 } |
215 | 251 |
216 void SyncPointClientState::ReleaseFenceSync(uint64_t release) { | 252 void SyncPointClientState::ReleaseFenceSync(uint64_t release) { |
253 // Validate that this Release call is between BeginProcessingOrderNumber() and | |
254 // FinishProcessingOrderNumber(), or else we may deadlock. | |
255 DCHECK(order_data_->IsProcessingOrderNumber()); | |
256 ReleaseFenceSyncHelper(release); | |
257 } | |
258 | |
259 void SyncPointClientState::ReleaseFenceSyncHelper(uint64_t release) { | |
217 // Call callbacks without the lock to avoid possible deadlocks. | 260 // Call callbacks without the lock to avoid possible deadlocks. |
218 std::vector<base::Closure> callback_list; | 261 std::vector<base::Closure> callback_list; |
219 { | 262 { |
220 base::AutoLock auto_lock(fence_sync_lock_); | 263 base::AutoLock auto_lock(fence_sync_lock_); |
221 | 264 |
222 DLOG_IF(ERROR, release <= fence_sync_release_) | 265 DLOG_IF(ERROR, release <= fence_sync_release_) |
223 << "Client submitted fence releases out of order."; | 266 << "Client submitted fence releases out of order."; |
224 fence_sync_release_ = release; | 267 fence_sync_release_ = release; |
225 | 268 |
226 while (!release_callback_queue_.empty() && | 269 while (!release_callback_queue_.empty() && |
227 release_callback_queue_.top().release_count <= release) { | 270 release_callback_queue_.top().release_count <= release) { |
228 callback_list.push_back(release_callback_queue_.top().callback_closure); | 271 callback_list.push_back(release_callback_queue_.top().callback_closure); |
229 release_callback_queue_.pop(); | 272 release_callback_queue_.pop(); |
230 } | 273 } |
231 } | 274 } |
232 | 275 |
233 for (const base::Closure& closure : callback_list) { | 276 for (const base::Closure& closure : callback_list) |
234 closure.Run(); | 277 closure.Run(); |
235 } | |
236 } | 278 } |
237 | 279 |
238 void SyncPointClientState::EnsureWaitReleased(uint64_t release, | 280 void SyncPointClientState::EnsureWaitReleased(uint64_t release, |
239 const base::Closure& callback) { | 281 const base::Closure& callback) { |
240 // Call callbacks without the lock to avoid possible deadlocks. | 282 // Call callbacks without the lock to avoid possible deadlocks. |
241 bool call_callback = false; | 283 bool call_callback = false; |
242 { | 284 { |
243 base::AutoLock auto_lock(fence_sync_lock_); | 285 base::AutoLock auto_lock(fence_sync_lock_); |
244 if (release <= fence_sync_release_) | 286 if (release <= fence_sync_release_) |
245 return; | 287 return; |
(...skipping 20 matching lines...) Expand all Loading... | |
266 release_callback_queue_.push(popped_callback); | 308 release_callback_queue_.push(popped_callback); |
267 } | 309 } |
268 } | 310 } |
269 | 311 |
270 if (call_callback) { | 312 if (call_callback) { |
271 // This effectively releases the wait without releasing the fence. | 313 // This effectively releases the wait without releasing the fence. |
272 callback.Run(); | 314 callback.Run(); |
273 } | 315 } |
274 } | 316 } |
275 | 317 |
276 SyncPointClient::SyncPointClient(SyncPointManager* sync_point_manager, | |
277 scoped_refptr<SyncPointOrderData> order_data, | |
278 CommandBufferNamespace namespace_id, | |
279 CommandBufferId command_buffer_id) | |
280 : sync_point_manager_(sync_point_manager), | |
281 order_data_(std::move(order_data)), | |
282 client_state_(new SyncPointClientState(order_data_)), | |
283 namespace_id_(namespace_id), | |
284 command_buffer_id_(command_buffer_id) { | |
285 sync_point_manager_->RegisterSyncPointClient(client_state_, namespace_id, | |
286 command_buffer_id); | |
287 } | |
288 | |
289 SyncPointClient::~SyncPointClient() { | |
290 // Release all fences on destruction. | |
291 client_state_->ReleaseFenceSync(UINT64_MAX); | |
292 sync_point_manager_->DeregisterSyncPointClient(namespace_id_, | |
293 command_buffer_id_); | |
294 } | |
295 | |
296 bool SyncPointClient::Wait(const SyncToken& sync_token, | |
297 const base::Closure& callback) { | |
298 // Validate that this Wait call is between BeginProcessingOrderNumber() and | |
299 // FinishProcessingOrderNumber(), or else we may deadlock. | |
300 DCHECK(order_data_->IsProcessingOrderNumber()); | |
301 if (sync_token.namespace_id() == namespace_id_ && | |
302 sync_token.command_buffer_id() == command_buffer_id_) { | |
303 return false; | |
304 } | |
305 uint32_t wait_order_number = order_data_->current_order_num(); | |
306 return sync_point_manager_->Wait(sync_token, wait_order_number, callback); | |
307 } | |
308 | |
309 bool SyncPointClient::WaitNonThreadSafe( | |
310 const SyncToken& sync_token, | |
311 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | |
312 const base::Closure& callback) { | |
313 return Wait(sync_token, base::Bind(&RunOnThread, task_runner, callback)); | |
314 } | |
315 | |
316 void SyncPointClient::ReleaseFenceSync(uint64_t release) { | |
317 // Validate that this Release call is between BeginProcessingOrderNumber() and | |
318 // FinishProcessingOrderNumber(), or else we may deadlock. | |
319 DCHECK(order_data_->IsProcessingOrderNumber()); | |
320 client_state_->ReleaseFenceSync(release); | |
321 } | |
322 | |
323 SyncPointManager::SyncPointManager() { | 318 SyncPointManager::SyncPointManager() { |
324 global_order_num_.GetNext(); | 319 order_num_generator_.GetNext(); |
325 } | 320 } |
326 | 321 |
327 SyncPointManager::~SyncPointManager() { | 322 SyncPointManager::~SyncPointManager() { |
328 for (const ClientStateMap& client_state_map : client_state_maps_) | 323 for (const ClientStateMap& client_state_map : client_state_maps_) |
329 DCHECK(client_state_map.empty()); | 324 DCHECK(client_state_map.empty()); |
piman
2017/03/17 19:12:37
nit: let's also DCHECK that the order_data_map_ is
sunnyps
2017/03/17 21:48:23
Done.
| |
330 } | 325 } |
331 | 326 |
327 scoped_refptr<SyncPointOrderData> SyncPointManager::CreateSyncPointOrderData() { | |
328 base::AutoLock auto_lock(lock_); | |
329 SequenceId sequence_id = SequenceId::FromUnsafeValue(next_sequence_id_++); | |
330 scoped_refptr<SyncPointOrderData> order_data = | |
331 new SyncPointOrderData(this, sequence_id); | |
332 DCHECK(!order_data_map_.count(sequence_id)); | |
333 order_data_map_.insert(std::make_pair(sequence_id, order_data)); | |
334 return order_data; | |
335 } | |
336 | |
337 void SyncPointManager::DestroyedSyncPointOrderData(SequenceId sequence_id) { | |
338 base::AutoLock auto_lock(lock_); | |
339 DCHECK(order_data_map_.count(sequence_id)); | |
340 order_data_map_.erase(sequence_id); | |
341 } | |
342 | |
343 scoped_refptr<SyncPointClientState> | |
344 SyncPointManager::CreateSyncPointClientState( | |
345 CommandBufferNamespace namespace_id, | |
346 CommandBufferId command_buffer_id, | |
347 SequenceId sequence_id) { | |
348 scoped_refptr<SyncPointOrderData> order_data = | |
349 GetSyncPointOrderData(sequence_id); | |
350 | |
351 scoped_refptr<SyncPointClientState> client_state = new SyncPointClientState( | |
352 this, order_data, namespace_id, command_buffer_id); | |
353 | |
354 { | |
355 base::AutoLock auto_lock(lock_); | |
356 DCHECK_GE(namespace_id, 0); | |
357 DCHECK_LT(static_cast<size_t>(namespace_id), arraysize(client_state_maps_)); | |
358 DCHECK(!client_state_maps_[namespace_id].count(command_buffer_id)); | |
359 client_state_maps_[namespace_id].insert( | |
360 std::make_pair(command_buffer_id, client_state)); | |
361 } | |
362 | |
363 return client_state; | |
364 } | |
365 | |
366 void SyncPointManager::DestroyedSyncPointClientState( | |
367 CommandBufferNamespace namespace_id, | |
368 CommandBufferId command_buffer_id) { | |
369 base::AutoLock auto_lock(lock_); | |
370 DCHECK_GE(namespace_id, 0); | |
371 DCHECK_LT(static_cast<size_t>(namespace_id), arraysize(client_state_maps_)); | |
372 DCHECK(client_state_maps_[namespace_id].count(command_buffer_id)); | |
373 client_state_maps_[namespace_id].erase(command_buffer_id); | |
374 } | |
375 | |
332 bool SyncPointManager::IsSyncTokenReleased(const SyncToken& sync_token) { | 376 bool SyncPointManager::IsSyncTokenReleased(const SyncToken& sync_token) { |
333 scoped_refptr<SyncPointClientState> release_state = GetSyncPointClientState( | 377 scoped_refptr<SyncPointClientState> release_state = GetSyncPointClientState( |
334 sync_token.namespace_id(), sync_token.command_buffer_id()); | 378 sync_token.namespace_id(), sync_token.command_buffer_id()); |
335 if (release_state) | 379 if (release_state) |
336 return release_state->IsFenceSyncReleased(sync_token.release_count()); | 380 return release_state->IsFenceSyncReleased(sync_token.release_count()); |
337 return true; | 381 return true; |
338 } | 382 } |
339 | 383 |
384 SequenceId SyncPointManager::GetSyncTokenReleaseSequenceId( | |
385 const SyncToken& sync_token) { | |
386 scoped_refptr<SyncPointClientState> client_state = GetSyncPointClientState( | |
387 sync_token.namespace_id(), sync_token.command_buffer_id()); | |
388 if (client_state) | |
389 return client_state->sequence_id(); | |
390 return SequenceId(); | |
391 } | |
392 | |
393 uint32_t SyncPointManager::GetProcessedOrderNum() const { | |
394 base::AutoLock auto_lock(lock_); | |
395 uint32_t processed_order_num = 0; | |
396 for (const auto& kv : order_data_map_) { | |
397 processed_order_num = | |
398 std::max(processed_order_num, kv.second->processed_order_num()); | |
399 } | |
400 return processed_order_num; | |
401 } | |
402 | |
403 uint32_t SyncPointManager::GetUnprocessedOrderNum() const { | |
404 base::AutoLock auto_lock(lock_); | |
405 uint32_t unprocessed_order_num = 0; | |
406 for (const auto& kv : order_data_map_) { | |
407 unprocessed_order_num = | |
408 std::max(unprocessed_order_num, kv.second->unprocessed_order_num()); | |
409 } | |
410 return unprocessed_order_num; | |
411 } | |
412 | |
340 bool SyncPointManager::Wait(const SyncToken& sync_token, | 413 bool SyncPointManager::Wait(const SyncToken& sync_token, |
341 uint32_t wait_order_num, | 414 uint32_t wait_order_num, |
342 const base::Closure& callback) { | 415 const base::Closure& callback) { |
343 scoped_refptr<SyncPointClientState> release_state = GetSyncPointClientState( | 416 scoped_refptr<SyncPointClientState> release_state = GetSyncPointClientState( |
344 sync_token.namespace_id(), sync_token.command_buffer_id()); | 417 sync_token.namespace_id(), sync_token.command_buffer_id()); |
345 if (release_state && | 418 if (release_state && |
346 release_state->WaitForRelease(sync_token.release_count(), wait_order_num, | 419 release_state->WaitForRelease(sync_token.release_count(), wait_order_num, |
347 callback)) { | 420 callback)) { |
348 return true; | 421 return true; |
349 } | 422 } |
(...skipping 19 matching lines...) Expand all Loading... | |
369 } | 442 } |
370 | 443 |
371 bool SyncPointManager::WaitOutOfOrderNonThreadSafe( | 444 bool SyncPointManager::WaitOutOfOrderNonThreadSafe( |
372 const SyncToken& trusted_sync_token, | 445 const SyncToken& trusted_sync_token, |
373 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 446 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
374 const base::Closure& callback) { | 447 const base::Closure& callback) { |
375 return WaitOutOfOrder(trusted_sync_token, | 448 return WaitOutOfOrder(trusted_sync_token, |
376 base::Bind(&RunOnThread, task_runner, callback)); | 449 base::Bind(&RunOnThread, task_runner, callback)); |
377 } | 450 } |
378 | 451 |
379 void SyncPointManager::RegisterSyncPointClient( | |
380 scoped_refptr<SyncPointClientState> client_state, | |
381 CommandBufferNamespace namespace_id, | |
382 CommandBufferId command_buffer_id) { | |
383 DCHECK_GE(namespace_id, 0); | |
384 DCHECK_LT(static_cast<size_t>(namespace_id), arraysize(client_state_maps_)); | |
385 | |
386 base::AutoLock auto_lock(client_state_maps_lock_); | |
387 DCHECK(!client_state_maps_[namespace_id].count(command_buffer_id)); | |
388 client_state_maps_[namespace_id].insert( | |
389 std::make_pair(command_buffer_id, std::move(client_state))); | |
390 } | |
391 | |
392 void SyncPointManager::DeregisterSyncPointClient( | |
393 CommandBufferNamespace namespace_id, | |
394 CommandBufferId command_buffer_id) { | |
395 DCHECK_GE(namespace_id, 0); | |
396 DCHECK_LT(static_cast<size_t>(namespace_id), arraysize(client_state_maps_)); | |
397 | |
398 base::AutoLock auto_lock(client_state_maps_lock_); | |
399 DCHECK(client_state_maps_[namespace_id].count(command_buffer_id)); | |
400 client_state_maps_[namespace_id].erase(command_buffer_id); | |
401 } | |
402 | |
403 uint32_t SyncPointManager::GenerateOrderNumber() { | 452 uint32_t SyncPointManager::GenerateOrderNumber() { |
404 return global_order_num_.GetNext(); | 453 return order_num_generator_.GetNext(); |
405 } | 454 } |
406 | 455 |
407 scoped_refptr<SyncPointClientState> SyncPointManager::GetSyncPointClientState( | 456 scoped_refptr<SyncPointClientState> SyncPointManager::GetSyncPointClientState( |
408 CommandBufferNamespace namespace_id, | 457 CommandBufferNamespace namespace_id, |
409 CommandBufferId command_buffer_id) { | 458 CommandBufferId command_buffer_id) { |
410 if (namespace_id >= 0) { | 459 if (namespace_id >= 0) { |
411 DCHECK_LT(static_cast<size_t>(namespace_id), arraysize(client_state_maps_)); | 460 DCHECK_LT(static_cast<size_t>(namespace_id), arraysize(client_state_maps_)); |
412 base::AutoLock auto_lock(client_state_maps_lock_); | 461 base::AutoLock auto_lock(lock_); |
413 ClientStateMap& client_state_map = client_state_maps_[namespace_id]; | 462 ClientStateMap& client_state_map = client_state_maps_[namespace_id]; |
414 auto it = client_state_map.find(command_buffer_id); | 463 auto it = client_state_map.find(command_buffer_id); |
415 if (it != client_state_map.end()) | 464 if (it != client_state_map.end()) |
416 return it->second; | 465 return it->second; |
417 } | 466 } |
418 return nullptr; | 467 return nullptr; |
419 } | 468 } |
420 | 469 |
470 scoped_refptr<SyncPointOrderData> SyncPointManager::GetSyncPointOrderData( | |
471 SequenceId sequence_id) { | |
472 base::AutoLock auto_lock(lock_); | |
473 auto it = order_data_map_.find(sequence_id); | |
474 if (it != order_data_map_.end()) | |
475 return it->second; | |
476 return nullptr; | |
477 } | |
478 | |
421 } // namespace gpu | 479 } // namespace gpu |
OLD | NEW |