Skip to content

Commit f6014f0

Browse files
authored
[Metal] Fix a few issues in MTLRasterizationRateLayerDescriptor. (#22804)
* Fix availability for the SampleCount property. * Fix the [Horizontal|Vertical]SampleStorage properties to actually work by marshalling a float array instead of double array. * Add tests.
1 parent d28e3be commit f6014f0

File tree

4 files changed

+96
-14
lines changed

4 files changed

+96
-14
lines changed

src/Metal/MTLRasterizationRateLayerDescriptor.cs

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#if IOS
21
using System;
32
using System.ComponentModel;
43
using System.Runtime.InteropServices;
@@ -12,34 +11,55 @@ namespace Metal {
1211
public partial class MTLRasterizationRateLayerDescriptor {
1312
[SupportedOSPlatform ("maccatalyst")]
1413
[SupportedOSPlatform ("ios13.0")]
15-
[UnsupportedOSPlatform ("macos")]
16-
[UnsupportedOSPlatform ("tvos")]
14+
[SupportedOSPlatform ("macos")]
15+
[SupportedOSPlatform ("tvos16.0")]
16+
#if XAMCORE_5_0
17+
public float [] HorizontalSampleStorage {
18+
#else
1719
public double [] HorizontalSampleStorage {
20+
#endif
1821
get {
1922
var width = (int) SampleCount.Width;
20-
var floatArray = new double [width];
23+
var floatArray = new float [width];
2124
Marshal.Copy (_HorizontalSampleStorage, floatArray, 0, width);
25+
#if XAMCORE_5_0
2226
return floatArray;
27+
#else
28+
return Array.ConvertAll (floatArray, v => (double) v);
29+
#endif
2330
}
2431
}
2532

2633
[SupportedOSPlatform ("maccatalyst")]
2734
[SupportedOSPlatform ("ios13.0")]
28-
[UnsupportedOSPlatform ("tvos")]
29-
[UnsupportedOSPlatform ("macos")]
35+
[SupportedOSPlatform ("macos")]
36+
[SupportedOSPlatform ("tvos16.0")]
37+
#if XAMCORE_5_0
38+
public float [] VerticalSampleStorage {
39+
#else
3040
public double [] VerticalSampleStorage {
41+
#endif
3142
get {
3243
var height = (int) SampleCount.Height;
33-
var floatArray = new double [height];
44+
var floatArray = new float [height];
3445
Marshal.Copy (_VerticalSampleStorage, floatArray, 0, height);
46+
#if XAMCORE_5_0
3547
return floatArray;
48+
#else
49+
return Array.ConvertAll (floatArray, v => (double) v);
50+
#endif
3651
}
3752
}
3853

54+
/// <summary>Create a new <see cref="MTLRasterizationRateLayerDescriptor" /> instance with the specified rasterization rates.</summary>
55+
/// <param name="sampleCount">The number of horizontal (<see cref="MTLSize.Width" />) and vertical (<see cref="MTLSize.Height" />) rasterization rates. The depth component (<see cref="MTLSize.Depth" />) is ignored.</param>
56+
/// <param name="horizontal">The horizontal rasterization rates for the new <see cref="MTLRasterizationRateLayerDescriptor" /> instance.</param>
57+
/// <param name="vertical">The vertical rasterization rates for the new <see cref="MTLRasterizationRateLayerDescriptor" /> instance.</param>
58+
/// <returns>A new <see cref="MTLRasterizationRateLayerDescriptor" /> instance with the specified rasterization rates.</returns>
3959
[SupportedOSPlatform ("maccatalyst")]
4060
[SupportedOSPlatform ("ios13.0")]
41-
[UnsupportedOSPlatform ("tvos")]
42-
[UnsupportedOSPlatform ("macos")]
61+
[SupportedOSPlatform ("macos")]
62+
[SupportedOSPlatform ("tvos16.0")]
4363
static public MTLRasterizationRateLayerDescriptor Create (MTLSize sampleCount, float [] horizontal, float [] vertical)
4464
{
4565
if (horizontal is null)
@@ -58,6 +78,23 @@ static public MTLRasterizationRateLayerDescriptor Create (MTLSize sampleCount, f
5878
}
5979
}
6080
}
81+
82+
/// <summary>Create a new <see cref="MTLRasterizationRateLayerDescriptor" /> instance with the specified rasterization rates.</summary>
83+
/// <param name="horizontal">The horizontal rasterization rates for the new <see cref="MTLRasterizationRateLayerDescriptor" /> instance.</param>
84+
/// <param name="vertical">The vertical rasterization rates for the new <see cref="MTLRasterizationRateLayerDescriptor" /> instance.</param>
85+
/// <returns>A new <see cref="MTLRasterizationRateLayerDescriptor" /> instance with the specified rasterization rates.</returns>
86+
[SupportedOSPlatform ("maccatalyst")]
87+
[SupportedOSPlatform ("ios13.0")]
88+
[SupportedOSPlatform ("macos")]
89+
[SupportedOSPlatform ("tvos16.0")]
90+
public static MTLRasterizationRateLayerDescriptor Create (float [] horizontal, float [] vertical)
91+
{
92+
if (horizontal is null)
93+
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (horizontal));
94+
if (vertical is null)
95+
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (vertical));
96+
97+
return Create (new MTLSize (horizontal.Length, vertical.Length, 0), horizontal, vertical);
98+
}
6199
}
62100
}
63-
#endif

src/metal.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5668,7 +5668,6 @@ interface MTLRasterizationRateLayerDescriptor : NSCopying {
56685668
[Export ("maxSampleCount")]
56695669
MTLSize MaxSampleCount { get; }
56705670

5671-
[iOS (15, 0), MacCatalyst (15, 0)]
56725671
[Export ("sampleCount", ArgumentSemantic.Assign)]
56735672
MTLSize SampleCount { get; set; }
56745673
}

