Visitar URL original
[Metal] Add typed SetCaptureObject and TryGetCaptureObject overloads on MTLCaptureDescriptor by rolfbjarne · Pull Request #27323 · dotnet/macios · GitHub
Skip to content

[Metal] Add typed SetCaptureObject and TryGetCaptureObject overloads on MTLCaptureDescriptor - #27323

Open
rolfbjarne wants to merge 3 commits into
dev/rolf/nsobject-as-protocolfrom
dev/rolf/metal-frame-capture-test
Open

rolfbjarne wants to merge 3 commits into
dev/rolf/nsobject-as-protocolfrom
dev/rolf/metal-frame-capture-test

Conversation

@rolfbjarne

Copy link
Copy Markdown
Member

MTLCaptureDescriptor.CaptureObject is typed as NSObject, whereas the objects it accepts (IMTLDevice, IMTLCommandQueue, and IMTLCaptureScope) are protocol interfaces whose runtime wrappers derive from BaseWrapper rather than NSObject.

  • Add NSObject.TryAsProtocol<T> ([NotNullWhen (true)] out T? result) and update NSObject.AsProtocol<T> () to call it.
  • Add MTLCaptureDescriptor.SetCaptureObject overloads for IMTLDevice?, IMTLCommandQueue?, and IMTLCaptureScope?.
  • Add MTLCaptureDescriptor.TryGetCaptureObject overloads for IMTLDevice?, IMTLCommandQueue?, and IMTLCaptureScope? backed by TryAsProtocol<T>.

This is a usability improvement discovered when investigating #6316.

🤖 Pull request created by Copilot

rolfbjarne and others added 3 commits November 11, 2026 09:55
…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>
Copilot AI balanced review requested due to automatic review settings November 12, 2026 21:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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 in AsProtocol<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))

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't this be:

Suggested change
if (CaptureObject is { } obj && obj.TryAsProtocol<IMTLDevice> (out value))
if (CaptureObject?.TryAsProtocol<IMTLDevice> (out value) == true)

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

✅ API diff for current PR / commit

NET (empty diffs)

✅ API diff vs stable

NET (empty diffs)

ℹ️ Generator diff

Generator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes)

Pipeline on Agent
Hash: 840b55566da14f268d6afbd8de05add68e502c31 [PR build]

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

