|
| 1 | +#nullable enable |
| 2 | + |
| 3 | +using System; |
| 4 | +using System.Buffers; |
| 5 | +using System.Runtime.InteropServices; |
| 6 | + |
| 7 | +using Foundation; |
| 8 | +using ObjCRuntime; |
| 9 | +using Metal; |
| 10 | +using MetalPerformanceShaders; |
| 11 | + |
| 12 | +namespace MetalPerformanceShadersGraph { |
| 13 | + /// <summary>This enum is used to select how to initialize a new instance of a <see cref="MPSGraphExecutable" />.</summary> |
| 14 | +#if NET |
| 15 | + [SupportedOSPlatform ("ios17.0")] |
| 16 | + [SupportedOSPlatform ("maccatalyst17.0")] |
| 17 | + [SupportedOSPlatform ("macos14.0")] |
| 18 | + [SupportedOSPlatform ("tvos17.0")] |
| 19 | +#else |
| 20 | + [TV (17, 0), Mac (14, 0), iOS (17, 0), MacCatalyst (17, 0)] |
| 21 | +#endif |
| 22 | + public enum MPSGraphExecutableInitializationOption { |
| 23 | + /// <summary>The <c>packageUrl</c> parameter passed to the constructor is a url to a CoreML package.</summary> |
| 24 | +#if NET |
| 25 | + [SupportedOSPlatform ("ios18.0")] |
| 26 | + [SupportedOSPlatform ("maccatalyst18.0")] |
| 27 | + [SupportedOSPlatform ("macos15.0")] |
| 28 | + [SupportedOSPlatform ("tvos18.0")] |
| 29 | +#else |
| 30 | + [TV (18, 0), Mac (15, 0), iOS (18, 0), MacCatalyst (18, 0)] |
| 31 | +#endif |
| 32 | + CoreMLPackage, |
| 33 | + |
| 34 | + /// <summary>The <c>packageUrl</c> parameter passed to the constructor is a url to a MPSGraph package.</summary> |
| 35 | + MPSGraphPackage, |
| 36 | + } |
| 37 | + |
| 38 | + public partial class MPSGraphExecutable { |
| 39 | + /// <summary>Create a new MPSGraphExecutable instance from a package url and a compilation descriptor..</summary> |
| 40 | + /// <param name="packageUrl">The url to the package to use.</param> |
| 41 | + /// <param name="compilationDescriptor">The optional compilation descriptor use.</param> |
| 42 | + /// <param name="option">Use this option to specify whether the package url points to a CoreML package or an MPSGraph package.</param> |
| 43 | +#if NET |
| 44 | + [SupportedOSPlatform ("ios17.0")] |
| 45 | + [SupportedOSPlatform ("maccatalyst17.0")] |
| 46 | + [SupportedOSPlatform ("macos14.0")] |
| 47 | + [SupportedOSPlatform ("tvos17.0")] |
| 48 | +#else |
| 49 | + [TV (17, 0), Mac (14, 0), iOS (17, 0), MacCatalyst (17, 0)] |
| 50 | +#endif |
| 51 | + public MPSGraphExecutable (NSUrl packageUrl, MPSGraphCompilationDescriptor? compilationDescriptor, MPSGraphExecutableInitializationOption option) |
| 52 | + : base (NSObjectFlag.Empty) |
| 53 | + { |
| 54 | + switch (option) { |
| 55 | + case MPSGraphExecutableInitializationOption.CoreMLPackage: |
| 56 | + InitializeHandle (_InitWithCoreMLPackage (packageUrl, compilationDescriptor)); |
| 57 | + break; |
| 58 | + case MPSGraphExecutableInitializationOption.MPSGraphPackage: |
| 59 | + InitializeHandle (_InitWithMPSGraphPackage (packageUrl, compilationDescriptor)); |
| 60 | + break; |
| 61 | + default: |
| 62 | + throw new ArgumentOutOfRangeException (nameof (option), option, "Invalid enum value."); |
| 63 | + } |
| 64 | + } |
| 65 | + } |
| 66 | +} |
0 commit comments