tests/cecil-tests/Documentation.KnownFailures.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12986,7 +12986,6 @@ M:Metal.MTLLibrary_Extensions.CreateFunctionAsync(Metal.IMTLLibrary,System.Strin
1298612986
M:Metal.MTLLibrary_Extensions.CreateIntersectionFunction(Metal.IMTLLibrary,Metal.MTLIntersectionFunctionDescriptor,Foundation.NSError@)
1298712987
M:Metal.MTLLibrary_Extensions.CreateIntersectionFunction(Metal.IMTLLibrary,Metal.MTLIntersectionFunctionDescriptor,System.Action{Metal.IMTLFunction,Foundation.NSError})
1298812988
M:Metal.MTLOrigin.#ctor(System.IntPtr,System.IntPtr,System.IntPtr)
12989-
M:Metal.MTLRasterizationRateLayerDescriptor.Create(Metal.MTLSize,System.Single[],System.Single[])
1299012989
M:Metal.MTLRegion.Create1D(System.IntPtr,System.IntPtr)
1299112990
M:Metal.MTLRegion.Create1D(System.UIntPtr,System.UIntPtr)
1299212991
M:Metal.MTLRegion.Create2D(System.IntPtr,System.IntPtr,System.IntPtr,System.IntPtr)

tests/monotouch-test/Metal/MTLRasterizationRateLayerDescriptorTest.cs

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#if __IOS__ || __MACOS__
1+
using System;
2+
23
using Foundation;
34
using Metal;
45

@@ -50,6 +51,52 @@ public void SampleCount ()
5051
=> Assert.DoesNotThrow (() => {
5152
var c = descriptor.SampleCount;
5253
});
54+
55+
[Test]
56+
public void Create_1 ()
57+
{
58+
var horizontal = new float [] { 1, 2, 3 };
59+
var vertical = new float [] { 5, 6, 7, 8 };
60+
using var obj = MTLRasterizationRateLayerDescriptor.Create (new MTLSize (horizontal.Length, vertical.Length, 42), horizontal, vertical);
61+
Assert.AreEqual ((nint) horizontal.Length, obj.SampleCount.Width, "Width");
62+
Assert.AreEqual ((nint) vertical.Length, obj.SampleCount.Height, "Height");
63+
Assert.AreEqual ((nint) 0, obj.SampleCount.Depth, "Depth");
64+
Assert.That (obj.HorizontalSampleStorage, Is.EqualTo (horizontal), "HorizontalSampleStorage");
65+
Assert.That (obj.VerticalSampleStorage, Is.EqualTo (vertical), "VerticalSampleStorage");
66+
67+
Assert.Throws<ArgumentNullException> (() => MTLRasterizationRateLayerDescriptor.Create (new MTLSize (horizontal.Length, vertical.Length, 0), null, vertical), "H-Null");
68+
Assert.Throws<ArgumentNullException> (() => MTLRasterizationRateLayerDescriptor.Create (new MTLSize (horizontal.Length, vertical.Length, 0), horizontal, null), "V-Null");
69+
Assert.Throws<ArgumentOutOfRangeException> (() => MTLRasterizationRateLayerDescriptor.Create (new MTLSize (horizontal.Length + 1, vertical.Length, 0), horizontal, vertical), "H-AOORE");
70+
Assert.Throws<ArgumentOutOfRangeException> (() => MTLRasterizationRateLayerDescriptor.Create (new MTLSize (horizontal.Length, vertical.Length - 1, 0), horizontal, vertical), "V-AOORE");
71+
}
72+
73+
[Test]
74+
public void Create_2 ()
75+
{
76+
var horizontal = new float [] { 1, 2, 3 };
77+
var vertical = new float [] { 5, 6, 7, 8 };
78+
using var obj = MTLRasterizationRateLayerDescriptor.Create (horizontal, vertical);
79+
Assert.AreEqual ((nint) horizontal.Length, obj.SampleCount.Width, "Width");
80+
Assert.AreEqual ((nint) vertical.Length, obj.SampleCount.Height, "Height");
81+
Assert.AreEqual ((nint) 0, obj.SampleCount.Depth, "Depth");
82+
Assert.That (obj.HorizontalSampleStorage, Is.EqualTo (horizontal), "HorizontalSampleStorage");
83+
Assert.That (obj.VerticalSampleStorage, Is.EqualTo (vertical), "VerticalSampleStorage");
84+
85+
Assert.Throws<ArgumentNullException> (() => MTLRasterizationRateLayerDescriptor.Create (null, vertical), "H-Null");
86+
Assert.Throws<ArgumentNullException> (() => MTLRasterizationRateLayerDescriptor.Create (horizontal, null), "V-Null");
87+
}
88+
89+
[Test]
90+
public void Ctor ()
91+
{
92+
var horizontal = new float [3];
93+
var vertical = new float [4];
94+
using var obj = new MTLRasterizationRateLayerDescriptor (new MTLSize (horizontal.Length, vertical.Length, 0));
95+
Assert.AreEqual ((nint) horizontal.Length, obj.SampleCount.Width, "Width");
96+
Assert.AreEqual ((nint) vertical.Length, obj.SampleCount.Height, "Height");
97+
Assert.AreEqual ((nint) 0, obj.SampleCount.Depth, "Depth");
98+
Assert.That (obj.HorizontalSampleStorage, Is.EqualTo (horizontal), "HorizontalSampleStorage");
99+
Assert.That (obj.VerticalSampleStorage, Is.EqualTo (vertical), "VerticalSampleStorage");
100+
}
53101
}
54102
}
55-
#endif

0 commit comments

Comments
 (0)