Commit fb201c5e by Michael Spang Committed by Commit Bot

Implement resource management for GL_EXT_memory_object

This implements glCreateMemoryObjectsEXT, glDeleteMemoryObjectsEXT, and glIsMemoryObjectEXT. It's not possible to do anything useful with them yet. Bug: angleproject:3289 Change-Id: I8882b657e9de564b5f97f8dea87838f67b1928f8 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1552025 Commit-Queue: Michael Spang <spang@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 7a8c3e5e
......@@ -26,6 +26,7 @@
#include "libANGLE/Fence.h"
#include "libANGLE/Framebuffer.h"
#include "libANGLE/FramebufferAttachment.h"
#include "libANGLE/MemoryObject.h"
#include "libANGLE/Path.h"
#include "libANGLE/Program.h"
#include "libANGLE/ProgramPipeline.h"
......@@ -727,6 +728,11 @@ GLuint Context::createShaderProgramv(ShaderType type, GLsizei count, const GLcha
return 0u;
}
GLuint Context::createMemoryObject()
{
return mState.mMemoryObjectManager->createMemoryObject(mImplementation.get());
}
void Context::deleteBuffer(GLuint bufferName)
{
Buffer *buffer = mState.mBufferManager->getBuffer(bufferName);
......@@ -787,6 +793,11 @@ void Context::deleteProgramPipeline(GLuint pipeline)
mState.mProgramPipelineManager->deleteObject(this, pipeline);
}
void Context::deleteMemoryObject(GLuint memoryObject)
{
mState.mMemoryObjectManager->deleteMemoryObject(this, memoryObject);
}
void Context::deletePaths(GLuint first, GLsizei range)
{
mState.mPathManager->deletePaths(first, range);
......@@ -5682,6 +5693,11 @@ void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
UNIMPLEMENTED();
}
MemoryObject *Context::getMemoryObject(GLuint handle) const
{
return mState.mMemoryObjectManager->getMemoryObject(handle);
}
void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
{
Program *programObject = getProgramResolveLink(program);
......@@ -7099,18 +7115,28 @@ GLboolean Context::testFenceNV(GLuint fence)
void Context::deleteMemoryObjects(GLsizei n, const GLuint *memoryObjects)
{
UNIMPLEMENTED();
for (int i = 0; i < n; i++)
{
deleteMemoryObject(memoryObjects[i]);
}
}
GLboolean Context::isMemoryObject(GLuint memoryObject)
{
UNIMPLEMENTED();
return GL_FALSE;
if (memoryObject == 0)
{
return GL_FALSE;
}
return (getMemoryObject(memoryObject) ? GL_TRUE : GL_FALSE);
}
void Context::createMemoryObjects(GLsizei n, GLuint *memoryObjects)
{
UNIMPLEMENTED();
for (int i = 0; i < n; i++)
{
memoryObjects[i] = createMemoryObject();
}
}
void Context::memoryObjectParameteriv(GLuint memoryObject, GLenum pname, const GLint *params)
......
......@@ -53,6 +53,7 @@ class FenceNV;
class Framebuffer;
class GLES1Renderer;
class MemoryProgramCache;
class MemoryObject;
class Program;
class ProgramPipeline;
class Query;
......@@ -312,6 +313,7 @@ class Context final : public egl::LabeledObject, angle::NonCopyable, public angl
GLuint genPaths(GLsizei range);
GLuint createProgramPipeline();
GLuint createShaderProgramv(ShaderType type, GLsizei count, const GLchar *const *strings);
GLuint createMemoryObject();
void deleteBuffer(GLuint buffer);
void deleteShader(GLuint shader);
......@@ -320,6 +322,7 @@ class Context final : public egl::LabeledObject, angle::NonCopyable, public angl
void deleteRenderbuffer(GLuint renderbuffer);
void deletePaths(GLuint first, GLsizei range);
void deleteProgramPipeline(GLuint pipeline);
void deleteMemoryObject(GLuint memoryObject);
// CHROMIUM_path_rendering
bool isPath(GLuint path) const;
......@@ -649,6 +652,7 @@ class Context final : public egl::LabeledObject, angle::NonCopyable, public angl
Query *getQuery(GLuint handle) const;
TransformFeedback *getTransformFeedback(GLuint handle) const;
ProgramPipeline *getProgramPipeline(GLuint handle) const;
MemoryObject *getMemoryObject(GLuint handle) const;
void objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label);
void objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label);
......
//
// Copyright 2019 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.
//
// MemoryObject.h: Implements the gl::MemoryObject class [EXT_external_objects]
#include "libANGLE/MemoryObject.h"
#include "common/angleutils.h"
#include "libANGLE/renderer/GLImplFactory.h"
#include "libANGLE/renderer/MemoryObjectImpl.h"
namespace gl
{
MemoryObject::MemoryObject(rx::GLImplFactory *factory, GLuint id)
: RefCountObject(id), mImplementation(factory->createMemoryObject())
{}
MemoryObject::~MemoryObject()
{
}
void MemoryObject::onDestroy(const Context *context)
{
mImplementation->onDestroy(context);
}
} // namespace gl
//
// Copyright 2019 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.
//
// MemoryObject.h: Defines the gl::MemoryObject class [EXT_external_objects]
#ifndef LIBANGLE_MEMORYOBJECT_H_
#define LIBANGLE_MEMORYOBJECT_H_
#include "angle_gl.h"
#include "common/angleutils.h"
#include "libANGLE/Error.h"
#include "libANGLE/RefCountObject.h"
namespace rx
{
class GLImplFactory;
class MemoryObjectImpl;
} // namespace rx
namespace gl
{
class MemoryObject final : public RefCountObject
{
public:
MemoryObject(rx::GLImplFactory *factory, GLuint id);
~MemoryObject() override;
void onDestroy(const Context *context) override;
private:
std::unique_ptr<rx::MemoryObjectImpl> mImplementation;
};
} // namespace gl
#endif // LIBANGLE_MEMORYOBJECT_H_
......@@ -12,6 +12,7 @@
#include "libANGLE/Buffer.h"
#include "libANGLE/Context.h"
#include "libANGLE/Fence.h"
#include "libANGLE/MemoryObject.h"
#include "libANGLE/Path.h"
#include "libANGLE/Program.h"
#include "libANGLE/ProgramPipeline.h"
......@@ -476,4 +477,51 @@ ProgramPipeline *ProgramPipelineManager::getProgramPipeline(GLuint handle) const
return mObjectMap.query(handle);
}
// MemoryObjectManager Implementation.
MemoryObjectManager::MemoryObjectManager() {}
MemoryObjectManager::~MemoryObjectManager()
{
ASSERT(mMemoryObjects.empty());
}
void MemoryObjectManager::reset(const Context *context)
{
while (!mMemoryObjects.empty())
{
deleteMemoryObject(context, mMemoryObjects.begin()->first);
}
mMemoryObjects.clear();
}
GLuint MemoryObjectManager::createMemoryObject(rx::GLImplFactory *factory)
{
GLuint handle = mHandleAllocator.allocate();
mMemoryObjects.assign(handle, new MemoryObject(factory, handle));
return handle;
}
void MemoryObjectManager::deleteMemoryObject(const Context *context, GLuint handle)
{
MemoryObject *memoryObject = nullptr;
if (!mMemoryObjects.erase(handle, &memoryObject))
{
return;
}
// Requires an explicit this-> because of C++ template rules.
this->mHandleAllocator.release(handle);
if (memoryObject)
{
memoryObject->release(context);
}
}
MemoryObject *MemoryObjectManager::getMemoryObject(GLuint handle) const
{
return mMemoryObjects.query(handle);
}
} // namespace gl
......@@ -30,6 +30,7 @@ class Context;
class Sync;
class Framebuffer;
struct Limitations;
class MemoryObject;
class Path;
class Program;
class ProgramPipeline;
......@@ -304,6 +305,24 @@ class ProgramPipelineManager
~ProgramPipelineManager() override {}
};
class MemoryObjectManager : public ResourceManagerBase<HandleAllocator>
{
public:
MemoryObjectManager();
GLuint createMemoryObject(rx::GLImplFactory *factory);
void deleteMemoryObject(const Context *context, GLuint handle);
MemoryObject *getMemoryObject(GLuint handle) const;
protected:
~MemoryObjectManager() override;
private:
void reset(const Context *context) override;
ResourceMap<MemoryObject> mMemoryObjects;
};
} // namespace gl
#endif // LIBANGLE_RESOURCEMANAGER_H_
......@@ -256,6 +256,8 @@ State::State(ContextID contextIn,
mPathManager(AllocateOrGetSharedResourceManager(shareContextState, &State::mPathManager)),
mFramebufferManager(new FramebufferManager()),
mProgramPipelineManager(new ProgramPipelineManager()),
mMemoryObjectManager(
AllocateOrGetSharedResourceManager(shareContextState, &State::mMemoryObjectManager)),
mMaxDrawBuffers(0),
mMaxCombinedTextureImageUnits(0),
mDepthClearValue(0),
......
......@@ -34,6 +34,7 @@ class BufferManager;
struct Caps;
class Context;
class FramebufferManager;
class MemoryObjectManager;
class PathManager;
class ProgramPipelineManager;
class Query;
......@@ -713,6 +714,7 @@ class State : angle::NonCopyable
PathManager *mPathManager;
FramebufferManager *mFramebufferManager;
ProgramPipelineManager *mProgramPipelineManager;
MemoryObjectManager *mMemoryObjectManager;
// Cached values from Context's caps
GLuint mMaxDrawBuffers;
......
......@@ -35,6 +35,7 @@ class ContextImpl;
class FenceNVImpl;
class SyncImpl;
class FramebufferImpl;
class MemoryObjectImpl;
class PathImpl;
class ProgramImpl;
class ProgramPipelineImpl;
......@@ -88,6 +89,9 @@ class GLImplFactory : angle::NonCopyable
virtual ProgramPipelineImpl *createProgramPipeline(const gl::ProgramPipelineState &data) = 0;
virtual std::vector<PathImpl *> createPaths(GLsizei range) = 0;
// Memory object creation
virtual MemoryObjectImpl *createMemoryObject() = 0;
};
} // namespace rx
......
//
// Copyright 2019 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.
//
// MemoryObjectImpl.h: Implements the rx::MemoryObjectImpl class [EXT_external_objects]
#ifndef LIBANGLE_RENDERER_MEMORYOBJECTIMPL_H_
#define LIBANGLE_RENDERER_MEMORYOBJECTIMPL_H_
#include "angle_gl.h"
#include "common/angleutils.h"
#include "libANGLE/Error.h"
namespace gl
{
class Context;
class MemoryObject;
} // namespace gl
namespace rx
{
class MemoryObjectImpl : angle::NonCopyable
{
public:
virtual ~MemoryObjectImpl() {}
virtual void onDestroy(const gl::Context *context) = 0;
};
} // namespace rx
#endif // LIBANGLE_RENDERER_MEMORYOBJECTIMPL_H_
......@@ -231,6 +231,12 @@ std::vector<PathImpl *> Context11::createPaths(GLsizei)
return std::vector<PathImpl *>();
}
MemoryObjectImpl *Context11::createMemoryObject()
{
UNREACHABLE();
return nullptr;
}
angle::Result Context11::flush(const gl::Context *context)
{
return mRenderer->flush(this);
......
......@@ -65,6 +65,9 @@ class Context11 : public ContextD3D, public MultisampleTextureInitializer
// Path object creation.
std::vector<PathImpl *> createPaths(GLsizei) override;
// Memory object creation.
MemoryObjectImpl *createMemoryObject() override;
// Flush and finish.
angle::Result flush(const gl::Context *context) override;
angle::Result finish(const gl::Context *context) override;
......
......@@ -133,6 +133,12 @@ std::vector<PathImpl *> Context9::createPaths(GLsizei)
return std::vector<PathImpl *>();
}
MemoryObjectImpl *Context9::createMemoryObject()
{
UNREACHABLE();
return nullptr;
}
angle::Result Context9::flush(const gl::Context *context)
{
return mRenderer->flush(context);
......
......@@ -64,6 +64,9 @@ class Context9 : public ContextD3D
// Path object creation
std::vector<PathImpl *> createPaths(GLsizei) override;
// Memory object creation.
MemoryObjectImpl *createMemoryObject() override;
// Flush and finish.
angle::Result flush(const gl::Context *context) override;
angle::Result finish(const gl::Context *context) override;
......
......@@ -168,6 +168,12 @@ std::vector<PathImpl *> ContextGL::createPaths(GLsizei range)
return ret;
}
MemoryObjectImpl *ContextGL::createMemoryObject()
{
UNREACHABLE();
return nullptr;
}
angle::Result ContextGL::flush(const gl::Context *context)
{
return mRenderer->flush();
......
......@@ -75,6 +75,9 @@ class ContextGL : public ContextImpl
// Path object creation
std::vector<PathImpl *> createPaths(GLsizei range) override;
// Memory object creation.
MemoryObjectImpl *createMemoryObject() override;
// Flush and finish.
angle::Result flush(const gl::Context *context) override;
angle::Result finish(const gl::Context *context) override;
......
......@@ -392,6 +392,12 @@ std::vector<PathImpl *> ContextNULL::createPaths(GLsizei range)
return result;
}
MemoryObjectImpl *ContextNULL::createMemoryObject()
{
UNREACHABLE();
return nullptr;
}
angle::Result ContextNULL::dispatchCompute(const gl::Context *context,
GLuint numGroupsX,
GLuint numGroupsY,
......
......@@ -198,6 +198,9 @@ class ContextNULL : public ContextImpl
std::vector<PathImpl *> createPaths(GLsizei range) override;
// Memory object creation.
MemoryObjectImpl *createMemoryObject() override;
angle::Result dispatchCompute(const gl::Context *context,
GLuint numGroupsX,
GLuint numGroupsY,
......
......@@ -1112,6 +1112,12 @@ std::vector<PathImpl *> ContextVk::createPaths(GLsizei)
return std::vector<PathImpl *>();
}
MemoryObjectImpl *ContextVk::createMemoryObject()
{
UNIMPLEMENTED();
return nullptr;
}
void ContextVk::invalidateCurrentTextures()
{
ASSERT(mProgram);
......
......@@ -155,6 +155,9 @@ class ContextVk : public ContextImpl, public vk::Context, public vk::CommandBuff
// Path object creation
std::vector<PathImpl *> createPaths(GLsizei) override;
// Memory object creation.
MemoryObjectImpl *createMemoryObject() override;
angle::Result dispatchCompute(const gl::Context *context,
GLuint numGroupsX,
GLuint numGroupsY,
......
......@@ -3057,8 +3057,7 @@ bool ValidateCreateMemoryObjectsEXT(Context *context, GLsizei n, GLuint *memoryO
return false;
}
UNIMPLEMENTED();
return false;
return ValidateGenOrDelete(context, n);
}
bool ValidateDeleteMemoryObjectsEXT(Context *context, GLsizei n, const GLuint *memoryObjects)
......@@ -3069,8 +3068,7 @@ bool ValidateDeleteMemoryObjectsEXT(Context *context, GLsizei n, const GLuint *m
return false;
}
UNIMPLEMENTED();
return false;
return ValidateGenOrDelete(context, n);
}
bool ValidateGetMemoryObjectParameterivEXT(Context *context,
......@@ -3120,8 +3118,7 @@ bool ValidateIsMemoryObjectEXT(Context *context, GLuint memoryObject)
return false;
}
UNIMPLEMENTED();
return false;
return true;
}
bool ValidateMemoryObjectParameterivEXT(Context *context,
......
......@@ -213,6 +213,8 @@ libangle_sources = [
"src/libANGLE/IndexRangeCache.h",
"src/libANGLE/LoggingAnnotator.cpp",
"src/libANGLE/LoggingAnnotator.h",
"src/libANGLE/MemoryObject.cpp",
"src/libANGLE/MemoryObject.h",
"src/libANGLE/MemoryProgramCache.cpp",
"src/libANGLE/MemoryProgramCache.h",
"src/libANGLE/Observer.cpp",
......@@ -298,6 +300,7 @@ libangle_sources = [
"src/libANGLE/renderer/FramebufferImpl.h",
"src/libANGLE/renderer/GLImplFactory.h",
"src/libANGLE/renderer/ImageImpl.h",
"src/libANGLE/renderer/MemoryObjectImpl.h",
"src/libANGLE/renderer/PathImpl.h",
"src/libANGLE/renderer/ProgramImpl.h",
"src/libANGLE/renderer/ProgramPipelineImpl.h",
......
......@@ -88,6 +88,7 @@ class MockGLFactory : public GLImplFactory
MOCK_METHOD1(createProgram, ProgramImpl *(const gl::ProgramState &));
MOCK_METHOD1(createProgramPipeline, ProgramPipelineImpl *(const gl::ProgramPipelineState &));
MOCK_METHOD1(createFramebuffer, FramebufferImpl *(const gl::FramebufferState &));
MOCK_METHOD0(createMemoryObject, MemoryObjectImpl *());
MOCK_METHOD1(createTexture, TextureImpl *(const gl::TextureState &));
MOCK_METHOD1(createRenderbuffer, RenderbufferImpl *(const gl::RenderbufferState &));
MOCK_METHOD1(createBuffer, BufferImpl *(const gl::BufferState &));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment