Skip to content

Commit

Permalink
Update WinUI sample to run on NativeAOT
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergio0694 committed Aug 24, 2024
1 parent 1286194 commit 47204e8
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,26 @@
<RuntimeIdentifiers>win-x64;win-arm64</RuntimeIdentifiers>
<PublishProfile>win-$(Platform).pubxml</PublishProfile>
<UseWinUI>true</UseWinUI>
<PublishAot>true</PublishAot>
<EnableMsixTooling>true</EnableMsixTooling>
</PropertyGroup>

<!-- Additional CsWinRT properties (temporary, until the .NET SDK is updated) -->
<PropertyGroup>

<!--
We're only referencing CsWinRT for the source generators, we don't need to read any WinRT metadata.
CsWinRT is in projection mode by default, so we want to disable it (or it'd need the Windows SDK).
-->
<CsWinRTGenerateProjection>false</CsWinRTGenerateProjection>

<!-- We'll never have any IIDs to patch in this library -->
<CsWinRTIIDOptimizerOptOut>true</CsWinRTIIDOptimizerOptOut>

<!-- Enable AOT warnings for types implementing projected WinRT interfaces mapped to built-in types (eg. 'INotifyPropertyChanged') -->
<CsWinRTAotWarningLevel>2</CsWinRTAotWarningLevel>
</PropertyGroup>

<ItemGroup>
<Content Include="Assets\SplashScreen.scale-200.png" />
<Content Include="Assets\LockScreenLogo.scale-200.png" />
Expand All @@ -33,6 +50,7 @@
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.3.0-build.5.g1bf778c86e" />
<PackageReference Include="CommunityToolkit.WinUI.Controls.Primitives" Version="8.2.240824-pull-488.1154" />
<PackageReference Include="CommunityToolkit.WinUI.Media" Version="8.2.240824-pull-488.1154" />
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.1.1" />
</ItemGroup>

<!--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace ComputeSharp.SwapChain.WinUI.Views;
/// A custom <see cref="Control"/> that can be used to render animated backgrounds via Win2D.
/// </summary>
[TemplatePart(Name = "PART_CanvasAnimatedControl", Type = typeof(CanvasAnimatedControl))]
public sealed class D2D1AnimatedPixelShaderPanel : Control
public sealed partial class D2D1AnimatedPixelShaderPanel : Control
{
/// <summary>
/// The <see cref="DependencyProperty"/> backing <see cref="PixelShaderEffect"/>.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,7 @@
<Platform>arm64</Platform>
<RuntimeIdentifier>win-arm64</RuntimeIdentifier>
<PublishDir>bin\$(Configuration)\$(TargetFramework)\$(RuntimeIdentifier)\publish\</PublishDir>
<PublishAot>true</PublishAot>
<SelfContained>true</SelfContained>
<PublishSingleFile>False</PublishSingleFile>
<PublishReadyToRun Condition="'$(Configuration)' == 'Debug'">False</PublishReadyToRun>
<PublishReadyToRun Condition="'$(Configuration)' != 'Debug'">True</PublishReadyToRun>
<!--
See https://github.com/microsoft/CsWinRT/issues/373
<PublishTrimmed>True</PublishTrimmed>
-->
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,7 @@
<Platform>x64</Platform>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<PublishDir>bin\$(Configuration)\$(TargetFramework)\$(RuntimeIdentifier)\publish\</PublishDir>
<PublishAot>true</PublishAot>
<SelfContained>true</SelfContained>
<PublishSingleFile>False</PublishSingleFile>
<PublishReadyToRun Condition="'$(Configuration)' == 'Debug'">False</PublishReadyToRun>
<PublishReadyToRun Condition="'$(Configuration)' != 'Debug'">True</PublishReadyToRun>
<!--
See https://github.com/microsoft/CsWinRT/issues/373
<PublishTrimmed>True</PublishTrimmed>
-->
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace ComputeSharp.SwapChain.Core.Shaders;
/// <summary>
/// An base effect for an animated pixel shader.
/// </summary>
public abstract class PixelShaderEffect : CanvasEffect
public abstract partial class PixelShaderEffect : CanvasEffect
{
/// <summary>
/// The current elapsed time.
Expand Down Expand Up @@ -57,7 +57,7 @@ public int ScreenHeight
/// </summary>
/// <typeparam name="T">The type of pixel shader to render.</typeparam>
/// <param name="factory">The input <typeparamref name="T"/> factory.</param>
public sealed class For<T>(For<T>.Factory factory) : PixelShaderEffect
public sealed partial class For<T>(For<T>.Factory factory) : PixelShaderEffect
where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor<T>
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace ComputeSharp.SwapChain.Core.Shaders.Runners;
/// <summary>
/// A specialized <see cref="PixelShaderEffect"/> for <see cref="ContouredLayers"/>.
/// </summary>
public sealed class D2D1ContouredLayersEffect : PixelShaderEffect
public sealed partial class D2D1ContouredLayersEffect : PixelShaderEffect
{
/// <summary>
/// The reusable <see cref="PixelShaderEffect{T}"/> node to use to render frames.
Expand Down
10 changes: 6 additions & 4 deletions samples/ComputeSharp.SwapChain.WinUI/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
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;

/// <summary>
Expand Down Expand Up @@ -68,13 +70,13 @@ public MainViewModel()
/// <summary>
/// Gets the available resolution scaling options (as percentage values).
/// </summary>
public IList<int> ResolutionScaleOptions { get; } = [25, 50, 75, 100];
public IList<int> ResolutionScaleOptions { get; } = new int[] { 25, 50, 75, 100 };

/// <summary>
/// Gets the collection of available compute shader.
/// </summary>
public IReadOnlyList<ShaderRunnerViewModel> ComputeShaderOptions { get; } =
[
public IReadOnlyList<ShaderRunnerViewModel> ComputeShaderOptions { get; } = new ShaderRunnerViewModel[]
{
new(
nameof(ColorfulInfinity),
new ShaderRunner<ColorfulInfinity>(static time => new((float)time.TotalSeconds)),
Expand Down Expand Up @@ -112,7 +114,7 @@ public MainViewModel()
nameof(TerracedHills),
new ShaderRunner<TerracedHills>(static time => new((float)time.TotalSeconds)),
new PixelShaderEffect.For<SwapChain.Shaders.D2D1.TerracedHills>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
];
};

/// <summary>
/// Checks whether the resolution scale can currently be expliclty set.
Expand Down
2 changes: 1 addition & 1 deletion src/ComputeSharp.WinUI/ComputeSharp.WinUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.6.240807006-preview1" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.6.240821007-preview2" />

<!-- Reference CsWinRT locally for the source generators (see comments in ComputeSharp.D2D1.WinUI) -->
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.1.1" PrivateAssets="all" />
Expand Down

0 comments on commit 47204e8

Please sign in to comment.