Skip to content

Commit 7ad1837

Browse files
mandel-macaqueGitHub Actions Autoformatterrolfbjarneharitha-mohandalexsoto
authored
[Metal] Add support for Xcode15. (#19379)
This PR brings all the changes from the new Metal APIs. During the review pay special attention to the changes done in the Protocols in order to add tvOS support. The main problem we have had doing this PR is that tvOS was not done on time before the NET branching, that left us with a lot of memebers that were NOT added in tvOS that are abstract on dotnet, which has left use in a pickle. Lets use the following code as an example. Code found before this commit: ```csharp [Mac (11, 0), iOS (14, 0), NoTV] [MacCatalyst (14, 0)] #if NET [Abstract] #endif [Export ("accelerationStructureCommandEncoder")] IMTLAccelerationStructureCommandEncoder CreateAccelerationStructureCommandEncoder (); ``` A naive approach would be to add just the tvOS suppor as follows: ```csharp [Mac (11, 0), iOS (14, 0), TV (16,0)] [MacCatalyst (14, 0)] #if NET [Abstract] #endif [Export ("accelerationStructureCommandEncoder")] IMTLAccelerationStructureCommandEncoder CreateAccelerationStructureCommandEncoder (); ``` The above change represents and API braking change on the donet tvOS dll because it adds a new Abstrtact members, so this is no an acceptable solution. There is a second naive approach we can take which is as follows: ```csharp [Mac (11, 0), iOS (14, 0), TV (16,0)] [MacCatalyst (14, 0)] #if NET &!TVOS [Abstract] #endif [Export ("accelerationStructureCommandEncoder")] IMTLAccelerationStructureCommandEncoder CreateAccelerationStructureCommandEncoder (); ``` Yet again, the naive approach has an issue with it. In this case, all the extension methods that are generated for tvOS (something the generator writes when methods are not abstract) will be decorated with availability attributes for all the other platforms, which is incorrect and will make developers life worse. That leaves us with the following approach: ```csharp #if NET #if !TVOS [Mac (11, 0), iOS (14, 0), NoTV, MacCatalyst (14, 0)] [Abstract] #else [NoMac, NoiOS, TV (16,0), NoMacCatalyst] #endif #else [Mac (11, 0), iOS (14, 0), TV (16,0), MacCatalyst (14, 0)] #endif [Export ("accelerationStructureCommandEncoder")] IMTLAccelerationStructureCommandEncoder CreateAccelerationStructureCommandEncoder (); ``` With the above change, we do not add an abstract method in tvOS and we only add the tvOS abailabity attribute to the extension methods, and use NoiOS etc for all the other platforms. The change had to be done to ALL methods that added tvOS support. The good news are that our cecil tests and our introspection tests catch the two naive approaces :) --------- Co-authored-by: GitHub Actions Autoformatter <[email protected]> Co-authored-by: Rolf Bjarne Kvinge <[email protected]> Co-authored-by: Haritha Mohan <[email protected]> Co-authored-by: Alex Soto <[email protected]>
1 parent 5cac237 commit 7ad1837

25 files changed

+2716
-2812
lines changed

src/Metal/Defs.cs

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -492,16 +492,18 @@ public struct MTLTextureSwizzleChannels {
492492
#endif
493493
}
494494

495-
#if IOS || MONOMAC || COREBUILD
495+
#if IOS || MONOMAC || COREBUILD || TVOS
496496

497497
#if NET
498498
[SupportedOSPlatform ("ios13.0")]
499499
[SupportedOSPlatform ("maccatalyst13.4")]
500500
[SupportedOSPlatform ("macos")]
501+
[SupportedOSPlatform ("tvos16.0")]
501502
#else
502503
[Introduced (PlatformName.iOS, 13,0, PlatformArchitecture.All)]
503504
[Introduced (PlatformName.MacCatalyst, 13, 4)]
504505
[Introduced (PlatformName.MacOSX, 10, 15, 4)]
506+
[Introduced (PlatformName.TvOS, 16, 0)]
505507
#endif
506508
[StructLayout (LayoutKind.Sequential)]
507509
public struct MTLVertexAmplificationViewMapping {
@@ -514,10 +516,12 @@ public struct MTLVertexAmplificationViewMapping {
514516
[SupportedOSPlatform ("ios13.0")]
515517
[SupportedOSPlatform ("maccatalyst13.4")]
516518
[SupportedOSPlatform ("macos")]
519+
[SupportedOSPlatform ("tvos17.0")]
517520
#else
518521
[Introduced (PlatformName.iOS, 13,0, PlatformArchitecture.All)]
519522
[Introduced (PlatformName.MacCatalyst, 13, 4)]
520523
[Introduced (PlatformName.MacOSX, 10, 15, 4)]
524+
[Introduced (PlatformName.TvOS, 17,0)]
521525
#endif
522526
[StructLayout (LayoutKind.Sequential)]
523527
public struct MTLCoordinate2D {
@@ -527,21 +531,16 @@ public struct MTLCoordinate2D {
527531
}
528532
#endif
529533

530-
#if !TVOS || !NET
531-
532534
#if NET
533535
[SupportedOSPlatform ("maccatalyst14.0")]
534536
[SupportedOSPlatform ("macos11.0")]
535537
[SupportedOSPlatform ("ios14.0")]
536-
[UnsupportedOSPlatform ("tvos")]
538+
[SupportedOSPlatform ("tvos16.1")]
537539
#else
538-
[Introduced (PlatformName.MacCatalyst, 14, 0)]
540+
[MacCatalyst (14, 0)]
539541
[Mac (11, 0)]
540542
[iOS (14, 0)]
541-
[NoTV]
542-
#if TVOS
543-
[Obsolete ("This API is not available on this platform.")]
544-
#endif
543+
[TV (16, 1)]
545544
#endif
546545
[StructLayout (LayoutKind.Sequential)]
547546
public struct MTLAccelerationStructureSizes {
@@ -551,5 +550,19 @@ public struct MTLAccelerationStructureSizes {
551550

552551
public nuint RefitScratchBufferSize;
553552
}
553+
554+
#if NET
555+
[SupportedOSPlatform ("ios16.0")]
556+
[SupportedOSPlatform ("maccatalyst16.0")]
557+
[SupportedOSPlatform ("macos13.0")]
558+
[SupportedOSPlatform ("tvos16.0")]
559+
#else
560+
[Mac (13, 0), iOS (16, 0), TV (16, 0), MacCatalyst (16, 0), NoWatch]
554561
#endif
562+
[NativeName ("MTLResourceID")]
563+
[StructLayout (LayoutKind.Sequential)]
564+
public struct MTLResourceId {
565+
public ulong Impl;
566+
}
567+
555568
}

0 commit comments

Comments
 (0)