Hash :
038ad6c7
Author :
Date :
2024-04-23T13:23:04
EGL: Use unlocked tail calls for surface, sync and img calls EGL surface and sync calls can be expensive to do while holding the global lock on EGL. They are safe because the parameters are captured by value and the underlying EGL driver is also thread safe. EGL image creation also tends to be expensive and is called freqently by Chrome. Bug: angleproject:8434 Change-Id: I7e554fe2e3700d98469de267f7bbff1e96358c78 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5478229 Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: Geoff Lang <geofflang@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
//
// Copyright 2018 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.
//
// ImageEGL.cpp: Implements the rx::ImageEGL class.
#include "libANGLE/renderer/gl/egl/ImageEGL.h"
#include "common/utilities.h"
#include "libANGLE/Context.h"
#include "libANGLE/Display.h"
#include "libANGLE/renderer/gl/FunctionsGL.h"
#include "libANGLE/renderer/gl/RenderbufferGL.h"
#include "libANGLE/renderer/gl/StateManagerGL.h"
#include "libANGLE/renderer/gl/TextureGL.h"
#include "libANGLE/renderer/gl/egl/ContextEGL.h"
#include "libANGLE/renderer/gl/egl/ExternalImageSiblingEGL.h"
#include "libANGLE/renderer/gl/egl/FunctionsEGL.h"
namespace rx
{
ImageEGL::ImageEGL(const egl::ImageState &state,
const gl::Context *context,
EGLenum target,
const egl::AttributeMap &attribs,
const FunctionsEGL *egl)
: ImageGL(state),
mEGL(egl),
mContext(EGL_NO_CONTEXT),
mTarget(target),
mPreserveImage(false),
mImage(EGL_NO_IMAGE)
{
if (context)
{
mContext = GetImplAs<ContextEGL>(context)->getContext();
}
mPreserveImage = attribs.get(EGL_IMAGE_PRESERVED, EGL_FALSE) == EGL_TRUE;
}
ImageEGL::~ImageEGL()
{
mEGL->destroyImageKHR(mImage);
}
egl::Error ImageEGL::initialize(const egl::Display *display)
{
EGLClientBuffer buffer = nullptr;
angle::FastVector<EGLint, 8> attributes;
if (egl::IsTextureTarget(mTarget))
{
attributes.push_back(EGL_GL_TEXTURE_LEVEL);
attributes.push_back(mState.imageIndex.getLevelIndex());
if (mState.imageIndex.has3DLayer())
{
attributes.push_back(EGL_GL_TEXTURE_ZOFFSET);
attributes.push_back(mState.imageIndex.getLayerIndex());
}
const TextureGL *textureGL = GetImplAs<TextureGL>(GetAs<gl::Texture>(mState.source));
buffer = gl_egl::GLObjectHandleToEGLClientBuffer(textureGL->getTextureID());
mNativeInternalFormat = textureGL->getNativeInternalFormat(mState.imageIndex);
}
else if (egl::IsRenderbufferTarget(mTarget))
{
const RenderbufferGL *renderbufferGL =
GetImplAs<RenderbufferGL>(GetAs<gl::Renderbuffer>(mState.source));
buffer = gl_egl::GLObjectHandleToEGLClientBuffer(renderbufferGL->getRenderbufferID());
mNativeInternalFormat = renderbufferGL->getNativeInternalFormat();
}
else if (egl::IsExternalImageTarget(mTarget))
{
const ExternalImageSiblingEGL *externalImageSibling =
GetImplAs<ExternalImageSiblingEGL>(GetAs<egl::ExternalImageSibling>(mState.source));
buffer = externalImageSibling->getBuffer();
mNativeInternalFormat = externalImageSibling->getFormat().info->sizedInternalFormat;
// Add any additional attributes this type of image sibline requires
std::vector<EGLint> tmp_attributes;
externalImageSibling->getImageCreationAttributes(&tmp_attributes);
attributes.reserve(attributes.size() + tmp_attributes.size());
for (EGLint attribute : tmp_attributes)
{
attributes.push_back(attribute);
}
}
else
{
UNREACHABLE();
}
attributes.push_back(EGL_IMAGE_PRESERVED);
attributes.push_back(mPreserveImage ? EGL_TRUE : EGL_FALSE);
attributes.push_back(EGL_NONE);
egl::Display::GetCurrentThreadUnlockedTailCall()->add([egl = mEGL, &image = mImage,
context = mContext, target = mTarget,
buffer, attributes](void *resultOut) {
image = egl->createImageKHR(context, target, buffer, attributes.data());
// If image creation failed, force the return value of eglCreateImage to EGL_NO_IMAGE. This
// won't delete this image object but a driver error is unexpected at this point.
if (image == EGL_NO_IMAGE)
{
ERR() << "eglCreateImage failed with " << gl::FmtHex(egl->getError());
*static_cast<EGLImage *>(resultOut) = EGL_NO_IMAGE;
}
});
return egl::NoError();
}
angle::Result ImageEGL::orphan(const gl::Context *context, egl::ImageSibling *sibling)
{
// Nothing to do, the native EGLImage will orphan automatically.
return angle::Result::Continue;
}
angle::Result ImageEGL::setTexture2D(const gl::Context *context,
gl::TextureType type,
TextureGL *texture,
GLenum *outInternalFormat)
{
const FunctionsGL *functionsGL = GetFunctionsGL(context);
StateManagerGL *stateManager = GetStateManagerGL(context);
// Make sure this texture is bound
stateManager->bindTexture(type, texture->getTextureID());
// Bind the image to the texture
functionsGL->eGLImageTargetTexture2DOES(ToGLenum(type), mImage);
*outInternalFormat = mNativeInternalFormat;
return angle::Result::Continue;
}
angle::Result ImageEGL::setRenderbufferStorage(const gl::Context *context,
RenderbufferGL *renderbuffer,
GLenum *outInternalFormat)
{
const FunctionsGL *functionsGL = GetFunctionsGL(context);
StateManagerGL *stateManager = GetStateManagerGL(context);
// Make sure this renderbuffer is bound
stateManager->bindRenderbuffer(GL_RENDERBUFFER, renderbuffer->getRenderbufferID());
// Bind the image to the renderbuffer
functionsGL->eGLImageTargetRenderbufferStorageOES(GL_RENDERBUFFER, mImage);
*outInternalFormat = mNativeInternalFormat;
return angle::Result::Continue;
}
} // namespace rx