From 4081d961b195ec3220deabea57997b07534254ff Mon Sep 17 00:00:00 2001 From: Sebastien Pouliot Date: Sat, 6 Jan 2018 13:03:44 -0500 Subject: [PATCH 1/2] [metalperformanceshaders] Fix MPSImageLanczosScale base class change Sadly this creates a breaking change since the `ScaleTransform` property was re-introduced with an incorrect signature in the new base class `MPSImageScale` Unless someone has an idea how to avoid it (I don't see an option) then we'll have to document it in the 15.7 release notes. --- ...SImageLanczosScale.cs => MPSImageScale.cs} | 2 +- src/frameworks.sources | 2 +- src/metalperformanceshaders.cs | 25 ++++++++----------- .../iOS-MetalPerformanceShaders.todo | 1 - .../macOS-MetalPerformanceShaders.todo | 1 - .../tvOS-MetalPerformanceShaders.todo | 1 - 6 files changed, 13 insertions(+), 19 deletions(-) rename src/MetalPerformanceShaders/{MPSImageLanczosScale.cs => MPSImageScale.cs} (95%) delete mode 100644 tests/xtro-sharpie/iOS-MetalPerformanceShaders.todo delete mode 100644 tests/xtro-sharpie/macOS-MetalPerformanceShaders.todo delete mode 100644 tests/xtro-sharpie/tvOS-MetalPerformanceShaders.todo diff --git a/src/MetalPerformanceShaders/MPSImageLanczosScale.cs b/src/MetalPerformanceShaders/MPSImageScale.cs similarity index 95% rename from src/MetalPerformanceShaders/MPSImageLanczosScale.cs rename to src/MetalPerformanceShaders/MPSImageScale.cs index 27f46fb7e12f..537ef1fda7a0 100644 --- a/src/MetalPerformanceShaders/MPSImageLanczosScale.cs +++ b/src/MetalPerformanceShaders/MPSImageScale.cs @@ -9,7 +9,7 @@ namespace XamCore.MetalPerformanceShaders { - public partial class MPSImageLanczosScale { + public partial class MPSImageScale { static int size_of_scale_transform = Marshal.SizeOf (typeof(MPSScaleTransform)); public virtual MPSScaleTransform? ScaleTransform { diff --git a/src/frameworks.sources b/src/frameworks.sources index 0d9b95d92387..e094fe21029f 100644 --- a/src/frameworks.sources +++ b/src/frameworks.sources @@ -1008,7 +1008,7 @@ METALPERFORMANCESHADERS_CORE_SOURCES = \ MetalPerformanceShaders/MPSKernel.cs \ METALPERFORMANCESHADERS_SOURCES = \ - MetalPerformanceShaders/MPSImageLanczosScale.cs \ + MetalPerformanceShaders/MPSImageScale.cs \ MetalPerformanceShaders/MPSCnnConvolutionDescriptor.cs \ MetalPerformanceShaders/MPSCnnNeuron.cs \ MetalPerformanceShaders/MPSCnnKernel.cs \ diff --git a/src/metalperformanceshaders.cs b/src/metalperformanceshaders.cs index 717b96795579..c44545cc54b3 100644 --- a/src/metalperformanceshaders.cs +++ b/src/metalperformanceshaders.cs @@ -499,20 +499,9 @@ interface MPSImageErode { // MPSImageResampling.h [iOS (9,0)][Mac (10, 13, onlyOn64: true)] - [BaseType (typeof (MPSUnaryImageKernel))] + [BaseType (typeof (MPSImageScale))] [DisableDefaultCtor] interface MPSImageLanczosScale { - // scaleTransform property should be like: - // unsafe MPSScaleTransform* ScaleTransform { get; set; } - // which is both ugly and not supported by the generator - [Export ("scaleTransform")] - [Internal] - IntPtr _GetScaleTransform (); - - [Export ("setScaleTransform:")] - [Internal] - void _SetScaleTransform (IntPtr value); - // inlining .ctor from base class [Export ("initWithDevice:")] @@ -1979,8 +1968,16 @@ interface MPSImageScale { [DesignatedInitializer] IntPtr Constructor (IMTLDevice device); - [NullAllowed, Export ("scaleTransform", ArgumentSemantic.Assign)] - MPSScaleTransform ScaleTransform { get; set; } + // scaleTransform property should be like: + // unsafe MPSScaleTransform* ScaleTransform { get; set; } + // which is both ugly and not supported by the generator + [Export ("scaleTransform")] + [Internal] + IntPtr _GetScaleTransform (); + + [Export ("setScaleTransform:")] + [Internal] + void _SetScaleTransform (IntPtr value); [Export ("initWithCoder:device:")] [DesignatedInitializer] diff --git a/tests/xtro-sharpie/iOS-MetalPerformanceShaders.todo b/tests/xtro-sharpie/iOS-MetalPerformanceShaders.todo deleted file mode 100644 index 8989cf4b4871..000000000000 --- a/tests/xtro-sharpie/iOS-MetalPerformanceShaders.todo +++ /dev/null @@ -1 +0,0 @@ -!wrong-base-type! MPSImageLanczosScale expected MPSImageScale actual MPSUnaryImageKernel diff --git a/tests/xtro-sharpie/macOS-MetalPerformanceShaders.todo b/tests/xtro-sharpie/macOS-MetalPerformanceShaders.todo deleted file mode 100644 index 8989cf4b4871..000000000000 --- a/tests/xtro-sharpie/macOS-MetalPerformanceShaders.todo +++ /dev/null @@ -1 +0,0 @@ -!wrong-base-type! MPSImageLanczosScale expected MPSImageScale actual MPSUnaryImageKernel diff --git a/tests/xtro-sharpie/tvOS-MetalPerformanceShaders.todo b/tests/xtro-sharpie/tvOS-MetalPerformanceShaders.todo deleted file mode 100644 index 8989cf4b4871..000000000000 --- a/tests/xtro-sharpie/tvOS-MetalPerformanceShaders.todo +++ /dev/null @@ -1 +0,0 @@ -!wrong-base-type! MPSImageLanczosScale expected MPSImageScale actual MPSUnaryImageKernel From 8fe599b49465d0198487a79b58e441e2eaa22d43 Mon Sep 17 00:00:00 2001 From: Sebastien Pouliot Date: Tue, 9 Jan 2018 10:43:35 -0500 Subject: [PATCH 2/2] Add missing _SetScaleTransform call and related unit tests --- src/MetalPerformanceShaders/MPSImageScale.cs | 1 + .../MetalPerformanceShaders/ImageScaleTest.cs | 56 +++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 tests/monotouch-test/MetalPerformanceShaders/ImageScaleTest.cs diff --git a/src/MetalPerformanceShaders/MPSImageScale.cs b/src/MetalPerformanceShaders/MPSImageScale.cs index 537ef1fda7a0..f89cdc788cb6 100644 --- a/src/MetalPerformanceShaders/MPSImageScale.cs +++ b/src/MetalPerformanceShaders/MPSImageScale.cs @@ -24,6 +24,7 @@ public virtual MPSScaleTransform? ScaleTransform { IntPtr ptr = Marshal.AllocHGlobal (size_of_scale_transform); try { Marshal.StructureToPtr (value.Value, ptr, false); + _SetScaleTransform (ptr); } finally { Marshal.FreeHGlobal (ptr); diff --git a/tests/monotouch-test/MetalPerformanceShaders/ImageScaleTest.cs b/tests/monotouch-test/MetalPerformanceShaders/ImageScaleTest.cs new file mode 100644 index 000000000000..d8cf27f306e1 --- /dev/null +++ b/tests/monotouch-test/MetalPerformanceShaders/ImageScaleTest.cs @@ -0,0 +1,56 @@ +#if !__WATCHOS__ + +using System; +using Foundation; + +#if XAMCORE_2_0 +using Metal; +using MetalPerformanceShaders; +#else +using MonoTouch.Metal; +using MonoTouch.MetalPerformanceShaders; +#endif + +using NUnit.Framework; + +namespace MonoTouchFixtures.MetalPerformanceShaders { + + [TestFixture] + public class ImageScaleTest { + + IMTLDevice device; + + [TestFixtureSetUp] + public void Metal () + { + TestRuntime.AssertXcodeVersion (9,0); + + device = MTLDevice.SystemDefault; + // some older hardware won't have a default + if (device == null) + Assert.Inconclusive ("Metal is not supported"); + } + + [Test] + public void ScaleTransform () + { + var st = new MPSScaleTransform () { + ScaleX = 1, + ScaleY = 2, + TranslateX = 3, + TranslateY = 4, + }; + using (var scale = new MPSImageScale (device)) { + scale.ScaleTransform = st; + // roundtrip with our (non generated) code + var rt = scale.ScaleTransform.Value; + Assert.That (rt.ScaleX, Is.EqualTo (st.ScaleX), "ScaleX"); + Assert.That (rt.ScaleY, Is.EqualTo (st.ScaleY), "ScaleY"); + Assert.That (rt.TranslateX, Is.EqualTo (st.TranslateX), "TranslateX"); + Assert.That (rt.TranslateY, Is.EqualTo (st.TranslateY), "TranslateY"); + } + } + } +} + +#endif