From 0fb876fde0e5c8a3e9e38285e183dfb301a260bf Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 30 Sep 2023 17:18:10 +0200 Subject: [PATCH] Update Win2D method signatures in all projects --- .../Shaders/PixelShaderEffect.cs | 3 ++- .../Backend/PixelShaderEffect.cs | 3 ++- .../Extensions/ID2D1EffectExtensions.cs | 11 +++++------ ...{T}.Properties.ResourceTextureManagerCollection.cs | 2 +- src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.cs | 3 ++- .../ComputeSharp.D2D1.Tests/Helpers/D2D1TestRunner.cs | 9 +++++---- tests/ComputeSharp.D2D1.Tests/ShadersTests.cs | 3 ++- tests/ComputeSharp.D2D1.UI.Tests/ShadersTests.cs | 5 +++-- 8 files changed, 22 insertions(+), 17 deletions(-) diff --git a/samples/ComputeSharp.SwapChain.Core.Shared/Shaders/PixelShaderEffect.cs b/samples/ComputeSharp.SwapChain.Core.Shared/Shaders/PixelShaderEffect.cs index 125c6e68..ddee56ac 100644 --- a/samples/ComputeSharp.SwapChain.Core.Shared/Shaders/PixelShaderEffect.cs +++ b/samples/ComputeSharp.SwapChain.Core.Shared/Shaders/PixelShaderEffect.cs @@ -1,5 +1,6 @@ using System; using ComputeSharp.D2D1; +using ComputeSharp.D2D1.Descriptors; #if WINDOWS_UWP using ComputeSharp.D2D1.Uwp; #else @@ -62,7 +63,7 @@ public abstract class PixelShaderEffect : CanvasEffect /// /// The type of pixel shader to render. public sealed class For : PixelShaderEffect - where T : unmanaged, ID2D1PixelShader + where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor { /// /// The node in use. diff --git a/samples/ComputeSharp.SwapChain.D2D1.Cli/Backend/PixelShaderEffect.cs b/samples/ComputeSharp.SwapChain.D2D1.Cli/Backend/PixelShaderEffect.cs index b6ccd257..c31a4a82 100644 --- a/samples/ComputeSharp.SwapChain.D2D1.Cli/Backend/PixelShaderEffect.cs +++ b/samples/ComputeSharp.SwapChain.D2D1.Cli/Backend/PixelShaderEffect.cs @@ -1,5 +1,6 @@ using System; using ComputeSharp.D2D1; +using ComputeSharp.D2D1.Descriptors; using ComputeSharp.D2D1.WinUI; namespace ComputeSharp.SwapChain.D2D1.Backend; @@ -56,7 +57,7 @@ internal abstract class PixelShaderEffect : CanvasEffect /// /// The type of pixel shader to render. public sealed class For : PixelShaderEffect - where T : unmanaged, ID2D1PixelShader + where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor { /// /// The node in use. diff --git a/src/ComputeSharp.D2D1.UI/Extensions/ID2D1EffectExtensions.cs b/src/ComputeSharp.D2D1.UI/Extensions/ID2D1EffectExtensions.cs index d4d40ebb..86133bab 100644 --- a/src/ComputeSharp.D2D1.UI/Extensions/ID2D1EffectExtensions.cs +++ b/src/ComputeSharp.D2D1.UI/Extensions/ID2D1EffectExtensions.cs @@ -2,6 +2,7 @@ using System; using System.Buffers; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; +using ComputeSharp.D2D1.Descriptors; using ComputeSharp.D2D1.Extensions; using ComputeSharp.D2D1.Interop; using ComputeSharp.D2D1.Shaders.Interop.Effects.ResourceManagers; @@ -9,8 +10,6 @@ using ComputeSharp.D2D1.Shaders.Interop.Effects.TransformMappers; using TerraFX.Interop.DirectX; using TerraFX.Interop.Windows; -#pragma warning disable CS0618 - #if WINDOWS_UWP namespace ComputeSharp.D2D1.Uwp.Extensions; #else @@ -29,7 +28,7 @@ internal static unsafe class ID2D1EffectExtensions /// The input instance. /// The constant buffer of type for . public static T GetConstantBuffer(this ref ID2D1Effect d2D1Effect) - where T : unmanaged, ID2D1PixelShader + where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor { int constantBufferSize = D2D1PixelShader.GetConstantBufferSize(); @@ -55,7 +54,7 @@ internal static unsafe class ID2D1EffectExtensions Unsafe.SkipInit(out T shader); - shader.InitializeFromDispatchData(buffer.AsSpan(0, constantBufferSize)); + shader = shader.CreateFromConstantBuffer(buffer.AsSpan(0, constantBufferSize)); ArrayPool.Shared.Return(buffer); @@ -69,7 +68,7 @@ internal static unsafe class ID2D1EffectExtensions /// The input instance. /// The constant buffer value to set. public static void SetConstantBuffer(this ref ID2D1Effect d2D1Effect, in T value) - where T : unmanaged, ID2D1PixelShader + where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor { // Same as above, simply do nothing for empty types. This case is still handled to // avoid crashing when someone's just setting an empty constant buffer, which is @@ -90,7 +89,7 @@ internal static unsafe class ID2D1EffectExtensions /// The input instance. /// The instance for . public static D2D1TransformMapper? GetTransformMapper(this ref ID2D1Effect d2D1Effect) - where T : unmanaged, ID2D1PixelShader + where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor { using ComPtr d2D1TransformMapper = default; diff --git a/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.ResourceTextureManagerCollection.cs b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.ResourceTextureManagerCollection.cs index 8a7cd163..5b47ee1d 100644 --- a/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.ResourceTextureManagerCollection.cs +++ b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.ResourceTextureManagerCollection.cs @@ -13,7 +13,7 @@ using ComputeSharp.D2D1.WinUI.Buffers; using ComputeSharp.D2D1.WinUI.Collections; #endif -#pragma warning disable CS0618, CS8767 +#pragma warning disable CS8767 #if WINDOWS_UWP namespace ComputeSharp.D2D1.Uwp; diff --git a/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.cs b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.cs index b9700090..863d7176 100644 --- a/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.cs +++ b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.cs @@ -2,6 +2,7 @@ using System.Diagnostics.CodeAnalysis; #endif using ABI.Microsoft.Graphics.Canvas; +using ComputeSharp.D2D1.Descriptors; using ComputeSharp.D2D1.Interop; using ComputeSharp.Interop; using Microsoft.Graphics.Canvas; @@ -20,7 +21,7 @@ namespace ComputeSharp.D2D1.WinUI; /// /// The type of shader to use to render frames. public sealed partial class PixelShaderEffect : IReferenceTrackedObject, ICanvasEffect, ICanvasImageInterop.Interface - where T : unmanaged, ID2D1PixelShader + where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor { /// /// The value for the current instance. diff --git a/tests/ComputeSharp.D2D1.Tests/Helpers/D2D1TestRunner.cs b/tests/ComputeSharp.D2D1.Tests/Helpers/D2D1TestRunner.cs index 919a763f..fd1de7f8 100644 --- a/tests/ComputeSharp.D2D1.Tests/Helpers/D2D1TestRunner.cs +++ b/tests/ComputeSharp.D2D1.Tests/Helpers/D2D1TestRunner.cs @@ -2,6 +2,7 @@ using System; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; +using ComputeSharp.D2D1.Descriptors; using ComputeSharp.D2D1.Interop; using ComputeSharp.Tests.Helpers; using Win32; @@ -32,7 +33,7 @@ internal static class D2D1TestRunner string expectedFileName, [CallerMemberName] string destinationFileName = "", float threshold = 0.00001f) - where T : unmanaged, ID2D1PixelShader + where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor { string assetsPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Assets"); string temporaryPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "temp"); @@ -73,7 +74,7 @@ internal static class D2D1TestRunner [CallerMemberName] string destinationFileName = "", float threshold = 0.00001f, params (int Index, D2D1ResourceTextureManager ResourceTextureManager)[] resourceTextures) - where T : unmanaged, ID2D1PixelShader + where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor { string assetsPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Assets"); string temporaryPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "temp"); @@ -109,7 +110,7 @@ internal static class D2D1TestRunner D2D1TransformMapper? transformMapper, string sourcePath, string destinationPath) - where T : unmanaged, ID2D1PixelShader + where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor { using ComPtr d2D1Factory2 = D2D1Helper.CreateD2D1Factory2(); using ComPtr d2D1Device = D2D1Helper.CreateD2D1Device(d2D1Factory2.Get()); @@ -158,7 +159,7 @@ internal static class D2D1TestRunner int height, string destinationPath, params (int Index, D2D1ResourceTextureManager ResourceTextureManager)[] resourceTextures) - where T : unmanaged, ID2D1PixelShader + where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor { using ComPtr d2D1Factory2 = D2D1Helper.CreateD2D1Factory2(); using ComPtr d2D1Device = D2D1Helper.CreateD2D1Device(d2D1Factory2.Get()); diff --git a/tests/ComputeSharp.D2D1.Tests/ShadersTests.cs b/tests/ComputeSharp.D2D1.Tests/ShadersTests.cs index 2c05cc1c..c171a6fb 100644 --- a/tests/ComputeSharp.D2D1.Tests/ShadersTests.cs +++ b/tests/ComputeSharp.D2D1.Tests/ShadersTests.cs @@ -2,6 +2,7 @@ using System; using System.IO; using System.Reflection; using System.Runtime.InteropServices; +using ComputeSharp.D2D1.Descriptors; using ComputeSharp.D2D1.Interop; using ComputeSharp.D2D1.Tests.Helpers; using ComputeSharp.SwapChain.Shaders.D2D1; @@ -114,7 +115,7 @@ public class ShadersTests } private static void RunTest(float threshold = 0.00001f) - where T : unmanaged, ID2D1PixelShader + where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor { T shader = (T)Activator.CreateInstance(typeof(T), 0f, new int2(1280, 720))!; diff --git a/tests/ComputeSharp.D2D1.UI.Tests/ShadersTests.cs b/tests/ComputeSharp.D2D1.UI.Tests/ShadersTests.cs index 9a4a8b86..bcc474da 100644 --- a/tests/ComputeSharp.D2D1.UI.Tests/ShadersTests.cs +++ b/tests/ComputeSharp.D2D1.UI.Tests/ShadersTests.cs @@ -2,6 +2,7 @@ using System; using System.Diagnostics.CodeAnalysis; using System.IO; using System.Threading.Tasks; +using ComputeSharp.D2D1.Descriptors; using ComputeSharp.D2D1.UI.Tests.Helpers; #if WINDOWS_UWP using ComputeSharp.D2D1.Uwp; @@ -79,7 +80,7 @@ public class ShadersTests } private static async Task RunTestAsync<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] T>(WrapperType wrapperType, float threshold = 0.00001f) - where T : unmanaged, ID2D1PixelShader + where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor { T shader = (T)Activator.CreateInstance(typeof(T), 0f, new int2(1280, 720))!; @@ -118,7 +119,7 @@ public class ShadersTests } private sealed class TestCanvasEffect : CanvasEffect - where T : unmanaged, ID2D1PixelShader + where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor { private static readonly EffectNode> Effect = new();