Repository navigation
[Metal] Add typed SetCaptureObject and TryGetCaptureObject overloads on MTLCaptureDescriptor - #27323
rolfbjarne wants to merge 3 commits into
Conversation
…on MTLCaptureDescriptor Add NSObject.TryAsProtocol<T>(out T?) and use it to implement MTLCaptureDescriptor.TryGetCaptureObject overloads for IMTLDevice, IMTLCommandQueue, and IMTLCaptureScope alongside typed SetCaptureObject overloads. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
The null-device guard does not prevent unsupported MTLCaptureManager.Shared calls on iOS/tvOS simulators, so scope creation needs a simulator-specific skip.
1 open issue
What changed in this PR
This PR improves Metal capture usability by allowing protocol interfaces to be used directly with MTLCaptureDescriptor, without changing its existing NSObject-typed property.
Changes:
- Add
NSObject.TryAsProtocol<T>and reuse it inAsProtocol<T>. - Add typed capture-object setters and try-getters for devices, command queues, and capture scopes.
- Add tests for protocol conversion, typed access, and clearing capture objects.
| File | Description |
|---|---|
tests/monotouch-test/Metal/MTLCaptureDescriptorTest.cs |
Tests typed capture-object access and clearing. |
tests/monotouch-test/Foundation/ObjectTest.cs |
Extends protocol-conversion tests to cover TryAsProtocol. |
src/Metal/MTLCaptureDescriptor.cs |
Implements three typed capture-object try-getters. |
src/metal.cs |
Adds three typed capture-object setter bindings. |
src/frameworks.sources |
Includes the new Metal implementation file. |
src/Foundation/NSObject2.cs |
Adds try-style protocol conversion and delegates AsProtocol to it. |
Review effort: Balanced
| } | ||
|
|
||
| // Set IMTLCaptureScope | ||
| using var scope = MTLCaptureManager.Shared.CreateNewCaptureScope (device); |
| /// <returns><see langword="true" /> if <see cref="CaptureObject" /> is non-null and conforms to <see cref="IMTLDevice" />; otherwise, <see langword="false" />.</returns> | ||
| public bool TryGetCaptureObject ([NotNullWhen (true)] out IMTLDevice? value) | ||
| { | ||
| if (CaptureObject is { } obj && obj.TryAsProtocol<IMTLDevice> (out value)) |
There was a problem hiding this comment.
Couldn't this be:
| if (CaptureObject is { } obj && obj.TryAsProtocol<IMTLDevice> (out value)) | |
| if (CaptureObject?.TryAsProtocol<IMTLDevice> (out value) == true) |
✅ API diff for current PR / commitNET (empty diffs)✅ API diff vs stableNET (empty diffs)ℹ️ Generator diffGenerator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes) Pipeline on Agent |
🔥 [CI Build #840b555] Test results 🔥Test results❌ Tests failed on VSTS: test results 1 tests crashed, 24 tests failed, 192 tests passed. Failures❌ dotnettests tests (iOS)1 tests failed, 0 tests passed.Failed tests
Html Report (VSDrops) Download ❌ dotnettests tests (macOS)1 tests failed, 0 tests passed.Failed tests
Html Report (VSDrops) Download ❌ dotnettests tests (Multiple platforms)🔥 Failed catastrophically on VSTS: test results - dotnettests_multiple (no summary found). Html Report (VSDrops) Download ❌ monotouch tests (iOS)8 tests failed, 12 tests passed.Failed tests
Html Report (VSDrops) Download ❌ monotouch tests (MacCatalyst)3 tests failed, 17 tests passed.Failed tests
Html Report (VSDrops) Download ❌ monotouch tests (macOS)1 tests failed, 19 tests passed.Failed tests
Html Report (VSDrops) Download ❌ monotouch tests (tvOS)8 tests failed, 12 tests passed.Failed tests
Html Report (VSDrops) Download ❌ Tests on macOS Sonoma (14) tests1 tests failed, 4 tests passed.Failed tests
Html Report (VSDrops) Download ❌ Tests on macOS Sequoia (15) tests1 tests failed, 4 tests passed.Failed tests
Html Report (VSDrops) Download Successes✅ assembly-processing: All 1 tests passed. Html Report (VSDrops) Download macOS tests✅ Tests on macOS Tahoe (26): All 5 tests passed. Html Report (VSDrops) Download Linux Build VerificationPipeline on Agent |
|

MTLCaptureDescriptor.CaptureObjectis typed asNSObject, whereas the objects it accepts (IMTLDevice,IMTLCommandQueue, andIMTLCaptureScope) are protocol interfaces whose runtime wrappers derive fromBaseWrapperrather thanNSObject.NSObject.TryAsProtocol<T> ([NotNullWhen (true)] out T? result)and updateNSObject.AsProtocol<T> ()to call it.MTLCaptureDescriptor.SetCaptureObjectoverloads forIMTLDevice?,IMTLCommandQueue?, andIMTLCaptureScope?.MTLCaptureDescriptor.TryGetCaptureObjectoverloads forIMTLDevice?,IMTLCommandQueue?, andIMTLCaptureScope?backed byTryAsProtocol<T>.This is a usability improvement discovered when investigating #6316.
🤖 Pull request created by Copilot