From 47204e8f83028e4bdcbc458190b6b6a03d65c0d8 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 24 Aug 2024 15:40:58 -0700 Subject: [PATCH] Update WinUI sample to run on NativeAOT --- .../ComputeSharp.SwapChain.WinUI.csproj | 18 ++++++++++++++++++ .../Controls/D2D1AnimatedPixelShaderPanel.cs | 2 +- .../PublishProfiles/win-arm64.pubxml | 8 +------- .../Properties/PublishProfiles/win-x64.pubxml | 8 +------- .../Shaders/PixelShaderEffect.cs | 4 ++-- .../Runners/D2D1ContouredLayersRunner.cs | 2 +- .../ViewModels/MainViewModel.cs | 10 ++++++---- .../ComputeSharp.WinUI.csproj | 2 +- 8 files changed, 31 insertions(+), 23 deletions(-) diff --git a/samples/ComputeSharp.SwapChain.WinUI/ComputeSharp.SwapChain.WinUI.csproj b/samples/ComputeSharp.SwapChain.WinUI/ComputeSharp.SwapChain.WinUI.csproj index e3011a7b..b81085b2 100644 --- a/samples/ComputeSharp.SwapChain.WinUI/ComputeSharp.SwapChain.WinUI.csproj +++ b/samples/ComputeSharp.SwapChain.WinUI/ComputeSharp.SwapChain.WinUI.csproj @@ -9,9 +9,26 @@ win-x64;win-arm64 win-$(Platform).pubxml true + true true + + + + + false + + + true + + + 2 + + @@ -33,6 +50,7 @@ + \ No newline at end of file diff --git a/samples/ComputeSharp.SwapChain.WinUI/Properties/PublishProfiles/win-x64.pubxml b/samples/ComputeSharp.SwapChain.WinUI/Properties/PublishProfiles/win-x64.pubxml index 69645733..bb66783c 100644 --- a/samples/ComputeSharp.SwapChain.WinUI/Properties/PublishProfiles/win-x64.pubxml +++ b/samples/ComputeSharp.SwapChain.WinUI/Properties/PublishProfiles/win-x64.pubxml @@ -6,13 +6,7 @@ x64 win-x64 bin\$(Configuration)\$(TargetFramework)\$(RuntimeIdentifier)\publish\ + true true - False - False - True - \ No newline at end of file diff --git a/samples/ComputeSharp.SwapChain.WinUI/Shaders/PixelShaderEffect.cs b/samples/ComputeSharp.SwapChain.WinUI/Shaders/PixelShaderEffect.cs index f4dcf177..f9273e44 100644 --- a/samples/ComputeSharp.SwapChain.WinUI/Shaders/PixelShaderEffect.cs +++ b/samples/ComputeSharp.SwapChain.WinUI/Shaders/PixelShaderEffect.cs @@ -8,7 +8,7 @@ namespace ComputeSharp.SwapChain.Core.Shaders; /// /// An base effect for an animated pixel shader. /// -public abstract class PixelShaderEffect : CanvasEffect +public abstract partial class PixelShaderEffect : CanvasEffect { /// /// The current elapsed time. @@ -57,7 +57,7 @@ public abstract class PixelShaderEffect : CanvasEffect /// /// The type of pixel shader to render. /// The input factory. - public sealed class For(For.Factory factory) : PixelShaderEffect + public sealed partial class For(For.Factory factory) : PixelShaderEffect where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor { /// diff --git a/samples/ComputeSharp.SwapChain.WinUI/Shaders/Runners/D2D1ContouredLayersRunner.cs b/samples/ComputeSharp.SwapChain.WinUI/Shaders/Runners/D2D1ContouredLayersRunner.cs index a49c6659..70c2ec39 100644 --- a/samples/ComputeSharp.SwapChain.WinUI/Shaders/Runners/D2D1ContouredLayersRunner.cs +++ b/samples/ComputeSharp.SwapChain.WinUI/Shaders/Runners/D2D1ContouredLayersRunner.cs @@ -11,7 +11,7 @@ namespace ComputeSharp.SwapChain.Core.Shaders.Runners; /// /// A specialized for . /// -public sealed class D2D1ContouredLayersEffect : PixelShaderEffect +public sealed partial class D2D1ContouredLayersEffect : PixelShaderEffect { /// /// The reusable node to use to render frames. diff --git a/samples/ComputeSharp.SwapChain.WinUI/ViewModels/MainViewModel.cs b/samples/ComputeSharp.SwapChain.WinUI/ViewModels/MainViewModel.cs index 7abe34bf..e9dd941b 100644 --- a/samples/ComputeSharp.SwapChain.WinUI/ViewModels/MainViewModel.cs +++ b/samples/ComputeSharp.SwapChain.WinUI/ViewModels/MainViewModel.cs @@ -7,6 +7,8 @@ using ComputeSharp.SwapChain.Core.Shaders.Runners; using ComputeSharp.SwapChain.Shaders; using ComputeSharp.WinUI; +#pragma warning disable IDE0300 // CsWinRT does not support marshalling collection expression (https://github.com/microsoft/CsWinRT/issues/1661) + namespace ComputeSharp.SwapChain.Core.ViewModels; /// @@ -68,13 +70,13 @@ public sealed partial class MainViewModel : ObservableObject /// /// Gets the available resolution scaling options (as percentage values). /// - public IList ResolutionScaleOptions { get; } = [25, 50, 75, 100]; + public IList ResolutionScaleOptions { get; } = new int[] { 25, 50, 75, 100 }; /// /// Gets the collection of available compute shader. /// - public IReadOnlyList ComputeShaderOptions { get; } = - [ + public IReadOnlyList ComputeShaderOptions { get; } = new ShaderRunnerViewModel[] + { new( nameof(ColorfulInfinity), new ShaderRunner(static time => new((float)time.TotalSeconds)), @@ -112,7 +114,7 @@ public sealed partial class MainViewModel : ObservableObject nameof(TerracedHills), new ShaderRunner(static time => new((float)time.TotalSeconds)), new PixelShaderEffect.For(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))), - ]; + }; /// /// Checks whether the resolution scale can currently be expliclty set. diff --git a/src/ComputeSharp.WinUI/ComputeSharp.WinUI.csproj b/src/ComputeSharp.WinUI/ComputeSharp.WinUI.csproj index 6509d14e..5f2f2c25 100644 --- a/src/ComputeSharp.WinUI/ComputeSharp.WinUI.csproj +++ b/src/ComputeSharp.WinUI/ComputeSharp.WinUI.csproj @@ -20,7 +20,7 @@ - +