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 { |
43 destroyed_ = true; | 62 base::AutoLock auto_lock(lock_); |
44 while (!order_fence_queue_.empty()) { | 63 DCHECK(!destroyed_); |
45 order_fence_queue_.pop(); | 64 destroyed_ = true; |
| 65 while (!order_fence_queue_.empty()) |
| 66 order_fence_queue_.pop(); |
46 } | 67 } |
| 68 // Call DestroyedSyncPointOrderData outside the lock to prevent deadlock. |
| 69 sync_point_manager_->DestroyedSyncPointOrderData(sequence_id_); |
47 } | 70 } |
48 | 71 |
49 uint32_t SyncPointOrderData::GenerateUnprocessedOrderNumber( | 72 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_); | 73 base::AutoLock auto_lock(lock_); |
53 unprocessed_order_num_ = order_num; | 74 DCHECK(!destroyed_); |
54 return order_num; | 75 unprocessed_order_num_ = sync_point_manager_->GenerateOrderNumber(); |
| 76 return unprocessed_order_num_; |
55 } | 77 } |
56 | 78 |
57 void SyncPointOrderData::BeginProcessingOrderNumber(uint32_t order_num) { | 79 void SyncPointOrderData::BeginProcessingOrderNumber(uint32_t order_num) { |
58 DCHECK(processing_thread_checker_.CalledOnValidThread()); | 80 DCHECK(processing_thread_checker_.CalledOnValidThread()); |
59 DCHECK_GE(order_num, current_order_num_); | 81 DCHECK_GE(order_num, current_order_num_); |
60 // Use thread-safe accessors here because |processed_order_num_| and | 82 // Use thread-safe accessors here because |processed_order_num_| and |
61 // |unprocessed_order_num_| are protected by a lock. | 83 // |unprocessed_order_num_| are protected by a lock. |
62 DCHECK_GT(order_num, processed_order_num()); | 84 DCHECK_GT(order_num, processed_order_num()); |
63 DCHECK_LE(order_num, unprocessed_order_num()); | 85 DCHECK_LE(order_num, unprocessed_order_num()); |
64 current_order_num_ = order_num; | 86 current_order_num_ = order_num; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 break; | 142 break; |
121 } | 143 } |
122 } | 144 } |
123 | 145 |
124 for (OrderFence& order_fence : ensure_releases) { | 146 for (OrderFence& order_fence : ensure_releases) { |
125 order_fence.client_state->EnsureWaitReleased(order_fence.fence_release, | 147 order_fence.client_state->EnsureWaitReleased(order_fence.fence_release, |
126 order_fence.release_callback); | 148 order_fence.release_callback); |
127 } | 149 } |
128 } | 150 } |
129 | 151 |
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( | 152 bool SyncPointOrderData::ValidateReleaseOrderNumber( |
149 scoped_refptr<SyncPointClientState> client_state, | 153 scoped_refptr<SyncPointClientState> client_state, |
150 uint32_t wait_order_num, | 154 uint32_t wait_order_num, |
151 uint64_t fence_release, | 155 uint64_t fence_release, |
152 const base::Closure& release_callback) { | 156 const base::Closure& release_callback) { |
153 base::AutoLock auto_lock(lock_); | 157 base::AutoLock auto_lock(lock_); |
154 if (destroyed_) | 158 if (destroyed_) |
155 return false; | 159 return false; |
156 | 160 |
157 // Release should have a possible unprocessed order number lower than the wait | 161 // Release should have a possible unprocessed order number lower than the wait |
(...skipping 19 matching lines...) Expand all Loading... |
177 uint64_t release, | 181 uint64_t release, |
178 const base::Closure& callback) | 182 const base::Closure& callback) |
179 : release_count(release), callback_closure(callback) {} | 183 : release_count(release), callback_closure(callback) {} |
180 | 184 |
181 SyncPointClientState::ReleaseCallback::ReleaseCallback( | 185 SyncPointClientState::ReleaseCallback::ReleaseCallback( |
182 const ReleaseCallback& other) = default; | 186 const ReleaseCallback& other) = default; |
183 | 187 |
184 SyncPointClientState::ReleaseCallback::~ReleaseCallback() {} | 188 SyncPointClientState::ReleaseCallback::~ReleaseCallback() {} |
185 | 189 |
186 SyncPointClientState::SyncPointClientState( | 190 SyncPointClientState::SyncPointClientState( |
187 scoped_refptr<SyncPointOrderData> order_data) | 191 SyncPointManager* sync_point_manager, |
188 : order_data_(std::move(order_data)) {} | 192 scoped_refptr<SyncPointOrderData> order_data, |
| 193 CommandBufferNamespace namespace_id, |
| 194 CommandBufferId command_buffer_id) |
| 195 : sync_point_manager_(sync_point_manager), |
| 196 order_data_(std::move(order_data)), |
| 197 namespace_id_(namespace_id), |
| 198 command_buffer_id_(command_buffer_id) {} |
189 | 199 |
190 SyncPointClientState::~SyncPointClientState() {} | 200 SyncPointClientState::~SyncPointClientState() { |
| 201 DCHECK_EQ(UINT64_MAX, fence_sync_release_); |
| 202 } |
| 203 |
| 204 void SyncPointClientState::Destroy() { |
| 205 // Release all fences on destruction. |
| 206 ReleaseFenceSyncHelper(UINT64_MAX); |
| 207 DCHECK(sync_point_manager_); // not destroyed |
| 208 sync_point_manager_->DestroyedSyncPointClientState(namespace_id_, |
| 209 command_buffer_id_); |
| 210 sync_point_manager_ = nullptr; |
| 211 } |
| 212 |
| 213 bool SyncPointClientState::Wait(const SyncToken& sync_token, |
| 214 const base::Closure& callback) { |
| 215 DCHECK(sync_point_manager_); // not destroyed |
| 216 // Validate that this Wait call is between BeginProcessingOrderNumber() and |
| 217 // FinishProcessingOrderNumber(), or else we may deadlock. |
| 218 DCHECK(order_data_->IsProcessingOrderNumber()); |
| 219 if (sync_token.namespace_id() == namespace_id_ && |
| 220 sync_token.command_buffer_id() == command_buffer_id_) { |
| 221 return false; |
| 222 } |
| 223 uint32_t wait_order_number = order_data_->current_order_num(); |
| 224 return sync_point_manager_->Wait(sync_token, wait_order_number, callback); |
| 225 } |
| 226 |
| 227 bool SyncPointClientState::WaitNonThreadSafe( |
| 228 const SyncToken& sync_token, |
| 229 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 230 const base::Closure& callback) { |
| 231 return Wait(sync_token, base::Bind(&RunOnThread, task_runner, callback)); |
| 232 } |
191 | 233 |
192 bool SyncPointClientState::IsFenceSyncReleased(uint64_t release) { | 234 bool SyncPointClientState::IsFenceSyncReleased(uint64_t release) { |
193 base::AutoLock lock(fence_sync_lock_); | 235 base::AutoLock lock(fence_sync_lock_); |
194 return release <= fence_sync_release_; | 236 return release <= fence_sync_release_; |
195 } | 237 } |
196 | 238 |
197 bool SyncPointClientState::WaitForRelease(uint64_t release, | 239 bool SyncPointClientState::WaitForRelease(uint64_t release, |
198 uint32_t wait_order_num, | 240 uint32_t wait_order_num, |
199 const base::Closure& callback) { | 241 const base::Closure& callback) { |
200 // Lock must be held the whole time while we validate otherwise it could be | 242 // Lock must be held the whole time while we validate otherwise it could be |
201 // released while we are checking. | 243 // released while we are checking. |
202 { | 244 { |
203 base::AutoLock auto_lock(fence_sync_lock_); | 245 base::AutoLock auto_lock(fence_sync_lock_); |
204 if (release > fence_sync_release_ && | 246 if (release > fence_sync_release_ && |
205 order_data_->ValidateReleaseOrderNumber(this, wait_order_num, release, | 247 order_data_->ValidateReleaseOrderNumber(this, wait_order_num, release, |
206 callback)) { | 248 callback)) { |
207 // Add the callback which will be called upon release. | 249 // Add the callback which will be called upon release. |
208 release_callback_queue_.push(ReleaseCallback(release, callback)); | 250 release_callback_queue_.push(ReleaseCallback(release, callback)); |
209 return true; | 251 return true; |
210 } | 252 } |
211 } | 253 } |
212 // Already released, do not run the callback. | 254 // Already released, do not run the callback. |
213 return false; | 255 return false; |
214 } | 256 } |
215 | 257 |
216 void SyncPointClientState::ReleaseFenceSync(uint64_t release) { | 258 void SyncPointClientState::ReleaseFenceSync(uint64_t release) { |
| 259 // Validate that this Release call is between BeginProcessingOrderNumber() and |
| 260 // FinishProcessingOrderNumber(), or else we may deadlock. |
| 261 DCHECK(order_data_->IsProcessingOrderNumber()); |
| 262 ReleaseFenceSyncHelper(release); |
| 263 } |
| 264 |
| 265 void SyncPointClientState::ReleaseFenceSyncHelper(uint64_t release) { |
217 // Call callbacks without the lock to avoid possible deadlocks. | 266 // Call callbacks without the lock to avoid possible deadlocks. |
218 std::vector<base::Closure> callback_list; | 267 std::vector<base::Closure> callback_list; |
219 { | 268 { |
220 base::AutoLock auto_lock(fence_sync_lock_); | 269 base::AutoLock auto_lock(fence_sync_lock_); |
221 | 270 |
222 DLOG_IF(ERROR, release <= fence_sync_release_) | 271 DLOG_IF(ERROR, release <= fence_sync_release_) |
223 << "Client submitted fence releases out of order."; | 272 << "Client submitted fence releases out of order."; |
224 fence_sync_release_ = release; | 273 fence_sync_release_ = release; |
225 | 274 |
226 while (!release_callback_queue_.empty() && | 275 while (!release_callback_queue_.empty() && |
227 release_callback_queue_.top().release_count <= release) { | 276 release_callback_queue_.top().release_count <= release) { |
228 callback_list.push_back(release_callback_queue_.top().callback_closure); | 277 callback_list.push_back(release_callback_queue_.top().callback_closure); |
229 release_callback_queue_.pop(); | 278 release_callback_queue_.pop(); |
230 } | 279 } |
231 } | 280 } |
232 | 281 |
233 for (const base::Closure& closure : callback_list) { | 282 for (const base::Closure& closure : callback_list) |
234 closure.Run(); | 283 closure.Run(); |
235 } | |
236 } | 284 } |
237 | 285 |
238 void SyncPointClientState::EnsureWaitReleased(uint64_t release, | 286 void SyncPointClientState::EnsureWaitReleased(uint64_t release, |
239 const base::Closure& callback) { | 287 const base::Closure& callback) { |
240 // Call callbacks without the lock to avoid possible deadlocks. | 288 // Call callbacks without the lock to avoid possible deadlocks. |
241 bool call_callback = false; | 289 bool call_callback = false; |
242 { | 290 { |
243 base::AutoLock auto_lock(fence_sync_lock_); | 291 base::AutoLock auto_lock(fence_sync_lock_); |
244 if (release <= fence_sync_release_) | 292 if (release <= fence_sync_release_) |
245 return; | 293 return; |
(...skipping 20 matching lines...) Expand all Loading... |
266 release_callback_queue_.push(popped_callback); | 314 release_callback_queue_.push(popped_callback); |
267 } | 315 } |
268 } | 316 } |
269 | 317 |
270 if (call_callback) { | 318 if (call_callback) { |
271 // This effectively releases the wait without releasing the fence. | 319 // This effectively releases the wait without releasing the fence. |
272 callback.Run(); | 320 callback.Run(); |
273 } | 321 } |
274 } | 322 } |
275 | 323 |
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() { | 324 SyncPointManager::SyncPointManager() { |
324 global_order_num_.GetNext(); | 325 order_num_generator_.GetNext(); |
325 } | 326 } |
326 | 327 |
327 SyncPointManager::~SyncPointManager() { | 328 SyncPointManager::~SyncPointManager() { |
| 329 DCHECK(order_data_map_.empty()); |
328 for (const ClientStateMap& client_state_map : client_state_maps_) | 330 for (const ClientStateMap& client_state_map : client_state_maps_) |
329 DCHECK(client_state_map.empty()); | 331 DCHECK(client_state_map.empty()); |
330 } | 332 } |
331 | 333 |
| 334 scoped_refptr<SyncPointOrderData> SyncPointManager::CreateSyncPointOrderData() { |
| 335 base::AutoLock auto_lock(lock_); |
| 336 SequenceId sequence_id = SequenceId::FromUnsafeValue(next_sequence_id_++); |
| 337 scoped_refptr<SyncPointOrderData> order_data = |
| 338 new SyncPointOrderData(this, sequence_id); |
| 339 DCHECK(!order_data_map_.count(sequence_id)); |
| 340 order_data_map_.insert(std::make_pair(sequence_id, order_data)); |
| 341 return order_data; |
| 342 } |
| 343 |
| 344 void SyncPointManager::DestroyedSyncPointOrderData(SequenceId sequence_id) { |
| 345 base::AutoLock auto_lock(lock_); |
| 346 DCHECK(order_data_map_.count(sequence_id)); |
| 347 order_data_map_.erase(sequence_id); |
| 348 } |
| 349 |
| 350 scoped_refptr<SyncPointClientState> |
| 351 SyncPointManager::CreateSyncPointClientState( |
| 352 CommandBufferNamespace namespace_id, |
| 353 CommandBufferId command_buffer_id, |
| 354 SequenceId sequence_id) { |
| 355 scoped_refptr<SyncPointOrderData> order_data = |
| 356 GetSyncPointOrderData(sequence_id); |
| 357 |
| 358 scoped_refptr<SyncPointClientState> client_state = new SyncPointClientState( |
| 359 this, order_data, namespace_id, command_buffer_id); |
| 360 |
| 361 { |
| 362 base::AutoLock auto_lock(lock_); |
| 363 DCHECK_GE(namespace_id, 0); |
| 364 DCHECK_LT(static_cast<size_t>(namespace_id), arraysize(client_state_maps_)); |
| 365 DCHECK(!client_state_maps_[namespace_id].count(command_buffer_id)); |
| 366 client_state_maps_[namespace_id].insert( |
| 367 std::make_pair(command_buffer_id, client_state)); |
| 368 } |
| 369 |
| 370 return client_state; |
| 371 } |
| 372 |
| 373 void SyncPointManager::DestroyedSyncPointClientState( |
| 374 CommandBufferNamespace namespace_id, |
| 375 CommandBufferId command_buffer_id) { |
| 376 base::AutoLock auto_lock(lock_); |
| 377 DCHECK_GE(namespace_id, 0); |
| 378 DCHECK_LT(static_cast<size_t>(namespace_id), arraysize(client_state_maps_)); |
| 379 DCHECK(client_state_maps_[namespace_id].count(command_buffer_id)); |
| 380 client_state_maps_[namespace_id].erase(command_buffer_id); |
| 381 } |
| 382 |
332 bool SyncPointManager::IsSyncTokenReleased(const SyncToken& sync_token) { | 383 bool SyncPointManager::IsSyncTokenReleased(const SyncToken& sync_token) { |
333 scoped_refptr<SyncPointClientState> release_state = GetSyncPointClientState( | 384 scoped_refptr<SyncPointClientState> release_state = GetSyncPointClientState( |
334 sync_token.namespace_id(), sync_token.command_buffer_id()); | 385 sync_token.namespace_id(), sync_token.command_buffer_id()); |
335 if (release_state) | 386 if (release_state) |
336 return release_state->IsFenceSyncReleased(sync_token.release_count()); | 387 return release_state->IsFenceSyncReleased(sync_token.release_count()); |
337 return true; | 388 return true; |
338 } | 389 } |
339 | 390 |
| 391 SequenceId SyncPointManager::GetSyncTokenReleaseSequenceId( |
| 392 const SyncToken& sync_token) { |
| 393 scoped_refptr<SyncPointClientState> client_state = GetSyncPointClientState( |
| 394 sync_token.namespace_id(), sync_token.command_buffer_id()); |
| 395 if (client_state) |
| 396 return client_state->sequence_id(); |
| 397 return SequenceId(); |
| 398 } |
| 399 |
| 400 uint32_t SyncPointManager::GetProcessedOrderNum() const { |
| 401 base::AutoLock auto_lock(lock_); |
| 402 uint32_t processed_order_num = 0; |
| 403 for (const auto& kv : order_data_map_) { |
| 404 processed_order_num = |
| 405 std::max(processed_order_num, kv.second->processed_order_num()); |
| 406 } |
| 407 return processed_order_num; |
| 408 } |
| 409 |
| 410 uint32_t SyncPointManager::GetUnprocessedOrderNum() const { |
| 411 base::AutoLock auto_lock(lock_); |
| 412 uint32_t unprocessed_order_num = 0; |
| 413 for (const auto& kv : order_data_map_) { |
| 414 unprocessed_order_num = |
| 415 std::max(unprocessed_order_num, kv.second->unprocessed_order_num()); |
| 416 } |
| 417 return unprocessed_order_num; |
| 418 } |
| 419 |
340 bool SyncPointManager::Wait(const SyncToken& sync_token, | 420 bool SyncPointManager::Wait(const SyncToken& sync_token, |
341 uint32_t wait_order_num, | 421 uint32_t wait_order_num, |
342 const base::Closure& callback) { | 422 const base::Closure& callback) { |
343 scoped_refptr<SyncPointClientState> release_state = GetSyncPointClientState( | 423 scoped_refptr<SyncPointClientState> release_state = GetSyncPointClientState( |
344 sync_token.namespace_id(), sync_token.command_buffer_id()); | 424 sync_token.namespace_id(), sync_token.command_buffer_id()); |
345 if (release_state && | 425 if (release_state && |
346 release_state->WaitForRelease(sync_token.release_count(), wait_order_num, | 426 release_state->WaitForRelease(sync_token.release_count(), wait_order_num, |
347 callback)) { | 427 callback)) { |
348 return true; | 428 return true; |
349 } | 429 } |
(...skipping 19 matching lines...) Expand all Loading... |
369 } | 449 } |
370 | 450 |
371 bool SyncPointManager::WaitOutOfOrderNonThreadSafe( | 451 bool SyncPointManager::WaitOutOfOrderNonThreadSafe( |
372 const SyncToken& trusted_sync_token, | 452 const SyncToken& trusted_sync_token, |
373 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 453 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
374 const base::Closure& callback) { | 454 const base::Closure& callback) { |
375 return WaitOutOfOrder(trusted_sync_token, | 455 return WaitOutOfOrder(trusted_sync_token, |
376 base::Bind(&RunOnThread, task_runner, callback)); | 456 base::Bind(&RunOnThread, task_runner, callback)); |
377 } | 457 } |
378 | 458 |
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() { | 459 uint32_t SyncPointManager::GenerateOrderNumber() { |
404 return global_order_num_.GetNext(); | 460 return order_num_generator_.GetNext(); |
405 } | 461 } |
406 | 462 |
407 scoped_refptr<SyncPointClientState> SyncPointManager::GetSyncPointClientState( | 463 scoped_refptr<SyncPointClientState> SyncPointManager::GetSyncPointClientState( |
408 CommandBufferNamespace namespace_id, | 464 CommandBufferNamespace namespace_id, |
409 CommandBufferId command_buffer_id) { | 465 CommandBufferId command_buffer_id) { |
410 if (namespace_id >= 0) { | 466 if (namespace_id >= 0) { |
411 DCHECK_LT(static_cast<size_t>(namespace_id), arraysize(client_state_maps_)); | 467 DCHECK_LT(static_cast<size_t>(namespace_id), arraysize(client_state_maps_)); |
412 base::AutoLock auto_lock(client_state_maps_lock_); | 468 base::AutoLock auto_lock(lock_); |
413 ClientStateMap& client_state_map = client_state_maps_[namespace_id]; | 469 ClientStateMap& client_state_map = client_state_maps_[namespace_id]; |
414 auto it = client_state_map.find(command_buffer_id); | 470 auto it = client_state_map.find(command_buffer_id); |
415 if (it != client_state_map.end()) | 471 if (it != client_state_map.end()) |
416 return it->second; | 472 return it->second; |
417 } | 473 } |
418 return nullptr; | 474 return nullptr; |
419 } | 475 } |
420 | 476 |
| 477 scoped_refptr<SyncPointOrderData> SyncPointManager::GetSyncPointOrderData( |
| 478 SequenceId sequence_id) { |
| 479 base::AutoLock auto_lock(lock_); |
| 480 auto it = order_data_map_.find(sequence_id); |
| 481 if (it != order_data_map_.end()) |
| 482 return it->second; |
| 483 return nullptr; |
| 484 } |
| 485 |
421 } // namespace gpu | 486 } // namespace gpu |
OLD | NEW |