Skip to content

Commit

Permalink
[Metal] Add support up to GM1 of metal. (#7007)
Browse files Browse the repository at this point in the history
  • Loading branch information
mandel-macaque committed Sep 23, 2019
1 parent 382083c commit 5703082
Show file tree
Hide file tree
Showing 15 changed files with 1,279 additions and 318 deletions.
40 changes: 40 additions & 0 deletions src/Metal/Defs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -342,5 +342,45 @@ public MTLIndirectCommandBufferExecutionRange (uint location, uint length)
}
}
#endif // MONOMAC

[Mac (10,15), iOS (13,0), TV (13,0)]
public enum MTLTextureSwizzle : byte {
Zero = 0,
One = 1,
Red = 2,
Green = 3,
Blue = 4,
Alpha = 5,
}

[StructLayout (LayoutKind.Sequential)]
public struct MTLTextureSwizzleChannels {
public MTLTextureSwizzle Red;

public MTLTextureSwizzle Green;

public MTLTextureSwizzle Blue;

public MTLTextureSwizzle Alpha;
}

#if IOS
[Introduced (PlatformName.iOS, 13,0, PlatformArchitecture.All)]
[StructLayout (LayoutKind.Sequential)]
public struct MTLVertexAmplificationViewMapping {
public uint ViewportArrayIndexOffset;

public uint RenderTargetArrayIndexOffset;
}

[Introduced (PlatformName.iOS, 13,0, PlatformArchitecture.All)]
[StructLayout (LayoutKind.Sequential)]
public struct MTLCoordinate2D {
public float X;

public float Y;
}
#endif

}
#endif
11 changes: 7 additions & 4 deletions src/Metal/MTLCompat.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#if XAMCORE_2_0 || !MONOMAC

using System;
using ObjCRuntime;

namespace Metal {

}
public partial class MTLSharedTextureHandle {

[Obsolete ("Default constructor was removed. Do not use.")]
public MTLSharedTextureHandle () {}
}

#endif
}
42 changes: 42 additions & 0 deletions src/Metal/MTLDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,48 @@ public unsafe static void GetDefaultSamplePositions (this IMTLDevice This, MTLSa
fixed (void * handle = positions)
GetDefaultSamplePositions (This, (IntPtr)handle, count);
}
#if IOS

[NoMac, NoTV, iOS (13,0)]
public static void ConvertSparseTileRegions (this IMTLDevice This, MTLRegion [] tileRegions, MTLRegion [] pixelRegions, MTLSize tileSize, nuint numRegions)
{
if (tileRegions == null)
throw new ArgumentNullException (nameof (tileRegions));
if (pixelRegions == null)
throw new ArgumentNullException (nameof (pixelRegions));

var tileRegionsHandle = GCHandle.Alloc (tileRegions, GCHandleType.Pinned);
var pixelRegionsHandle = GCHandle.Alloc (pixelRegions, GCHandleType.Pinned);
try {
IntPtr tilePtr = tileRegionsHandle.AddrOfPinnedObject ();
IntPtr pixelPtr = pixelRegionsHandle.AddrOfPinnedObject ();
This.ConvertSparseTileRegions (tilePtr, pixelPtr, tileSize, numRegions);
} finally {
tileRegionsHandle.Free ();
pixelRegionsHandle.Free ();
}
}

[NoMac, NoTV, iOS (13,0)]
public static void ConvertSparsePixelRegions (this IMTLDevice This, MTLRegion [] pixelRegions, MTLRegion [] tileRegions, MTLSize tileSize, MTLSparseTextureRegionAlignmentMode mode, nuint numRegions)
{
if (tileRegions == null)
throw new ArgumentNullException (nameof (tileRegions));
if (pixelRegions == null)
throw new ArgumentNullException (nameof (pixelRegions));

var tileRegionsHandle = GCHandle.Alloc (tileRegions, GCHandleType.Pinned);
var pixelRegionsHandle = GCHandle.Alloc (pixelRegions, GCHandleType.Pinned);
try {
IntPtr tilePtr = tileRegionsHandle.AddrOfPinnedObject ();
IntPtr pixelPtr = pixelRegionsHandle.AddrOfPinnedObject ();
This.ConvertSparsePixelRegions (pixelPtr, tilePtr, tileSize, mode, numRegions);
} finally {
tileRegionsHandle.Free ();
pixelRegionsHandle.Free ();
}
}
#endif

#if !XAMCORE_4_0
[return: Release]
Expand Down
142 changes: 141 additions & 1 deletion src/Metal/MTLEnums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ public enum MTLSamplerBorderColor : ulong {
OpaqueWhite = 2
}

