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

Unified Diff: gpu/command_buffer/client/share_group.cc

Issue 154263011: Reduce cost of glBind* on contexts without bind_generates_resource. (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 side-by-side diff with in-line comments
Download patch
Index: gpu/command_buffer/client/share_group.cc
diff --git a/gpu/command_buffer/client/share_group.cc b/gpu/command_buffer/client/share_group.cc
index cb9f9bca5c6819e8769fdf11e738046eddafa364..6b5a254a005eef356669b6c0efb100c82828e86b 100644
--- a/gpu/command_buffer/client/share_group.cc
+++ b/gpu/command_buffer/client/share_group.cc
@@ -26,6 +26,7 @@ class IdHandler : public IdHandlerInterface {
virtual void MakeIds(
GLES2Implementation* /* gl_impl */,
GLuint id_offset, GLsizei n, GLuint* ids) OVERRIDE {
+ base::AutoLock auto_lock(lock_);
if (id_offset == 0) {
for (GLsizei ii = 0; ii < n; ++ii) {
ids[ii] = id_allocator_.AllocateID();
@@ -42,6 +43,7 @@ class IdHandler : public IdHandlerInterface {
virtual bool FreeIds(
GLES2Implementation* gl_impl,
GLsizei n, const GLuint* ids, DeleteFn delete_fn) OVERRIDE {
+ base::AutoLock auto_lock(lock_);
for (GLsizei ii = 0; ii < n; ++ii) {
id_allocator_.FreeID(ids[ii]);
}
@@ -54,23 +56,25 @@ class IdHandler : public IdHandlerInterface {
// Overridden from IdHandlerInterface.
virtual bool MarkAsUsedForBind(GLuint id) OVERRIDE {
- return id == 0 ? true : id_allocator_.MarkAsUsed(id);
+ if (id == 0)
+ return true;
+ base::AutoLock auto_lock(lock_);
+ return id_allocator_.MarkAsUsed(id);
}
+
protected:
IdAllocator id_allocator_;
+ base::Lock lock_;
piman 2014/02/12 00:52:53 nit: a common pattern is to put the lock before th
vmiura 2014/02/12 02:03:52 Done.
};
-// An id handler that require Gen before Bind.
+// An id handler that requires Gen before Bind.
class StrictIdHandler : public IdHandler {
public:
StrictIdHandler() {}
virtual ~StrictIdHandler() {}
// Overridden from IdHandler.
- virtual bool MarkAsUsedForBind(GLuint id) OVERRIDE {
- DCHECK(id == 0 || id_allocator_.InUse(id));
- return IdHandler::MarkAsUsedForBind(id);
- }
+ virtual bool MarkAsUsedForBind(GLuint id) OVERRIDE { return true; }
piman 2014/02/12 00:52:53 nit: it'd be nice to keep the DCHECK. We can do: #
no sievers 2014/02/12 01:09:04 Although at other times we argue that you shouldn'
vmiura 2014/02/12 02:03:52 Done.
};
// An id handler for ids that are never reused.
@@ -83,6 +87,7 @@ class NonReusedIdHandler : public IdHandlerInterface {
virtual void MakeIds(
GLES2Implementation* /* gl_impl */,
GLuint id_offset, GLsizei n, GLuint* ids) OVERRIDE {
+ base::AutoLock auto_lock(lock_);
for (GLsizei ii = 0; ii < n; ++ii) {
ids[ii] = ++last_id_ + id_offset;
no sievers 2014/02/12 01:09:04 I guess we could make that use an atomic as a foll
}
@@ -105,80 +110,7 @@ class NonReusedIdHandler : public IdHandlerInterface {
private:
GLuint last_id_;
-};
-
-// An id handler for shared ids.
-class SharedIdHandler : public IdHandlerInterface {
- public:
- SharedIdHandler(
- id_namespaces::IdNamespaces id_namespace)
- : id_namespace_(id_namespace) {
- }
-
- virtual ~SharedIdHandler() {}
-
- virtual void MakeIds(GLES2Implementation* gl_impl,
- GLuint id_offset,
- GLsizei n,
- GLuint* ids) OVERRIDE {
- gl_impl->GenSharedIdsCHROMIUM(id_namespace_, id_offset, n, ids);
- }
-
- virtual bool FreeIds(GLES2Implementation* gl_impl,
- GLsizei n,
- const GLuint* ids,
- DeleteFn delete_fn) OVERRIDE {
- gl_impl->DeleteSharedIdsCHROMIUM(id_namespace_, n, ids);
- (gl_impl->*delete_fn)(n, ids);
- // We need to ensure that the delete call is evaluated on the service side
- // before any other contexts issue commands using these client ids.
- gl_impl->helper()->CommandBufferHelper::Flush();
- return true;
- }
-
- virtual bool MarkAsUsedForBind(GLuint id) OVERRIDE {
- // This has no meaning for shared resources.
- return true;
- }
-
- private:
- id_namespaces::IdNamespaces id_namespace_;
-};
-
-class ThreadSafeIdHandlerWrapper : public IdHandlerInterface {
- public:
- ThreadSafeIdHandlerWrapper(IdHandlerInterface* id_handler)
- : id_handler_(id_handler) {
- }
- virtual ~ThreadSafeIdHandlerWrapper() { }
-
- // Overridden from IdHandlerInterface.
- virtual void MakeIds(GLES2Implementation* gl_impl,
- GLuint id_offset,
- GLsizei n,
- GLuint* ids) OVERRIDE {
- base::AutoLock auto_lock(lock_);
- id_handler_->MakeIds(gl_impl, id_offset, n, ids);
- }
-
- // Overridden from IdHandlerInterface.
- virtual bool FreeIds(GLES2Implementation* gl_impl,
- GLsizei n,
- const GLuint* ids,
- DeleteFn delete_fn) OVERRIDE {
- base::AutoLock auto_lock(lock_);
- return id_handler_->FreeIds(gl_impl, n, ids, delete_fn);
- }
-
- // Overridden from IdHandlerInterface.
- virtual bool MarkAsUsedForBind(GLuint id) OVERRIDE {
- base::AutoLock auto_lock(lock_);
- return id_handler_->MarkAsUsedForBind(id);
- }
-
- private:
- scoped_ptr<IdHandlerInterface> id_handler_;
- base::Lock lock_;
+ base::Lock lock_;
};
ShareGroup::ShareGroup(bool bind_generates_resource)
@@ -186,21 +118,17 @@ ShareGroup::ShareGroup(bool bind_generates_resource)
if (bind_generates_resource) {
for (int i = 0; i < id_namespaces::kNumIdNamespaces; ++i) {
if (i == id_namespaces::kProgramsAndShaders) {
- id_handlers_[i].reset(new ThreadSafeIdHandlerWrapper(
- new NonReusedIdHandler()));
+ id_handlers_[i].reset(new NonReusedIdHandler());
} else {
- id_handlers_[i].reset(new ThreadSafeIdHandlerWrapper(
- new IdHandler()));
+ id_handlers_[i].reset(new IdHandler());
}
}
} else {
for (int i = 0; i < id_namespaces::kNumIdNamespaces; ++i) {
if (i == id_namespaces::kProgramsAndShaders) {
- id_handlers_[i].reset(new ThreadSafeIdHandlerWrapper(
- new NonReusedIdHandler()));
+ id_handlers_[i].reset(new NonReusedIdHandler());
} else {
- id_handlers_[i].reset(new ThreadSafeIdHandlerWrapper(
- new StrictIdHandler()));
+ id_handlers_[i].reset(new StrictIdHandler());
}
}
}
« no previous file with comments | « no previous file | gpu/command_buffer/service/gles2_cmd_decoder.cc » ('j') | gpu/command_buffer/service/gles2_cmd_decoder.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698