Skip to content

Commit

Permalink
[Metal] Add Support for DotNet Attributes (#12604)
Browse files Browse the repository at this point in the history
  • Loading branch information
tj-devel709 authored Sep 10, 2021
1 parent aadd532 commit fc8b7c9
Show file tree
Hide file tree
Showing 12 changed files with 247 additions and 11 deletions.
2 changes: 2 additions & 0 deletions src/Metal/Defs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,9 @@ public partial interface IMTLTexture {
}
#endif // COREBUILD
#if MONOMAC
#if !NET
[NoiOS, NoTV, NoWatch, Mac (10,14)]
#endif
public struct MTLIndirectCommandBufferExecutionRange
{
public uint Location;
Expand Down
14 changes: 10 additions & 4 deletions src/Metal/MTLCompat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using Foundation;
using ObjCRuntime;
using System.Runtime.Versioning;

#nullable enable

Expand All @@ -22,9 +23,11 @@ public static IMTLCounterSet[] GetIMTLCounterSets (this IMTLDevice This)
return NSArray.ArrayFromHandle<IMTLCounterSet>(global::ObjCRuntime.Messaging.IntPtr_objc_msgSend (This.Handle, Selector.GetHandle ("counterSets")));
}

[Unavailable (PlatformName.iOS, PlatformArchitecture.All)]
[Unavailable (PlatformName.TvOS, PlatformArchitecture.All)]
#if !NET
[Introduced (PlatformName.MacOSX, 10,15, PlatformArchitecture.All)]
#else
[SupportedOSPlatform ("macos10.15")]
#endif
[BindingImpl (BindingImplOptions.Optimizable)]
public static IMTLCounterSampleBuffer CreateIMTLCounterSampleBuffer (this IMTLDevice This, MTLCounterSampleBufferDescriptor descriptor, out NSError error)
{
Expand All @@ -40,9 +43,12 @@ public static IMTLCounterSampleBuffer CreateIMTLCounterSampleBuffer (this IMTLDe
}

public static partial class MTLComputeCommandEncoder_Extensions {
[Unavailable (PlatformName.iOS, PlatformArchitecture.All)]
[Unavailable (PlatformName.TvOS, PlatformArchitecture.All)]
#if !NET
[Introduced (PlatformName.MacOSX, 10,15, PlatformArchitecture.All)]
#else
[SupportedOSPlatform ("macos10.15")]
#endif

[BindingImpl (BindingImplOptions.Optimizable)]
public static void SampleCounters (this IMTLComputeCommandEncoder This, IMTLCounterSampleBuffer sampleBuffer, nuint sampleIndex, bool barrier)
{
Expand Down
17 changes: 13 additions & 4 deletions src/Metal/MTLDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,27 @@ public static IMTLDevice? SystemDefault {
}

#if MONOMAC
[NoiOS, NoWatch, NoTV]
[DllImport (Constants.MetalLibrary)]
unsafe static extern IntPtr MTLCopyAllDevices ();

#if !NET
[NoiOS, NoWatch, NoTV]
#endif
public static IMTLDevice [] GetAllDevices ()
{
var rv = MTLCopyAllDevices ();
return NSArray.ArrayFromHandle<IMTLDevice> (rv);
}

[Mac (10, 13), NoiOS, NoWatch, NoTV]
#if !NET
[Mac (10, 13)]
#endif
[DllImport (Constants.MetalLibrary)]
unsafe static extern IntPtr MTLCopyAllDevicesWithObserver (ref IntPtr observer, void* handler);

[Mac (10, 13), NoiOS, NoWatch, NoTV]
#if !NET
[Mac (10, 13)]
#endif
[BindingImpl (BindingImplOptions.Optimizable)]
public static IMTLDevice [] GetAllDevices (ref NSObject observer, MTLDeviceNotificationHandler handler)
{
Expand Down Expand Up @@ -105,11 +110,15 @@ public static unsafe void TrampolineNotificationHandler (IntPtr block, IntPtr de
del ((IMTLDevice) Runtime.GetNSObject (device), (Foundation.NSString) Runtime.GetNSObject (notifyName));
}

[Mac (10, 13), NoiOS, NoWatch, NoTV]
#if !NET
[Mac (10, 13)]
#endif
[DllImport (Constants.MetalLibrary)]
static extern void MTLRemoveDeviceObserver (IntPtr observer);

#if !NET
[Mac (10, 13), NoiOS, NoWatch, NoTV]
#endif
public static void RemoveObserver (NSObject observer)
{
if (observer == null)
Expand Down
13 changes: 13 additions & 0 deletions src/Metal/MTLRenderCommandEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;

using Foundation;
using ObjCRuntime;
Expand All @@ -10,29 +11,41 @@

namespace Metal {
public static class IMTLRenderCommandEncoder_Extensions {
#if !NET
[Mac (10,13), NoiOS, NoTV, NoWatch]
#endif
public unsafe static void SetViewports (this IMTLRenderCommandEncoder This, MTLViewport [] viewports)
{
fixed (void* handle = viewports)
This.SetViewports ((IntPtr)handle, (nuint)(viewports?.Length ?? 0));
}

#if !NET
[Mac (10,13), NoiOS, NoTV, NoWatch]
#endif
public unsafe static void SetScissorRects (this IMTLRenderCommandEncoder This, MTLScissorRect [] scissorRects)
{
fixed (void* handle = scissorRects)
This.SetScissorRects ((IntPtr)handle, (nuint)(scissorRects?.Length ?? 0));
}

#if IOS
#if !NET
[iOS (11,0), NoTV, NoMac, NoWatch]
#else
[SupportedOSPlatform ("ios11.0")]
#endif
public unsafe static void SetTileBuffers (this IMTLRenderCommandEncoder This, IMTLBuffer[] buffers, nuint[] offsets, NSRange range)
{
fixed (void* handle = offsets)
This.SetTileBuffers (buffers, (IntPtr)handle, range);
}

#if !NET
[iOS (11,0), NoTV, NoMac, NoWatch]
#else
[SupportedOSPlatform ("ios11.0")]
#endif
public unsafe static void SetTileSamplerStates (this IMTLRenderCommandEncoder This, IMTLSamplerState[] samplers, float[] lodMinClamps, float[] lodMaxClamps, NSRange range)
{
fixed (void* minHandle = lodMinClamps) {
Expand Down
6 changes: 6 additions & 0 deletions src/MetalPerformanceShaders/MPSCnnConvolutionDescriptor.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
using System;
using ObjCRuntime;
using System.Runtime.Versioning;

namespace MetalPerformanceShaders {
public partial class MPSCnnConvolutionDescriptor {

#if !NET
[Introduced (PlatformName.TvOS, 11, 0, PlatformArchitecture.All, null)]
[Introduced (PlatformName.iOS, 11, 0, PlatformArchitecture.All, null)]
#else
[SupportedOSPlatform ("ios11.0")]
[SupportedOSPlatform ("tvos11.0")]
#endif
public unsafe void SetBatchNormalizationParameters (float [] mean, float [] variance, float [] gamma, float [] beta, float epsilon)
{
fixed (void* meanHandle = mean)
Expand Down
20 changes: 17 additions & 3 deletions src/MetalPerformanceShaders/MPSCnnNeuron.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,26 @@
using Metal;
using Foundation;
using ObjCRuntime;
using System.Runtime.Versioning;

namespace MetalPerformanceShaders {
public partial class MPSCnnNeuronPReLU {
[Deprecated (PlatformName.TvOS, 12, 0, message: "Please use '.ctor (IMTLDevice, MPSNNNeuronDescriptor)' overload instead.")]
[Deprecated (PlatformName.iOS, 12, 0, message: "Please use '.ctor (IMTLDevice, MPSNNNeuronDescriptor)' overload instead.")]
[Deprecated (PlatformName.MacOSX, 10, 14, message: "Please use '.ctor (IMTLDevice, MPSNNNeuronDescriptor)' overload instead.")]
#if !NET
[Deprecated (PlatformName.TvOS, 12, 0, message: "Please use the '.ctor (IMTLDevice, MPSNNNeuronDescriptor)' overload instead.")]
[Deprecated (PlatformName.iOS, 12, 0, message: "Please use the '.ctor (IMTLDevice, MPSNNNeuronDescriptor)' overload instead.")]
[Deprecated (PlatformName.MacOSX, 10, 14, message: "Please use the '.ctor (IMTLDevice, MPSNNNeuronDescriptor)' overload instead.")]
#else
[UnsupportedOSPlatform ("ios12.0")]
[UnsupportedOSPlatform ("tvos12.0")]
[UnsupportedOSPlatform ("macos10.14")]
#if IOS
[Obsolete ("Starting with ios12.0 please use the '.ctor (IMTLDevice, MPSNNNeuronDescriptor)' overload instead.", DiagnosticId = "BI1234", UrlFormat = "https://github.com/xamarin/xamarin-macios/wiki/Obsolete")]
#elif TVOS
[Obsolete ("Starting with tvos12.0 please use the '.ctor (IMTLDevice, MPSNNNeuronDescriptor)' overload instead.", DiagnosticId = "BI1234", UrlFormat = "https://github.com/xamarin/xamarin-macios/wiki/Obsolete")]
#elif MONOMAC
[Obsolete ("Starting with macos10.14 please use the '.ctor (IMTLDevice, MPSNNNeuronDescriptor)' overload instead.", DiagnosticId = "BI1234", UrlFormat = "https://github.com/xamarin/xamarin-macios/wiki/Obsolete")]
#endif
#endif
public unsafe MPSCnnNeuronPReLU (IMTLDevice device, float [] a) : this (NSObjectFlag.Empty)
{
fixed (void* aHandle = a)
Expand Down
13 changes: 13 additions & 0 deletions src/MetalPerformanceShaders/MPSCompat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using System;
using Metal;
using System.Runtime.Versioning;

using ObjCRuntime;

Expand Down Expand Up @@ -35,14 +36,26 @@ public virtual MPSImage EncodeToCommandBuffer (IMTLCommandBuffer commandBuffer,
}

public partial class MPSCnnConvolution {
#if !NET
[TV (11, 0), iOS (11, 0)]
[Obsolete ("Always throws 'NotSupportedException' (not a public API).")]
#else
[SupportedOSPlatform ("ios11.0")]
[SupportedOSPlatform ("tvos11.0")]
[Obsolete ("Always throws 'NotSupportedException' (not a public API).", DiagnosticId = "BI1234", UrlFormat = "https://github.com/xamarin/xamarin-macios/wiki/Obsolete")]
#endif
public virtual void EncodeToCommandBuffer (IMTLCommandBuffer commandBuffer, MPSImage sourceImage, MPSImage destinationImage, out MPSCnnConvolutionState state)
=> throw new NotSupportedException ();
}

#if !NET
[TV (11,0), Mac (10, 13), iOS (11,0)]
[Obsolete ("Empty stub (not a public API).")]
#else
[SupportedOSPlatform ("ios11.0")]
[SupportedOSPlatform ("tvos11.0")]
[Obsolete ("Empty stub (not a public API).", DiagnosticId = "BI1234", UrlFormat = "https://github.com/xamarin/xamarin-macios/wiki/Obsolete")]
#endif
public partial class MPSCnnConvolutionState : MPSState, IMPSImageSizeEncodingState {

[Obsolete ("Always throws 'NotSupportedException' (not a public API).")]
Expand Down
Loading

7 comments on commit fc8b7c9

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

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

❌ [CI Build] Tests failed on Build ❌

Tests failed on Build.

API diff

✅ API Diff from stable

View API diff

API & Generator diff

API Diff (from PR only) (no change)
Generator Diff (only version changes)

Packages generated

View packages

Test results

1 tests failed, 242 tests passed.

Failed tests

  • monotouch-test/tvOS - simulator/Debug (static registrar) [dotnet]: Failed

Pipeline on Agent XAMBOT-1037.BigSur
[Metal] Add Support for DotNet Attributes (#12604)

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

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

⚠️ Tests were not ran (VSTS: device tests tvOS). ⚠️

Results were skipped for this run due to provisioning problems Azure Devops. Please contact the bot administrator.

Pipeline on Agent
[Metal] Add Support for DotNet Attributes (#12604)

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

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

⚠️ Tests were not ran (VSTS: device tests iOS). ⚠️

Results were skipped for this run due to provisioning problems Azure Devops. Please contact the bot administrator.

Pipeline on Agent
[Metal] Add Support for DotNet Attributes (#12604)

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

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

✅ Tests passed on macOS M1 - Mac Big Sur (11.5) ✅

Tests passed

All tests on macOS X M1 - Mac Big Sur (11.5) passed.

Pipeline on Agent
[Metal] Add Support for DotNet Attributes (#12604)

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

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

✅ Tests passed on macOS Mac Mojave (10.14) ✅

Tests passed

All tests on macOS X Mac Mojave (10.14) passed.

Pipeline on Agent
[Metal] Add Support for DotNet Attributes (#12604)

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

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

❌ Status for 'xamarin-macios - sample testing (build)': failure.

  • ❌ Debug_iPhone_AF: Failed
  • ❌ Debug_iPhone_GR: Failed
  • ❌ Debug_iPhone_SZ: Failed
  • ❌ Debug_iPhoneSimulator: Failed
  • ❌ Release_iPhone_AF: Failed
  • ❌ Release_iPhone_GR: Failed
  • ❌ Release_iPhone_SZ: Failed
  • ❌ Release_iPhoneSimulator: Failed
  • ❌ Debug_Mac: Failed
  • ❌ Release_Mac: Failed
  • ❌ PublishPerformanceData: Failed

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

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

⚠️ Tests were not ran (Build). ⚠️

Results were skipped for this run Azure Devops.

Pipeline on Agent
[Metal] Add Support for DotNet Attributes (#12604)

Please sign in to comment.