WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED FIXED
233941
Add support to attribute ownership of ANGLE Metal's resources
https://bugs.webkit.org/show_bug.cgi?id=233941
Summary
Add support to attribute ownership of ANGLE Metal's resources
John Cunningham
Reported
2021-12-07 11:23:50 PST
Add support to attribute ownership of ANGLE Metal's resources
Attachments
Patch
(80.95 KB, patch)
2021-12-07 11:31 PST
,
John Cunningham
no flags
Details
Formatted Diff
Diff
Patch
(79.64 KB, patch)
2021-12-07 17:42 PST
,
John Cunningham
ews-feeder
: commit-queue-
Details
Formatted Diff
Diff
Patch
(79.82 KB, patch)
2021-12-07 18:52 PST
,
John Cunningham
no flags
Details
Formatted Diff
Diff
Patch
(87.80 KB, patch)
2021-12-07 22:09 PST
,
John Cunningham
ews-feeder
: commit-queue-
Details
Formatted Diff
Diff
Patch
(87.80 KB, patch)
2021-12-07 22:54 PST
,
John Cunningham
no flags
Details
Formatted Diff
Diff
Patch
(98.16 KB, patch)
2021-12-08 15:01 PST
,
John Cunningham
no flags
Details
Formatted Diff
Diff
Patch
(98.19 KB, patch)
2021-12-08 15:25 PST
,
John Cunningham
no flags
Details
Formatted Diff
Diff
Patch
(97.60 KB, patch)
2021-12-08 15:41 PST
,
John Cunningham
no flags
Details
Formatted Diff
Diff
Patch
(117.03 KB, patch)
2021-12-09 13:18 PST
,
John Cunningham
no flags
Details
Formatted Diff
Diff
Patch
(127.71 KB, patch)
2021-12-09 23:18 PST
,
John Cunningham
no flags
Details
Formatted Diff
Diff
Patch
(129.51 KB, patch)
2021-12-10 02:15 PST
,
John Cunningham
no flags
Details
Formatted Diff
Diff
Patch
(106.18 KB, patch)
2021-12-10 03:28 PST
,
John Cunningham
no flags
Details
Formatted Diff
Diff
Patch
(107.22 KB, patch)
2021-12-10 11:32 PST
,
John Cunningham
no flags
Details
Formatted Diff
Diff
Patch for landing
(108.58 KB, patch)
2021-12-10 16:26 PST
,
John Cunningham
no flags
Details
Formatted Diff
Diff
Patch for landing
(108.57 KB, patch)
2021-12-12 22:52 PST
,
John Cunningham
ews-feeder
: commit-queue-
Details
Formatted Diff
Diff
Patch for landing
(118.68 KB, patch)
2021-12-13 10:00 PST
,
John Cunningham
no flags
Details
Formatted Diff
Diff
Patch for landing
(131.84 KB, patch)
2021-12-14 00:53 PST
,
John Cunningham
no flags
Details
Formatted Diff
Diff
Patch for landing
(3.83 KB, patch)
2021-12-15 08:46 PST
,
John Cunningham
no flags
Details
Formatted Diff
Diff
Patch for landing
(7.92 KB, patch)
2021-12-15 09:48 PST
,
John Cunningham
no flags
Details
Formatted Diff
Diff
Show Obsolete
(18)
View All
Add attachment
proposed patch, testcase, etc.
John Cunningham
Comment 1
2021-12-07 11:31:10 PST
Created
attachment 446209
[details]
Patch
EWS Watchlist
Comment 2
2021-12-07 11:32:19 PST
Note that there are important steps to take when updating ANGLE. See
https://trac.webkit.org/wiki/UpdatingANGLE
John Cunningham
Comment 3
2021-12-07 17:42:15 PST
Created
attachment 446269
[details]
Patch
John Cunningham
Comment 4
2021-12-07 18:52:42 PST
Created
attachment 446276
[details]
Patch
John Cunningham
Comment 5
2021-12-07 22:09:02 PST
Created
attachment 446295
[details]
Patch
John Cunningham
Comment 6
2021-12-07 22:54:06 PST
Created
attachment 446308
[details]
Patch
John Cunningham
Comment 7
2021-12-08 15:01:32 PST
Created
attachment 446433
[details]
Patch
John Cunningham
Comment 8
2021-12-08 15:25:29 PST
Created
attachment 446438
[details]
Patch
John Cunningham
Comment 9
2021-12-08 15:41:51 PST
Created
attachment 446442
[details]
Patch
Kimmo Kinnunen
Comment 10
2021-12-09 02:37:51 PST
Comment on
attachment 446442
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=446442&action=review
> Source/ThirdParty/ANGLE/include/EGL/eglext_angle.h:181 > +#define EGL_CONTEXT_OWNERSHIP_IDENTITY_METAL_ANGLE 0x33B0
Let's put 0x34A7 for now (reserved for ANGLE)
> Source/ThirdParty/ANGLE/src/libANGLE/Caps.h:647 > + bool createContextOwnershipIdentity = false;
createContextOwnershipIdentity*Metal* ?
> Source/ThirdParty/ANGLE/src/libANGLE/Context.cpp:235 > +EGLint GetOwnershipIdentity(const egl::AttributeMap &attribs)
This file is for *all* implementations. Ownership identity is a property of the Metal backend. You need to move this to ContextMtl
> Source/ThirdParty/ANGLE/src/libANGLE/Context.cpp:237 > + return static_cast<EGLint>(attribs.getAsInt(EGL_CONTEXT_OWNERSHIP_IDENTITY_METAL_ANGLE, EGL_FALSE));
getAsInt already returns int. The default value should be 0, not EGL_FALSE
> Source/ThirdParty/ANGLE/src/libANGLE/State.h:105 > + EGLint owwnershipIdentity);
Typo, but anyway needs to move away from the State.
> Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/ContextMtl.mm:198 > + mContextDevice(
here you would add as the attribs: ContextMtl(.., AttributeMap& attribs) mContextDevice(GetOwenershipIdentity(attribs)) and in GetOwenershipIdentity you'd #ifdef
> Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/ContextMtl.mm:2449 > +#endif
Maybe remove, read the token off from attributes in the constructor and pass it to ContextDevice
> Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/mtl_context_device.h:28 > + ContextDevice(task_id_token_t ownershipIdentity) { mOwnershipIdentity = ownershipIdentity; }
Maybe: 1) remove ifdef 2) set the parameter as GLint 3) move the implementation to .mm file. In implementation, do following ContextDevice(GLint ownerIdentity) { #if ANGLE_USE_METAL_OWNERSHIP_IDENTITY auto ownerIdentity = static_cast<task_id_token_t>(ownerIdentity); if (ownerIdentity != TASK_ID_TOKEN_NULL) { kr = mach_port_mod_refs(mach_task_self(), ownerIdentity, MACH_PORT_RIGHT_SEND, 1); .... check kr, etc. mOwnerIdentity = ownerIdentity; } #endif } in ~ContextDevice, unref the task token.
> Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/mtl_context_device.mm:18 > +#pragma mark - Context Device implementation
I don't think you need a pragma mark categorisation for a 50 line implementation?
> Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/mtl_context_device.mm:36 > +#if USE_OWNERSHIP_IDENTITY_PRIVATE
so remove the extra ifdefs the code should be auto texture = [get() newTextureWithDescriptor:descriptor]; setOwnerWithIdentity(texture);
> Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/mtl_context_device.mm:124 > +}
Here you would #if: void ContextDevice::setOwnerWithIdentity(id<MTLResource> resource) { #if ANGLE_USE_METAL_OWNERSHIP_IDENTITY setOwnerWithIdentity(resource, mOwnerIdentity); #endif }
> Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/mtl_format_table_autogen.mm:304 > + id<MTLDevice> device = display->getMetalDevice();
these probably are now somehow wrong. Anyway, we shouldn't modify the autopen tables unless the generator is modified. I don't see the python files modified.
> Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/mtl_ownership_identity.h:21 > +#import "libANGLE/renderer/metal/mtl_ownership_identity_private.h"
Is it useful to have the thing implemented as: - if MTLResource_Private.h is missing, don't use - if mtl_ownership_identity_private.h is missing, don't use Can we just remove this file and use the define: ANGLE_USE_METAL_OWNERSHIP_IDENTITY. Then we make sure by default, ANGLE_USE_METAL_OWNERSHIP_IDENTITY is only defined if 1) os version is correct 2) internal headers are visible 3) user has requested the feature (e.g. this define is what common/apple/apple_platform.h would set, see below)
> Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/mtl_ownership_identity_private.h:36 > +
This file could be called mtl_resource_spi.h Contents would be: #if ANGLE_USE_METAL_OWNERSHIP_IDENTITY #import <Metal/Metal.h> #import <Metal/MTLResource_Private.h> #import <mach/mach_types.h> namespace rx { .... } #endif
> Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/mtl_task_identity_token.h:21 > +#define ANGLE_HAVE_MTLRESOURCE_SET_OWNERSHIP_IDENTITY 0
I think this could be moved to common/apple/apple_platform.h I think additionally you could have the __has_include(<Metal/MTLResource_Private.h>) here There you could have additionally #define ANGLE_USE_METAL_OWNERSHIP_IDENTITY (ANGLE_HAVE_MTLRESOURCE_SET_OWNERSHIP_IDENTITY && defined(ANGLE_ENABLE_METAL_OWNERSHIP_IDENTITY))
> Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/mtl_utils.mm:224 > + if ([[metalDevice name] rangeOfString:it.trademark].location != NSNotFound)
might be unneeded change?
> Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/mtl_utils.mm:238 > + return angle::GetVendorIDFromMetalDeviceRegistryID([device registryID]);
might be unneeded change?
> Source/ThirdParty/ANGLE/src/libANGLE/validationEGL.cpp:1634 >
Here you would validate that the passed identity is a task_id_token_t (e.g. at least that it's a send right? I'm not 100% sure) or null token. I don't know yet how to do that, but we want to be relatively sure that there's no error when we ref it
Radar WebKit Bug Importer
Comment 11
2021-12-09 13:13:41 PST
<
rdar://problem/86287434
>
John Cunningham
Comment 12
2021-12-09 13:18:47 PST
Created
attachment 446598
[details]
Patch
John Cunningham
Comment 13
2021-12-09 13:19:15 PST
Comment on
attachment 446442
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=446442&action=review
>> Source/ThirdParty/ANGLE/include/EGL/eglext_angle.h:181 >> +#define EGL_CONTEXT_OWNERSHIP_IDENTITY_METAL_ANGLE 0x33B0 > > Let's put 0x34A7 for now (reserved for ANGLE)
Ok, I think it's already taken by EGL_METAL_TEXTURE_ANGLE but I'll use that for now
>> Source/ThirdParty/ANGLE/src/libANGLE/Caps.h:647 >> + bool createContextOwnershipIdentity = false; > > createContextOwnershipIdentity*Metal* ?
I went ahead and matched the style of ones such as "EGL_ANGLE_vulkan_image/vulkanImageANGLE" and "EGL_ANGLE_d3d_share_handle_client_buffer/d3dShareHandleClientBuffer"
>> Source/ThirdParty/ANGLE/src/libANGLE/Context.cpp:235 >> +EGLint GetOwnershipIdentity(const egl::AttributeMap &attribs) > > This file is for *all* implementations. > Ownership identity is a property of the Metal backend. > You need to move this to ContextMtl
Done
>> Source/ThirdParty/ANGLE/src/libANGLE/Context.cpp:237 >> + return static_cast<EGLint>(attribs.getAsInt(EGL_CONTEXT_OWNERSHIP_IDENTITY_METAL_ANGLE, EGL_FALSE)); > > getAsInt already returns int. > The default value should be 0, not EGL_FALSE
Done
>> Source/ThirdParty/ANGLE/src/libANGLE/State.h:105 >> + EGLint owwnershipIdentity); > > Typo, but anyway needs to move away from the State.
Done
>> Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/ContextMtl.mm:198 >> + mContextDevice( > > here you would add as the attribs: ContextMtl(.., AttributeMap& attribs) > mContextDevice(GetOwenershipIdentity(attribs)) > > and in GetOwenershipIdentity you'd #ifdef
Done
>> Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/ContextMtl.mm:2449 >> +#endif > > Maybe remove, read the token off from attributes in the constructor and pass it to ContextDevice
Done
>> Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/mtl_context_device.h:28 >> + ContextDevice(task_id_token_t ownershipIdentity) { mOwnershipIdentity = ownershipIdentity; } > > Maybe: > 1) remove ifdef > 2) set the parameter as GLint > 3) move the implementation to .mm file. > > In implementation, do following > > ContextDevice(GLint ownerIdentity) > { > #if ANGLE_USE_METAL_OWNERSHIP_IDENTITY > auto ownerIdentity = static_cast<task_id_token_t>(ownerIdentity); > if (ownerIdentity != TASK_ID_TOKEN_NULL) > { > kr = mach_port_mod_refs(mach_task_self(), ownerIdentity, MACH_PORT_RIGHT_SEND, 1); > .... check kr, etc. > mOwnerIdentity = ownerIdentity; > } > #endif > } > in ~ContextDevice, unref the task token.
Done
>> Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/mtl_context_device.mm:18 >> +#pragma mark - Context Device implementation > > I don't think you need a pragma mark categorisation for a 50 line implementation?
True, originally added as I thought there would be more uses of MTLDevice, but there aren't that many, at least not many used by the context. Done
>> Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/mtl_context_device.mm:36 >> +#if USE_OWNERSHIP_IDENTITY_PRIVATE > > so remove the extra ifdefs > the code should be > > auto texture = [get() newTextureWithDescriptor:descriptor]; > setOwnerWithIdentity(texture);
Done
>> Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/mtl_format_table_autogen.mm:304 >> + id<MTLDevice> device = display->getMetalDevice(); > > these probably are now somehow wrong. > Anyway, we shouldn't modify the autopen tables unless the generator is modified. > I don't see the python files modified.
Yeah accidental rename.
>> Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/mtl_ownership_identity_private.h:36 >> + > > This file could be called mtl_resource_spi.h > > Contents would be: > > #if ANGLE_USE_METAL_OWNERSHIP_IDENTITY > > #import <Metal/Metal.h> > #import <Metal/MTLResource_Private.h> > #import <mach/mach_types.h> > > namespace rx > { > > .... > > } > > #endif
Done
>> Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/mtl_task_identity_token.h:21 >> +#define ANGLE_HAVE_MTLRESOURCE_SET_OWNERSHIP_IDENTITY 0 > > I think this could be moved to common/apple/apple_platform.h > I think additionally you could have the __has_include(<Metal/MTLResource_Private.h>) here > > There you could have additionally > > #define ANGLE_USE_METAL_OWNERSHIP_IDENTITY (ANGLE_HAVE_MTLRESOURCE_SET_OWNERSHIP_IDENTITY && defined(ANGLE_ENABLE_METAL_OWNERSHIP_IDENTITY))
Done
>> Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/mtl_utils.mm:224 >> + if ([[metalDevice name] rangeOfString:it.trademark].location != NSNotFound) > > might be unneeded change?
I attempted to make it very explicit when we were using the objective c object rather than C++, but it's okay to be reverted Done
>> Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/mtl_utils.mm:238 >> + return angle::GetVendorIDFromMetalDeviceRegistryID([device registryID]); > > might be unneeded change?
Done
>> Source/ThirdParty/ANGLE/src/libANGLE/validationEGL.cpp:1634 >> > > Here you would validate that the passed identity is a task_id_token_t (e.g. at least that it's a send right? I'm not 100% sure) or null token. > I don't know yet how to do that, but we want to be relatively sure that there's no error when we ref it
I'll add a TODO for now.
John Cunningham
Comment 14
2021-12-09 23:18:48 PST
Created
attachment 446670
[details]
Patch
John Cunningham
Comment 15
2021-12-09 23:19:44 PST
I ran clang-format using the ANGLE style on the changed files.
John Cunningham
Comment 16
2021-12-10 02:15:03 PST
Created
attachment 446691
[details]
Patch
Kimmo Kinnunen
Comment 17
2021-12-10 02:26:47 PST
Comment on
attachment 446691
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=446691&action=review
> Source/ThirdParty/ANGLE/src/libANGLE/Caps.cpp:1297 > // clang-format on
strangely the clang-format off / on doesn't apply here?
> Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/ContextMtl.mm:2450 > +GLint ContextMtl::getOwnershipIdentity(const egl::AttributeMap &attribs) const
This function should be just a compile-unit local function in the anonymous namespace at the top of the file, GetOwnershipIdentity...
> Source/WebCore/platform/graphics/cocoa/GraphicsContextGLCocoa.mm:326 > +#if HAVE(MTLRESOURCE_SET_OWNERSHIP_IDENTITY) && HAVE(TASK_IDENTITY_TOKEN)
move this to new bug and some other feedback in slack
John Cunningham
Comment 18
2021-12-10 03:28:19 PST
Created
attachment 446703
[details]
Patch
John Cunningham
Comment 19
2021-12-10 11:32:22 PST
Created
attachment 446769
[details]
Patch
Jonah RD
Comment 20
2021-12-10 14:03:45 PST
Comment on
attachment 446769
[details]
Patch Looks good to me. Two things that should be added: - Entry to egl_angle_ext.xml (for an enum like so:
https://source.chromium.org/chromium/chromium/src/+/main:third_party/angle/scripts/egl_angle_ext.xml;l=175?q=EGL_ANGLE_display_semaphore_share_group&ss=chromium&start=1
) - Entry in registry_xml.py for supported_egl_extensions:
https://source.chromium.org/chromium/chromium/src/+/main:third_party/angle/scripts/registry_xml.py;l=276
John Cunningham
Comment 21
2021-12-10 16:26:27 PST
Created
attachment 446844
[details]
Patch for landing
Kenneth Russell
Comment 22
2021-12-10 17:54:40 PST
Comment on
attachment 446844
[details]
Patch for landing View in context:
https://bugs.webkit.org/attachment.cgi?id=446844&action=review
Couple of quick points: 1) If at all possible let's land this upstream in ANGLE first and then roll it into WebKit. This touches a lot of files, and given that we're still upstreaming WebKit's changes, has the potential to introduce a lot of conflicts during the next roll. 2) I've allocated an enum value in ANGLE's internal doc for the new extension. Please follow Jonah's recommendations about making sure all the bookkeeping files are updated in the repo. Thanks.
> Source/ThirdParty/ANGLE/include/EGL/eglext_angle.h:181 > +#define EGL_CONTEXT_METAL_OWNERSHIP_IDENTITY_ANGLE 0x34A7
The ANGLE team maintains an internal document allocating these enums. I've reserved 0x34D2 for this purpose.
John Cunningham
Comment 23
2021-12-12 22:52:32 PST
Created
attachment 446970
[details]
Patch for landing
John Cunningham
Comment 24
2021-12-12 22:53:14 PST
(In reply to Kenneth Russell from
comment #22
)
> Comment on
attachment 446844
[details]
> Patch for landing > > View in context: >
https://bugs.webkit.org/attachment.cgi?id=446844&action=review
> > Couple of quick points: > > 1) If at all possible let's land this upstream in ANGLE first and then roll > it into WebKit. This touches a lot of files, and given that we're still > upstreaming WebKit's changes, has the potential to introduce a lot of > conflicts during the next roll. > > 2) I've allocated an enum value in ANGLE's internal doc for the new > extension. Please follow Jonah's recommendations about making sure all the > bookkeeping files are updated in the repo. > > Thanks. > > > Source/ThirdParty/ANGLE/include/EGL/eglext_angle.h:181 > > +#define EGL_CONTEXT_METAL_OWNERSHIP_IDENTITY_ANGLE 0x34A7 > > The ANGLE team maintains an internal document allocating these enums. I've > reserved 0x34D2 for this purpose.
Updated to 0x34D2.
John Cunningham
Comment 25
2021-12-13 10:00:56 PST
Created
attachment 447021
[details]
Patch for landing
Kenneth Russell
Comment 26
2021-12-13 10:23:49 PST
Comment on
attachment 447021
[details]
Patch for landing The latest patch looks good to me though I'd again suggest that this first be landed upstream in ANGLE and then rolled forward into WebKit to reduce merge conflicts and reduce the chance of accidents.
John Cunningham
Comment 27
2021-12-14 00:53:05 PST
Created
attachment 447114
[details]
Patch for landing
John Cunningham
Comment 28
2021-12-15 08:46:15 PST
Created
attachment 447237
[details]
Patch for landing
John Cunningham
Comment 29
2021-12-15 09:48:29 PST
Created
attachment 447246
[details]
Patch for landing
Kenneth Russell
Comment 30
2021-12-15 15:06:31 PST
Comment on
attachment 447246
[details]
Patch for landing This patch is pleasingly small now! Great work John doing the major upstreaming first!
EWS
Comment 31
2021-12-16 08:33:48 PST
johncunningham@apple.com
does not have committer permissions according to
https://raw.githubusercontent.com/WebKit/WebKit/main/metadata/contributors.json
. Rejecting
attachment 447246
[details]
from commit queue.
EWS
Comment 32
2021-12-16 09:53:13 PST
Committed
r287143
(
245327@main
): <
https://commits.webkit.org/245327@main
> All reviewed patches have been landed. Closing bug and clearing flags on
attachment 447246
[details]
.
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug