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

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: test_contexts_[2] -> test_contexts_[kNumTestContexts] 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
« no previous file with comments | « gpu/command_buffer/client/share_group.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 {
15 17
18 ShareGroupContextData::IdHandlerData::IdHandlerData() { flush_generation_ = 0; }
19
16 COMPILE_ASSERT(gpu::kInvalidResource == 0, 20 COMPILE_ASSERT(gpu::kInvalidResource == 0,
17 INVALID_RESOURCE_NOT_0_AS_GL_EXPECTS); 21 INVALID_RESOURCE_NOT_0_AS_GL_EXPECTS);
18 22
19 // The standard id handler. 23 // The standard id handler.
20 class IdHandler : public IdHandlerInterface { 24 class IdHandler : public IdHandlerInterface {
21 public: 25 public:
22 IdHandler() { } 26 IdHandler() { }
23 virtual ~IdHandler() { } 27 virtual ~IdHandler() { }
24 28
25 // Overridden from IdHandlerInterface. 29 // Overridden from IdHandlerInterface.
(...skipping 17 matching lines...) Expand all
43 virtual bool FreeIds( 47 virtual bool FreeIds(
44 GLES2Implementation* gl_impl, 48 GLES2Implementation* gl_impl,
45 GLsizei n, const GLuint* ids, DeleteFn delete_fn) OVERRIDE { 49 GLsizei n, const GLuint* ids, DeleteFn delete_fn) OVERRIDE {
46 base::AutoLock auto_lock(lock_); 50 base::AutoLock auto_lock(lock_);
47 for (GLsizei ii = 0; ii < n; ++ii) { 51 for (GLsizei ii = 0; ii < n; ++ii) {
48 id_allocator_.FreeID(ids[ii]); 52 id_allocator_.FreeID(ids[ii]);
49 } 53 }
50 (gl_impl->*delete_fn)(n, ids); 54 (gl_impl->*delete_fn)(n, ids);
51 // We need to ensure that the delete call is evaluated on the service side 55 // 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. 56 // before any other contexts issue commands using these client ids.
57 // TODO(vmiura): Can remove this by virtualizing internal ids, however
58 // this code only affects PPAPI for now.
53 gl_impl->helper()->CommandBufferHelper::Flush(); 59 gl_impl->helper()->CommandBufferHelper::Flush();
54 return true; 60 return true;
55 } 61 }
56 62
57 // Overridden from IdHandlerInterface. 63 // Overridden from IdHandlerInterface.
58 virtual bool MarkAsUsedForBind(GLuint id) OVERRIDE { 64 virtual bool MarkAsUsedForBind(GLES2Implementation* /* gl_impl */,
65 GLuint id) OVERRIDE {
59 if (id == 0) 66 if (id == 0)
60 return true; 67 return true;
61 base::AutoLock auto_lock(lock_); 68 base::AutoLock auto_lock(lock_);
62 return id_allocator_.MarkAsUsed(id); 69 return id_allocator_.MarkAsUsed(id);
63 } 70 }
64 71
65 protected: 72 virtual void FreeContext(GLES2Implementation* gl_impl) OVERRIDE {}
73
74 private:
66 base::Lock lock_; 75 base::Lock lock_;
67 IdAllocator id_allocator_; 76 IdAllocator id_allocator_;
68 }; 77 };
69 78
70 // An id handler that requires Gen before Bind. 79 // An id handler that requires Gen before Bind.
71 class StrictIdHandler : public IdHandler { 80 class StrictIdHandler : public IdHandlerInterface {
72 public: 81 public:
73 StrictIdHandler() {} 82 StrictIdHandler(int id_namespace) : id_namespace_(id_namespace) {}
piman 2014/02/14 01:56:20 nit: explicit
vmiura 2014/02/14 02:18:12 Done.
74 virtual ~StrictIdHandler() {} 83 virtual ~StrictIdHandler() {}
75 84
76 // Overridden from IdHandler. 85 // Overridden from IdHandler.
77 virtual bool MarkAsUsedForBind(GLuint id) OVERRIDE { 86 virtual void MakeIds(GLES2Implementation* gl_impl,
87 GLuint id_offset,
88 GLsizei n,
89 GLuint* ids) OVERRIDE {
90 base::AutoLock auto_lock(lock_);
91
92 // Collect pending FreeIds from other flush_generation.
93 CollectPendingFreeIds(gl_impl);
94
95 // Allocate Ids.
96 if (id_offset == 0) {
97 for (GLsizei ii = 0; ii < n; ++ii) {
98 ids[ii] = id_allocator_.AllocateID();
99 }
100 } else {
101 for (GLsizei ii = 0; ii < n; ++ii) {
102 ids[ii] = id_allocator_.AllocateIDAtOrAbove(id_offset);
103 id_offset = ids[ii] + 1;
104 }
105 }
106 }
107
108 // Overridden from IdHandler.
109 virtual bool FreeIds(GLES2Implementation* gl_impl,
110 GLsizei n,
111 const GLuint* ids,
112 DeleteFn delete_fn) OVERRIDE {
113 base::AutoLock auto_lock(lock_);
114
115 // Collect pending FreeIds from other flush_generation.
116 CollectPendingFreeIds(gl_impl);
117
118 // Save Ids to free in a later flush_generation.
119 ShareGroupContextData::IdHandlerData* ctxt_data =
120 gl_impl->share_group_context_data()->id_handler_data(id_namespace_);
121 for (GLsizei ii = 0; ii < n; ++ii) {
122 ctxt_data->freed_ids_.push_back(ids[ii]);
123 }
124
125 (gl_impl->*delete_fn)(n, ids);
126 return true;
127 }
128
129 // Overridden from IdHandler.
130 virtual bool MarkAsUsedForBind(GLES2Implementation* gl_impl,
131 GLuint id) OVERRIDE {
78 #ifndef NDEBUG 132 #ifndef NDEBUG
79 { 133 {
80 base::AutoLock auto_lock(lock_); 134 base::AutoLock auto_lock(lock_);
135 ShareGroupContextData::IdHandlerData* ctxt_data =
136 gl_impl->share_group_context_data()->id_handler_data(id_namespace_);
137 for (uint32 ii = 0; ii < ctxt_data->freed_ids_.size(); ++ii) {
138 DCHECK(id == 0 || id != ctxt_data->freed_ids_[ii]);
139 }
81 DCHECK(id == 0 || id_allocator_.InUse(id)); 140 DCHECK(id == 0 || id_allocator_.InUse(id));
82 } 141 }
142 #else
143 (void)gl_impl;
83 #endif 144 #endif
84 return true; 145 return true;
85 } 146 }
147
148 // Overridden from IdHandlerInterface.
149 virtual void FreeContext(GLES2Implementation* gl_impl) OVERRIDE {
150 CollectPendingFreeIds(gl_impl);
151 }
152
153 private:
154 void CollectPendingFreeIds(GLES2Implementation* gl_impl) {
155 uint32 flush_generation = gl_impl->helper()->flush_generation();
156 ShareGroupContextData::IdHandlerData* ctxt_data =
157 gl_impl->share_group_context_data()->id_handler_data(id_namespace_);
158
159 if (ctxt_data->flush_generation_ != flush_generation) {
160 ctxt_data->flush_generation_ = flush_generation;
161 for (uint32 ii = 0; ii < ctxt_data->freed_ids_.size(); ++ii) {
162 id_allocator_.FreeID(ctxt_data->freed_ids_[ii]);
163 }
164 ctxt_data->freed_ids_.clear();
165 }
166 }
167
168 int id_namespace_;
169
170 base::Lock lock_;
171 IdAllocator id_allocator_;
86 }; 172 };
87 173
88 // An id handler for ids that are never reused. 174 // An id handler for ids that are never reused.
89 class NonReusedIdHandler : public IdHandlerInterface { 175 class NonReusedIdHandler : public IdHandlerInterface {
90 public: 176 public:
91 NonReusedIdHandler() : last_id_(0) {} 177 NonReusedIdHandler() : last_id_(0) {}
92 virtual ~NonReusedIdHandler() {} 178 virtual ~NonReusedIdHandler() {}
93 179
94 // Overridden from IdHandlerInterface. 180 // Overridden from IdHandlerInterface.
95 virtual void MakeIds( 181 virtual void MakeIds(
96 GLES2Implementation* /* gl_impl */, 182 GLES2Implementation* /* gl_impl */,
97 GLuint id_offset, GLsizei n, GLuint* ids) OVERRIDE { 183 GLuint id_offset, GLsizei n, GLuint* ids) OVERRIDE {
98 base::AutoLock auto_lock(lock_); 184 base::AutoLock auto_lock(lock_);
99 for (GLsizei ii = 0; ii < n; ++ii) { 185 for (GLsizei ii = 0; ii < n; ++ii) {
100 ids[ii] = ++last_id_ + id_offset; 186 ids[ii] = ++last_id_ + id_offset;
101 } 187 }
102 } 188 }
103 189
104 // Overridden from IdHandlerInterface. 190 // Overridden from IdHandlerInterface.
105 virtual bool FreeIds( 191 virtual bool FreeIds(
106 GLES2Implementation* gl_impl, 192 GLES2Implementation* gl_impl,
107 GLsizei n, const GLuint* ids, DeleteFn delete_fn) OVERRIDE { 193 GLsizei n, const GLuint* ids, DeleteFn delete_fn) OVERRIDE {
108 // Ids are never freed. 194 // Ids are never freed.
109 (gl_impl->*delete_fn)(n, ids); 195 (gl_impl->*delete_fn)(n, ids);
110 return true; 196 return true;
111 } 197 }
112 198
113 // Overridden from IdHandlerInterface. 199 // Overridden from IdHandlerInterface.
114 virtual bool MarkAsUsedForBind(GLuint /* id */) OVERRIDE { 200 virtual bool MarkAsUsedForBind(GLES2Implementation* /* gl_impl */,
201 GLuint /* id */) OVERRIDE {
115 // This is only used for Shaders and Programs which have no bind. 202 // This is only used for Shaders and Programs which have no bind.
116 return false; 203 return false;
117 } 204 }
118 205
206 virtual void FreeContext(GLES2Implementation* gl_impl) OVERRIDE {}
207
119 private: 208 private:
120 base::Lock lock_; 209 base::Lock lock_;
121 GLuint last_id_; 210 GLuint last_id_;
122 }; 211 };
123 212
124 ShareGroup::ShareGroup(bool bind_generates_resource) 213 ShareGroup::ShareGroup(bool bind_generates_resource)
125 : bind_generates_resource_(bind_generates_resource) { 214 : bind_generates_resource_(bind_generates_resource) {
126 if (bind_generates_resource) { 215 if (bind_generates_resource) {
127 for (int i = 0; i < id_namespaces::kNumIdNamespaces; ++i) { 216 for (int i = 0; i < id_namespaces::kNumIdNamespaces; ++i) {
128 if (i == id_namespaces::kProgramsAndShaders) { 217 if (i == id_namespaces::kProgramsAndShaders) {
129 id_handlers_[i].reset(new NonReusedIdHandler()); 218 id_handlers_[i].reset(new NonReusedIdHandler());
130 } else { 219 } else {
131 id_handlers_[i].reset(new IdHandler()); 220 id_handlers_[i].reset(new IdHandler());
132 } 221 }
133 } 222 }
134 } else { 223 } else {
135 for (int i = 0; i < id_namespaces::kNumIdNamespaces; ++i) { 224 for (int i = 0; i < id_namespaces::kNumIdNamespaces; ++i) {
136 if (i == id_namespaces::kProgramsAndShaders) { 225 if (i == id_namespaces::kProgramsAndShaders) {
137 id_handlers_[i].reset(new NonReusedIdHandler()); 226 id_handlers_[i].reset(new NonReusedIdHandler());
138 } else { 227 } else {
139 id_handlers_[i].reset(new StrictIdHandler()); 228 id_handlers_[i].reset(new StrictIdHandler(i));
140 } 229 }
141 } 230 }
142 } 231 }
143 program_info_manager_.reset(ProgramInfoManager::Create(false)); 232 program_info_manager_.reset(ProgramInfoManager::Create(false));
144 } 233 }
145 234
146 void ShareGroup::set_program_info_manager(ProgramInfoManager* manager) { 235 void ShareGroup::set_program_info_manager(ProgramInfoManager* manager) {
147 program_info_manager_.reset(manager); 236 program_info_manager_.reset(manager);
148 } 237 }
149 238
150 ShareGroup::~ShareGroup() {} 239 ShareGroup::~ShareGroup() {}
151 240
152 } // namespace gles2 241 } // namespace gles2
153 } // namespace gpu 242 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/client/share_group.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698