Skip to content

Commit

Permalink
Cherry-pick from gles3-dev: WIP: Support importing external metal tex…
Browse files Browse the repository at this point in the history
…tures (2D, Cube) via KHR_image_base.

Change-Id: I525eb0a0160c67bbbc6baf8107429e08b2d67f6d

# Conflicts:
#	extensions/EGL_MGL_texture_client_buffer.txt
#	src/libANGLE/Caps.cpp
#	src/libANGLE/renderer/metal/DisplayMtl.h
#	src/libANGLE/renderer/metal/DisplayMtl.mm
#	src/tests/angle_end2end_tests.gni
  • Loading branch information
kakashidinho committed Jul 31, 2020
1 parent f2ae5d3 commit 596db81
Show file tree
Hide file tree
Showing 27 changed files with 1,252 additions and 12 deletions.
81 changes: 81 additions & 0 deletions extensions/EGL_MGL_texture_client_buffer.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
Name

MGL_texture_client_buffer

Name Strings

EGL_MGL_mtl_texture_client_buffer

Contributors

Le Hoang Quyen

Contacts

Le Hoang Quyen (lehoangq 'at' gmail.com)

Status

Draft

Version
Version 1, Jul 19, 2020

Number

EGL Extension #??

Dependencies

This extension is written against the wording of the EGL 1.4
Specification.

Overview

This extension allows creating EGL images from external metal texture objects.

New Types

None

New Procedures and Functions

None

New Tokens

Accepted in the <target> parameter of eglCreateImageKHR:

EGL_MTL_TEXTURE_MGL 0x3456

Additions to Chapter 2 of the EGL 1.2 Specification (EGL Operation)

Add to section 2.5.1 "EGLImage Specification" (as defined by the
EGL_KHR_image_base specification), in the description of
eglCreateImageKHR:

"Values accepted for <target> are listed in Table aaa, below.

+----------------------------+-----------------------------------------+
| <target> | Notes |
+----------------------------+-----------------------------------------+
| EGL_MTL_TEXTURE_MGL | Used for Metal texture objects |
+----------------------------+-----------------------------------------+
Table aaa. Legal values for eglCreateImageKHR <target> parameter

...

If <target> is EGL_MTL_TEXTURE_MGL, <dpy> must be a valid display, <ctx>
must be EGL_NO_CONTEXT, <buffer> must be a pointer to a valid MTLTexture
object (cast into the type EGLClientBuffer), and attributes are ignored.
The width and height of the pbuffer are determined by the width and height
of <buffer>."

If the EGL_ANGLE_device_mtl extension is present, the provided Metal texture
object must have been created by the same Metal device queried from the
display. If these requirements are not met, an EGL_BAD_PARAMETER error is
generated."

Revision History

Version 1, 2020/19/07 - First draft
81 changes: 81 additions & 0 deletions extensions/GL_MGL_EGL_image_cube.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
Name

MGL_EGL_image_cube

Name Strings

GL_MGL_EGL_image_cube

Contact

Le Hoang Quyen ([email protected])

Contributors

Le Hoang Quyen

Status

Draft

Version

Revision: 0.1

Number

OpenGL ES Extension #XXX

Dependencies

OpenGL ES 2.0 is required.

Requires EGL 1.2 and either the EGL_KHR_image or EGL_KHR_image_base
extensions as well as OES_EGL_image.

This extension is written against the OpenGL ES 2.0 specification and
the OES_EGL_image extension.

Overview

This extension adds functionality to that provided by OES_EGL_image in
order to support cube map EGLImage. It extends the existing
EGLImageTargetTexture2DOES entry point from OES_EGL_image. Render buffers
are not extended to include cube map support.

EGLImage cube map can be created using extended versions of eglCreateImageKHR.
For example, EGL_MGL_mtl_texture_client_buffer can import cube map image native metal textures
on devices where such native textures can be created.

New Procedures and Functions

None.

New Tokens

None.

Additions to Chapter 3 of the OpenGL ES 2.0 Specification

In section 3.8.2 within the specification added by OES_EGL_Image:

"Currently, <target> must be TEXTURE_2D or TEXTURE_CUBE_MAP."

Errors

GL_INVALID_ENUM is generated by EGLImageTargetTexture2DOES if
<target> is not TEXTURE_2D or TEXTURE_CUBE_MAP

GL_INVALID_OPERATION is generated by EGLImageTargetTexture2DOES if:
- <target> is TEXTURE_CUBE_MAP and <image> is not cube map image.
- <target> is TEXTURE_2D and <image> is not 2d image.