[NoTV]
[TV (13,0)]
[iOS (12,0)]
[Mac (10,11)]
[Native]
Expand Down Expand Up @@ -1003,5 +1003,145 @@ public enum MTLMultisampleStencilResolveFilter : ulong
Sample0 = 0,
DepthResolvedSample = 1,
}

[Unavailable (PlatformName.MacCatalyst)]
[Flags, NoMac, NoTV, iOS (13,0)]
[Native, Advice ("This API is not available when using UIKit on macOS.")]
public enum MTLSparseTextureRegionAlignmentMode : ulong {
Outward = 0x0,
Inward = 0x1,
}

[Unavailable (PlatformName.MacCatalyst)]
[Flags, NoMac, NoTV, iOS (13,0)]
[Native, Advice ("This API is not available when using UIKit on macOS.")]
public enum MTLSparseTextureMappingMode : ulong {
Map = 0x0,
Unmap = 0x1,
}

[Mac (10,15), iOS (13,0)]
[Native]
public enum MTLHazardTrackingMode : ulong {
Default = 0,
Untracked = 1,
Tracked = 2,
}

[TV (13,0), Mac (10,15), iOS (13,0)]
[Native]
[ErrorDomain ("MTLCaptureErrorDomain")]
public enum MTLCaptureError : long {
NotSupported = 1,
AlreadyCapturing,
InvalidDescriptor,
}

[TV (13,0), Mac (10,15), iOS (13,0)]
[Native]
public enum MTLGpuFamily : long {
Apple1 = 1001,
Apple2 = 1002,
Apple3 = 1003,
Apple4 = 1004,
Apple5 = 1005,
Mac1 = 2001,
Mac2 = 2002,
Common1 = 3001,
Common2 = 3002,
Common3 = 3003,
iOSMac1 = 4001,
iOSMac2 = 4002,
}

[TV (13,0), Mac (10,15), iOS (13,0)]
[Native]
public enum MTLHeapType : long {
Automatic = 0,
Placement = 1,
}

[Mac (10,15), iOS (13,0), TV (13,0)]
[Native]
public enum MTLCaptureDestination : long {
DeveloperTools = 1,
GpuTraceDocument,
}

[NoiOS, NoTV, Mac (10,15)]
[Native]
public enum MTLDeviceLocation : ulong {
BuiltIn = 0,
Slot = 1,
External = 2,
Unspecified = ulong.MaxValue,
}

[NoiOS, NoTV, Mac (10,15)]
[Native]
[ErrorDomain ("MTLCounterErrorDomain")]
public enum MTLCounterSampleBufferError : long {
OutOfMemory,
Internal,
}
#if MONOMAC
[NoiOS, NoTV, Mac (10,15)]
public enum MTLCommonCounter {
[Field ("MTLCommonCounterTimestamp")]
Timestamp,

[Field ("MTLCommonCounterTessellationInputPatches")]
TessellationInputPatches,

[Field ("MTLCommonCounterVertexInvocations")]
VertexInvocations,

[Field ("MTLCommonCounterPostTessellationVertexInvocations")]
PostTessellationVertexInvocations,

[Field ("MTLCommonCounterClipperInvocations")]
ClipperInvocations,

[Field ("MTLCommonCounterClipperPrimitivesOut")]
ClipperPrimitivesOut,

[Field ("MTLCommonCounterFragmentInvocations")]
FragmentInvocations,

[Field ("MTLCommonCounterFragmentsPassed")]
FragmentsPassed,

[Field ("MTLCommonCounterComputeKernelInvocations")]
ComputeKernelInvocations,

[Field ("MTLCommonCounterTotalCycles")]
TotalCycles,

[Field ("MTLCommonCounterVertexCycles")]
VertexCycles,

[Field ("MTLCommonCounterTessellationCycles")]
TessellationCycles,

[Field ("MTLCommonCounterPostTessellationVertexCycles")]
PostTessellationVertexCycles,

[Field ("MTLCommonCounterFragmentCycles")]
FragmentCycles,

[Field ("MTLCommonCounterRenderTargetWriteCycles")]
RenderTargetWriteCycles,

[Field ("MTLCommonCounterSetTimestamp")]
SetTimestamp,

[Field ("MTLCommonCounterSetStageUtilization")]
SetStageUtilization,

[Field ("MTLCommonCounterSetStatistic")]
SetStatistic,
}

