Skip to content

Commit

Permalink
[Metal] Implement Xcode 16.0 beta 1, beta 2 and beta 3 changes.
Browse files Browse the repository at this point in the history
Note: there were no changes in beta 3.

Draft because tests are needed for manual APIs, and the changes on the generator should be extracted to a separate PR.

See the CoreSpotlight [PR](#20866) for more generator changes in this area.
  • Loading branch information
rolfbjarne committed Jul 12, 2024
1 parent 3789ab0 commit 1d18c72
Show file tree
Hide file tree
Showing 24 changed files with 620 additions and 494 deletions.
17 changes: 17 additions & 0 deletions src/Metal/MTLCommandBuffer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;

using ObjCRuntime;

#nullable enable

namespace Metal {

public partial interface IMTLCommandBuffer {

/// <summary>Marks the specified residency sets as part of the current command buffer execution.</summary>
public void UseResidencySets (IMTLResidencySet [] residencySets)
{
NativeObjectExtensions.CallWithPointerToFirstElementAndCount (residencySets, nameof (residencySets), UseResidencySets);
}
}
}
23 changes: 23 additions & 0 deletions src/Metal/MTLCommandQueue.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;

using ObjCRuntime;

#nullable enable

namespace Metal {

public partial interface IMTLCommandQueue {

/// <summary>Marks the specified residency sets as part of the current command buffer execution.</summary>
public void AddResidencySets (IMTLResidencySet [] residencySets)
{
NativeObjectExtensions.CallWithPointerToFirstElementAndCount (residencySets, nameof (residencySets), AddResidencySets);
}

/// <summary>Removes the specified residency sets from the current command buffer execution.</summary>
public void RemoveResidencySets (IMTLResidencySet [] residencySets)
{
NativeObjectExtensions.CallWithPointerToFirstElementAndCount (residencySets, nameof (residencySets), RemoveResidencySets);
}
}
}
18 changes: 8 additions & 10 deletions src/Metal/MTLDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,26 +55,26 @@ public static IMTLDevice? SystemDefault {
}
}

#if MONOMAC || __MACCATALYST__

#if NET
[SupportedOSPlatform ("maccatalyst15.0")]
[SupportedOSPlatform ("macos")]
[UnsupportedOSPlatform ("ios")]
[UnsupportedOSPlatform ("tvos")]
[SupportedOSPlatform ("ios18.0")]
[SupportedOSPlatform ("tvos18.0")]
#else
[MacCatalyst (15,0)]
[MacCatalyst (15, 0)]
[iOS (18, 0), TV (18, 0)]
#endif
[DllImport (Constants.MetalLibrary)]
unsafe static extern IntPtr MTLCopyAllDevices ();

#if NET
[SupportedOSPlatform ("maccatalyst15.0")]
[SupportedOSPlatform ("macos")]
[UnsupportedOSPlatform ("ios")]
[UnsupportedOSPlatform ("tvos")]
[SupportedOSPlatform ("ios18.0")]
[SupportedOSPlatform ("tvos18.0")]
#else
[MacCatalyst (15,0)]
[MacCatalyst (15, 0)]
[iOS (18, 0), TV (18, 0)]
#endif
public static IMTLDevice [] GetAllDevices ()
{
Expand All @@ -84,8 +84,6 @@ public static IMTLDevice [] GetAllDevices ()
return devices;
}

#endif

#if MONOMAC

