daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 1 | // |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 2 | // Copyright (c) 2002-2016 The ANGLE Project Authors. All rights reserved. |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 7 | // ResourceManager.cpp: Implements the the ResourceManager classes, which handle allocation and |
| 8 | // lifetime of GL objects. |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 9 | |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 10 | #include "libANGLE/ResourceManager.h" |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 11 | |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 12 | #include "libANGLE/Buffer.h" |
Jamie Madill | 526392d | 2018-11-16 09:35:14 -0500 | [diff] [blame] | 13 | #include "libANGLE/Context.h" |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 14 | #include "libANGLE/Fence.h" |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 15 | #include "libANGLE/Path.h" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 16 | #include "libANGLE/Program.h" |
Yunchao He | a336b90 | 2017-08-02 16:05:21 +0800 | [diff] [blame] | 17 | #include "libANGLE/ProgramPipeline.h" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 18 | #include "libANGLE/Renderbuffer.h" |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 19 | #include "libANGLE/Sampler.h" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 20 | #include "libANGLE/Shader.h" |
| 21 | #include "libANGLE/Texture.h" |
Jamie Madill | 526392d | 2018-11-16 09:35:14 -0500 | [diff] [blame] | 22 | #include "libANGLE/renderer/ContextImpl.h" |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 23 | |
| 24 | namespace gl |
| 25 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 26 | |
| 27 | namespace |
| 28 | { |
| 29 | |
| 30 | template <typename ResourceType> |
| 31 | GLuint AllocateEmptyObject(HandleAllocator *handleAllocator, ResourceMap<ResourceType> *objectMap) |
| 32 | { |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 33 | GLuint handle = handleAllocator->allocate(); |
| 34 | objectMap->assign(handle, nullptr); |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 35 | return handle; |
| 36 | } |
| 37 | |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 38 | } // anonymous namespace |
| 39 | |
| 40 | template <typename HandleAllocatorType> |
| 41 | ResourceManagerBase<HandleAllocatorType>::ResourceManagerBase() : mRefCount(1) |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 42 | { |
| 43 | } |
| 44 | |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 45 | template <typename HandleAllocatorType> |
| 46 | void ResourceManagerBase<HandleAllocatorType>::addRef() |
daniel@transgaming.com | 0d25b00 | 2010-07-28 19:21:07 +0000 | [diff] [blame] | 47 | { |
| 48 | mRefCount++; |
| 49 | } |
| 50 | |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 51 | template <typename HandleAllocatorType> |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 52 | void ResourceManagerBase<HandleAllocatorType>::release(const Context *context) |
daniel@transgaming.com | 0d25b00 | 2010-07-28 19:21:07 +0000 | [diff] [blame] | 53 | { |
| 54 | if (--mRefCount == 0) |
| 55 | { |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 56 | reset(context); |
daniel@transgaming.com | 0d25b00 | 2010-07-28 19:21:07 +0000 | [diff] [blame] | 57 | delete this; |
| 58 | } |
| 59 | } |
| 60 | |
Jamie Madill | 5f45e7c | 2017-02-10 15:23:28 -0800 | [diff] [blame] | 61 | template <typename ResourceType, typename HandleAllocatorType, typename ImplT> |
| 62 | TypedResourceManager<ResourceType, HandleAllocatorType, ImplT>::~TypedResourceManager() |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 63 | { |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 64 | ASSERT(mObjectMap.empty()); |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 65 | } |
| 66 | |
Jamie Madill | 5f45e7c | 2017-02-10 15:23:28 -0800 | [diff] [blame] | 67 | template <typename ResourceType, typename HandleAllocatorType, typename ImplT> |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 68 | void TypedResourceManager<ResourceType, HandleAllocatorType, ImplT>::reset(const Context *context) |
| 69 | { |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 70 | this->mHandleAllocator.reset(); |
| 71 | for (const auto &resource : mObjectMap) |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 72 | { |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 73 | if (resource.second) |
| 74 | { |
| 75 | ImplT::DeleteObject(context, resource.second); |
| 76 | } |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 77 | } |
| 78 | mObjectMap.clear(); |
| 79 | } |
| 80 | |
| 81 | template <typename ResourceType, typename HandleAllocatorType, typename ImplT> |
| 82 | void TypedResourceManager<ResourceType, HandleAllocatorType, ImplT>::deleteObject( |
| 83 | const Context *context, |
| 84 | GLuint handle) |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 85 | { |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 86 | ResourceType *resource = nullptr; |
| 87 | if (!mObjectMap.erase(handle, &resource)) |
Jamie Madill | 5f45e7c | 2017-02-10 15:23:28 -0800 | [diff] [blame] | 88 | { |
| 89 | return; |
| 90 | } |
| 91 | |
Jamie Madill | 5f45e7c | 2017-02-10 15:23:28 -0800 | [diff] [blame] | 92 | // Requires an explicit this-> because of C++ template rules. |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 93 | this->mHandleAllocator.release(handle); |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 94 | |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 95 | if (resource) |
Jamie Madill | 5f45e7c | 2017-02-10 15:23:28 -0800 | [diff] [blame] | 96 | { |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 97 | ImplT::DeleteObject(context, resource); |
Jamie Madill | 5f45e7c | 2017-02-10 15:23:28 -0800 | [diff] [blame] | 98 | } |
Jamie Madill | 5f45e7c | 2017-02-10 15:23:28 -0800 | [diff] [blame] | 99 | } |
| 100 | |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 101 | template class ResourceManagerBase<HandleAllocator>; |
| 102 | template class ResourceManagerBase<HandleRangeAllocator>; |
Jamie Madill | 5f45e7c | 2017-02-10 15:23:28 -0800 | [diff] [blame] | 103 | template class TypedResourceManager<Buffer, HandleAllocator, BufferManager>; |
Jamie Madill | 5f45e7c | 2017-02-10 15:23:28 -0800 | [diff] [blame] | 104 | template class TypedResourceManager<Texture, HandleAllocator, TextureManager>; |
Jamie Madill | 5f45e7c | 2017-02-10 15:23:28 -0800 | [diff] [blame] | 105 | template class TypedResourceManager<Renderbuffer, HandleAllocator, RenderbufferManager>; |
Jamie Madill | 5f45e7c | 2017-02-10 15:23:28 -0800 | [diff] [blame] | 106 | template class TypedResourceManager<Sampler, HandleAllocator, SamplerManager>; |
Jamie Madill | 70b5bb0 | 2017-08-28 13:32:37 -0400 | [diff] [blame] | 107 | template class TypedResourceManager<Sync, HandleAllocator, SyncManager>; |
Jamie Madill | 5f45e7c | 2017-02-10 15:23:28 -0800 | [diff] [blame] | 108 | template class TypedResourceManager<Framebuffer, HandleAllocator, FramebufferManager>; |
Yunchao He | a336b90 | 2017-08-02 16:05:21 +0800 | [diff] [blame] | 109 | template class TypedResourceManager<ProgramPipeline, HandleAllocator, ProgramPipelineManager>; |
Jamie Madill | 5f45e7c | 2017-02-10 15:23:28 -0800 | [diff] [blame] | 110 | |
| 111 | // BufferManager Implementation. |
| 112 | |
| 113 | // static |
| 114 | Buffer *BufferManager::AllocateNewObject(rx::GLImplFactory *factory, GLuint handle) |
| 115 | { |
| 116 | Buffer *buffer = new Buffer(factory, handle); |
| 117 | buffer->addRef(); |
| 118 | return buffer; |
| 119 | } |
| 120 | |
| 121 | // static |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 122 | void BufferManager::DeleteObject(const Context *context, Buffer *buffer) |
Jamie Madill | 5f45e7c | 2017-02-10 15:23:28 -0800 | [diff] [blame] | 123 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 124 | buffer->release(context); |
Jamie Madill | 5f45e7c | 2017-02-10 15:23:28 -0800 | [diff] [blame] | 125 | } |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 126 | |
| 127 | GLuint BufferManager::createBuffer() |
| 128 | { |
| 129 | return AllocateEmptyObject(&mHandleAllocator, &mObjectMap); |
| 130 | } |
| 131 | |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 132 | Buffer *BufferManager::getBuffer(GLuint handle) const |
| 133 | { |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 134 | return mObjectMap.query(handle); |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 135 | } |
| 136 | |
Jamie Madill | 5f45e7c | 2017-02-10 15:23:28 -0800 | [diff] [blame] | 137 | // ShaderProgramManager Implementation. |
| 138 | |
Jamie Madill | acf2f3a | 2017-11-21 19:22:44 -0500 | [diff] [blame] | 139 | ShaderProgramManager::ShaderProgramManager() |
| 140 | { |
| 141 | } |
| 142 | |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 143 | ShaderProgramManager::~ShaderProgramManager() |
| 144 | { |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 145 | ASSERT(mPrograms.empty()); |
| 146 | ASSERT(mShaders.empty()); |
| 147 | } |
| 148 | |
| 149 | void ShaderProgramManager::reset(const Context *context) |
| 150 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 151 | while (!mPrograms.empty()) |
| 152 | { |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 153 | deleteProgram(context, mPrograms.begin()->first); |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 154 | } |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 155 | mPrograms.clear(); |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 156 | while (!mShaders.empty()) |
| 157 | { |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 158 | deleteShader(context, mShaders.begin()->first); |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 159 | } |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 160 | mShaders.clear(); |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | GLuint ShaderProgramManager::createShader(rx::GLImplFactory *factory, |
| 164 | const gl::Limitations &rendererLimitations, |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 165 | ShaderType type) |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 166 | { |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 167 | ASSERT(type != ShaderType::InvalidEnum); |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 168 | GLuint handle = mHandleAllocator.allocate(); |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 169 | mShaders.assign(handle, new Shader(this, factory, rendererLimitations, type, handle)); |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 170 | return handle; |
| 171 | } |
| 172 | |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 173 | void ShaderProgramManager::deleteShader(const Context *context, GLuint shader) |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 174 | { |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 175 | deleteObject(context, &mShaders, shader); |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 176 | } |
| 177 | |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 178 | Shader *ShaderProgramManager::getShader(GLuint handle) const |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 179 | { |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 180 | return mShaders.query(handle); |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 181 | } |
| 182 | |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 183 | GLuint ShaderProgramManager::createProgram(rx::GLImplFactory *factory) |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 184 | { |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 185 | GLuint handle = mHandleAllocator.allocate(); |
| 186 | mPrograms.assign(handle, new Program(factory, this, handle)); |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 187 | return handle; |
| 188 | } |
| 189 | |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 190 | void ShaderProgramManager::deleteProgram(const gl::Context *context, GLuint program) |
Jamie Madill | dc35604 | 2013-07-19 16:36:57 -0400 | [diff] [blame] | 191 | { |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 192 | deleteObject(context, &mPrograms, program); |
Jamie Madill | dc35604 | 2013-07-19 16:36:57 -0400 | [diff] [blame] | 193 | } |
| 194 | |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 195 | template <typename ObjectType> |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 196 | void ShaderProgramManager::deleteObject(const Context *context, |
| 197 | ResourceMap<ObjectType> *objectMap, |
| 198 | GLuint id) |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 199 | { |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 200 | ObjectType *object = objectMap->query(id); |
| 201 | if (!object) |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 202 | { |
| 203 | return; |
| 204 | } |
| 205 | |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 206 | if (object->getRefCount() == 0) |
| 207 | { |
| 208 | mHandleAllocator.release(id); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 209 | object->onDestroy(context); |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 210 | objectMap->erase(id, &object); |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 211 | } |
| 212 | else |
| 213 | { |
| 214 | object->flagForDeletion(); |
| 215 | } |
| 216 | } |
| 217 | |
Jamie Madill | 5f45e7c | 2017-02-10 15:23:28 -0800 | [diff] [blame] | 218 | // TextureManager Implementation. |
| 219 | |
| 220 | // static |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 221 | Texture *TextureManager::AllocateNewObject(rx::GLImplFactory *factory, |
| 222 | GLuint handle, |
| 223 | TextureType type) |
Jamie Madill | 5f45e7c | 2017-02-10 15:23:28 -0800 | [diff] [blame] | 224 | { |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 225 | Texture *texture = new Texture(factory, handle, type); |
Jamie Madill | 5f45e7c | 2017-02-10 15:23:28 -0800 | [diff] [blame] | 226 | texture->addRef(); |
| 227 | return texture; |
| 228 | } |
| 229 | |
| 230 | // static |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 231 | void TextureManager::DeleteObject(const Context *context, Texture *texture) |
Jamie Madill | 5f45e7c | 2017-02-10 15:23:28 -0800 | [diff] [blame] | 232 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 233 | texture->release(context); |
Jamie Madill | 5f45e7c | 2017-02-10 15:23:28 -0800 | [diff] [blame] | 234 | } |
| 235 | |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 236 | GLuint TextureManager::createTexture() |
| 237 | { |
| 238 | return AllocateEmptyObject(&mHandleAllocator, &mObjectMap); |
| 239 | } |
| 240 | |
Jamie Madill | d444255 | 2018-02-27 22:03:47 -0500 | [diff] [blame] | 241 | void TextureManager::signalAllTexturesDirty(const Context *context) const |
Geoff Lang | 9aded17 | 2017-04-05 11:07:56 -0400 | [diff] [blame] | 242 | { |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 243 | for (const auto &texture : mObjectMap) |
Geoff Lang | 9aded17 | 2017-04-05 11:07:56 -0400 | [diff] [blame] | 244 | { |
| 245 | if (texture.second) |
| 246 | { |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 247 | // We don't know if the Texture needs init, but that's ok, since it will only force |
| 248 | // a re-check, and will not initialize the pixels if it's not needed. |
Jamie Madill | d444255 | 2018-02-27 22:03:47 -0500 | [diff] [blame] | 249 | texture.second->signalDirty(context, InitState::MayNeedInit); |
Geoff Lang | 9aded17 | 2017-04-05 11:07:56 -0400 | [diff] [blame] | 250 | } |
| 251 | } |
| 252 | } |
| 253 | |
Jamie Madill | fc3463d | 2018-01-03 13:46:21 -0500 | [diff] [blame] | 254 | void TextureManager::enableHandleAllocatorLogging() |
| 255 | { |
| 256 | mHandleAllocator.enableLogging(true); |
| 257 | } |
| 258 | |
Jamie Madill | 5f45e7c | 2017-02-10 15:23:28 -0800 | [diff] [blame] | 259 | // RenderbufferManager Implementation. |
| 260 | |
| 261 | // static |
| 262 | Renderbuffer *RenderbufferManager::AllocateNewObject(rx::GLImplFactory *factory, GLuint handle) |
| 263 | { |
Jamie Madill | e703c60 | 2018-02-20 10:21:48 -0500 | [diff] [blame] | 264 | Renderbuffer *renderbuffer = new Renderbuffer(factory, handle); |
Jamie Madill | 5f45e7c | 2017-02-10 15:23:28 -0800 | [diff] [blame] | 265 | renderbuffer->addRef(); |
| 266 | return renderbuffer; |
| 267 | } |
| 268 | |
| 269 | // static |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 270 | void RenderbufferManager::DeleteObject(const Context *context, Renderbuffer *renderbuffer) |
Jamie Madill | 5f45e7c | 2017-02-10 15:23:28 -0800 | [diff] [blame] | 271 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 272 | renderbuffer->release(context); |
Jamie Madill | 5f45e7c | 2017-02-10 15:23:28 -0800 | [diff] [blame] | 273 | } |
| 274 | |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 275 | GLuint RenderbufferManager::createRenderbuffer() |
| 276 | { |
| 277 | return AllocateEmptyObject(&mHandleAllocator, &mObjectMap); |
| 278 | } |
| 279 | |
Yunchao He | a438f4e | 2017-08-04 13:42:39 +0800 | [diff] [blame] | 280 | Renderbuffer *RenderbufferManager::getRenderbuffer(GLuint handle) const |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 281 | { |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 282 | return mObjectMap.query(handle); |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 283 | } |
| 284 | |
Jamie Madill | 5f45e7c | 2017-02-10 15:23:28 -0800 | [diff] [blame] | 285 | // SamplerManager Implementation. |
| 286 | |
| 287 | // static |
| 288 | Sampler *SamplerManager::AllocateNewObject(rx::GLImplFactory *factory, GLuint handle) |
| 289 | { |
| 290 | Sampler *sampler = new Sampler(factory, handle); |
| 291 | sampler->addRef(); |
| 292 | return sampler; |
| 293 | } |
| 294 | |
| 295 | // static |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 296 | void SamplerManager::DeleteObject(const Context *context, Sampler *sampler) |
Jamie Madill | 5f45e7c | 2017-02-10 15:23:28 -0800 | [diff] [blame] | 297 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 298 | sampler->release(context); |
Jamie Madill | 5f45e7c | 2017-02-10 15:23:28 -0800 | [diff] [blame] | 299 | } |
| 300 | |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 301 | GLuint SamplerManager::createSampler() |
| 302 | { |
| 303 | return AllocateEmptyObject(&mHandleAllocator, &mObjectMap); |
| 304 | } |
| 305 | |
Yunchao He | a438f4e | 2017-08-04 13:42:39 +0800 | [diff] [blame] | 306 | Sampler *SamplerManager::getSampler(GLuint handle) const |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 307 | { |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 308 | return mObjectMap.query(handle); |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 309 | } |
| 310 | |
Yunchao He | a438f4e | 2017-08-04 13:42:39 +0800 | [diff] [blame] | 311 | bool SamplerManager::isSampler(GLuint sampler) const |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 312 | { |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 313 | return mObjectMap.contains(sampler); |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 314 | } |
| 315 | |
Jamie Madill | 70b5bb0 | 2017-08-28 13:32:37 -0400 | [diff] [blame] | 316 | // SyncManager Implementation. |
Jamie Madill | 5f45e7c | 2017-02-10 15:23:28 -0800 | [diff] [blame] | 317 | |
| 318 | // static |
Jamie Madill | 70b5bb0 | 2017-08-28 13:32:37 -0400 | [diff] [blame] | 319 | void SyncManager::DeleteObject(const Context *context, Sync *sync) |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 320 | { |
Jamie Madill | 70b5bb0 | 2017-08-28 13:32:37 -0400 | [diff] [blame] | 321 | sync->release(context); |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 322 | } |
| 323 | |
Jamie Madill | 70b5bb0 | 2017-08-28 13:32:37 -0400 | [diff] [blame] | 324 | GLuint SyncManager::createSync(rx::GLImplFactory *factory) |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 325 | { |
Jamie Madill | 70b5bb0 | 2017-08-28 13:32:37 -0400 | [diff] [blame] | 326 | GLuint handle = mHandleAllocator.allocate(); |
| 327 | Sync *sync = new Sync(factory->createSync(), handle); |
| 328 | sync->addRef(); |
| 329 | mObjectMap.assign(handle, sync); |
Jamie Madill | 5f45e7c | 2017-02-10 15:23:28 -0800 | [diff] [blame] | 330 | return handle; |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 331 | } |
| 332 | |
Jamie Madill | 70b5bb0 | 2017-08-28 13:32:37 -0400 | [diff] [blame] | 333 | Sync *SyncManager::getSync(GLuint handle) const |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 334 | { |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 335 | return mObjectMap.query(handle); |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 336 | } |
| 337 | |
Jamie Madill | 5f45e7c | 2017-02-10 15:23:28 -0800 | [diff] [blame] | 338 | // PathManager Implementation. |
| 339 | |
Jamie Madill | 526392d | 2018-11-16 09:35:14 -0500 | [diff] [blame] | 340 | PathManager::PathManager() = default; |
Jamie Madill | acf2f3a | 2017-11-21 19:22:44 -0500 | [diff] [blame] | 341 | |
Jamie Madill | 526392d | 2018-11-16 09:35:14 -0500 | [diff] [blame] | 342 | angle::Result PathManager::createPaths(Context *context, GLsizei range, GLuint *createdOut) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 343 | { |
Jamie Madill | 1395134 | 2018-09-30 15:24:28 -0400 | [diff] [blame] | 344 | *createdOut = 0; |
| 345 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 346 | // Allocate client side handles. |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 347 | const GLuint client = mHandleAllocator.allocateRange(static_cast<GLuint>(range)); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 348 | if (client == HandleRangeAllocator::kInvalidHandle) |
Jamie Madill | 526392d | 2018-11-16 09:35:14 -0500 | [diff] [blame] | 349 | { |
| 350 | context->handleError(GL_OUT_OF_MEMORY, "Failed to allocate path handle range.", __FILE__, |
| 351 | ANGLE_FUNCTION, __LINE__); |
| 352 | return angle::Result::Stop(); |
| 353 | } |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 354 | |
Jamie Madill | 526392d | 2018-11-16 09:35:14 -0500 | [diff] [blame] | 355 | const auto &paths = context->getImplementation()->createPaths(range); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 356 | if (paths.empty()) |
| 357 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 358 | mHandleAllocator.releaseRange(client, range); |
Jamie Madill | 526392d | 2018-11-16 09:35:14 -0500 | [diff] [blame] | 359 | context->handleError(GL_OUT_OF_MEMORY, "Failed to allocate path objects.", __FILE__, |
| 360 | ANGLE_FUNCTION, __LINE__); |
| 361 | return angle::Result::Stop(); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 362 | } |
| 363 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 364 | for (GLsizei i = 0; i < range; ++i) |
| 365 | { |
Jamie Madill | acf2f3a | 2017-11-21 19:22:44 -0500 | [diff] [blame] | 366 | rx::PathImpl *impl = paths[static_cast<unsigned>(i)]; |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 367 | const auto id = client + i; |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 368 | mPaths.assign(id, new Path(impl)); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 369 | } |
Jamie Madill | 1395134 | 2018-09-30 15:24:28 -0400 | [diff] [blame] | 370 | *createdOut = client; |
Jamie Madill | 526392d | 2018-11-16 09:35:14 -0500 | [diff] [blame] | 371 | return angle::Result::Continue(); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 372 | } |
| 373 | |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 374 | void PathManager::deletePaths(GLuint first, GLsizei range) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 375 | { |
| 376 | for (GLsizei i = 0; i < range; ++i) |
| 377 | { |
| 378 | const auto id = first + i; |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 379 | Path *p = nullptr; |
| 380 | if (!mPaths.erase(id, &p)) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 381 | continue; |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 382 | delete p; |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 383 | } |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 384 | mHandleAllocator.releaseRange(first, static_cast<GLuint>(range)); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 385 | } |
| 386 | |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 387 | Path *PathManager::getPath(GLuint handle) const |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 388 | { |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 389 | return mPaths.query(handle); |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 390 | } |
| 391 | |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 392 | bool PathManager::hasPath(GLuint handle) const |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 393 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 394 | return mHandleAllocator.isUsed(handle); |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 395 | } |
| 396 | |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 397 | PathManager::~PathManager() |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 398 | { |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 399 | ASSERT(mPaths.empty()); |
| 400 | } |
| 401 | |
| 402 | void PathManager::reset(const Context *context) |
| 403 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 404 | for (auto path : mPaths) |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 405 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 406 | SafeDelete(path.second); |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 407 | } |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 408 | mPaths.clear(); |
Geoff Lang | f41a715 | 2016-09-19 15:11:17 -0400 | [diff] [blame] | 409 | } |
| 410 | |
Jamie Madill | 5f45e7c | 2017-02-10 15:23:28 -0800 | [diff] [blame] | 411 | // FramebufferManager Implementation. |
| 412 | |
| 413 | // static |
| 414 | Framebuffer *FramebufferManager::AllocateNewObject(rx::GLImplFactory *factory, |
| 415 | GLuint handle, |
| 416 | const Caps &caps) |
Geoff Lang | 3bf8e3a | 2016-12-01 17:28:52 -0500 | [diff] [blame] | 417 | { |
Jamie Madill | 5f45e7c | 2017-02-10 15:23:28 -0800 | [diff] [blame] | 418 | return new Framebuffer(caps, factory, handle); |
| 419 | } |
| 420 | |
| 421 | // static |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 422 | void FramebufferManager::DeleteObject(const Context *context, Framebuffer *framebuffer) |
Jamie Madill | 5f45e7c | 2017-02-10 15:23:28 -0800 | [diff] [blame] | 423 | { |
Geoff Lang | bf7b95d | 2018-05-01 16:48:21 -0400 | [diff] [blame] | 424 | framebuffer->onDestroy(context); |
| 425 | delete framebuffer; |
Geoff Lang | 3bf8e3a | 2016-12-01 17:28:52 -0500 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | GLuint FramebufferManager::createFramebuffer() |
| 429 | { |
Jamie Madill | 5f45e7c | 2017-02-10 15:23:28 -0800 | [diff] [blame] | 430 | return AllocateEmptyObject(&mHandleAllocator, &mObjectMap); |
Geoff Lang | 3bf8e3a | 2016-12-01 17:28:52 -0500 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | Framebuffer *FramebufferManager::getFramebuffer(GLuint handle) const |
| 434 | { |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 435 | return mObjectMap.query(handle); |
Geoff Lang | 3bf8e3a | 2016-12-01 17:28:52 -0500 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | void FramebufferManager::setDefaultFramebuffer(Framebuffer *framebuffer) |
| 439 | { |
| 440 | ASSERT(framebuffer == nullptr || framebuffer->id() == 0); |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 441 | mObjectMap.assign(0, framebuffer); |
Geoff Lang | 3bf8e3a | 2016-12-01 17:28:52 -0500 | [diff] [blame] | 442 | } |
| 443 | |
Jamie Madill | b983a4b | 2018-08-01 11:34:51 -0400 | [diff] [blame] | 444 | void FramebufferManager::invalidateFramebufferComplenessCache(const Context *context) const |
Geoff Lang | 9aded17 | 2017-04-05 11:07:56 -0400 | [diff] [blame] | 445 | { |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 446 | for (const auto &framebuffer : mObjectMap) |
Geoff Lang | 9aded17 | 2017-04-05 11:07:56 -0400 | [diff] [blame] | 447 | { |
| 448 | if (framebuffer.second) |
| 449 | { |
Jamie Madill | b983a4b | 2018-08-01 11:34:51 -0400 | [diff] [blame] | 450 | framebuffer.second->invalidateCompletenessCache(context); |
Geoff Lang | 9aded17 | 2017-04-05 11:07:56 -0400 | [diff] [blame] | 451 | } |
| 452 | } |
| 453 | } |
| 454 | |
Yunchao He | a336b90 | 2017-08-02 16:05:21 +0800 | [diff] [blame] | 455 | // ProgramPipelineManager Implementation. |
| 456 | |
| 457 | // static |
| 458 | ProgramPipeline *ProgramPipelineManager::AllocateNewObject(rx::GLImplFactory *factory, |
| 459 | GLuint handle) |
| 460 | { |
| 461 | ProgramPipeline *pipeline = new ProgramPipeline(factory, handle); |
| 462 | pipeline->addRef(); |
| 463 | return pipeline; |
| 464 | } |
| 465 | |
| 466 | // static |
| 467 | void ProgramPipelineManager::DeleteObject(const Context *context, ProgramPipeline *pipeline) |
| 468 | { |
| 469 | pipeline->release(context); |
| 470 | } |
| 471 | |
| 472 | GLuint ProgramPipelineManager::createProgramPipeline() |
| 473 | { |
| 474 | return AllocateEmptyObject(&mHandleAllocator, &mObjectMap); |
| 475 | } |
| 476 | |
| 477 | ProgramPipeline *ProgramPipelineManager::getProgramPipeline(GLuint handle) const |
| 478 | { |
| 479 | return mObjectMap.query(handle); |
| 480 | } |
| 481 | |
Jamie Madill | 3f01e6c | 2016-03-08 13:53:02 -0500 | [diff] [blame] | 482 | } // namespace gl |