🔥 [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

  • DotNet tests: Failed (Execution failed with exit code 1)
    • Xamarin.Tests.DotNetWatchTest.DotNetWatch(iOS,False): Timed out waiting for the app to start. Output:
      dotnet watch 🔥 Hot reload enabled. For a list of supported edits, see https://a...

Html Report (VSDrops) Download

❌ dotnettests tests (macOS)

1 tests failed, 0 tests passed.

Failed tests

  • DotNet tests: Failed (Execution failed with exit code 1)
    • Xamarin.Tests.AppSizeTest.CoreCLR_R2R(MacOSX,"osx-arm64;osx-x64"...: App size changed significantly (+14,883 bytes (14.5 KB = 0.0 MB) different > tolerance of +-10,240 bytes (10.0 KB = 0.0 MB)). Ex...

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

  • monotouch-test/iOS - simulator/Debug: Failed
  • monotouch-test/iOS - simulator/Debug (PrepareAssemblies): Failed
  • monotouch-test/iOS - simulator/Debug (static registrar): Failed
  • monotouch-test/iOS - simulator/Debug (managed static registrar): Failed
  • monotouch-test/iOS - simulator/Release (compat inline Class.GetHandle): Failed
  • monotouch-test/iOS - simulator/Release (strict inline Class.GetHandle): Failed
  • monotouch-test/iOS - simulator/Release (compat inline dlfcn): Failed
  • monotouch-test/iOS - simulator/Release (NativeAOT, .NET 11 defaults): Failed

Html Report (VSDrops) Download

❌ monotouch tests (MacCatalyst)

3 tests failed, 17 tests passed.

Failed tests

  • monotouch-test/Mac Catalyst/Debug (managed static registrar): Failed (Test run failed.
    Tests run: 3919 Passed: 3746 Inconclusive: 20 Failed: 1 Ignored: 172)
  • monotouch-test/Mac Catalyst/Release (managed static registrar): Failed (Test run failed.
    Tests run: 3919 Passed: 3741 Inconclusive: 20 Failed: 1 Ignored: 177)
  • monotouch-test/Mac Catalyst/Release (NativeAOT, .NET 11 defaults): Failed (Test run failed.
    Tests run: 3919 Passed: 3716 Inconclusive: 20 Failed: 1 Ignored: 202)

Html Report (VSDrops) Download

❌ monotouch tests (macOS)

1 tests failed, 19 tests passed.

Failed tests

  • monotouch-test/macOS/Release (NativeAOT, .NET 11 defaults): Failed (Test run failed.
    Tests run: 3902 Passed: 3753 Inconclusive: 14 Failed: 1 Ignored: 148)

Html Report (VSDrops) Download

❌ monotouch tests (tvOS)

8 tests failed, 12 tests passed.

Failed tests

  • monotouch-test/tvOS - simulator/Debug: Failed
  • monotouch-test/tvOS - simulator/Debug (PrepareAssemblies): Failed
  • monotouch-test/tvOS - simulator/Debug (static registrar): Failed
  • monotouch-test/tvOS - simulator/Debug (managed static registrar): Failed
  • monotouch-test/tvOS - simulator/Release (compat inline Class.GetHandle): Failed
  • monotouch-test/tvOS - simulator/Release (strict inline Class.GetHandle): Failed
  • monotouch-test/tvOS - simulator/Release (compat inline dlfcn): Failed
  • monotouch-test/tvOS - simulator/Release (NativeAOT, .NET 11 defaults): Failed

Html Report (VSDrops) Download

❌ Tests on macOS Sonoma (14) tests

1 tests failed, 4 tests passed.

Failed tests

  • macOS/osx-x64 monotouch-test: Failed (exit code 1)
    • [FAIL] Trust_FullChain : Evaluate: “mail.google.com” certificate is not standards compliant
    • [FAIL] Trust2_FullChain : Evaluate: “mail.google.com” certificate is not standards compliant
  • MacCatalyst/maccatalyst-x64 monotouch-test: Failed (exit code 1)
    • [FAIL] Trust_FullChain : Evaluate: “mail.google.com” certificate is not standards compliant
    • [FAIL] Trust2_FullChain : Evaluate: “mail.google.com” certificate is not standards compliant
    • [FAIL] PerformAsynchronousFileAccess_Null : System.UnauthorizedAccessException : Access to the path '/Users/builder/Documents/mydocument.txt' is denied.
    • ... and 1 more failures

Html Report (VSDrops) Download

❌ Tests on macOS Sequoia (15) tests

1 tests failed, 4 tests passed.

Failed tests

  • macOS/osx-x64 monotouch-test: Failed (exit code 1)
    • [FAIL] Trust_FullChain : Evaluate: “mail.google.com” certificate is not standards compliant
    • [FAIL] Trust2_FullChain : Evaluate: “mail.google.com” certificate is not standards compliant
  • macOS/osx-arm64 monotouch-test: Failed (exit code 1)
    • [FAIL] Trust_FullChain : Evaluate: “mail.google.com” certificate is not standards compliant
    • [FAIL] Trust2_FullChain : Evaluate: “mail.google.com” certificate is not standards compliant
  • MacCatalyst/maccatalyst-x64 monotouch-test: Failed (exit code 137)
    • [FAIL] Trust_FullChain : Evaluate: “mail.google.com” certificate is not standards compliant
    • [FAIL] Trust2_FullChain : Evaluate: “mail.google.com” certificate is not standards compliant
  • MacCatalyst/maccatalyst-arm64 monotouch-test: Failed (exit code 137)
    • [FAIL] Trust_FullChain : Evaluate: “mail.google.com” certificate is not standards compliant
    • [FAIL] Trust2_FullChain : Evaluate: “mail.google.com” certificate is not standards compliant

Html Report (VSDrops) Download

Successes

✅ assembly-processing: All 1 tests passed. Html Report (VSDrops) Download
✅ cecil: All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (MacCatalyst): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (tvOS): All 1 tests passed. Html Report (VSDrops) Download
✅ framework: All 2 tests passed. Html Report (VSDrops) Download
✅ fsharp: All 4 tests passed. Html Report (VSDrops) Download
✅ generator: All 1 tests passed. Html Report (VSDrops) Download
✅ interdependent-binding-projects: All 4 tests passed. Html Report (VSDrops) Download
✅ introspection: All 4 tests passed. Html Report (VSDrops) Download
✅ linker (iOS): All 21 tests passed. Html Report (VSDrops) Download
✅ linker (MacCatalyst): All 21 tests passed. Html Report (VSDrops) Download
✅ linker (macOS): All 21 tests passed. Html Report (VSDrops) Download
✅ linker (tvOS): All 21 tests passed. Html Report (VSDrops) Download
✅ msbuild: All 2 tests passed. Html Report (VSDrops) Download
✅ sharpie: All 1 tests passed. Html Report (VSDrops) Download
✅ windows: All 3 tests passed. Html Report (VSDrops) Download
✅ xcframework: All 4 tests passed. Html Report (VSDrops) Download
✅ xtro: All 1 tests passed. Html Report (VSDrops) Download

macOS tests

✅ Tests on macOS Tahoe (26): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Golden Gate (27): All 5 tests passed. Html Report (VSDrops) Download

Linux Build Verification

✅ Linux build succeeded

Pipeline on Agent
Hash: 840b55566da14f268d6afbd8de05add68e502c31 [PR build]

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

⚠️ AppSizeTest expected files changed ⚠️

The AppSizeTest detected changes in the expected app size files.

To update the expected files, add a comment with the following command:

/apply-gist https://gist.github.com/vs-mobiletools-engineering-service2/49a2c5b6218def8464ee928fe0b8670d
Updated files
  • MacOSX-CoreCLR-R2R-size.txt

Pipeline on Agent
Hash: 840b55566da14f268d6afbd8de05add68e502c31 [PR build]

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants