Commit 29bb612e by Charlie Lao Committed by Commit Bot

Add egl::ShareGroup class to abstract the share context group

Vulkan backend has a barrier tracker that tracks memory barrier needs of all shared resources. Because the buffer/texture objects are shared resources within a shared group, the tracker can not live in a context. Putting it in a device/renderer requires locks. It fits perfectly in a shareGroup object. The work is already done at API level to handle the mutex lock for shared context access so that no extra lock needs to be taken in the backend. This CL adds egl::ShareGroup class that represents the object that are shared among all share context group. At the front end this usually will include all the shared resource managers (not done in this CL). The ShareGroup object is accessible from gl::State object. This CL also adds ability for backend driver to allocate implementation specific ShareGroupImpl object. Vulkan backend will then use it to keeps the barrier tracker and other things that naturally fits the share group concept. Bug: angleproject:4664 Change-Id: Ifcd975cbdf5130022e21c41397894afc28f572e7 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2217252Reviewed-by: 's avatarCourtney Goeltzenleuchter <courtneygo@google.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Charlie Lao <cclao@google.com>
parent 209cf8fa
......@@ -50,6 +50,20 @@ namespace gl
{
namespace
{
egl::ShareGroup *AllocateOrGetShareGroup(egl::Display *display, const gl::Context *shareContext)
{
if (shareContext)
{
egl::ShareGroup *shareGroup = shareContext->getState().getShareGroup();
shareGroup->addRef();
return shareGroup;
}
else
{
return new egl::ShareGroup(display->getImplementation());
}
}
template <typename T>
angle::Result GetQueryObjectParameter(const Context *context, Query *query, GLenum pname, T *params)
{
......@@ -256,6 +270,7 @@ Context::Context(egl::Display *display,
const egl::DisplayExtensions &displayExtensions,
const egl::ClientExtensions &clientExtensions)
: mState(shareContext ? &shareContext->mState : nullptr,
AllocateOrGetShareGroup(display, shareContext),
shareTextures,
&mOverlay,
clientType,
......@@ -584,6 +599,7 @@ egl::Error Context::onDestroy(const egl::Display *display)
mState.mFramebufferManager->release(this);
mState.mMemoryObjectManager->release(this);
mState.mSemaphoreManager->release(this);
mState.mShareGroup->release(this);
mThreadPool.reset();
......
......@@ -421,6 +421,31 @@ static constexpr uint32_t kScratchBufferLifetime = 64u;
} // anonymous namespace
// ShareGroup
ShareGroup::ShareGroup(rx::EGLImplFactory *factory)
: mRefCount(1), mImplementation(factory->createShareGroup())
{}
ShareGroup::~ShareGroup()
{
SafeDelete(mImplementation);
}
void ShareGroup::addRef()
{
// This is protected by global lock, so no atomic is required
mRefCount++;
}
void ShareGroup::release(const gl::Context *context)
{
if (--mRefCount == 0)
{
delete this;
}
}
// DisplayState
DisplayState::DisplayState(EGLNativeDisplayType nativeDisplayId)
: label(nullptr), featuresAllDisabled(false), displayId(nativeDisplayId)
{}
......
......@@ -36,7 +36,9 @@ class TextureManager;
namespace rx
{
class DisplayImpl;
}
class EGLImplFactory;
class ShareGroupImpl;
} // namespace rx
namespace egl
{
......@@ -62,6 +64,25 @@ struct DisplayState final : private angle::NonCopyable
EGLNativeDisplayType displayId;
};
class ShareGroup final : angle::NonCopyable
{
public:
ShareGroup(rx::EGLImplFactory *factory);
void addRef();
void release(const gl::Context *context);
rx::ShareGroupImpl *getImplementation() const { return mImplementation; }
protected:
~ShareGroup();
private:
size_t mRefCount;
rx::ShareGroupImpl *mImplementation;
};
// Constant coded here as a sanity limit.
constexpr EGLAttrib kProgramCacheSizeAbsoluteMax = 0x4000000;
......
......@@ -1841,8 +1841,9 @@ void CaptureMidExecutionSetup(const gl::Context *context,
const TextureLevelDataMap &cachedTextureLevelData)
{
const gl::State &apiState = context->getState();
gl::State replayState(nullptr, nullptr, nullptr, EGL_OPENGL_ES_API, apiState.getClientVersion(),
false, true, true, true, false, EGL_CONTEXT_PRIORITY_MEDIUM_IMG);
gl::State replayState(nullptr, nullptr, nullptr, nullptr, EGL_OPENGL_ES_API,
apiState.getClientVersion(), false, true, true, true, false,
EGL_CONTEXT_PRIORITY_MEDIUM_IMG);
// Small helper function to make the code more readable.
auto cap = [setupCalls](CallCapture &&call) { setupCalls->emplace_back(std::move(call)); };
......
......@@ -306,6 +306,7 @@ ANGLE_INLINE void ActiveTexturesCache::set(ContextID contextID,
}
State::State(const State *shareContextState,
egl::ShareGroup *shareGroup,
TextureManager *shareTextures,
const OverlayType *overlay,
const EGLenum clientType,
......@@ -320,6 +321,7 @@ State::State(const State *shareContextState,
mClientType(clientType),
mContextPriority(contextPriority),
mClientVersion(clientVersion),
mShareGroup(shareGroup),
mBufferManager(AllocateOrGetSharedResourceManager(shareContextState, &State::mBufferManager)),
mShaderProgramManager(
AllocateOrGetSharedResourceManager(shareContextState, &State::mShaderProgramManager)),
......
......@@ -30,6 +30,11 @@
#include "libANGLE/VertexArray.h"
#include "libANGLE/angletypes.h"
namespace egl
{
class ShareGroup;
} // namespace egl
namespace gl
{
class BufferManager;
......@@ -85,6 +90,7 @@ class State : angle::NonCopyable
{
public:
State(const State *shareContextState,
egl::ShareGroup *shareGroup,
TextureManager *shareTextures,
const OverlayType *overlay,
const EGLenum clientType,
......@@ -111,6 +117,7 @@ class State : angle::NonCopyable
const TextureCapsMap &getTextureCaps() const { return mTextureCaps; }
const Extensions &getExtensions() const { return mExtensions; }
const Limitations &getLimitations() const { return mLimitations; }
egl::ShareGroup *getShareGroup() const { return mShareGroup; }
bool isWebGL() const { return mExtensions.webglCompatibility; }
......@@ -853,6 +860,8 @@ class State : angle::NonCopyable
Extensions mExtensions;
Limitations mLimitations;
egl::ShareGroup *mShareGroup;
// Resource managers.
BufferManager *mBufferManager;
ShaderProgramManager *mShaderProgramManager;
......
......@@ -51,6 +51,13 @@ struct ConfigDesc;
class DeviceImpl;
class StreamProducerImpl;
class ShareGroupImpl : angle::NonCopyable
{
public:
ShareGroupImpl() {}
virtual ~ShareGroupImpl() {}
};
class DisplayImpl : public EGLImplFactory
{
public:
......
......@@ -35,6 +35,7 @@ class EGLSyncImpl;
class ImageImpl;
class ExternalImageSiblingImpl;
class SurfaceImpl;
class ShareGroupImpl;
class EGLImplFactory : angle::NonCopyable
{
......@@ -76,6 +77,8 @@ class EGLImplFactory : angle::NonCopyable
const egl::AttributeMap &attribs);
virtual EGLSyncImpl *createSync(const egl::AttributeMap &attribs);
virtual ShareGroupImpl *createShareGroup() = 0;
};
inline ExternalImageSiblingImpl *EGLImplFactory::createExternalImageSibling(
......
......@@ -225,6 +225,11 @@ ExternalImageSiblingImpl *DisplayD3D::createExternalImageSibling(const gl::Conte
return mRenderer->createExternalImageSibling(context, target, buffer, attribs);
}
ShareGroupImpl *DisplayD3D::createShareGroup()
{
return new ShareGroupD3D();
}
egl::Error DisplayD3D::makeCurrent(egl::Surface *drawSurface,
egl::Surface *readSurface,
gl::Context *context)
......
......@@ -16,6 +16,9 @@
namespace rx
{
class ShareGroupD3D : public ShareGroupImpl
{};
class DisplayD3D : public DisplayImpl, public d3d::Context
{
public:
......@@ -57,6 +60,8 @@ class DisplayD3D : public DisplayImpl, public d3d::Context
EGLClientBuffer buffer,
const egl::AttributeMap &attribs) override;
ShareGroupImpl *createShareGroup() override;
egl::Error makeCurrent(egl::Surface *drawSurface,
egl::Surface *readSurface,
gl::Context *context) override;
......
......@@ -50,6 +50,11 @@ StreamProducerImpl *DisplayGL::createStreamProducerD3DTexture(
return nullptr;
}
ShareGroupImpl *DisplayGL::createShareGroup()
{
return new ShareGroupGL();
}
egl::Error DisplayGL::makeCurrent(egl::Surface *drawSurface,
egl::Surface *readSurface,
gl::Context *context)
......
......@@ -19,6 +19,8 @@ class Surface;
namespace rx
{
class ShareGroupGL : public ShareGroupImpl
{};
class RendererGL;
......@@ -39,6 +41,8 @@ class DisplayGL : public DisplayImpl
StreamProducerImpl *createStreamProducerD3DTexture(egl::Stream::ConsumerType consumerType,
const egl::AttributeMap &attribs) override;
ShareGroupImpl *createShareGroup() override;
egl::Error makeCurrent(egl::Surface *drawSurface,
egl::Surface *readSurface,
gl::Context *context) override;
......
......@@ -27,6 +27,9 @@ class Surface;
namespace rx
{
class ShareGroupMtl : public ShareGroupImpl
{};
class ContextMtl;
class DisplayMtl : public DisplayImpl
......@@ -75,6 +78,8 @@ class DisplayMtl : public DisplayImpl
StreamProducerImpl *createStreamProducerD3DTexture(egl::Stream::ConsumerType consumerType,
const egl::AttributeMap &attribs) override;
ShareGroupImpl *createShareGroup() override;
gl::Version getMaxSupportedESVersion() const override;
gl::Version getMaxConformantESVersion() const override;
......
......@@ -210,6 +210,11 @@ StreamProducerImpl *DisplayMtl::createStreamProducerD3DTexture(
return nullptr;
}
ShareGroupImpl *DisplayMtl::createShareGroup()
{
return new ShareGroupMtl();
}
gl::Version DisplayMtl::getMaxSupportedESVersion() const
{
return mtl::kMaxSupportedGLVersion;
......
......@@ -184,6 +184,11 @@ StreamProducerImpl *DisplayNULL::createStreamProducerD3DTexture(
return nullptr;
}
ShareGroupImpl *DisplayNULL::createShareGroup()
{
return new ShareGroupNULL();
}
void DisplayNULL::generateExtensions(egl::DisplayExtensions *outExtensions) const
{
outExtensions->createContextRobustness = true;
......
......@@ -14,6 +14,8 @@
namespace rx
{
class ShareGroupNULL : public ShareGroupImpl
{};
class AllocationTrackerNULL;
......@@ -73,6 +75,8 @@ class DisplayNULL : public DisplayImpl
StreamProducerImpl *createStreamProducerD3DTexture(egl::Stream::ConsumerType consumerType,
const egl::AttributeMap &attribs) override;
ShareGroupImpl *createShareGroup() override;
void populateFeatureList(angle::FeatureList *features) override {}
private:
......
......@@ -153,11 +153,16 @@ ImageImpl *DisplayVk::createImage(const egl::ImageState &state,
return new ImageVk(state, context);
}
rx::ContextImpl *DisplayVk::createContext(const gl::State &state,
gl::ErrorSet *errorSet,
const egl::Config *configuration,
const gl::Context *shareContext,
const egl::AttributeMap &attribs)
ShareGroupImpl *DisplayVk::createShareGroup()
{
return new ShareGroupVk();
}
ContextImpl *DisplayVk::createContext(const gl::State &state,
gl::ErrorSet *errorSet,
const egl::Config *configuration,
const gl::Context *shareContext,
const egl::AttributeMap &attribs)
{
return new ContextVk(state, errorSet, mRenderer);
}
......
......@@ -18,6 +18,11 @@ namespace rx
{
class RendererVk;
class ShareGroupVk : public ShareGroupImpl
{
private:
};
class DisplayVk : public DisplayImpl, public vk::Context
{
public:
......@@ -97,6 +102,8 @@ class DisplayVk : public DisplayImpl, public vk::Context
bool isRobustResourceInitEnabled() const override;
ShareGroupImpl *createShareGroup() override;
protected:
void generateExtensions(egl::DisplayExtensions *outExtensions) const override;
......
......@@ -133,6 +133,7 @@ class MockEGLFactory : public EGLImplFactory
const egl::AttributeMap &));
MOCK_METHOD2(createStreamProducerD3DTexture,
StreamProducerImpl *(egl::Stream::ConsumerType, const egl::AttributeMap &));
MOCK_METHOD0(createShareGroup, ShareGroupImpl *());
};
} // namespace rx
......
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