Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Metal] Implement Xcode 16.0 beta 1-6 changes. #20895

Merged
merged 17 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/Metal/MTLCommandBuffer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
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>
/// <param name="residencySets">The residency sets to mark.</param>
public void UseResidencySets (params IMTLResidencySet [] residencySets)
{
NativeObjectExtensions.CallWithPointerToFirstElementAndCount (residencySets, nameof (residencySets), UseResidencySets);
}
}
}
25 changes: 25 additions & 0 deletions src/Metal/MTLCommandQueue.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
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>
/// <param name="residencySets">The residency sets to mark.</param>
public void AddResidencySets (params IMTLResidencySet [] residencySets)
{
NativeObjectExtensions.CallWithPointerToFirstElementAndCount (residencySets, nameof (residencySets), AddResidencySets);
}

/// <summary>Removes the specified residency sets from the current command buffer execution.</summary>
/// <param name="residencySets">The residency sets to mark.</param>
public void RemoveResidencySets (params 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
60 changes: 59 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 @@ -1690,7 +1740,15 @@ public enum MTLFunctionOptions : ulong {
[MacCatalyst (14, 0)]
CompileToBinary = 1uL << 0,
[iOS (17, 0), TV (17, 0), MacCatalyst (17, 0), Mac (14, 0)]
[Deprecated (PlatformName.MacCatalyst, 18, 0, message: "Use 'StoreFunctionInMetalPipelinesScript' instead.")]
[Deprecated (PlatformName.iOS, 18, 0, message: "Use 'StoreFunctionInMetalPipelinesScript' instead.")]
[Deprecated (PlatformName.TvOS, 18, 0, message: "Use 'StoreFunctionInMetalPipelinesScript' instead.")]
[Deprecated (PlatformName.MacOSX, 15, 0, message: "Use 'StoreFunctionInMetalPipelinesScript' instead.")]
StoreFunctionInMetalScript = 1uL << 1,
[TV (18, 0), Mac (15, 0), iOS (18, 0), MacCatalyst (18, 0)]
StoreFunctionInMetalPipelinesScript = 1 << 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
25 changes: 25 additions & 0 deletions src/Metal/MTLResidencySet.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
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>
/// <param name="allocations">The allocations to add.</param>
public void AddAllocations (params IMTLAllocation [] allocations)
{
NativeObjectExtensions.CallWithPointerToFirstElementAndCount (allocations, nameof (allocations), AddAllocations);
}

/// <summary>Marks allocations to be removed the next time <see cref="Commit" /> is called.</summary>
/// <param name="allocations">The allocations to remove.</param>
public void RemoveAllocations (params 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 @@ -13230,6 +13230,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 @@ -1223,6 +1223,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 @@ -1234,6 +1236,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
Loading