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

Side by Side Diff: gpu/command_buffer/client/share_group.cc

Issue 162023002: Reduce internal Flush() in GL resource glGen/Delete APIs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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
OLDNEW
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 <vector>
6
5 #include "gpu/command_buffer/client/share_group.h" 7 #include "gpu/command_buffer/client/share_group.h"
6 8
7 #include "base/logging.h" 9 #include "base/logging.h"
8 #include "base/synchronization/lock.h" 10 #include "base/synchronization/lock.h"
9 #include "gpu/command_buffer/client/gles2_implementation.h" 11 #include "gpu/command_buffer/client/gles2_implementation.h"
10 #include "gpu/command_buffer/client/program_info_manager.h" 12 #include "gpu/command_buffer/client/program_info_manager.h"
11 #include "gpu/command_buffer/common/id_allocator.h" 13 #include "gpu/command_buffer/common/id_allocator.h"
12 14
13 namespace gpu { 15 namespace gpu {
14 namespace gles2 { 16 namespace gles2 {
(...skipping 14 matching lines...) Expand all
29 base::AutoLock auto_lock(lock_); 31 base::AutoLock auto_lock(lock_);
30 if (id_offset == 0) { 32 if (id_offset == 0) {
31 for (GLsizei ii = 0; ii < n; ++ii) { 33 for (GLsizei ii = 0; ii < n; ++ii) {
32 ids[ii] = id_allocator_.AllocateID(); 34 ids[ii] = id_allocator_.AllocateID();
33 } 35 }
34 } else { 36 } else {
35 for (GLsizei ii = 0; ii < n; ++ii) { 37 for (GLsizei ii = 0; ii < n; ++ii) {
36 ids[ii] = id_allocator_.AllocateIDAtOrAbove(id_offset); 38 ids[ii] = id_allocator_.AllocateIDAtOrAbove(id_offset);
37 id_offset = ids[ii] + 1; 39 id_offset = ids[ii] + 1;
38 } 40 }
39 } 41 }
piman 2014/02/12 23:52:34 We should restore the Flush() here that was remove
vmiura 2014/02/13 00:20:17 OK, but not here since we have to flush after the
piman 2014/02/13 00:48:53 Oh, yeah. Or be more symmetrical with FreeIds and
40 } 42 }
41 43
42 // Overridden from IdHandlerInterface. 44 // Overridden from IdHandlerInterface.
43 virtual bool FreeIds( 45 virtual bool FreeIds(
44 GLES2Implementation* gl_impl, 46 GLES2Implementation* gl_impl,
45 GLsizei n, const GLuint* ids, DeleteFn delete_fn) OVERRIDE { 47 GLsizei n, const GLuint* ids, DeleteFn delete_fn) OVERRIDE {
46 base::AutoLock auto_lock(lock_); 48 base::AutoLock auto_lock(lock_);
47 for (GLsizei ii = 0; ii < n; ++ii) { 49 for (GLsizei ii = 0; ii < n; ++ii) {
48 id_allocator_.FreeID(ids[ii]); 50 id_allocator_.FreeID(ids[ii]);
49 } 51 }
50 (gl_impl->*delete_fn)(n, ids); 52 (gl_impl->*delete_fn)(n, ids);
51 // We need to ensure that the delete call is evaluated on the service side 53 // We need to ensure that the delete call is evaluated on the service side
52 // before any other contexts issue commands using these client ids. 54 // before any other contexts issue commands using these client ids.
55 // TODO(vmiura): Can remove this by virtualizing internal ids, however
56 // this code only affects PPAPI for now.
53 gl_impl->helper()->CommandBufferHelper::Flush(); 57 gl_impl->helper()->CommandBufferHelper::Flush();
54 return true; 58 return true;
55 } 59 }
56 60
57 // Overridden from IdHandlerInterface. 61 // Overridden from IdHandlerInterface.
58 virtual bool MarkAsUsedForBind(GLuint id) OVERRIDE { 62 virtual bool MarkAsUsedForBind(GLuint id) OVERRIDE {
59 if (id == 0) 63 if (id == 0)
60 return true; 64 return true;
61 base::AutoLock auto_lock(lock_); 65 base::AutoLock auto_lock(lock_);
62 return id_allocator_.MarkAsUsed(id); 66 return id_allocator_.MarkAsUsed(id);
63 } 67 }
64 68
65 protected: 69 protected:
66 base::Lock lock_; 70 base::Lock lock_;
67 IdAllocator id_allocator_; 71 IdAllocator id_allocator_;
68 }; 72 };
69 73
70 // An id handler that requires Gen before Bind. 74 // An id handler that requires Gen before Bind.
71 class StrictIdHandler : public IdHandler { 75 class StrictIdHandler : public IdHandler {
piman 2014/02/12 23:52:34 nit: at this point, there's little advantage to in
vmiura 2014/02/14 00:11:11 Done.
72 public: 76 public:
73 StrictIdHandler() {} 77 StrictIdHandler() : pending_flush_generation_(0) {}
74 virtual ~StrictIdHandler() {} 78 virtual ~StrictIdHandler() {}
75 79
80 // Overridden from IdHandlerInterface.
81 virtual void MakeIds(GLES2Implementation* gl_impl,
82 GLuint id_offset,
83 GLsizei n,
84 GLuint* ids) OVERRIDE {
85 base::AutoLock auto_lock(lock_);
86
87 // Collect pending FreeIds from other flush_generation.
88 CollectPendingFreeIds(gl_impl);
89
90 // Allocate Ids.
91 for (GLsizei ii = 0; ii < n; ++ii) {
92 ids[ii] = id_allocator_.AllocateID();
93 }
94 }
95
96 // Overridden from IdHandlerInterface.
97 virtual bool FreeIds(GLES2Implementation* gl_impl,
98 GLsizei n,
99 const GLuint* ids,
100 DeleteFn delete_fn) OVERRIDE {
101 base::AutoLock auto_lock(lock_);
102
103 // Collect pending FreeIds from other flush_generation.
104 CollectPendingFreeIds(gl_impl);
105
106 // Save Ids to free in a later flush_generation.
107 for (GLsizei ii = 0; ii < n; ++ii) {
108 pending_free_ids_.push_back(ids[ii]);
109 }
110
111 (gl_impl->*delete_fn)(n, ids);
112 return true;
113 }
114
76 // Overridden from IdHandler. 115 // Overridden from IdHandler.
77 virtual bool MarkAsUsedForBind(GLuint id) OVERRIDE { 116 virtual bool MarkAsUsedForBind(GLuint id) OVERRIDE {
78 #ifndef NDEBUG 117 #ifndef NDEBUG
79 { 118 {
80 base::AutoLock auto_lock(lock_); 119 base::AutoLock auto_lock(lock_);
81 DCHECK(id == 0 || id_allocator_.InUse(id)); 120 DCHECK(id == 0 || id_allocator_.InUse(id));
piman 2014/02/12 23:52:34 Can we update the DCHECK to take into account the
vmiura 2014/02/14 00:11:11 Done.
82 } 121 }
83 #endif 122 #endif
84 return true; 123 return true;
85 } 124 }
125
126 private:
127 void CollectPendingFreeIds(GLES2Implementation* gl_impl) {
128 uint32 flush_generation = gl_impl->helper()->flush_generation();
129 if (pending_flush_generation_ != flush_generation) {
piman 2014/02/12 23:52:34 gl_impl->helper()->flush_generation() is per-comma
vmiura 2014/02/13 00:20:17 Great point. I think this pending free handling c
vmiura 2014/02/14 00:11:11 Moved these into per-GLES2Implementation data, but
130 pending_flush_generation_ = flush_generation;
131 for (uint32 ii = 0; ii < pending_free_ids_.size(); ++ii) {
132 id_allocator_.FreeID(pending_free_ids_[ii]);
133 }
134 pending_free_ids_.clear();
135 }
136 }
137
138 std::vector<GLuint> pending_free_ids_;
139 uint32 pending_flush_generation_;
86 }; 140 };
87 141
88 // An id handler for ids that are never reused. 142 // An id handler for ids that are never reused.
89 class NonReusedIdHandler : public IdHandlerInterface { 143 class NonReusedIdHandler : public IdHandlerInterface {
90 public: 144 public:
91 NonReusedIdHandler() : last_id_(0) {} 145 NonReusedIdHandler() : last_id_(0) {}
92 virtual ~NonReusedIdHandler() {} 146 virtual ~NonReusedIdHandler() {}
93 147
94 // Overridden from IdHandlerInterface. 148 // Overridden from IdHandlerInterface.
95 virtual void MakeIds( 149 virtual void MakeIds(
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 } 198 }
145 199
146 void ShareGroup::set_program_info_manager(ProgramInfoManager* manager) { 200 void ShareGroup::set_program_info_manager(ProgramInfoManager* manager) {
147 program_info_manager_.reset(manager); 201 program_info_manager_.reset(manager);
148 } 202 }
149 203
150 ShareGroup::~ShareGroup() {} 204 ShareGroup::~ShareGroup() {}
151 205
152 } // namespace gles2 206 } // namespace gles2
153 } // namespace gpu 207 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698