diff options
author | gman@chromium.org <gman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-04 21:33:49 +0000 |
---|---|---|
committer | gman@chromium.org <gman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-04 21:33:49 +0000 |
commit | 92fa5b98619fb7edaa39b31a4f0473e72ae5d11e (patch) | |
tree | 6062982749e218d881a9fe5dbb19d869aad5d640 /gpu | |
parent | ee731a5aab73c78a3787c939b8f1ad731d9539ba (diff) | |
download | chromium_src-92fa5b98619fb7edaa39b31a4f0473e72ae5d11e.zip chromium_src-92fa5b98619fb7edaa39b31a4f0473e72ae5d11e.tar.gz chromium_src-92fa5b98619fb7edaa39b31a4f0473e72ae5d11e.tar.bz2 |
Make contexts actually use ShareGroup for shared contexts.
The service ALWAYS has bind_generates_resource set to true.
In fact we can just remove that flag on the service in another CL.
It doesn't need to be enforced on the service. It was only there
to help the client find bugs. Now the client and find them itself
in a Debug build.
I can remove share_resources everywhere. That flag is no longer
needed. Because removing that flag touches so many files I'd
prefer to do that in another CL.
Note: I probably can't check this in until the bugs it
uncovers are fixed. Maybe they can be marked as failing.
For example the webgl context-lost tests hit an assert.
TEST=ran the webgl conformance tests.
BUG=120297
Review URL: https://chromiumcodereview.appspot.com/9958038
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@130737 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'gpu')
-rw-r--r-- | gpu/command_buffer/client/gles2_implementation.cc | 60 | ||||
-rw-r--r-- | gpu/command_buffer/client/gles2_implementation.h | 9 | ||||
-rw-r--r-- | gpu/command_buffer/client/program_info_manager.cc | 5 | ||||
-rw-r--r-- | gpu/command_buffer/client/program_info_manager.h | 4 | ||||
-rw-r--r-- | gpu/command_buffer/client/share_group.cc | 209 | ||||
-rw-r--r-- | gpu/command_buffer/client/share_group.h | 5 |
6 files changed, 149 insertions, 143 deletions
diff --git a/gpu/command_buffer/client/gles2_implementation.cc b/gpu/command_buffer/client/gles2_implementation.cc index cfd4063..b7b72a7 100644 --- a/gpu/command_buffer/client/gles2_implementation.cc +++ b/gpu/command_buffer/client/gles2_implementation.cc @@ -505,7 +505,8 @@ GLuint GLES2Implementation::MakeTextureId() { } void GLES2Implementation::FreeTextureId(GLuint id) { - GetIdHandler(id_namespaces::kTextures)->FreeIds(this, 1, &id); + GetIdHandler(id_namespaces::kTextures)->FreeIds( + this, 1, &id, &GLES2Implementation::DeleteTexturesStub); } IdHandlerInterface* GLES2Implementation::GetIdHandler(int namespace_id) const { @@ -1072,30 +1073,41 @@ void GLES2Implementation::GetVertexAttribPointerv( bool GLES2Implementation::DeleteProgramHelper(GLuint program) { if (!GetIdHandler(id_namespaces::kProgramsAndShaders)->FreeIds( - this, 1, &program)) { + this, 1, &program, &GLES2Implementation::DeleteProgramStub)) { SetGLError( GL_INVALID_VALUE, "glDeleteProgram: id not created by this context."); return false; } - share_group_->program_info_manager()->DeleteInfo(program); - helper_->DeleteProgram(program); return true; } +void GLES2Implementation::DeleteProgramStub( + GLsizei n, const GLuint* programs) { + GPU_DCHECK_EQ(1, n); + share_group_->program_info_manager()->DeleteInfo(programs[0]); + helper_->DeleteProgram(programs[0]); +} + bool GLES2Implementation::DeleteShaderHelper(GLuint shader) { if (!GetIdHandler(id_namespaces::kProgramsAndShaders)->FreeIds( - this, 1, &shader)) { + this, 1, &shader, &GLES2Implementation::DeleteShaderStub)) { SetGLError( GL_INVALID_VALUE, "glDeleteShader: id not created by this context."); return false; } - share_group_->program_info_manager()->DeleteInfo(shader); - helper_->DeleteShader(shader); return true; } +void GLES2Implementation::DeleteShaderStub( + GLsizei n, const GLuint* shaders) { + GPU_DCHECK_EQ(1, n); + share_group_->program_info_manager()->DeleteInfo(shaders[0]); + helper_->DeleteShader(shaders[0]); +} + + GLint GLES2Implementation::GetAttribLocationHelper( GLuint program, const char* name) { typedef GetAttribLocationBucket::Result Result; @@ -2212,7 +2224,8 @@ bool GLES2Implementation::IsBufferReservedId(GLuint /* id */) { void GLES2Implementation::DeleteBuffersHelper( GLsizei n, const GLuint* buffers) { - if (!GetIdHandler(id_namespaces::kBuffers)->FreeIds(this, n, buffers)) { + if (!GetIdHandler(id_namespaces::kBuffers)->FreeIds( + this, n, buffers, &GLES2Implementation::DeleteBuffersStub)) { SetGLError( GL_INVALID_VALUE, "glDeleteBuffers: id not created by this context."); @@ -2226,13 +2239,18 @@ void GLES2Implementation::DeleteBuffersHelper( bound_element_array_buffer_id_ = 0; } } +} + +void GLES2Implementation::DeleteBuffersStub( + GLsizei n, const GLuint* buffers) { helper_->DeleteBuffersImmediate(n, buffers); } + void GLES2Implementation::DeleteFramebuffersHelper( GLsizei n, const GLuint* framebuffers) { if (!GetIdHandler(id_namespaces::kFramebuffers)->FreeIds( - this, n, framebuffers)) { + this, n, framebuffers, &GLES2Implementation::DeleteFramebuffersStub)) { SetGLError( GL_INVALID_VALUE, "glDeleteFramebuffers: id not created by this context."); @@ -2243,13 +2261,17 @@ void GLES2Implementation::DeleteFramebuffersHelper( bound_framebuffer_ = 0; } } +} + +void GLES2Implementation::DeleteFramebuffersStub( + GLsizei n, const GLuint* framebuffers) { helper_->DeleteFramebuffersImmediate(n, framebuffers); } void GLES2Implementation::DeleteRenderbuffersHelper( GLsizei n, const GLuint* renderbuffers) { if (!GetIdHandler(id_namespaces::kRenderbuffers)->FreeIds( - this, n, renderbuffers)) { + this, n, renderbuffers, &GLES2Implementation::DeleteRenderbuffersStub)) { SetGLError( GL_INVALID_VALUE, "glDeleteRenderbuffers: id not created by this context."); @@ -2260,13 +2282,17 @@ void GLES2Implementation::DeleteRenderbuffersHelper( bound_renderbuffer_ = 0; } } +} + +void GLES2Implementation::DeleteRenderbuffersStub( + GLsizei n, const GLuint* renderbuffers) { helper_->DeleteRenderbuffersImmediate(n, renderbuffers); } void GLES2Implementation::DeleteTexturesHelper( GLsizei n, const GLuint* textures) { if (!GetIdHandler(id_namespaces::kTextures)->FreeIds( - this, n, textures)) { + this, n, textures, &GLES2Implementation::DeleteTexturesStub)) { SetGLError( GL_INVALID_VALUE, "glDeleteTextures: id not created by this context."); @@ -2283,6 +2309,10 @@ void GLES2Implementation::DeleteTexturesHelper( } } } +} + +void GLES2Implementation::DeleteTexturesStub( + GLsizei n, const GLuint* textures) { helper_->DeleteTexturesImmediate(n, textures); } @@ -2795,8 +2825,9 @@ void GLES2Implementation::PostSubBufferCHROMIUM( void GLES2Implementation::DeleteQueriesEXTHelper( GLsizei n, const GLuint* queries) { + // TODO(gman): Remove this as queries are not shared resources. if (!GetIdHandler(id_namespaces::kQueries)->FreeIds( - this, n, queries)) { + this, n, queries, &GLES2Implementation::DeleteQueriesStub)) { SetGLError( GL_INVALID_VALUE, "glDeleteTextures: id not created by this context."); @@ -2832,6 +2863,11 @@ void GLES2Implementation::DeleteQueriesEXTHelper( helper_->DeleteQueriesEXTImmediate(n, queries); } +// TODO(gman): Remove this. Queries are not shared resources. +void GLES2Implementation::DeleteQueriesStub( + GLsizei /* n */, const GLuint* /* queries */) { +} + GLboolean GLES2Implementation::IsQueryEXT(GLuint id) { GPU_CLIENT_SINGLE_THREAD_CHECK(); GPU_CLIENT_LOG("[" << this << "] IsQueryEXT(" << id << ")"); diff --git a/gpu/command_buffer/client/gles2_implementation.h b/gpu/command_buffer/client/gles2_implementation.h index ba1aef8..69e875c 100644 --- a/gpu/command_buffer/client/gles2_implementation.h +++ b/gpu/command_buffer/client/gles2_implementation.h @@ -390,6 +390,15 @@ class GLES2_IMPL_EXPORT GLES2Implementation { bool DeleteShaderHelper(GLuint shader); void DeleteQueriesEXTHelper(GLsizei n, const GLuint* textures); + void DeleteBuffersStub(GLsizei n, const GLuint* buffers); + void DeleteFramebuffersStub(GLsizei n, const GLuint* framebuffers); + void DeleteRenderbuffersStub(GLsizei n, const GLuint* renderbuffers); + void DeleteTexturesStub(GLsizei n, const GLuint* textures); + void DeleteProgramStub(GLsizei n, const GLuint* programs); + void DeleteShaderStub(GLsizei n, const GLuint* shaders); + // TODO(gman): Remove this as queries are not shared. + void DeleteQueriesStub(GLsizei n, const GLuint* queries); + void BufferDataHelper( GLenum target, GLsizeiptr size, const void* data, GLenum usage); void BufferSubDataHelper( diff --git a/gpu/command_buffer/client/program_info_manager.cc b/gpu/command_buffer/client/program_info_manager.cc index d953914..86fbd13 100644 --- a/gpu/command_buffer/client/program_info_manager.cc +++ b/gpu/command_buffer/client/program_info_manager.cc @@ -492,8 +492,9 @@ ProgramInfoManager::ProgramInfoManager() { ProgramInfoManager::~ProgramInfoManager() { } -ProgramInfoManager* ProgramInfoManager::Create(bool shared_resources) { - if (shared_resources) { +ProgramInfoManager* ProgramInfoManager::Create( + bool shared_resources_across_processes) { + if (shared_resources_across_processes) { return new NonCachedProgramInfoManager(); } else { return new CachedProgramInfoManager(); diff --git a/gpu/command_buffer/client/program_info_manager.h b/gpu/command_buffer/client/program_info_manager.h index 5b3e559..25108e2 100644 --- a/gpu/command_buffer/client/program_info_manager.h +++ b/gpu/command_buffer/client/program_info_manager.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -17,7 +17,7 @@ class ProgramInfoManager { public: virtual ~ProgramInfoManager(); - static ProgramInfoManager* Create(bool shared_resources); + static ProgramInfoManager* Create(bool shared_resources_across_processes); virtual void CreateInfo(GLuint program) = 0; diff --git a/gpu/command_buffer/client/share_group.cc b/gpu/command_buffer/client/share_group.cc index e195e19..23e5456 100644 --- a/gpu/command_buffer/client/share_group.cc +++ b/gpu/command_buffer/client/share_group.cc @@ -15,11 +15,11 @@ namespace gles2 { COMPILE_ASSERT(gpu::kInvalidResource == 0, INVALID_RESOURCE_NOT_0_AS_GL_EXPECTS); -// An id handler for non-shared ids. -class NonSharedIdHandler : public IdHandlerInterface { +// The standard id handler. +class IdHandler : public IdHandlerInterface { public: - NonSharedIdHandler() { } - virtual ~NonSharedIdHandler() { } + IdHandler() { } + virtual ~IdHandler() { } // Overridden from IdHandlerInterface. virtual void Destroy(GLES2Implementation* /* gl_impl */) { @@ -43,11 +43,15 @@ class NonSharedIdHandler : public IdHandlerInterface { // Overridden from IdHandlerInterface. virtual bool FreeIds( - GLES2Implementation* /* gl_impl */, - GLsizei n, const GLuint* ids) { + GLES2Implementation* gl_impl, + GLsizei n, const GLuint* ids, DeleteFn delete_fn) { for (GLsizei ii = 0; ii < n; ++ii) { id_allocator_.FreeID(ids[ii]); } + (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; } @@ -59,11 +63,11 @@ class NonSharedIdHandler : public IdHandlerInterface { IdAllocator id_allocator_; }; -// An id handler for non-shared ids that are never reused. -class NonSharedNonReusedIdHandler : public IdHandlerInterface { +// An id handler that require Gen before Bind. +class StrictIdHandler : public IdHandlerInterface { public: - NonSharedNonReusedIdHandler() : last_id_(0) { } - virtual ~NonSharedNonReusedIdHandler() { } + StrictIdHandler() { } + virtual ~StrictIdHandler() { } // Overridden from IdHandlerInterface. virtual void Destroy(GLES2Implementation* /* gl_impl */) { @@ -73,128 +77,107 @@ class NonSharedNonReusedIdHandler : public IdHandlerInterface { virtual void MakeIds( GLES2Implementation* /* gl_impl */, GLuint id_offset, GLsizei n, GLuint* ids) { - for (GLsizei ii = 0; ii < n; ++ii) { - ids[ii] = ++last_id_ + id_offset; + if (id_offset == 0) { + for (GLsizei ii = 0; ii < n; ++ii) { + ids[ii] = id_allocator_.AllocateID(); + } + } else { + for (GLsizei ii = 0; ii < n; ++ii) { + ids[ii] = id_allocator_.AllocateIDAtOrAbove(id_offset); + id_offset = ids[ii] + 1; + } } } // Overridden from IdHandlerInterface. virtual bool FreeIds( - GLES2Implementation* /* gl_impl */, - GLsizei /* n */, const GLuint* /* ids */) { - // Ids are never freed. + GLES2Implementation* gl_impl, + GLsizei n, const GLuint* ids, DeleteFn delete_fn) { + for (GLsizei ii = 0; ii < n; ++ii) { + id_allocator_.FreeID(ids[ii]); + } + (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; } // Overridden from IdHandlerInterface. - virtual bool MarkAsUsedForBind(GLuint /* id */) { - // This is only used for Shaders and Programs which have no bind. - return false; + virtual bool MarkAsUsedForBind(GLuint id) { + GPU_DCHECK(id == 0 || id_allocator_.InUse(id)); + return true; } - private: - GLuint last_id_; + IdAllocator id_allocator_; }; -// An id handler for shared ids. -class SharedIdHandler : public IdHandlerInterface { +// An id handler for ids that are never reused. +class NonReusedIdHandler : public IdHandlerInterface { public: - SharedIdHandler( - id_namespaces::IdNamespaces id_namespace) - : id_namespace_(id_namespace) { - } - - virtual ~SharedIdHandler() { } + NonReusedIdHandler() : last_id_(0) { } + virtual ~NonReusedIdHandler() { } // Overridden from IdHandlerInterface. virtual void Destroy(GLES2Implementation* /* gl_impl */) { } + // Overridden from IdHandlerInterface. virtual void MakeIds( - GLES2Implementation* gl_impl, + GLES2Implementation* /* gl_impl */, GLuint id_offset, GLsizei n, GLuint* ids) { - gl_impl->GenSharedIdsCHROMIUM(id_namespace_, id_offset, n, ids); + for (GLsizei ii = 0; ii < n; ++ii) { + ids[ii] = ++last_id_ + id_offset; + } } + // Overridden from IdHandlerInterface. virtual bool FreeIds( GLES2Implementation* gl_impl, - GLsizei n, const GLuint* ids) { - gl_impl->DeleteSharedIdsCHROMIUM(id_namespace_, 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(); + GLsizei n, const GLuint* ids, DeleteFn delete_fn) { + // Ids are never freed. + (gl_impl->*delete_fn)(n, ids); return true; } + // Overridden from IdHandlerInterface. virtual bool MarkAsUsedForBind(GLuint /* id */) { - // This has no meaning for shared resources. - return true; + // This is only used for Shaders and Programs which have no bind. + return false; } private: - id_namespaces::IdNamespaces id_namespace_; + GLuint last_id_; }; -// An id handler for shared ids that requires ids are made before using and -// that only the context that created the id can delete it. -// Assumes the service will enforce that non made ids generate an error. -class StrictSharedIdHandler : public IdHandlerInterface { +// An id handler for shared ids. +class SharedIdHandler : public IdHandlerInterface { public: - StrictSharedIdHandler( + SharedIdHandler( id_namespaces::IdNamespaces id_namespace) : id_namespace_(id_namespace) { } - virtual ~StrictSharedIdHandler() { - } + virtual ~SharedIdHandler() { } // Overridden from IdHandlerInterface. - virtual void Destroy(GLES2Implementation* gl_impl) { - GPU_DCHECK(gl_impl); - // Free all the ids not being used. - while (!free_ids_.empty()) { - GLuint ids[kNumIdsToGet]; - int count = 0; - while (count < kNumIdsToGet && !free_ids_.empty()) { - ids[count++] = free_ids_.front(); - free_ids_.pop(); - } - gl_impl->DeleteSharedIdsCHROMIUM(id_namespace_, count, ids); - } + virtual void Destroy(GLES2Implementation* /* gl_impl */) { } virtual void MakeIds( GLES2Implementation* gl_impl, GLuint id_offset, GLsizei n, GLuint* ids) { - GPU_DCHECK(gl_impl); - for (GLsizei ii = 0; ii < n; ++ii) { - ids[ii] = GetId(gl_impl, id_offset); - } + gl_impl->GenSharedIdsCHROMIUM(id_namespace_, id_offset, n, ids); } virtual bool FreeIds( - GLES2Implementation* /* gl_impl */, - GLsizei n, const GLuint* ids) { - // OpenGL sematics. If any id is bad none of them get freed. - for (GLsizei ii = 0; ii < n; ++ii) { - GLuint id = ids[ii]; - if (id != 0) { - ResourceIdSet::iterator it = used_ids_.find(id); - if (it == used_ids_.end()) { - return false; - } - } - } - for (GLsizei ii = 0; ii < n; ++ii) { - GLuint id = ids[ii]; - if (id != 0) { - ResourceIdSet::iterator it = used_ids_.find(id); - if (it != used_ids_.end()) { - used_ids_.erase(it); - free_ids_.push(id); - } - } - } + GLES2Implementation* gl_impl, + GLsizei n, const GLuint* ids, DeleteFn delete_fn) { + 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; } @@ -204,35 +187,9 @@ class StrictSharedIdHandler : public IdHandlerInterface { } private: - static const GLsizei kNumIdsToGet = 2048; - typedef std::queue<GLuint> ResourceIdQueue; - typedef std::set<GLuint> ResourceIdSet; - - GLuint GetId(GLES2Implementation* gl_impl, GLuint id_offset) { - GPU_DCHECK(gl_impl); - if (free_ids_.empty()) { - GLuint ids[kNumIdsToGet]; - gl_impl->GenSharedIdsCHROMIUM( - id_namespace_, id_offset, kNumIdsToGet, ids); - for (GLsizei ii = 0; ii < kNumIdsToGet; ++ii) { - free_ids_.push(ids[ii]); - } - } - GLuint id = free_ids_.front(); - free_ids_.pop(); - used_ids_.insert(id); - return id; - } - id_namespaces::IdNamespaces id_namespace_; - ResourceIdSet used_ids_; - ResourceIdQueue free_ids_; }; -#ifndef _MSC_VER -const GLsizei StrictSharedIdHandler::kNumIdsToGet; -#endif - class ThreadSafeIdHandlerWrapper : public IdHandlerInterface { public: ThreadSafeIdHandlerWrapper(IdHandlerInterface* id_handler) @@ -255,9 +212,10 @@ class ThreadSafeIdHandlerWrapper : public IdHandlerInterface { // Overridden from IdHandlerInterface. virtual bool FreeIds( - GLES2Implementation* gl_impl, GLsizei n, const GLuint* ids) { + GLES2Implementation* gl_impl, GLsizei n, const GLuint* ids, + DeleteFn delete_fn) { AutoLock auto_lock(lock_); - return id_handler_->FreeIds(gl_impl, n, ids); + return id_handler_->FreeIds(gl_impl, n, ids, delete_fn); } // Overridden from IdHandlerInterface. @@ -277,29 +235,28 @@ ShareGroup::ShareGroup(bool share_resources, bool bind_generates_resource) gles2_(NULL) { GPU_CHECK(ShareGroup::ImplementsThreadSafeReferenceCounting()); - if (sharing_resources_) { - if (!bind_generates_resource_) { - for (int i = 0; i < id_namespaces::kNumIdNamespaces; ++i) { + 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 StrictSharedIdHandler( - static_cast<id_namespaces::IdNamespaces>(i)))); - } - } else { - for (int i = 0; i < id_namespaces::kNumIdNamespaces; ++i) { + new NonReusedIdHandler())); + } else { id_handlers_[i].reset(new ThreadSafeIdHandlerWrapper( - new SharedIdHandler( - static_cast<id_namespaces::IdNamespaces>(i)))); + new IdHandler())); } } } else { for (int i = 0; i < id_namespaces::kNumIdNamespaces; ++i) { - if (i == id_namespaces::kProgramsAndShaders) - id_handlers_[i].reset(new NonSharedNonReusedIdHandler); - else - id_handlers_[i].reset(new NonSharedIdHandler); + if (i == id_namespaces::kProgramsAndShaders) { + id_handlers_[i].reset(new ThreadSafeIdHandlerWrapper( + new NonReusedIdHandler())); + } else { + id_handlers_[i].reset(new ThreadSafeIdHandlerWrapper( + new StrictIdHandler())); + } } } - program_info_manager_.reset(ProgramInfoManager::Create(sharing_resources_)); + program_info_manager_.reset(ProgramInfoManager::Create(false)); } ShareGroup::~ShareGroup() { diff --git a/gpu/command_buffer/client/share_group.h b/gpu/command_buffer/client/share_group.h index cf3c44b..3a0df32 100644 --- a/gpu/command_buffer/client/share_group.h +++ b/gpu/command_buffer/client/share_group.h @@ -17,6 +17,8 @@ namespace gles2 { class GLES2Implementation; class ProgramInfoManager; +typedef void (GLES2Implementation::*DeleteFn)(GLsizei n, const GLuint* ids); + // Base class for IdHandlers class IdHandlerInterface { public: @@ -33,7 +35,8 @@ class IdHandlerInterface { // Frees some ids. virtual bool FreeIds( - GLES2Implementation* gl_impl, GLsizei n, const GLuint* ids) = 0; + GLES2Implementation* gl_impl, GLsizei n, const GLuint* ids, + DeleteFn delete_fn) = 0; // Marks an id as used for glBind functions. id = 0 does nothing. virtual bool MarkAsUsedForBind(GLuint id) = 0; |