From 0a7aebadfbb3534284546aa3ca8612314c08f136 Mon Sep 17 00:00:00 2001 From: Miguel Costa Date: Tue, 26 Jun 2018 16:56:45 +0200 Subject: Update ANGLE to chromium/3280 Change-Id: I0802c0d7486f772d361f87a544d6c5af937f4ca1 Reviewed-by: Friedemann Kleint --- src/3rdparty/angle/src/libANGLE/ResourceManager.h | 298 +++++++++++++++++----- 1 file changed, 236 insertions(+), 62 deletions(-) (limited to 'src/3rdparty/angle/src/libANGLE/ResourceManager.h') diff --git a/src/3rdparty/angle/src/libANGLE/ResourceManager.h b/src/3rdparty/angle/src/libANGLE/ResourceManager.h index 2073e9d728..2dfeff5234 100644 --- a/src/3rdparty/angle/src/libANGLE/ResourceManager.h +++ b/src/3rdparty/angle/src/libANGLE/ResourceManager.h @@ -1,115 +1,289 @@ // -// Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved. +// Copyright (c) 2002-2016 The ANGLE Project Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// ResourceManager.h : Defines the ResourceManager class, which tracks objects -// shared by multiple GL contexts. +// ResourceManager.h : Defines the ResourceManager classes, which handle allocation and lifetime of +// GL objects. #ifndef LIBANGLE_RESOURCEMANAGER_H_ #define LIBANGLE_RESOURCEMANAGER_H_ #include "angle_gl.h" #include "common/angleutils.h" -#include "libANGLE/angletypes.h" +#include "libANGLE/Error.h" #include "libANGLE/HandleAllocator.h" - -#include +#include "libANGLE/HandleRangeAllocator.h" +#include "libANGLE/ResourceMap.h" namespace rx { -class ImplFactory; +class GLImplFactory; } namespace gl { class Buffer; -struct Data; -class FenceSync; +struct Caps; +class Context; +class Sync; +class Framebuffer; struct Limitations; +class Path; class Program; +class ProgramPipeline; class Renderbuffer; class Sampler; class Shader; class Texture; -class ResourceManager : angle::NonCopyable +template +class ResourceManagerBase : angle::NonCopyable { public: - explicit ResourceManager(rx::ImplFactory *factory); - ~ResourceManager(); + ResourceManagerBase(); void addRef(); - void release(); + void release(const Context *context); + + protected: + virtual void reset(const Context *context) = 0; + virtual ~ResourceManagerBase() {} + + HandleAllocatorType mHandleAllocator; + + private: + size_t mRefCount; +}; + +template +class TypedResourceManager : public ResourceManagerBase +{ + public: + TypedResourceManager() {} + + void deleteObject(const Context *context, GLuint handle); + bool isHandleGenerated(GLuint handle) const + { + // Zero is always assumed to have been generated implicitly. + return handle == 0 || mObjectMap.contains(handle); + } + + protected: + ~TypedResourceManager() override; + + // Inlined in the header for performance. + template + ResourceType *checkObjectAllocation(rx::GLImplFactory *factory, GLuint handle, ArgTypes... args) + { + ResourceType *value = mObjectMap.query(handle); + if (value) + { + return value; + } + + if (handle == 0) + { + return nullptr; + } + + ResourceType *object = ImplT::AllocateNewObject(factory, handle, args...); + + if (!mObjectMap.contains(handle)) + { + this->mHandleAllocator.reserve(handle); + } + mObjectMap.assign(handle, object); + + return object; + } + + void reset(const Context *context) override; + + ResourceMap mObjectMap; +}; +class BufferManager : public TypedResourceManager +{ + public: GLuint createBuffer(); - GLuint createShader(const gl::Limitations &rendererLimitations, GLenum type); - GLuint createProgram(); + Buffer *getBuffer(GLuint handle) const; + + Buffer *checkBufferAllocation(rx::GLImplFactory *factory, GLuint handle) + { + return checkObjectAllocation(factory, handle); + } + + // TODO(jmadill): Investigate design which doesn't expose these methods publicly. + static Buffer *AllocateNewObject(rx::GLImplFactory *factory, GLuint handle); + static void DeleteObject(const Context *context, Buffer *buffer); + + protected: + ~BufferManager() override {} +}; + +class ShaderProgramManager : public ResourceManagerBase +{ + public: + ShaderProgramManager(); + + GLuint createShader(rx::GLImplFactory *factory, + const Limitations &rendererLimitations, + GLenum type); + void deleteShader(const Context *context, GLuint shader); + Shader *getShader(GLuint handle) const; + + GLuint createProgram(rx::GLImplFactory *factory); + void deleteProgram(const Context *context, GLuint program); + Program *getProgram(GLuint handle) const; + + protected: + ~ShaderProgramManager() override; + + private: + template + void deleteObject(const Context *context, ResourceMap *objectMap, GLuint id); + + void reset(const Context *context) override; + + ResourceMap mShaders; + ResourceMap mPrograms; +}; + +class TextureManager : public TypedResourceManager +{ + public: GLuint createTexture(); + Texture *getTexture(GLuint handle) const; + + void signalAllTexturesDirty() const; + + Texture *checkTextureAllocation(rx::GLImplFactory *factory, GLuint handle, GLenum target) + { + return checkObjectAllocation(factory, handle, target); + } + + static Texture *AllocateNewObject(rx::GLImplFactory *factory, GLuint handle, GLenum target); + static void DeleteObject(const Context *context, Texture *texture); + + protected: + ~TextureManager() override {} +}; + +class RenderbufferManager + : public TypedResourceManager +{ + public: GLuint createRenderbuffer(); + Renderbuffer *getRenderbuffer(GLuint handle) const; + + Renderbuffer *checkRenderbufferAllocation(rx::GLImplFactory *factory, GLuint handle) + { + return checkObjectAllocation(factory, handle); + } + + static Renderbuffer *AllocateNewObject(rx::GLImplFactory *factory, GLuint handle); + static void DeleteObject(const Context *context, Renderbuffer *renderbuffer); + + protected: + ~RenderbufferManager() override {} +}; + +class SamplerManager : public TypedResourceManager +{ + public: GLuint createSampler(); - GLuint createFenceSync(); - - void deleteBuffer(GLuint buffer); - void deleteShader(GLuint shader); - void deleteProgram(GLuint program); - void deleteTexture(GLuint texture); - void deleteRenderbuffer(GLuint renderbuffer); - void deleteSampler(GLuint sampler); - void deleteFenceSync(GLuint fenceSync); - - Buffer *getBuffer(GLuint handle); - Shader *getShader(GLuint handle); - Program *getProgram(GLuint handle) const; - Texture *getTexture(GLuint handle); - Renderbuffer *getRenderbuffer(GLuint handle); - Sampler *getSampler(GLuint handle); - FenceSync *getFenceSync(GLuint handle); + Sampler *getSampler(GLuint handle) const; + bool isSampler(GLuint sampler) const; + + Sampler *checkSamplerAllocation(rx::GLImplFactory *factory, GLuint handle) + { + return checkObjectAllocation(factory, handle); + } - void setRenderbuffer(GLuint handle, Renderbuffer *renderbuffer); + static Sampler *AllocateNewObject(rx::GLImplFactory *factory, GLuint handle); + static void DeleteObject(const Context *context, Sampler *sampler); - void checkBufferAllocation(GLuint handle); - void checkTextureAllocation(GLuint handle, GLenum type); - void checkRenderbufferAllocation(GLuint handle); - void checkSamplerAllocation(GLuint sampler); + protected: + ~SamplerManager() override {} +}; + +class SyncManager : public TypedResourceManager +{ + public: + GLuint createSync(rx::GLImplFactory *factory); + Sync *getSync(GLuint handle) const; + + static void DeleteObject(const Context *context, Sync *sync); + + protected: + ~SyncManager() override {} +}; + +class PathManager : public ResourceManagerBase +{ + public: + PathManager(); - bool isSampler(GLuint sampler); + ErrorOrResult createPaths(rx::GLImplFactory *factory, GLsizei range); + void deletePaths(GLuint first, GLsizei range); + Path *getPath(GLuint handle) const; + bool hasPath(GLuint handle) const; + + protected: + ~PathManager() override; + void reset(const Context *context) override; private: - void createTextureInternal(GLuint handle); + ResourceMap mPaths; +}; - rx::ImplFactory *mFactory; - std::size_t mRefCount; +class FramebufferManager + : public TypedResourceManager +{ + public: + GLuint createFramebuffer(); + Framebuffer *getFramebuffer(GLuint handle) const; + void setDefaultFramebuffer(Framebuffer *framebuffer); - typedef std::map BufferMap; - BufferMap mBufferMap; - HandleAllocator mBufferHandleAllocator; + void invalidateFramebufferComplenessCache() const; - typedef std::map ShaderMap; - ShaderMap mShaderMap; + Framebuffer *checkFramebufferAllocation(rx::GLImplFactory *factory, + const Caps &caps, + GLuint handle) + { + return checkObjectAllocation(factory, handle, caps); + } - typedef std::map ProgramMap; - ProgramMap mProgramMap; - HandleAllocator mProgramShaderHandleAllocator; + static Framebuffer *AllocateNewObject(rx::GLImplFactory *factory, + GLuint handle, + const Caps &caps); + static void DeleteObject(const Context *context, Framebuffer *framebuffer); - typedef std::map TextureMap; - TextureMap mTextureMap; - HandleAllocator mTextureHandleAllocator; + protected: + ~FramebufferManager() override {} +}; - typedef std::map RenderbufferMap; - RenderbufferMap mRenderbufferMap; - HandleAllocator mRenderbufferHandleAllocator; +class ProgramPipelineManager + : public TypedResourceManager +{ + public: + GLuint createProgramPipeline(); + ProgramPipeline *getProgramPipeline(GLuint handle) const; - typedef std::map SamplerMap; - SamplerMap mSamplerMap; - HandleAllocator mSamplerHandleAllocator; + ProgramPipeline *checkProgramPipelineAllocation(rx::GLImplFactory *factory, GLuint handle) + { + return checkObjectAllocation(factory, handle); + } - typedef std::map FenceMap; - FenceMap mFenceSyncMap; - HandleAllocator mFenceSyncHandleAllocator; + static ProgramPipeline *AllocateNewObject(rx::GLImplFactory *factory, GLuint handle); + static void DeleteObject(const Context *context, ProgramPipeline *pipeline); + + protected: + ~ProgramPipelineManager() override {} }; -} +} // namespace gl #endif // LIBANGLE_RESOURCEMANAGER_H_ -- cgit v1.2.3