#if NET
Expand Down
54 changes: 53 additions & 1 deletion src/Metal/MTLEnums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -405,14 +405,55 @@ public enum MTLPixelFormat : ulong {
[NoiOS]
[NoMacCatalyst]
BC7_RGBAUnorm_sRGB = 153,

[Deprecated (PlatformName.iOS, 18, 0, message: "Use ASTC/ETC2/BC formats instead.")]
[Deprecated (PlatformName.MacCatalyst, 18, 0, message: "Use ASTC/ETC2/BC formats instead.")]
[Deprecated (PlatformName.MacOSX, 15, 0, message: "Use ASTC/ETC2/BC formats instead.")]
[Deprecated (PlatformName.TvOS, 18, 0, message: "Use ASTC/ETC2/BC formats instead.")]
PVRTC_RGB_2BPP = 160,

[Deprecated (PlatformName.iOS, 18, 0, message: "Use ASTC/ETC2/BC formats instead.")]
[Deprecated (PlatformName.MacCatalyst, 18, 0, message: "Use ASTC/ETC2/BC formats instead.")]
[Deprecated (PlatformName.MacOSX, 15, 0, message: "Use ASTC/ETC2/BC formats instead.")]
[Deprecated (PlatformName.TvOS, 18, 0, message: "Use ASTC/ETC2/BC formats instead.")]
PVRTC_RGB_2BPP_sRGB = 161,

[Deprecated (PlatformName.iOS, 18, 0, message: "Use ASTC/ETC2/BC formats instead.")]
[Deprecated (PlatformName.MacCatalyst, 18, 0, message: "Use ASTC/ETC2/BC formats instead.")]
[Deprecated (PlatformName.MacOSX, 15, 0, message: "Use ASTC/ETC2/BC formats instead.")]
[Deprecated (PlatformName.TvOS, 18, 0, message: "Use ASTC/ETC2/BC formats instead.")]
PVRTC_RGB_4BPP = 162,

[Deprecated (PlatformName.iOS, 18, 0, message: "Use ASTC/ETC2/BC formats instead.")]
[Deprecated (PlatformName.MacCatalyst, 18, 0, message: "Use ASTC/ETC2/BC formats instead.")]
[Deprecated (PlatformName.MacOSX, 15, 0, message: "Use ASTC/ETC2/BC formats instead.")]
[Deprecated (PlatformName.TvOS, 18, 0, message: "Use ASTC/ETC2/BC formats instead.")]
PVRTC_RGB_4BPP_sRGB = 163,

[Deprecated (PlatformName.iOS, 18, 0, message: "Use ASTC/ETC2/BC formats instead.")]
[Deprecated (PlatformName.MacCatalyst, 18, 0, message: "Use ASTC/ETC2/BC formats instead.")]
[Deprecated (PlatformName.MacOSX, 15, 0, message: "Use ASTC/ETC2/BC formats instead.")]
[Deprecated (PlatformName.TvOS, 18, 0, message: "Use ASTC/ETC2/BC formats instead.")]
PVRTC_RGBA_2BPP = 164,

[Deprecated (PlatformName.iOS, 18, 0, message: "Use ASTC/ETC2/BC formats instead.")]
[Deprecated (PlatformName.MacCatalyst, 18, 0, message: "Use ASTC/ETC2/BC formats instead.")]
[Deprecated (PlatformName.MacOSX, 15, 0, message: "Use ASTC/ETC2/BC formats instead.")]
[Deprecated (PlatformName.TvOS, 18, 0, message: "Use ASTC/ETC2/BC formats instead.")]
PVRTC_RGBA_2BPP_sRGB = 165,

[Deprecated (PlatformName.iOS, 18, 0, message: "Use ASTC/ETC2/BC formats instead.")]
[Deprecated (PlatformName.MacCatalyst, 18, 0, message: "Use ASTC/ETC2/BC formats instead.")]
[Deprecated (PlatformName.MacOSX, 15, 0, message: "Use ASTC/ETC2/BC formats instead.")]
[Deprecated (PlatformName.TvOS, 18, 0, message: "Use ASTC/ETC2/BC formats instead.")]
PVRTC_RGBA_4BPP = 166,

[Deprecated (PlatformName.iOS, 18, 0, message: "Use ASTC/ETC2/BC formats instead.")]
[Deprecated (PlatformName.MacCatalyst, 18, 0, message: "Use ASTC/ETC2/BC formats instead.")]
[Deprecated (PlatformName.MacOSX, 15, 0, message: "Use ASTC/ETC2/BC formats instead.")]
[Deprecated (PlatformName.TvOS, 18, 0, message: "Use ASTC/ETC2/BC formats instead.")]
PVRTC_RGBA_4BPP_sRGB = 167,

EAC_R11Unorm = 170,
EAC_R11Snorm = 172,
EAC_RG11Unorm = 174,
Expand Down Expand Up @@ -966,7 +1007,14 @@ public enum MTLArgumentAccess : ulong {
[Flags]
public enum MTLPipelineOption : ulong {
None,
ArgumentInfo,
#if !XAMCORE_5_0
[Deprecated (PlatformName.iOS, 18, 0, message: "Use 'BindingInfo' instead.")]
[Deprecated (PlatformName.TvOS, 18, 0, message: "Use 'BindingInfo' instead.")]
[Deprecated (PlatformName.MacCatalyst, 18, 0, message: "Use 'BindingInfo' instead.")]
[Deprecated (PlatformName.MacOSX, 15, 0, message: "Use 'BindingInfo' instead.")]
ArgumentInfo = 1 << 0,
#endif
BindingInfo = 1 << 0,
BufferTypeInfo,
[iOS (14, 0)]
[TV (14, 0)]
Expand Down Expand Up @@ -1109,6 +1157,8 @@ public enum MTLLanguageVersion : ulong {
v3_0 = (3uL << 16) + 0,
[iOS (17, 0), TV (17, 0), MacCatalyst (17, 0), Mac (14, 0), NoWatch]
v3_1 = (3uL << 16) + 1,
[TV (18, 0), Mac (15, 0), iOS (18, 0), MacCatalyst (18, 0)]
v3_2 = (3ul << 16) + 2,
}

/// <summary>Enumerates values that indicate whether to clip or clamp depth values.</summary>
Expand Down Expand Up @@ -1691,6 +1741,8 @@ public enum MTLFunctionOptions : ulong {
CompileToBinary = 1uL << 0,
[iOS (17, 0), TV (17, 0), MacCatalyst (17, 0), Mac (14, 0)]
StoreFunctionInMetalScript = 1uL << 1,
[TV (18, 0), Mac (15, 0), iOS (18, 0), MacCatalyst (18, 0)]
FailOnBinaryArchiveMiss = 1 << 2,
}

[Flags, Mac (11, 0), iOS (14, 0), TV (16, 0)]
Expand Down
23 changes: 23 additions & 0 deletions src/Metal/MTLResidencySet.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;

using ObjCRuntime;

#nullable enable

namespace Metal {

public partial interface IMTLResidencySet {

/// <summary>Adds allocations to be committed the next time <see cref="Commit" /> is called.</summary>
public void AddAllocations (IMTLAllocation [] allocations)
{
NativeObjectExtensions.CallWithPointerToFirstElementAndCount (allocations, nameof (allocations), AddAllocations);
}

/// <summary>Marks allocations to be removed the next time <see cref="Commit" /> is called.</summary>
public void RemoveAllocations (IMTLAllocation [] allocations)
{
NativeObjectExtensions.CallWithPointerToFirstElementAndCount (allocations, nameof (allocations), RemoveAllocations);
}
}
}
19 changes: 19 additions & 0 deletions src/ObjCRuntime/INativeObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,25 @@ public static NativeHandle GetCheckedHandle (this INativeObject self)
return h;
}
#endif

internal static void CallWithPointerToFirstElementAndCount<T> (T [] array, string arrayVariableName, Action<IntPtr, nuint> callback)
where T : INativeObject
{
if (array is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (arrayVariableName);

var handles = new IntPtr [array.Length];
for (var i = 0; i < handles.Length; i++)
handles [i] = array [i].GetNonNullHandle (arrayVariableName + $"[{i}]");

unsafe {
fixed (IntPtr* handlesPtr = handles) {
callback ((IntPtr) handlesPtr, (nuint) handles.Length);
}
}

GC.KeepAlive (array);
}
}
#endif
}
5 changes: 5 additions & 0 deletions src/foundation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13179,6 +13179,11 @@ interface NSProcessInfo {
[Export ("iOSAppOnMac")]
bool IsiOSApplicationOnMac { [Bind ("isiOSAppOnMac")] get; }
#endregion

[Field ("NSProcessInfoPerformanceProfileDidChangeNotification", "Metal")]
[Notification]
[TV (18, 0), Mac (15, 0), iOS (18, 0), MacCatalyst (18, 0), NoWatch]
NSString PerformanceProfileDidChangeNotification { get; }
}

[NoWatch]
Expand Down
3 changes: 3 additions & 0 deletions src/frameworks.sources
Original file line number Diff line number Diff line change
Expand Up @@ -1204,6 +1204,8 @@ METAL_CORE_SOURCES = \
METAL_SOURCES = \
Metal/MTLArgumentEncoder.cs \
Metal/MTLBlitPassSampleBufferAttachmentDescriptorArray.cs \
Metal/MTLCommandBuffer.cs \
Metal/MTLCommandQueue.cs \
Metal/MTLCompat.cs \
Metal/MTLIOCompression.cs \
Metal/MTLComputeCommandEncoder.cs \
Expand All @@ -1215,6 +1217,7 @@ METAL_SOURCES = \
Metal/MTLRenderCommandEncoder.cs \
Metal/MTLRenderPassDescriptor.cs \
Metal/MTLRenderPassSampleBufferAttachmentDescriptorArray.cs \
Metal/MTLResidencySet.cs \
Metal/MTLResourceStateCommandEncoder.cs \
Metal/MTLResourceStatePassSampleBufferAttachmentDescriptorArray.cs \
Metal/MTLVertexDescriptor.cs \
Expand Down
Loading

0 comments on commit 1d18c72

Please sign in to comment.