Skip to content

Commit

Permalink
[Metal] Add support for Xcode15. (#19379)
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
5 people authored Dec 12, 2023
1 parent 5cac237 commit 7ad1837
Show file tree
Hide file tree
Showing 25 changed files with 2,716 additions and 2,812 deletions.
31 changes: 22 additions & 9 deletions src/Metal/Defs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -492,16 +492,18 @@ public struct MTLTextureSwizzleChannels {
#endif
}

#if IOS || MONOMAC || COREBUILD
#if IOS || MONOMAC || COREBUILD || TVOS

#if NET
[SupportedOSPlatform ("ios13.0")]
[SupportedOSPlatform ("maccatalyst13.4")]
[SupportedOSPlatform ("macos")]
[SupportedOSPlatform ("tvos16.0")]
#else
[Introduced (PlatformName.iOS, 13,0, PlatformArchitecture.All)]
[Introduced (PlatformName.MacCatalyst, 13, 4)]
[Introduced (PlatformName.MacOSX, 10, 15, 4)]
[Introduced (PlatformName.TvOS, 16, 0)]
#endif
[StructLayout (LayoutKind.Sequential)]
public struct MTLVertexAmplificationViewMapping {
Expand All @@ -514,10 +516,12 @@ public struct MTLVertexAmplificationViewMapping {
[SupportedOSPlatform ("ios13.0")]
[SupportedOSPlatform ("maccatalyst13.4")]
[SupportedOSPlatform ("macos")]
[SupportedOSPlatform ("tvos17.0")]
#else
[Introduced (PlatformName.iOS, 13,0, PlatformArchitecture.All)]
[Introduced (PlatformName.MacCatalyst, 13, 4)]
[Introduced (PlatformName.MacOSX, 10, 15, 4)]
[Introduced (PlatformName.TvOS, 17,0)]
#endif
[StructLayout (LayoutKind.Sequential)]
public struct MTLCoordinate2D {
Expand All @@ -527,21 +531,16 @@ public struct MTLCoordinate2D {
}
#endif

#if !TVOS || !NET

#if NET
[SupportedOSPlatform ("maccatalyst14.0")]
[SupportedOSPlatform ("macos11.0")]
[SupportedOSPlatform ("ios14.0")]
[UnsupportedOSPlatform ("tvos")]
[SupportedOSPlatform ("tvos16.1")]
#else
[Introduced (PlatformName.MacCatalyst, 14, 0)]
[MacCatalyst (14, 0)]
[Mac (11, 0)]
[iOS (14, 0)]
[NoTV]
#if TVOS
[Obsolete ("This API is not available on this platform.")]
#endif
[TV (16, 1)]
#endif
[StructLayout (LayoutKind.Sequential)]
public struct MTLAccelerationStructureSizes {
Expand All @@ -551,5 +550,19 @@ public struct MTLAccelerationStructureSizes {

public nuint RefitScratchBufferSize;
}

#if NET
[SupportedOSPlatform ("ios16.0")]
[SupportedOSPlatform ("maccatalyst16.0")]
[SupportedOSPlatform ("macos13.0")]
[SupportedOSPlatform ("tvos16.0")]
#else
[Mac (13, 0), iOS (16, 0), TV (16, 0), MacCatalyst (16, 0), NoWatch]
#endif
[NativeName ("MTLResourceID")]
[StructLayout (LayoutKind.Sequential)]
public struct MTLResourceId {
public ulong Impl;
}

}
Loading

6 comments on commit 7ad1837

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

Please sign in to comment.