Commit 8b2dfa0f by Geoff Lang Committed by Commit Bot

GL: Implement EXT_external_objects

This allows the GL backend to import Vulkan resources. BUG=angleproject:3656 Change-Id: Ie5e55ce3e1ba05e917619e3f192c13dcc36c3739 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1688507Reviewed-by: 's avatarShahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: 's avatarClemen Deng <clemendeng@google.com> Commit-Queue: Geoff Lang <geofflang@chromium.org>
parent 5c6a6cb6
......@@ -505,14 +505,18 @@ using TransformFeedbackBuffersArray =
std::array<T, gl::IMPLEMENTATION_MAX_TRANSFORM_FEEDBACK_BUFFERS>;
constexpr size_t kBarrierVectorDefaultSize = 16;
using BufferBarrierVector = angle::FastVector<Buffer *, kBarrierVectorDefaultSize>;
template <typename T>
using BarrierVector = angle::FastVector<T, kBarrierVectorDefaultSize>;
using BufferBarrierVector = BarrierVector<Buffer *>;
struct TextureAndLayout
{
Texture *texture;
GLenum layout;
};
using TextureBarrierVector = angle::FastVector<TextureAndLayout, kBarrierVectorDefaultSize>;
using TextureBarrierVector = BarrierVector<TextureAndLayout>;
// OffsetBindingPointer.getSize() returns the size specified by the user, which may be larger than
// the size of the bound buffer. This function reduces the returned size to fit the bound buffer if
......
......@@ -15,6 +15,7 @@
#include "libANGLE/renderer/gl/FenceNVGL.h"
#include "libANGLE/renderer/gl/FramebufferGL.h"
#include "libANGLE/renderer/gl/FunctionsGL.h"
#include "libANGLE/renderer/gl/MemoryObjectGL.h"
#include "libANGLE/renderer/gl/PathGL.h"
#include "libANGLE/renderer/gl/ProgramGL.h"
#include "libANGLE/renderer/gl/ProgramPipelineGL.h"
......@@ -22,6 +23,7 @@
#include "libANGLE/renderer/gl/RenderbufferGL.h"
#include "libANGLE/renderer/gl/RendererGL.h"
#include "libANGLE/renderer/gl/SamplerGL.h"
#include "libANGLE/renderer/gl/SemaphoreGL.h"
#include "libANGLE/renderer/gl/ShaderGL.h"
#include "libANGLE/renderer/gl/StateManagerGL.h"
#include "libANGLE/renderer/gl/SyncGL.h"
......@@ -170,14 +172,22 @@ std::vector<PathImpl *> ContextGL::createPaths(GLsizei range)
MemoryObjectImpl *ContextGL::createMemoryObject()
{
UNREACHABLE();
return nullptr;
const FunctionsGL *functions = getFunctions();
GLuint memoryObject = 0;
functions->createMemoryObjectsEXT(1, &memoryObject);
return new MemoryObjectGL(memoryObject);
}
SemaphoreImpl *ContextGL::createSemaphore()
{
UNREACHABLE();
return nullptr;
const FunctionsGL *functions = getFunctions();
GLuint semaphore = 0;
functions->genSemaphoresEXT(1, &semaphore);
return new SemaphoreGL(semaphore);
}
angle::Result ContextGL::flush(const gl::Context *context)
......
// Copyright 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.
//
#include "libANGLE/renderer/gl/MemoryObjectGL.h"
#include "libANGLE/Context.h"
#include "libANGLE/renderer/gl/ContextGL.h"
#include "libANGLE/renderer/gl/FunctionsGL.h"
#include "libANGLE/renderer/gl/renderergl_utils.h"
namespace rx
{
MemoryObjectGL::MemoryObjectGL(GLuint memoryObject) : mMemoryObject(memoryObject)
{
ASSERT(mMemoryObject != 0);
}
MemoryObjectGL::~MemoryObjectGL()
{
ASSERT(mMemoryObject == 0);
}
void MemoryObjectGL::onDestroy(const gl::Context *context)
{
const FunctionsGL *functions = GetFunctionsGL(context);
functions->deleteMemoryObjectsEXT(1, &mMemoryObject);
mMemoryObject = 0;
}
angle::Result MemoryObjectGL::importFd(gl::Context *context,
GLuint64 size,
gl::HandleType handleType,
GLint fd)
{
const FunctionsGL *functions = GetFunctionsGL(context);
functions->importMemoryFdEXT(mMemoryObject, size, ToGLenum(handleType), fd);
return angle::Result::Continue;
}
GLuint MemoryObjectGL::getMemoryObjectID() const
{
return mMemoryObject;
}
} // namespace rx
// Copyright 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.
//
// MemoryObjectGL.h: Defines the class interface for MemoryObjectGL,
// implementing MemoryObjectImpl.
#ifndef LIBANGLE_RENDERER_GL_MEMORYOBJECTGL_H_
#define LIBANGLE_RENDERER_GL_MEMORYOBJECTGL_H_
#include "libANGLE/renderer/MemoryObjectImpl.h"
namespace rx
{
class MemoryObjectGL : public MemoryObjectImpl
{
public:
MemoryObjectGL(GLuint memoryObject);
~MemoryObjectGL() override;
void onDestroy(const gl::Context *context) override;
angle::Result importFd(gl::Context *context,
GLuint64 size,
gl::HandleType handleType,
GLint fd) override;
GLuint getMemoryObjectID() const;
private:
GLuint mMemoryObject;
};
} // namespace rx
#endif // LIBANGLE_RENDERER_GL_MEMORYOBJECTGL_H_
//
// Copyright 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.
//
#include "libANGLE/renderer/gl/SemaphoreGL.h"
#include "libANGLE/Context.h"
#include "libANGLE/renderer/gl/BufferGL.h"
#include "libANGLE/renderer/gl/ContextGL.h"
#include "libANGLE/renderer/gl/FunctionsGL.h"
#include "libANGLE/renderer/gl/TextureGL.h"
#include "libANGLE/renderer/gl/renderergl_utils.h"
namespace rx
{
namespace
{
void GatherNativeBufferIDs(const gl::BufferBarrierVector &bufferBarriers,
gl::BarrierVector<GLuint> *outIDs)
{
outIDs->resize(bufferBarriers.size());
for (GLuint bufferIdx = 0; bufferIdx < bufferBarriers.size(); bufferIdx++)
{
(*outIDs)[bufferIdx] = GetImplAs<BufferGL>(bufferBarriers[bufferIdx])->getBufferID();
}
}
void GatherNativeTextureIDs(const gl::TextureBarrierVector &textureBarriers,
gl::BarrierVector<GLuint> *outIDs,
gl::BarrierVector<GLenum> *outLayouts)
{
outIDs->resize(textureBarriers.size());
outLayouts->resize(textureBarriers.size());
for (GLuint textureIdx = 0; textureIdx < textureBarriers.size(); textureIdx++)
{
(*outIDs)[textureIdx] =
GetImplAs<TextureGL>(textureBarriers[textureIdx].texture)->getTextureID();
(*outLayouts)[textureIdx] = textureBarriers[textureIdx].layout;
}
}
} // anonymous namespace
SemaphoreGL::SemaphoreGL(GLuint semaphoreID) : mSemaphoreID(semaphoreID)
{
ASSERT(mSemaphoreID != 0);
}
SemaphoreGL::~SemaphoreGL()
{
ASSERT(mSemaphoreID == 0);
}
void SemaphoreGL::onDestroy(const gl::Context *context)
{
const FunctionsGL *functions = GetFunctionsGL(context);
functions->deleteSemaphoresEXT(1, &mSemaphoreID);
mSemaphoreID = 0;
}
angle::Result SemaphoreGL::importFd(gl::Context *context, gl::HandleType handleType, GLint fd)
{
const FunctionsGL *functions = GetFunctionsGL(context);
functions->importSemaphoreFdEXT(mSemaphoreID, ToGLenum(handleType), fd);
return angle::Result::Continue;
}
angle::Result SemaphoreGL::wait(gl::Context *context,
const gl::BufferBarrierVector &bufferBarriers,
const gl::TextureBarrierVector &textureBarriers)
{
const FunctionsGL *functions = GetFunctionsGL(context);
gl::BarrierVector<GLuint> bufferIDs(bufferBarriers.size());
GatherNativeBufferIDs(bufferBarriers, &bufferIDs);
gl::BarrierVector<GLuint> textureIDs(textureBarriers.size());
gl::BarrierVector<GLenum> textureLayouts(textureBarriers.size());
GatherNativeTextureIDs(textureBarriers, &textureIDs, &textureLayouts);
ASSERT(textureIDs.size() == textureLayouts.size());
functions->waitSemaphoreEXT(mSemaphoreID, bufferIDs.size(), bufferIDs.data(), textureIDs.size(),
textureIDs.data(), textureLayouts.data());
return angle::Result::Continue;
}
angle::Result SemaphoreGL::signal(gl::Context *context,
const gl::BufferBarrierVector &bufferBarriers,
const gl::TextureBarrierVector &textureBarriers)
{
const FunctionsGL *functions = GetFunctionsGL(context);
gl::BarrierVector<GLuint> bufferIDs(bufferBarriers.size());
GatherNativeBufferIDs(bufferBarriers, &bufferIDs);
gl::BarrierVector<GLuint> textureIDs(textureBarriers.size());
gl::BarrierVector<GLenum> textureLayouts(textureBarriers.size());
GatherNativeTextureIDs(textureBarriers, &textureIDs, &textureLayouts);
ASSERT(textureIDs.size() == textureLayouts.size());
functions->signalSemaphoreEXT(mSemaphoreID, bufferIDs.size(), bufferIDs.data(),
textureIDs.size(), textureIDs.data(), textureLayouts.data());
return angle::Result::Continue;
}
GLuint SemaphoreGL::getSemaphoreID() const
{
return mSemaphoreID;
}
} // namespace rx
//
// Copyright 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.
//
// SempahoreGL.h: Defines the rx::SempahoreGL class, an implementation of SemaphoreImpl.
#ifndef LIBANGLE_RENDERER_GL_SEMAPHOREGL_H_
#define LIBANGLE_RENDERER_GL_SEMAPHOREGL_H_
#include "libANGLE/angletypes.h"
#include "libANGLE/renderer/SemaphoreImpl.h"
namespace rx
{
class SemaphoreGL : public SemaphoreImpl
{
public:
SemaphoreGL(GLuint semaphoreID);
~SemaphoreGL() override;
void onDestroy(const gl::Context *context) override;
angle::Result importFd(gl::Context *context, gl::HandleType handleType, GLint fd) override;
angle::Result wait(gl::Context *context,
const gl::BufferBarrierVector &bufferBarriers,
const gl::TextureBarrierVector &textureBarriers) override;
angle::Result signal(gl::Context *context,
const gl::BufferBarrierVector &bufferBarriers,
const gl::TextureBarrierVector &textureBarriers) override;
GLuint getSemaphoreID() const;
private:
GLuint mSemaphoreID;
};
} // namespace rx
#endif // LIBANGLE_RENDERER_GL_SEMAPHOREGL_H_
......@@ -12,6 +12,7 @@
#include "common/debug.h"
#include "common/utilities.h"
#include "libANGLE/Context.h"
#include "libANGLE/MemoryObject.h"
#include "libANGLE/State.h"
#include "libANGLE/angletypes.h"
#include "libANGLE/formatutils.h"
......@@ -22,6 +23,7 @@
#include "libANGLE/renderer/gl/FramebufferGL.h"
#include "libANGLE/renderer/gl/FunctionsGL.h"
#include "libANGLE/renderer/gl/ImageGL.h"
#include "libANGLE/renderer/gl/MemoryObjectGL.h"
#include "libANGLE/renderer/gl/StateManagerGL.h"
#include "libANGLE/renderer/gl/formatutilsgl.h"
#include "libANGLE/renderer/gl/renderergl_utils.h"
......@@ -1109,8 +1111,34 @@ angle::Result TextureGL::setStorageExternalMemory(const gl::Context *context,
gl::MemoryObject *memoryObject,
GLuint64 offset)
{
ANGLE_GL_UNREACHABLE(GetImplAs<ContextGL>(context));
return angle::Result::Stop;
const FunctionsGL *functions = GetFunctionsGL(context);
StateManagerGL *stateManager = GetStateManagerGL(context);
const angle::FeaturesGL &features = GetFeaturesGL(context);
MemoryObjectGL *memoryObjectGL = GetImplAs<MemoryObjectGL>(memoryObject);
nativegl::TexStorageFormat texStorageFormat =
nativegl::GetTexStorageFormat(functions, features, internalFormat);
stateManager->bindTexture(getType(), mTextureID);
if (nativegl::UseTexImage2D(getType()))
{
functions->texStorageMem2DEXT(ToGLenum(type), levels, texStorageFormat.internalFormat,
size.width, size.height, memoryObjectGL->getMemoryObjectID(),
offset);
}
else
{
ASSERT(nativegl::UseTexImage3D(getType()));
functions->texStorageMem3DEXT(ToGLenum(type), levels, texStorageFormat.internalFormat,
size.width, size.height, size.depth,
memoryObjectGL->getMemoryObjectID(), offset);
}
setLevelInfo(context, type, 0, levels,
GetLevelInfo(internalFormat, texStorageFormat.internalFormat));
return angle::Result::Continue;
}
angle::Result TextureGL::setImageExternal(const gl::Context *context,
......
......@@ -1425,6 +1425,15 @@ void GenerateCaps(const FunctionsGL *functions,
extensions->texture3DOES = functions->isAtLeastGL(gl::Version(1, 2)) ||
functions->isAtLeastGLES(gl::Version(3, 0)) ||
functions->hasGLESExtension("GL_OES_texture_3D");
extensions->memoryObject = functions->hasGLExtension("GL_EXT_memory_object") ||
functions->hasGLESExtension("GL_EXT_memory_object");
extensions->semaphore = functions->hasGLExtension("GL_EXT_semaphore") ||
functions->hasGLESExtension("GL_EXT_semaphore");
extensions->memoryObjectFd = functions->hasGLExtension("GL_EXT_memory_object_fd") ||
functions->hasGLESExtension("GL_EXT_memory_object_fd");
extensions->semaphoreFd = functions->hasGLExtension("GL_EXT_semaphore_fd") ||
functions->hasGLESExtension("GL_EXT_semaphore_fd");
}
void InitializeFeatures(const FunctionsGL *functions, angle::FeaturesGL *features)
......
......@@ -691,6 +691,8 @@ libangle_gl_sources = [
"src/libANGLE/renderer/gl/FunctionsGL.h",
"src/libANGLE/renderer/gl/ImageGL.cpp",
"src/libANGLE/renderer/gl/ImageGL.h",
"src/libANGLE/renderer/gl/MemoryObjectGL.cpp",
"src/libANGLE/renderer/gl/MemoryObjectGL.h",
"src/libANGLE/renderer/gl/PathGL.h",
"src/libANGLE/renderer/gl/PathGL.cpp",
"src/libANGLE/renderer/gl/ProgramGL.cpp",
......@@ -705,6 +707,8 @@ libangle_gl_sources = [
"src/libANGLE/renderer/gl/RendererGL.h",
"src/libANGLE/renderer/gl/SamplerGL.cpp",
"src/libANGLE/renderer/gl/SamplerGL.h",
"src/libANGLE/renderer/gl/SemaphoreGL.cpp",
"src/libANGLE/renderer/gl/SemaphoreGL.h",
"src/libANGLE/renderer/gl/ShaderGL.cpp",
"src/libANGLE/renderer/gl/ShaderGL.h",
"src/libANGLE/renderer/gl/StateManagerGL.cpp",
......
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