#endif
}
#endif
54 changes: 54 additions & 0 deletions src/Metal/MTLRasterizationRateLayerDescriptor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#if IOS
using System;
using System.ComponentModel;
using System.Runtime.InteropServices;

using Foundation;
using ObjCRuntime;

namespace Metal {
public partial class MTLRasterizationRateLayerDescriptor
{
/* Selectors reported as not working by instrospection: https://github.com/xamarin/maccore/issues/1976
[NoMac, NoTV, iOS (13,0)]
public double[] HorizontalSampleStorage {
get {
var width = (int)SampleCount.Width;
var floatArray = new double[width];
Marshal.Copy (_HorizontalSampleStorage, floatArray, 0, width);
return floatArray;
}
}
[NoMac, NoTV, iOS (13,0)]
public double[] VerticalSampleStorage {
get {
var height = (int)SampleCount.Height;
var floatArray = new double[height];
Marshal.Copy (_VerticalSampleStorage, floatArray, 0, height);
return floatArray;
}
}
*/
[NoMac, NoTV, iOS (13,0)]
static public MTLRasterizationRateLayerDescriptor Create (MTLSize sampleCount, float[] horizontal, float[] vertical)
{
if (horizontal == null)
throw new ArgumentNullException (nameof (horizontal));
if (vertical == null)
throw new ArgumentNullException (nameof (vertical));
if (sampleCount.Width != horizontal.Length)
throw new ArgumentOutOfRangeException ("Horizontal length should be equal to the sampleCount.Width.");
if (sampleCount.Height != vertical.Length)
throw new ArgumentOutOfRangeException ("Vertical length should be equal to the sampleCount.Height.");

unsafe {
fixed (void* horizontalHandle = horizontal)
fixed (void* verticalHandle = vertical) {
return new MTLRasterizationRateLayerDescriptor (sampleCount, (IntPtr) horizontalHandle, (IntPtr) verticalHandle);
}
}
}
}
}
#endif
47 changes: 47 additions & 0 deletions src/Metal/MTLResourceStateCommandEncoder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//
// API for the Metal framework
//
// Authors:
// Manuel de la Pena <mandel@microsoft.com>
//
#if IOS
using System;
using System.ComponentModel;
using System.Runtime.InteropServices;

using Foundation;
using ObjCRuntime;

namespace Metal {

public static partial class MTLResourceStateCommandEncoder_Extensions {

[NoMac, NoTV, iOS (13,0)]
public static void Update (this IMTLResourceStateCommandEncoder This, IMTLTexture texture, MTLSparseTextureMappingMode mode, MTLRegion[] regions, nuint[] mipLevels, nuint[] slices)
{
if (texture == null)
throw new ArgumentNullException (nameof (texture));
if (regions == null)
throw new ArgumentNullException (nameof (regions));
if (mipLevels == null)
throw new ArgumentNullException (nameof (mipLevels));
if (slices == null)
throw new ArgumentNullException (nameof (slices));

var regionsHandle = GCHandle.Alloc (regions, GCHandleType.Pinned);
var mipLevelsHandle = GCHandle.Alloc (mipLevels, GCHandleType.Pinned);
var slicesHandle = GCHandle.Alloc (slices, GCHandleType.Pinned);
try {
var regionsPtr = regionsHandle.AddrOfPinnedObject ();
var mipLevelsPtr = mipLevelsHandle.AddrOfPinnedObject ();
var slicesPtr = slicesHandle.AddrOfPinnedObject ();
This.Update (texture, mode, regionsPtr, mipLevelsPtr, slicesPtr, (nuint)regions.Length);
} finally {
regionsHandle.Free ();
mipLevelsHandle.Free ();
slicesHandle.Free ();
}
}
}
}
#endif
2 changes: 2 additions & 0 deletions src/frameworks.sources
Original file line number Diff line number Diff line change
Expand Up @@ -1083,8 +1083,10 @@ METAL_SOURCES = \
Metal/MTLCompat.cs \
Metal/MTLDevice.cs \
Metal/MTLArrays.cs \
Metal/MTLRasterizationRateLayerDescriptor.cs \
Metal/MTLRenderCommandEncoder.cs \
Metal/MTLRenderPassDescriptor.cs \
Metal/MTLResourceStateCommandEncoder.cs \
Metal/MTLVertexDescriptor.cs \

# MetalKit
Expand Down
Loading

1 comment on commit 5703082

@xamarin-release-manager
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Build was (probably) aborted

🔥 Jenkins job (on internal Jenkins) failed in stage(s) 'Build' 🔥 : hudson.AbortException: script returned exit code 2

🔥 Build failed 🔥

Please sign in to comment.