Skip to content

Commit

Permalink
Implement resource management for GL_EXT_memory_object
Browse files Browse the repository at this point in the history
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: Jamie Madill <jmadill@chromium.org>
  • Loading branch information
mspang authored and Commit Bot committed Apr 5, 2019
1 parent 7a8c3e5 commit fb201c5
Show file tree
Hide file tree
Showing 23 changed files with 264 additions and 10 deletions.
34 changes: 30 additions & 4 deletions src/libANGLE/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions src/libANGLE/Context.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class FenceNV;
class Framebuffer;
class GLES1Renderer;
class MemoryProgramCache;
class MemoryObject;
class Program;
class ProgramPipeline;
class Query;
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
30 changes: 30 additions & 0 deletions src/libANGLE/MemoryObject.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// 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
39 changes: 39 additions & 0 deletions src/libANGLE/MemoryObject.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// 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_
48 changes: 48 additions & 0 deletions src/libANGLE/ResourceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
19 changes: 19 additions & 0 deletions src/libANGLE/ResourceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class Context;
class Sync;
class Framebuffer;
struct Limitations;
class MemoryObject;
class Path;
class Program;
class ProgramPipeline;
Expand Down Expand Up @@ -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_
2 changes: 2 additions & 0 deletions src/libANGLE/State.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 2 additions & 0 deletions src/libANGLE/State.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class BufferManager;
struct Caps;
class Context;
class FramebufferManager;
class MemoryObjectManager;
class PathManager;
class ProgramPipelineManager;
class Query;
Expand Down Expand Up @@ -713,6 +714,7 @@ class State : angle::NonCopyable
PathManager *mPathManager;
FramebufferManager *mFramebufferManager;
ProgramPipelineManager *mProgramPipelineManager;
MemoryObjectManager *mMemoryObjectManager;

// Cached values from Context's caps
GLuint mMaxDrawBuffers;
Expand Down
4 changes: 4 additions & 0 deletions src/libANGLE/renderer/GLImplFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class ContextImpl;
class FenceNVImpl;
class SyncImpl;
class FramebufferImpl;
class MemoryObjectImpl;
class PathImpl;
class ProgramImpl;
class ProgramPipelineImpl;
Expand Down Expand Up @@ -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
Expand Down
34 changes: 34 additions & 0 deletions src/libANGLE/renderer/MemoryObjectImpl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// 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_
6 changes: 6 additions & 0 deletions src/libANGLE/renderer/d3d/d3d11/Context11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions src/libANGLE/renderer/d3d/d3d11/Context11.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions src/libANGLE/renderer/d3d/d3d9/Context9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions src/libANGLE/renderer/d3d/d3d9/Context9.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading

0 comments on commit fb201c5

Please sign in to comment.