Issues

None.

Revision History

Rev. Date Author Changes
---- ---------- -------- -----------------------------------------
0.1 07/30/2020 Quyen Initial draft
18 changes: 18 additions & 0 deletions include/EGL/eglext_angle.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,24 @@ EGLAPI EGLint EGLAPIENTRY eglProgramCacheResizeANGLE(EGLDisplay dpy, EGLint limi
#define EGL_TEXTURE_INTERNAL_FORMAT_ANGLE 0x345D
#endif /* EGL_ANGLE_iosurface_client_buffer */

#ifndef MGL_texture_client_buffer
#define MGL_texture_client_buffer 1
#define EGL_MTL_TEXTURE_MGL 0x3456
#define EGL_GL_TEXTURE_MGL 0x3457
#ifndef EGL_TEXTURE_RECTANGLE_ANGLE
#define EGL_TEXTURE_RECTANGLE_ANGLE 0x345B
#endif
#ifndef EGL_TEXTURE_TYPE_ANGLE
#define EGL_TEXTURE_TYPE_ANGLE 0x345C
#endif
#ifndef EGL_TEXTURE_INTERNAL_FORMAT_ANGLE
#define EGL_TEXTURE_INTERNAL_FORMAT_ANGLE 0x345D
#endif
#ifndef EGL_BIND_TO_TEXTURE_TARGET_ANGLE
#define EGL_BIND_TO_TEXTURE_TARGET_ANGLE 0x348D
#endif
#endif /* MGL_texture_client_buffer */

#ifndef EGL_ANGLE_create_context_extensions_enabled
#define EGL_ANGLE_create_context_extensions_enabled 1
#define EGL_EXTENSIONS_ENABLED_ANGLE 0x345F
Expand Down
12 changes: 12 additions & 0 deletions ios/xcode/OpenGLES.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2749,6 +2749,10 @@
0AFDDB91244C9DE1000B60B1 /* libglslang_tvos.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 0AF956F8244C7C8700F59740 /* libglslang_tvos.a */; };
0AFDDB92244C9DE1000B60B1 /* libjsoncpp_tvos.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 0AF956B5244C7BF300F59740 /* libjsoncpp_tvos.a */; };
0AFDDB93244C9DE1000B60B1 /* libspirv-cross_tvos.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 0AF956C6244C7C5100F59740 /* libspirv-cross_tvos.a */; };
0AFFDCB624D42F7F0015E16A /* ImageMtl.mm in Sources */ = {isa = PBXBuildFile; fileRef = 0AFFDCB524D42F760015E16A /* ImageMtl.mm */; };
0AFFDCB724D42F820015E16A /* ImageMtl.mm in Sources */ = {isa = PBXBuildFile; fileRef = 0AFFDCB524D42F760015E16A /* ImageMtl.mm */; };
0AFFDCB824D42F860015E16A /* ImageMtl.mm in Sources */ = {isa = PBXBuildFile; fileRef = 0AFFDCB524D42F760015E16A /* ImageMtl.mm */; };
0AFFDCB924D42F880015E16A /* ImageMtl.mm in Sources */ = {isa = PBXBuildFile; fileRef = 0AFFDCB524D42F760015E16A /* ImageMtl.mm */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -5059,6 +5063,8 @@
0AF959B3244C7D5800F59740 /* sample_util_tvos.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = sample_util_tvos.framework; sourceTree = BUILT_PRODUCTS_DIR; };
0AF959EB244C7EE900F59740 /* simple_vertex_shader_tvos.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = simple_vertex_shader_tvos.app; sourceTree = BUILT_PRODUCTS_DIR; };
0AF959ED244C7FF800F59740 /* Info_tvos.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; name = Info_tvos.plist; path = samples/Info_tvos.plist; sourceTree = "<group>"; };
0AFFDCB424D42F760015E16A /* ImageMtl.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ImageMtl.h; path = ../../src/libANGLE/renderer/metal/ImageMtl.h; sourceTree = "<group>"; };
0AFFDCB524D42F760015E16A /* ImageMtl.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; name = ImageMtl.mm; path = ../../src/libANGLE/renderer/metal/ImageMtl.mm; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -6089,6 +6095,8 @@
0A605609234655FF005CEA98 /* DisplayMtl.mm */,
0A6055D1234655FC005CEA98 /* FrameBufferMtl.h */,
0A605603234655FE005CEA98 /* FrameBufferMtl.mm */,
0AFFDCB424D42F760015E16A /* ImageMtl.h */,
0AFFDCB524D42F760015E16A /* ImageMtl.mm */,
0A605601234655FE005CEA98 /* mtl_glslang_utils.h */,
0A6055D5234655FC005CEA98 /* mtl_glslang_utils.mm */,
0A6055D0234655FC005CEA98 /* mtl_buffer_pool.h */,
Expand Down Expand Up @@ -10288,6 +10296,7 @@
0A60564923465667005CEA98 /* ContextMtl.mm in Sources */,
0A60564C23465667005CEA98 /* mtl_glslang_utils.mm in Sources */,
0A60564823465667005CEA98 /* CompilerMtl.mm in Sources */,
0AFFDCB624D42F7F0015E16A /* ImageMtl.mm in Sources */,
0A60565C23465667005CEA98 /* TextureMtl.mm in Sources */,
0A60565A23465667005CEA98 /* mtl_state_cache.mm in Sources */,
0A60565D23465667005CEA98 /* mtl_render_utils.mm in Sources */,
Expand Down Expand Up @@ -10514,6 +10523,7 @@
0A90F76724065B06005BA9A8 /* ContextMtl.mm in Sources */,
0A90F76824065B06005BA9A8 /* mtl_glslang_utils.mm in Sources */,
0A90F76924065B06005BA9A8 /* CompilerMtl.mm in Sources */,
0AFFDCB724D42F820015E16A /* ImageMtl.mm in Sources */,
0A90F76A24065B06005BA9A8 /* TextureMtl.mm in Sources */,
0A90F76B24065B06005BA9A8 /* mtl_state_cache.mm in Sources */,
0A90F76C24065B06005BA9A8 /* mtl_render_utils.mm in Sources */,
Expand Down Expand Up @@ -11677,6 +11687,7 @@
0AA2FFBE234727A400E0B98C /* ContextMtl.mm in Sources */,
0AA2FFBF234727A400E0B98C /* mtl_glslang_utils.mm in Sources */,
0AA2FFC0234727A400E0B98C /* CompilerMtl.mm in Sources */,
0AFFDCB924D42F880015E16A /* ImageMtl.mm in Sources */,
0AA2FFC1234727A400E0B98C /* TextureMtl.mm in Sources */,
0AA2FFC2234727A400E0B98C /* mtl_state_cache.mm in Sources */,
0AA2FFC4234727A400E0B98C /* mtl_render_utils.mm in Sources */,
Expand Down Expand Up @@ -11869,6 +11880,7 @@
0AF95740244C7CC300F59740 /* ContextMtl.mm in Sources */,
0AF95741244C7CC300F59740 /* mtl_glslang_utils.mm in Sources */,
0AF95742244C7CC300F59740 /* CompilerMtl.mm in Sources */,
0AFFDCB824D42F860015E16A /* ImageMtl.mm in Sources */,
0AF95743244C7CC300F59740 /* TextureMtl.mm in Sources */,
0AF95744244C7CC300F59740 /* mtl_state_cache.mm in Sources */,
0AF95745244C7CC300F59740 /* mtl_render_utils.mm in Sources */,
Expand Down
1 change: 1 addition & 0 deletions src/common/utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1034,6 +1034,7 @@ bool IsExternalImageTarget(EGLenum target)
{
case EGL_NATIVE_BUFFER_ANDROID:
case EGL_D3D11_TEXTURE_ANGLE:
case EGL_MTL_TEXTURE_MGL:
return true;

default:
Expand Down
2 changes: 2 additions & 0 deletions src/libANGLE/Caps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,7 @@ const ExtensionInfoMap &GetExtensionInfoMap()
map["GL_OES_EGL_image"] = enableableExtension(&Extensions::eglImage);
map["GL_OES_EGL_image_external"] = enableableExtension(&Extensions::eglImageExternal);
map["GL_OES_EGL_image_external_essl3"] = enableableExtension(&Extensions::eglImageExternalEssl3);
map["GL_MGL_EGL_image_cube"] = enableableExtension(&Extensions::eglImageCubeMGL);
map["GL_OES_EGL_sync"] = esOnlyExtension(&Extensions::eglSync);
map["GL_EXT_memory_object"] = enableableExtension(&Extensions::memoryObject);
map["GL_EXT_memory_object_fd"] = enableableExtension(&Extensions::memoryObjectFd);
Expand Down Expand Up @@ -1245,6 +1246,7 @@ std::vector<std::string> DisplayExtensions::getStrings() const
InsertExtensionString("EGL_ANGLE_program_cache_control", programCacheControl, &extensionStrings);
InsertExtensionString("EGL_ANGLE_robust_resource_initialization", robustResourceInitialization, &extensionStrings);
InsertExtensionString("EGL_ANGLE_iosurface_client_buffer", iosurfaceClientBuffer, &extensionStrings);
InsertExtensionString("EGL_MGL_mtl_texture_client_buffer", mtlTextureClientBuffer, &extensionStrings);
InsertExtensionString("EGL_ANGLE_create_context_extensions_enabled", createContextExtensionsEnabled, &extensionStrings);
InsertExtensionString("EGL_ANDROID_presentation_time", presentationTime, &extensionStrings);
InsertExtensionString("EGL_ANDROID_blob_cache", blobCache, &extensionStrings);
Expand Down
6 changes: 6 additions & 0 deletions src/libANGLE/Caps.h
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,9 @@ struct Extensions
// GL_OES_EGL_image_external_essl3
bool eglImageExternalEssl3 = false;

// GL_MGL_EGL_image_cube
bool eglImageCubeMGL = false;

// GL_OES_EGL_sync
bool eglSync = false;

Expand Down Expand Up @@ -908,6 +911,9 @@ struct DisplayExtensions
// EGL_ANGLE_iosurface_client_buffer
bool iosurfaceClientBuffer = false;

// EGL_mtl_texture_client_buffer
bool mtlTextureClientBuffer = false;

// EGL_ANGLE_create_context_extensions_enabled
bool createContextExtensionsEnabled = false;

Expand Down
18 changes: 15 additions & 3 deletions src/libANGLE/Texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1534,7 +1534,8 @@ angle::Result Texture::setEGLImageTarget(Context *context,
egl::Image *imageTarget)
{
ASSERT(type == mState.mType);
ASSERT(type == TextureType::_2D || type == TextureType::External);
ASSERT(type == TextureType::_2D || type == TextureType::External ||
type == TextureType::CubeMap);

// Release from previous calls to eglBindTexImage, to avoid calling the Impl after
ANGLE_TRY(releaseTexImageInternal(context));
Expand All @@ -1550,8 +1551,19 @@ angle::Result Texture::setEGLImageTarget(Context *context,
auto initState = imageTarget->sourceInitState();

mState.clearImageDescs();
mState.setImageDesc(NonCubeTextureTypeToTarget(type), 0,
ImageDesc(size, imageTarget->getFormat(), initState));
if (type == TextureType::CubeMap)
{
for (int face = 0; face < 6; ++face)
{
mState.setImageDesc(FromGLenum<TextureTarget>(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face), 0,
ImageDesc(size, imageTarget->getFormat(), initState));
}
}
else
{
mState.setImageDesc(NonCubeTextureTypeToTarget(type), 0,
ImageDesc(size, imageTarget->getFormat(), initState));
}
signalDirtyStorage(initState);

return angle::Result::Continue;
Expand Down
2 changes: 2 additions & 0 deletions src/libANGLE/renderer/metal/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ _metal_backend_sources = [
"DisplayMtl.mm",
"FrameBufferMtl.h",
"FrameBufferMtl.mm",
"ImageMtl.h",
"ImageMtl.mm",
"ProgramMtl.h",
"ProgramMtl.mm",
"QueryMtl.h",
Expand Down
8 changes: 8 additions & 0 deletions src/libANGLE/renderer/metal/DisplayMtl.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ class DisplayMtl : public DisplayImpl
StreamProducerImpl *createStreamProducerD3DTexture(egl::Stream::ConsumerType consumerType,
const egl::AttributeMap &attribs) override;

ExternalImageSiblingImpl *createExternalImageSibling(const gl::Context *context,
EGLenum target,
EGLClientBuffer buffer,
const egl::AttributeMap &attribs) override;
gl::Version getMaxSupportedESVersion() const override;
gl::Version getMaxConformantESVersion() const override;

Expand All @@ -88,6 +92,10 @@ class DisplayMtl : public DisplayImpl

bool isValidNativeWindow(EGLNativeWindowType window) const override;

egl::Error validateImageClientBuffer(const gl::Context *context,
EGLenum target,
EGLClientBuffer clientBuffer,
const egl::AttributeMap &attribs) const override;
egl::ConfigSet generateConfigs() override;

std::string getRendererDescription() const;
Expand Down
Loading

0 comments on commit 596db81

Please sign in to comment.