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

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

Issue 1331843005: Implemented new fence syncs which replaces the old sync points. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Some fixes Created 5 years, 3 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/mailbox_manager_sync.h" 5 #include "gpu/command_buffer/service/mailbox_manager_sync.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <queue> 8 #include <queue>
9 9
10 #include "base/memory/linked_ptr.h" 10 #include "base/memory/linked_ptr.h"
11 #include "base/synchronization/lock.h" 11 #include "base/synchronization/lock.h"
12 #include "gpu/command_buffer/service/texture_manager.h" 12 #include "gpu/command_buffer/service/texture_manager.h"
13 #include "ui/gl/gl_fence.h" 13 #include "ui/gl/gl_fence.h"
14 #include "ui/gl/gl_implementation.h" 14 #include "ui/gl/gl_implementation.h"
15 15
16 #if !defined(OS_MACOSX) 16 #if !defined(OS_MACOSX)
17 #include "ui/gl/gl_fence_egl.h" 17 #include "ui/gl/gl_fence_egl.h"
18 #endif 18 #endif
19 19
20 namespace gpu { 20 namespace gpu {
21 namespace gles2 { 21 namespace gles2 {
22 22
23 namespace { 23 namespace {
24 24
25 base::LazyInstance<base::Lock> g_lock = LAZY_INSTANCE_INITIALIZER; 25 base::LazyInstance<base::Lock> g_lock = LAZY_INSTANCE_INITIALIZER;
26 26
27 typedef std::map<uint32, linked_ptr<gfx::GLFence>> SyncPointToFenceMap; 27 typedef std::pair<int, std::pair<uint32, uint32>> SyncToken;
piman 2015/09/10 23:55:32 Can you use SyncToken from gles2_cmd_format.h inst
28 base::LazyInstance<SyncPointToFenceMap> g_sync_point_to_fence = 28 typedef std::map<SyncToken, linked_ptr<gfx::GLFence>> SyncTokenToFenceMap;
29 base::LazyInstance<SyncTokenToFenceMap> g_sync_point_to_fence =
29 LAZY_INSTANCE_INITIALIZER; 30 LAZY_INSTANCE_INITIALIZER;
30 #if !defined(OS_MACOSX) 31 #if !defined(OS_MACOSX)
31 base::LazyInstance<std::queue<SyncPointToFenceMap::iterator>> g_sync_points = 32 base::LazyInstance<std::queue<SyncTokenToFenceMap::iterator>> g_sync_points =
32 LAZY_INSTANCE_INITIALIZER; 33 LAZY_INSTANCE_INITIALIZER;
33 #endif 34 #endif
34 35
35 void CreateFenceLocked(uint32 sync_point) { 36 void CreateFenceLocked(int channel_client_id, uint32 route_id, uint32 release) {
36 g_lock.Get().AssertAcquired(); 37 g_lock.Get().AssertAcquired();
37 if (gfx::GetGLImplementation() == gfx::kGLImplementationMockGL) 38 if (gfx::GetGLImplementation() == gfx::kGLImplementationMockGL)
38 return; 39 return;
39 40
40 #if !defined(OS_MACOSX) 41 #if !defined(OS_MACOSX)
41 std::queue<SyncPointToFenceMap::iterator>& sync_points = g_sync_points.Get(); 42 std::queue<SyncTokenToFenceMap::iterator>& sync_points = g_sync_points.Get();
42 SyncPointToFenceMap& sync_point_to_fence = g_sync_point_to_fence.Get(); 43 SyncTokenToFenceMap& sync_point_to_fence = g_sync_point_to_fence.Get();
43 if (sync_point) { 44 if (release) {
44 while (!sync_points.empty() && 45 while (!sync_points.empty() &&
45 sync_points.front()->second->HasCompleted()) { 46 sync_points.front()->second->HasCompleted()) {
46 sync_point_to_fence.erase(sync_points.front()); 47 sync_point_to_fence.erase(sync_points.front());
47 sync_points.pop(); 48 sync_points.pop();
48 } 49 }
49 // Need to use EGL fences since we are likely not in a single share group. 50 // Need to use EGL fences since we are likely not in a single share group.
50 linked_ptr<gfx::GLFence> fence(make_linked_ptr(new gfx::GLFenceEGL)); 51 linked_ptr<gfx::GLFence> fence(make_linked_ptr(new gfx::GLFenceEGL));
51 if (fence.get()) { 52 if (fence.get()) {
52 std::pair<SyncPointToFenceMap::iterator, bool> result = 53 const SyncToken sync_token =
53 sync_point_to_fence.insert(std::make_pair(sync_point, fence)); 54 std::make_pair(channel_client_id, std::make_pair(route_id, release));
55 std::pair<SyncTokenToFenceMap::iterator, bool> result =
56 sync_point_to_fence.insert(std::make_pair(sync_token, fence));
54 DCHECK(result.second); 57 DCHECK(result.second);
55 sync_points.push(result.first); 58 sync_points.push(result.first);
56 } 59 }
57 DCHECK(sync_points.size() == sync_point_to_fence.size()); 60 DCHECK(sync_points.size() == sync_point_to_fence.size());
58 } 61 }
59 #endif 62 #endif
60 } 63 }
61 64
62 void AcquireFenceLocked(uint32 sync_point) { 65 void AcquireFenceLocked(int channel_client_id,
66 uint32 route_id,
67 uint32 release) {
68 #if !defined(OS_MACOSX)
63 g_lock.Get().AssertAcquired(); 69 g_lock.Get().AssertAcquired();
64 SyncPointToFenceMap::iterator fence_it = 70 const SyncToken sync_token =
65 g_sync_point_to_fence.Get().find(sync_point); 71 std::make_pair(channel_client_id, std::make_pair(route_id, release));
72
73 SyncTokenToFenceMap::iterator fence_it =
74 g_sync_point_to_fence.Get().find(sync_token);
66 if (fence_it != g_sync_point_to_fence.Get().end()) { 75 if (fence_it != g_sync_point_to_fence.Get().end()) {
67 fence_it->second->ServerWait(); 76 fence_it->second->ServerWait();
68 } 77 }
78 #endif
69 } 79 }
70 80
71 static const unsigned kNewTextureVersion = 1; 81 static const unsigned kNewTextureVersion = 1;
72 82
73 } // anonymous namespace 83 } // anonymous namespace
74 84
75 base::LazyInstance<MailboxManagerSync::TextureGroup::MailboxToGroupMap> 85 base::LazyInstance<MailboxManagerSync::TextureGroup::MailboxToGroupMap>
76 MailboxManagerSync::TextureGroup::mailbox_to_group_ = 86 MailboxManagerSync::TextureGroup::mailbox_to_group_ =
77 LAZY_INSTANCE_INITIALIZER; 87 LAZY_INSTANCE_INITIALIZER;
78 88
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 DCHECK_IMPLIES(gl_image, image_buffer.get()); 297 DCHECK_IMPLIES(gl_image, image_buffer.get());
288 if (gl_image && !image_buffer->IsClient(gl_image)) { 298 if (gl_image && !image_buffer->IsClient(gl_image)) {
289 LOG(ERROR) << "MailboxSync: Incompatible attachment"; 299 LOG(ERROR) << "MailboxSync: Incompatible attachment";
290 return; 300 return;
291 } 301 }
292 302
293 group->SetDefinition(TextureDefinition(texture, ++group_ref->version, 303 group->SetDefinition(TextureDefinition(texture, ++group_ref->version,
294 gl_image ? image_buffer : NULL)); 304 gl_image ? image_buffer : NULL));
295 } 305 }
296 306
297 void MailboxManagerSync::PushTextureUpdates(uint32 sync_point) { 307 void MailboxManagerSync::PushTextureUpdates(int channel_client_id,
308 uint32 route_id,
309 uint32 release) {
298 base::AutoLock lock(g_lock.Get()); 310 base::AutoLock lock(g_lock.Get());
299 311
300 for (TextureToGroupMap::iterator it = texture_to_group_.begin(); 312 for (TextureToGroupMap::iterator it = texture_to_group_.begin();
301 it != texture_to_group_.end(); it++) { 313 it != texture_to_group_.end(); it++) {
302 UpdateDefinitionLocked(it->first, &it->second); 314 UpdateDefinitionLocked(it->first, &it->second);
303 } 315 }
304 CreateFenceLocked(sync_point); 316 CreateFenceLocked(channel_client_id, route_id, release);
305 } 317 }
306 318
307 void MailboxManagerSync::PullTextureUpdates(uint32 sync_point) { 319 void MailboxManagerSync::PullTextureUpdates(int channel_client_id,
320 uint32 route_id,
321 uint32 release) {
308 using TextureUpdatePair = std::pair<Texture*, TextureDefinition>; 322 using TextureUpdatePair = std::pair<Texture*, TextureDefinition>;
309 std::vector<TextureUpdatePair> needs_update; 323 std::vector<TextureUpdatePair> needs_update;
310 { 324 {
311 base::AutoLock lock(g_lock.Get()); 325 base::AutoLock lock(g_lock.Get());
312 AcquireFenceLocked(sync_point); 326 AcquireFenceLocked(channel_client_id, route_id, release);
313 327
314 for (TextureToGroupMap::iterator it = texture_to_group_.begin(); 328 for (TextureToGroupMap::iterator it = texture_to_group_.begin();
315 it != texture_to_group_.end(); it++) { 329 it != texture_to_group_.end(); it++) {
316 const TextureDefinition& definition = it->second.group->GetDefinition(); 330 const TextureDefinition& definition = it->second.group->GetDefinition();
317 Texture* texture = it->first; 331 Texture* texture = it->first;
318 unsigned& texture_version = it->second.version; 332 unsigned& texture_version = it->second.version;
319 if (texture_version == definition.version() || 333 if (texture_version == definition.version() ||
320 definition.IsOlderThan(texture_version)) 334 definition.IsOlderThan(texture_version))
321 continue; 335 continue;
322 texture_version = definition.version(); 336 texture_version = definition.version();
323 needs_update.push_back(TextureUpdatePair(texture, definition)); 337 needs_update.push_back(TextureUpdatePair(texture, definition));
324 } 338 }
325 } 339 }
326 340
327 if (!needs_update.empty()) { 341 if (!needs_update.empty()) {
328 ScopedUpdateTexture scoped_update_texture; 342 ScopedUpdateTexture scoped_update_texture;
329 for (const TextureUpdatePair& pair : needs_update) { 343 for (const TextureUpdatePair& pair : needs_update) {
330 pair.second.UpdateTexture(pair.first); 344 pair.second.UpdateTexture(pair.first);
331 } 345 }
332 } 346 }
333 } 347 }
334 348
335 } // namespace gles2 349 } // namespace gles2
336 } // namespace gpu 350 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698