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 ...@@ -50,6 +50,20 @@ namespace gl
{ {
namespace 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> template <typename T>
angle::Result GetQueryObjectParameter(const Context *context, Query *query, GLenum pname, T *params) angle::Result GetQueryObjectParameter(const Context *context, Query *query, GLenum pname, T *params)
{ {
...@@ -256,6 +270,7 @@ Context::Context(egl::Display *display, ...@@ -256,6 +270,7 @@ Context::Context(egl::Display *display,
const egl::DisplayExtensions &displayExtensions, const egl::DisplayExtensions &displayExtensions,
const egl::ClientExtensions &clientExtensions) const egl::ClientExtensions &clientExtensions)
: mState(shareContext ? &shareContext->mState : nullptr, : mState(shareContext ? &shareContext->mState : nullptr,
AllocateOrGetShareGroup(display, shareContext),
shareTextures, shareTextures,
&mOverlay, &mOverlay,
clientType, clientType,
...@@ -584,6 +599,7 @@ egl::Error Context::onDestroy(const egl::Display *display) ...@@ -584,6 +599,7 @@ egl::Error Context::onDestroy(const egl::Display *display)
mState.mFramebufferManager->release(this); mState.mFramebufferManager->release(this);
mState.mMemoryObjectManager->release(this); mState.mMemoryObjectManager->release(this);
mState.mSemaphoreManager->release(this); mState.mSemaphoreManager->release(this);
mState.mShareGroup->release(this);
mThreadPool.reset(); mThreadPool.reset();
......
...@@ -421,6 +421,31 @@ static constexpr uint32_t kScratchBufferLifetime = 64u; ...@@ -421,6 +421,31 @@ static constexpr uint32_t kScratchBufferLifetime = 64u;
} // anonymous namespace } // 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) DisplayState::DisplayState(EGLNativeDisplayType nativeDisplayId)
: label(nullptr), featuresAllDisabled(false), displayId(nativeDisplayId) : label(nullptr), featuresAllDisabled(false), displayId(nativeDisplayId)
{} {}
......
...@@ -36,7 +36,9 @@ class TextureManager; ...@@ -36,7 +36,9 @@ class TextureManager;
namespace rx namespace rx
{ {
class DisplayImpl; class DisplayImpl;
} class EGLImplFactory;
class ShareGroupImpl;
} // namespace rx
namespace egl namespace egl
{ {
...@@ -62,6 +64,25 @@ struct DisplayState final : private angle::NonCopyable ...@@ -62,6 +64,25 @@ struct DisplayState final : private angle::NonCopyable
EGLNativeDisplayType displayId; 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. // Constant coded here as a sanity limit.
constexpr EGLAttrib kProgramCacheSizeAbsoluteMax = 0x4000000; constexpr EGLAttrib kProgramCacheSizeAbsoluteMax = 0x4000000;
......
...@@ -1841,8 +1841,9 @@ void CaptureMidExecutionSetup(const gl::Context *context, ...@@ -1841,8 +1841,9 @@ void CaptureMidExecutionSetup(const gl::Context *context,
const TextureLevelDataMap &cachedTextureLevelData) const TextureLevelDataMap &cachedTextureLevelData)
{ {
const gl::State &apiState = context->getState(); const gl::State &apiState = context->getState();
gl::State replayState(nullptr, nullptr, nullptr, EGL_OPENGL_ES_API, apiState.getClientVersion(), gl::State replayState(nullptr, nullptr, nullptr, nullptr, EGL_OPENGL_ES_API,
false, true, true, true, false, EGL_CONTEXT_PRIORITY_MEDIUM_IMG); apiState.getClientVersion(), false, true, true, true, false,
EGL_CONTEXT_PRIORITY_MEDIUM_IMG);
// Small helper function to make the code more readable. // Small helper function to make the code more readable.
auto cap = [setupCalls](CallCapture &&call) { setupCalls->emplace_back(std::move(call)); }; auto cap = [setupCalls](CallCapture &&call) { setupCalls->emplace_back(std::move(call)); };
......
...@@ -306,6 +306,7 @@ ANGLE_INLINE void ActiveTexturesCache::set(ContextID contextID, ...@@ -306,6 +306,7 @@ ANGLE_INLINE void ActiveTexturesCache::set(ContextID contextID,
} }
State::State(const State *shareContextState, State::State(const State *shareContextState,
egl::ShareGroup *shareGroup,
TextureManager *shareTextures, TextureManager *shareTextures,
const OverlayType *overlay, const OverlayType *overlay,
const EGLenum clientType, const EGLenum clientType,
...@@ -320,6 +321,7 @@ State::State(const State *shareContextState, ...@@ -320,6 +321,7 @@ State::State(const State *shareContextState,
mClientType(clientType), mClientType(clientType),
mContextPriority(contextPriority), mContextPriority(contextPriority),
mClientVersion(clientVersion), mClientVersion(clientVersion),
mShareGroup(shareGroup),
mBufferManager(AllocateOrGetSharedResourceManager(shareContextState, &State::mBufferManager)), mBufferManager(AllocateOrGetSharedResourceManager(shareContextState, &State::mBufferManager)),
mShaderProgramManager( mShaderProgramManager(
AllocateOrGetSharedResourceManager(shareContextState, &State::mShaderProgramManager)), AllocateOrGetSharedResourceManager(shareContextState, &State::mShaderProgramManager)),
......
...@@ -30,6 +30,11 @@ ...@@ -30,6 +30,11 @@
#include "libANGLE/VertexArray.h" #include "libANGLE/VertexArray.h"
#include "libANGLE/angletypes.h" #include "libANGLE/angletypes.h"
namespace egl
{
class ShareGroup;
} // namespace egl
namespace gl namespace gl
{ {
class BufferManager; class BufferManager;
...@@ -85,6 +90,7 @@ class State : angle::NonCopyable ...@@ -85,6 +90,7 @@ class State : angle::NonCopyable
{ {
public: public:
State(const State *shareContextState, State(const State *shareContextState,
egl::ShareGroup *shareGroup,
TextureManager *shareTextures, TextureManager *shareTextures,
const OverlayType *overlay, const OverlayType *overlay,
const EGLenum clientType, const EGLenum clientType,
...@@ -111,6 +117,7 @@ class State : angle::NonCopyable ...@@ -111,6 +117,7 @@ class State : angle::NonCopyable
const TextureCapsMap &getTextureCaps() const { return mTextureCaps; } const TextureCapsMap &getTextureCaps() const { return mTextureCaps; }
const Extensions &getExtensions() const { return mExtensions; } const Extensions &getExtensions() const { return mExtensions; }
const Limitations &getLimitations() const { return mLimitations; } const Limitations &getLimitations() const { return mLimitations; }
egl::ShareGroup *getShareGroup() const { return mShareGroup; }
bool isWebGL() const { return mExtensions.webglCompatibility; } bool isWebGL() const { return mExtensions.webglCompatibility; }
...@@ -853,6 +860,8 @@ class State : angle::NonCopyable ...@@ -853,6 +860,8 @@ class State : angle::NonCopyable
Extensions mExtensions; Extensions mExtensions;
Limitations mLimitations; Limitations mLimitations;
egl::ShareGroup *mShareGroup;
// Resource managers. // Resource managers.
BufferManager *mBufferManager; BufferManager *mBufferManager;
ShaderProgramManager *mShaderProgramManager; ShaderProgramManager *mShaderProgramManager;
......
...@@ -51,6 +51,13 @@ struct ConfigDesc; ...@@ -51,6 +51,13 @@ struct ConfigDesc;
class DeviceImpl; class DeviceImpl;
class StreamProducerImpl; class StreamProducerImpl;
class ShareGroupImpl : angle::NonCopyable
{
public:
ShareGroupImpl() {}
virtual ~ShareGroupImpl() {}
};
class DisplayImpl : public EGLImplFactory class DisplayImpl : public EGLImplFactory
{ {
public: public:
......
...@@ -35,6 +35,7 @@ class EGLSyncImpl; ...@@ -35,6 +35,7 @@ class EGLSyncImpl;
class ImageImpl; class ImageImpl;
class ExternalImageSiblingImpl; class ExternalImageSiblingImpl;
class SurfaceImpl; class SurfaceImpl;
class ShareGroupImpl;
class EGLImplFactory : angle::NonCopyable class EGLImplFactory : angle::NonCopyable
{ {
...@@ -76,6 +77,8 @@ class EGLImplFactory : angle::NonCopyable ...@@ -76,6 +77,8 @@ class EGLImplFactory : angle::NonCopyable
const egl::AttributeMap &attribs); const egl::AttributeMap &attribs);
virtual EGLSyncImpl *createSync(const egl::AttributeMap &attribs); virtual EGLSyncImpl *createSync(const egl::AttributeMap &attribs);
virtual ShareGroupImpl *createShareGroup() = 0;
}; };
inline ExternalImageSiblingImpl *EGLImplFactory::createExternalImageSibling( inline ExternalImageSiblingImpl *EGLImplFactory::createExternalImageSibling(
......
...@@ -225,6 +225,11 @@ ExternalImageSiblingImpl *DisplayD3D::createExternalImageSibling(const gl::Conte ...@@ -225,6 +225,11 @@ ExternalImageSiblingImpl *DisplayD3D::createExternalImageSibling(const gl::Conte
return mRenderer->createExternalImageSibling(context, target, buffer, attribs); return mRenderer->createExternalImageSibling(context, target, buffer, attribs);
} }
ShareGroupImpl *DisplayD3D::createShareGroup()
{
return new ShareGroupD3D();
}
egl::Error DisplayD3D::makeCurrent(egl::Surface *drawSurface, egl::Error DisplayD3D::makeCurrent(egl::Surface *drawSurface,
egl::Surface *readSurface, egl::Surface *readSurface,
gl::Context *context) gl::Context *context)
......
...@@ -16,6 +16,9 @@ ...@@ -16,6 +16,9 @@
namespace rx namespace rx
{ {
class ShareGroupD3D : public ShareGroupImpl
{};
class DisplayD3D : public DisplayImpl, public d3d::Context class DisplayD3D : public DisplayImpl, public d3d::Context
{ {
public: public:
...@@ -57,6 +60,8 @@ class DisplayD3D : public DisplayImpl, public d3d::Context ...@@ -57,6 +60,8 @@ class DisplayD3D : public DisplayImpl, public d3d::Context
EGLClientBuffer buffer, EGLClientBuffer buffer,
const egl::AttributeMap &attribs) override; const egl::AttributeMap &attribs) override;
ShareGroupImpl *createShareGroup() override;
egl::Error makeCurrent(egl::Surface *drawSurface, egl::Error makeCurrent(egl::Surface *drawSurface,
egl::Surface *readSurface, egl::Surface *readSurface,
gl::Context *context) override; gl::Context *context) override;
......
...@@ -50,6 +50,11 @@ StreamProducerImpl *DisplayGL::createStreamProducerD3DTexture( ...@@ -50,6 +50,11 @@ StreamProducerImpl *DisplayGL::createStreamProducerD3DTexture(
return nullptr; return nullptr;
} }
ShareGroupImpl *DisplayGL::createShareGroup()
{
return new ShareGroupGL();
}
egl::Error DisplayGL::makeCurrent(egl::Surface *drawSurface, egl::Error DisplayGL::makeCurrent(egl::Surface *drawSurface,
egl::Surface *readSurface, egl::Surface *readSurface,
gl::Context *context) gl::Context *context)
......
...@@ -19,6 +19,8 @@ class Surface; ...@@ -19,6 +19,8 @@ class Surface;
namespace rx namespace rx
{ {
class ShareGroupGL : public ShareGroupImpl
{};
class RendererGL; class RendererGL;
...@@ -39,6 +41,8 @@ class DisplayGL : public DisplayImpl ...@@ -39,6 +41,8 @@ class DisplayGL : public DisplayImpl
StreamProducerImpl *createStreamProducerD3DTexture(egl::Stream::ConsumerType consumerType, StreamProducerImpl *createStreamProducerD3DTexture(egl::Stream::ConsumerType consumerType,
const egl::AttributeMap &attribs) override; const egl::AttributeMap &attribs) override;
ShareGroupImpl *createShareGroup() override;
egl::Error makeCurrent(egl::Surface *drawSurface, egl::Error makeCurrent(egl::Surface *drawSurface,
egl::Surface *readSurface, egl::Surface *readSurface,
gl::Context *context) override; gl::Context *context) override;
......
...@@ -27,6 +27,9 @@ class Surface; ...@@ -27,6 +27,9 @@ class Surface;
namespace rx namespace rx
{ {
class ShareGroupMtl : public ShareGroupImpl
{};
class ContextMtl; class ContextMtl;
class DisplayMtl : public DisplayImpl class DisplayMtl : public DisplayImpl
...@@ -75,6 +78,8 @@ class DisplayMtl : public DisplayImpl ...@@ -75,6 +78,8 @@ class DisplayMtl : public DisplayImpl
StreamProducerImpl *createStreamProducerD3DTexture(egl::Stream::ConsumerType consumerType, StreamProducerImpl *createStreamProducerD3DTexture(egl::Stream::ConsumerType consumerType,
const egl::AttributeMap &attribs) override; const egl::AttributeMap &attribs) override;
ShareGroupImpl *createShareGroup() override;
gl::Version getMaxSupportedESVersion() const override; gl::Version getMaxSupportedESVersion() const override;
gl::Version getMaxConformantESVersion() const override; gl::Version getMaxConformantESVersion() const override;
......
...@@ -210,6 +210,11 @@ StreamProducerImpl *DisplayMtl::createStreamProducerD3DTexture( ...@@ -210,6 +210,11 @@ StreamProducerImpl *DisplayMtl::createStreamProducerD3DTexture(
return nullptr; return nullptr;
} }
ShareGroupImpl *DisplayMtl::createShareGroup()
{
return new ShareGroupMtl();
}
gl::Version DisplayMtl::getMaxSupportedESVersion() const gl::Version DisplayMtl::getMaxSupportedESVersion() const
{ {
return mtl::kMaxSupportedGLVersion; return mtl::kMaxSupportedGLVersion;
......
...@@ -184,6 +184,11 @@ StreamProducerImpl *DisplayNULL::createStreamProducerD3DTexture( ...@@ -184,6 +184,11 @@ StreamProducerImpl *DisplayNULL::createStreamProducerD3DTexture(
return nullptr; return nullptr;
} }
ShareGroupImpl *DisplayNULL::createShareGroup()
{
return new ShareGroupNULL();
}
void DisplayNULL::generateExtensions(egl::DisplayExtensions *outExtensions) const void DisplayNULL::generateExtensions(egl::DisplayExtensions *outExtensions) const
{ {
outExtensions->createContextRobustness = true; outExtensions->createContextRobustness = true;
......
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
namespace rx namespace rx
{ {
class ShareGroupNULL : public ShareGroupImpl
{};
class AllocationTrackerNULL; class AllocationTrackerNULL;
...@@ -73,6 +75,8 @@ class DisplayNULL : public DisplayImpl ...@@ -73,6 +75,8 @@ class DisplayNULL : public DisplayImpl
StreamProducerImpl *createStreamProducerD3DTexture(egl::Stream::ConsumerType consumerType, StreamProducerImpl *createStreamProducerD3DTexture(egl::Stream::ConsumerType consumerType,
const egl::AttributeMap &attribs) override; const egl::AttributeMap &attribs) override;
ShareGroupImpl *createShareGroup() override;
void populateFeatureList(angle::FeatureList *features) override {} void populateFeatureList(angle::FeatureList *features) override {}
private: private:
......
...@@ -153,11 +153,16 @@ ImageImpl *DisplayVk::createImage(const egl::ImageState &state, ...@@ -153,11 +153,16 @@ ImageImpl *DisplayVk::createImage(const egl::ImageState &state,
return new ImageVk(state, context); return new ImageVk(state, context);
} }
rx::ContextImpl *DisplayVk::createContext(const gl::State &state, ShareGroupImpl *DisplayVk::createShareGroup()
gl::ErrorSet *errorSet, {
const egl::Config *configuration, return new ShareGroupVk();
const gl::Context *shareContext, }
const egl::AttributeMap &attribs)
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); return new ContextVk(state, errorSet, mRenderer);
} }
......
...@@ -18,6 +18,11 @@ namespace rx ...@@ -18,6 +18,11 @@ namespace rx
{ {
class RendererVk; class RendererVk;
class ShareGroupVk : public ShareGroupImpl
{
private:
};
class DisplayVk : public DisplayImpl, public vk::Context class DisplayVk : public DisplayImpl, public vk::Context
{ {
public: public:
...@@ -97,6 +102,8 @@ class DisplayVk : public DisplayImpl, public vk::Context ...@@ -97,6 +102,8 @@ class DisplayVk : public DisplayImpl, public vk::Context
bool isRobustResourceInitEnabled() const override; bool isRobustResourceInitEnabled() const override;
ShareGroupImpl *createShareGroup() override;
protected: protected:
void generateExtensions(egl::DisplayExtensions *outExtensions) const override; void generateExtensions(egl::DisplayExtensions *outExtensions) const override;
......
...@@ -133,6 +133,7 @@ class MockEGLFactory : public EGLImplFactory ...@@ -133,6 +133,7 @@ class MockEGLFactory : public EGLImplFactory
const egl::AttributeMap &)); const egl::AttributeMap &));
MOCK_METHOD2(createStreamProducerD3DTexture, MOCK_METHOD2(createStreamProducerD3DTexture,
StreamProducerImpl *(egl::Stream::ConsumerType, const egl::AttributeMap &)); StreamProducerImpl *(egl::Stream::ConsumerType, const egl::AttributeMap &));
MOCK_METHOD0(createShareGroup, ShareGroupImpl *());
}; };
} // namespace rx } // 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