From 2d368e46d02b9f08e2d48c87f472e9eedce65a36 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 21 Oct 2023 19:20:13 +0200 Subject: [PATCH 1/9] Add blank WinRT native library sample --- ComputeSharp.sln | 13 +++++++++- .../ComputeSharp.NativeLibrary.WinRT.csproj | 26 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 samples/ComputeSharp.NativeLibrary.WinRT/ComputeSharp.NativeLibrary.WinRT.csproj diff --git a/ComputeSharp.sln b/ComputeSharp.sln index 4797a17ee..21b6900aa 100644 --- a/ComputeSharp.sln +++ b/ComputeSharp.sln @@ -164,7 +164,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "arm64", "arm64", "{B4F6A41C libs\arm64\WinPixEventRuntime_UAP.dll = libs\arm64\WinPixEventRuntime_UAP.dll EndProjectSection EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComputeSharp.NativeLibrary", "samples\ComputeSharp.NativeLibrary\ComputeSharp.NativeLibrary.csproj", "{1A3E20B3-F711-41C0-82EA-3B53A575955C}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputeSharp.NativeLibrary", "samples\ComputeSharp.NativeLibrary\ComputeSharp.NativeLibrary.csproj", "{1A3E20B3-F711-41C0-82EA-3B53A575955C}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComputeSharp.NativeLibrary.WinRT", "samples\ComputeSharp.NativeLibrary.WinRT\ComputeSharp.NativeLibrary.WinRT.csproj", "{551EF4FB-F34F-412A-B3E6-E345797560ED}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -454,6 +456,14 @@ Global {1A3E20B3-F711-41C0-82EA-3B53A575955C}.Release|ARM64.Build.0 = Release|Any CPU {1A3E20B3-F711-41C0-82EA-3B53A575955C}.Release|x64.ActiveCfg = Release|Any CPU {1A3E20B3-F711-41C0-82EA-3B53A575955C}.Release|x64.Build.0 = Release|Any CPU + {551EF4FB-F34F-412A-B3E6-E345797560ED}.Debug|ARM64.ActiveCfg = Debug|Any CPU + {551EF4FB-F34F-412A-B3E6-E345797560ED}.Debug|ARM64.Build.0 = Debug|Any CPU + {551EF4FB-F34F-412A-B3E6-E345797560ED}.Debug|x64.ActiveCfg = Debug|Any CPU + {551EF4FB-F34F-412A-B3E6-E345797560ED}.Debug|x64.Build.0 = Debug|Any CPU + {551EF4FB-F34F-412A-B3E6-E345797560ED}.Release|ARM64.ActiveCfg = Release|Any CPU + {551EF4FB-F34F-412A-B3E6-E345797560ED}.Release|ARM64.Build.0 = Release|Any CPU + {551EF4FB-F34F-412A-B3E6-E345797560ED}.Release|x64.ActiveCfg = Release|Any CPU + {551EF4FB-F34F-412A-B3E6-E345797560ED}.Release|x64.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -492,6 +502,7 @@ Global {79FD7862-4707-4DE0-8777-3872558E4C1C} = {A5013F9B-92EC-419F-B0B3-3D6B721E7104} {B4F6A41C-AA9A-4302-92B3-AC64CF2E30F5} = {A5013F9B-92EC-419F-B0B3-3D6B721E7104} {1A3E20B3-F711-41C0-82EA-3B53A575955C} = {0ED8F632-5E17-46BE-8CC3-B14A82D4AEB1} + {551EF4FB-F34F-412A-B3E6-E345797560ED} = {0ED8F632-5E17-46BE-8CC3-B14A82D4AEB1} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {4664C5E3-0340-4E22-BCFD-98AAEDF5F2DC} diff --git a/samples/ComputeSharp.NativeLibrary.WinRT/ComputeSharp.NativeLibrary.WinRT.csproj b/samples/ComputeSharp.NativeLibrary.WinRT/ComputeSharp.NativeLibrary.WinRT.csproj new file mode 100644 index 000000000..eba952e1f --- /dev/null +++ b/samples/ComputeSharp.NativeLibrary.WinRT/ComputeSharp.NativeLibrary.WinRT.csproj @@ -0,0 +1,26 @@ + + + net8.0 + AnyCPU;x64;ARM64 + + + + + true + true + true + Size + false + false + false + false + false + + + + + + + + + From c424f54de9a6a540f9a5a6b17dc8a01c80f15044 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sun, 22 Oct 2023 11:35:28 +0200 Subject: [PATCH 2/9] Implement HelloWorldEffect for WinRT library sample --- ComputeSharp.sln | 16 ++-- .../ComputeSharp.NativeLibrary.WinRT.csproj | 6 +- .../HelloWorldEffect.cs | 91 +++++++++++++++++++ 3 files changed, 103 insertions(+), 10 deletions(-) create mode 100644 samples/ComputeSharp.NativeLibrary.WinRT/HelloWorldEffect.cs diff --git a/ComputeSharp.sln b/ComputeSharp.sln index 21b6900aa..af1ec1b28 100644 --- a/ComputeSharp.sln +++ b/ComputeSharp.sln @@ -456,14 +456,14 @@ Global {1A3E20B3-F711-41C0-82EA-3B53A575955C}.Release|ARM64.Build.0 = Release|Any CPU {1A3E20B3-F711-41C0-82EA-3B53A575955C}.Release|x64.ActiveCfg = Release|Any CPU {1A3E20B3-F711-41C0-82EA-3B53A575955C}.Release|x64.Build.0 = Release|Any CPU - {551EF4FB-F34F-412A-B3E6-E345797560ED}.Debug|ARM64.ActiveCfg = Debug|Any CPU - {551EF4FB-F34F-412A-B3E6-E345797560ED}.Debug|ARM64.Build.0 = Debug|Any CPU - {551EF4FB-F34F-412A-B3E6-E345797560ED}.Debug|x64.ActiveCfg = Debug|Any CPU - {551EF4FB-F34F-412A-B3E6-E345797560ED}.Debug|x64.Build.0 = Debug|Any CPU - {551EF4FB-F34F-412A-B3E6-E345797560ED}.Release|ARM64.ActiveCfg = Release|Any CPU - {551EF4FB-F34F-412A-B3E6-E345797560ED}.Release|ARM64.Build.0 = Release|Any CPU - {551EF4FB-F34F-412A-B3E6-E345797560ED}.Release|x64.ActiveCfg = Release|Any CPU - {551EF4FB-F34F-412A-B3E6-E345797560ED}.Release|x64.Build.0 = Release|Any CPU + {551EF4FB-F34F-412A-B3E6-E345797560ED}.Debug|ARM64.ActiveCfg = Debug|ARM64 + {551EF4FB-F34F-412A-B3E6-E345797560ED}.Debug|ARM64.Build.0 = Debug|ARM64 + {551EF4FB-F34F-412A-B3E6-E345797560ED}.Debug|x64.ActiveCfg = Debug|x64 + {551EF4FB-F34F-412A-B3E6-E345797560ED}.Debug|x64.Build.0 = Debug|x64 + {551EF4FB-F34F-412A-B3E6-E345797560ED}.Release|ARM64.ActiveCfg = Release|ARM64 + {551EF4FB-F34F-412A-B3E6-E345797560ED}.Release|ARM64.Build.0 = Release|ARM64 + {551EF4FB-F34F-412A-B3E6-E345797560ED}.Release|x64.ActiveCfg = Release|x64 + {551EF4FB-F34F-412A-B3E6-E345797560ED}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/samples/ComputeSharp.NativeLibrary.WinRT/ComputeSharp.NativeLibrary.WinRT.csproj b/samples/ComputeSharp.NativeLibrary.WinRT/ComputeSharp.NativeLibrary.WinRT.csproj index eba952e1f..86a66fd8d 100644 --- a/samples/ComputeSharp.NativeLibrary.WinRT/ComputeSharp.NativeLibrary.WinRT.csproj +++ b/samples/ComputeSharp.NativeLibrary.WinRT/ComputeSharp.NativeLibrary.WinRT.csproj @@ -1,7 +1,8 @@ - net8.0 - AnyCPU;x64;ARM64 + net8.0-windows10.0.22621.0 + x64;ARM64 + win-x64;win-arm64 @@ -21,6 +22,7 @@ + diff --git a/samples/ComputeSharp.NativeLibrary.WinRT/HelloWorldEffect.cs b/samples/ComputeSharp.NativeLibrary.WinRT/HelloWorldEffect.cs new file mode 100644 index 000000000..c6552951c --- /dev/null +++ b/samples/ComputeSharp.NativeLibrary.WinRT/HelloWorldEffect.cs @@ -0,0 +1,91 @@ +using ComputeSharp.D2D1; +using ComputeSharp.D2D1.WinUI; +using Windows.Foundation; + +namespace ComputeSharp.NativeLibrary.WinRT; + +/// +/// A hello world effect that displays a color gradient. +/// +public sealed partial class HelloWorldEffect : CanvasEffect +{ + /// + /// The node in use. + /// + private static readonly CanvasEffectNode> EffectNode = new(); + + /// + private float time; + + /// + private Rect dispatchArea; + + /// + /// Gets or sets the current time since the start of the application. + /// + public float Time + { + get => this.time; + set => SetAndInvalidateEffectGraph(ref this.time, value); + } + + /// + /// Gets or sets the dispatch area for the current output. + /// + public Rect DispatchArea + { + get => this.dispatchArea; + set => SetAndInvalidateEffectGraph(ref this.dispatchArea, value); + } + + /// + protected override void BuildEffectGraph(CanvasEffectGraph effectGraph) + { + effectGraph.RegisterOutputNode(EffectNode, new PixelShaderEffect()); + } + + /// + protected override void ConfigureEffectGraph(CanvasEffectGraph effectGraph) + { + effectGraph.GetNode(EffectNode).ConstantBuffer = new Shader( + time: this.time, + dispatchSize: new int2( + x: (int)double.Round(this.dispatchArea.Width), + y: (int)double.Round(this.dispatchArea.Height))); + } + + /// + /// The D2D1 shader for . + /// + [D2DEffectDisplayName(nameof(HelloWorldEffect))] + [D2DEffectDescription("A hello world effect that displays a color gradient.")] + [D2DEffectCategory("Render")] + [D2DEffectAuthor("ComputeSharp.D2D1")] + [D2DInputCount(0)] + [D2DRequiresScenePosition] + [D2DShaderProfile(D2D1ShaderProfile.PixelShader50)] + [D2DGeneratedPixelShaderDescriptor] + [AutoConstructor] + internal readonly partial struct Shader : ID2D1PixelShader + { + /// + /// The current time since the start of the application. + /// + private readonly float time; + + /// + /// The dispatch size for the current output. + /// + private readonly int2 dispatchSize; + + /// + public float4 Execute() + { + int2 xy = (int2)D2D.GetScenePosition().XY; + float2 uv = xy / (float2)this.dispatchSize; + float3 color = 0.5f + (0.5f * Hlsl.Cos(this.time + new float3(uv, uv.X) + new float3(0, 2, 4))); + + return new(color, 1f); + } + } +} From f4efb00a96930dfef1151912a2f84ba62dc1e73f Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sun, 22 Oct 2023 11:41:23 +0200 Subject: [PATCH 3/9] Add CsWinRT reference to WinRT sample --- .../ComputeSharp.NativeLibrary.WinRT.csproj | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/samples/ComputeSharp.NativeLibrary.WinRT/ComputeSharp.NativeLibrary.WinRT.csproj b/samples/ComputeSharp.NativeLibrary.WinRT/ComputeSharp.NativeLibrary.WinRT.csproj index 86a66fd8d..44d8da2b4 100644 --- a/samples/ComputeSharp.NativeLibrary.WinRT/ComputeSharp.NativeLibrary.WinRT.csproj +++ b/samples/ComputeSharp.NativeLibrary.WinRT/ComputeSharp.NativeLibrary.WinRT.csproj @@ -3,6 +3,7 @@ net8.0-windows10.0.22621.0 x64;ARM64 win-x64;win-arm64 + true @@ -17,6 +18,10 @@ false false + + + + From 147f3af32fa37755b94221092815a997c03a3689 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Tue, 21 Nov 2023 14:28:13 +0100 Subject: [PATCH 4/9] Switch hello world WinRT shader to primary constructor --- .../HelloWorldEffect.cs | 25 ++++++------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/samples/ComputeSharp.NativeLibrary.WinRT/HelloWorldEffect.cs b/samples/ComputeSharp.NativeLibrary.WinRT/HelloWorldEffect.cs index c6552951c..f99063c17 100644 --- a/samples/ComputeSharp.NativeLibrary.WinRT/HelloWorldEffect.cs +++ b/samples/ComputeSharp.NativeLibrary.WinRT/HelloWorldEffect.cs @@ -14,10 +14,10 @@ public sealed partial class HelloWorldEffect : CanvasEffect /// private static readonly CanvasEffectNode> EffectNode = new(); - /// + /// private float time; - /// + /// private Rect dispatchArea; /// @@ -55,8 +55,10 @@ protected override void ConfigureEffectGraph(CanvasEffectGraph effectGraph) } /// - /// The D2D1 shader for . + /// A hello world effect that displays a color gradient. /// + /// The current time since the start of the application. + /// The dispatch size for the current output. [D2DEffectDisplayName(nameof(HelloWorldEffect))] [D2DEffectDescription("A hello world effect that displays a color gradient.")] [D2DEffectCategory("Render")] @@ -65,25 +67,14 @@ protected override void ConfigureEffectGraph(CanvasEffectGraph effectGraph) [D2DRequiresScenePosition] [D2DShaderProfile(D2D1ShaderProfile.PixelShader50)] [D2DGeneratedPixelShaderDescriptor] - [AutoConstructor] - internal readonly partial struct Shader : ID2D1PixelShader + internal readonly partial struct Shader(float time, int2 dispatchSize) : ID2D1PixelShader { - /// - /// The current time since the start of the application. - /// - private readonly float time; - - /// - /// The dispatch size for the current output. - /// - private readonly int2 dispatchSize; - /// public float4 Execute() { int2 xy = (int2)D2D.GetScenePosition().XY; - float2 uv = xy / (float2)this.dispatchSize; - float3 color = 0.5f + (0.5f * Hlsl.Cos(this.time + new float3(uv, uv.X) + new float3(0, 2, 4))); + float2 uv = xy / (float2)dispatchSize; + float3 color = 0.5f + (0.5f * Hlsl.Cos(time + new float3(uv, uv.X) + new float3(0, 2, 4))); return new(color, 1f); } From e2756fa24cbec22cf2a96e9dabea5f9498cf41e2 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Fri, 14 Jun 2024 16:56:36 -0700 Subject: [PATCH 5/9] Update NuGet packages to CsWinRT preview --- .../ComputeSharp.NativeLibrary.WinRT.csproj | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/samples/ComputeSharp.NativeLibrary.WinRT/ComputeSharp.NativeLibrary.WinRT.csproj b/samples/ComputeSharp.NativeLibrary.WinRT/ComputeSharp.NativeLibrary.WinRT.csproj index 44d8da2b4..a2e85fb0c 100644 --- a/samples/ComputeSharp.NativeLibrary.WinRT/ComputeSharp.NativeLibrary.WinRT.csproj +++ b/samples/ComputeSharp.NativeLibrary.WinRT/ComputeSharp.NativeLibrary.WinRT.csproj @@ -1,6 +1,7 @@ net8.0-windows10.0.22621.0 + 10.0.22621.35-preview x64;ARM64 win-x64;win-arm64 true @@ -20,7 +21,7 @@ - + From 5297913ba6d8c1b86b00069edbab40526733304e Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Fri, 14 Jun 2024 17:04:13 -0700 Subject: [PATCH 6/9] Add CsWinRT size saving options to sample --- .../ComputeSharp.NativeLibrary.WinRT.csproj | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/samples/ComputeSharp.NativeLibrary.WinRT/ComputeSharp.NativeLibrary.WinRT.csproj b/samples/ComputeSharp.NativeLibrary.WinRT/ComputeSharp.NativeLibrary.WinRT.csproj index a2e85fb0c..588c8b7bb 100644 --- a/samples/ComputeSharp.NativeLibrary.WinRT/ComputeSharp.NativeLibrary.WinRT.csproj +++ b/samples/ComputeSharp.NativeLibrary.WinRT/ComputeSharp.NativeLibrary.WinRT.csproj @@ -4,18 +4,27 @@ 10.0.22621.35-preview x64;ARM64 win-x64;win-arm64 + + + true + + + false + true + false + false + false + false - + true true true Size false - false - false false false From 68c5f7e3970b1366312994020c63508ab9c93817 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Fri, 14 Jun 2024 17:06:46 -0700 Subject: [PATCH 7/9] Suppress LNK4104 warning from MSVC in sample --- .../ComputeSharp.NativeLibrary.WinRT.csproj | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/samples/ComputeSharp.NativeLibrary.WinRT/ComputeSharp.NativeLibrary.WinRT.csproj b/samples/ComputeSharp.NativeLibrary.WinRT/ComputeSharp.NativeLibrary.WinRT.csproj index 588c8b7bb..eb6713bab 100644 --- a/samples/ComputeSharp.NativeLibrary.WinRT/ComputeSharp.NativeLibrary.WinRT.csproj +++ b/samples/ComputeSharp.NativeLibrary.WinRT/ComputeSharp.NativeLibrary.WinRT.csproj @@ -16,6 +16,13 @@ false false false + + + $(NoWarn);LNK4104 From 6fed3333245a54f2b17743db6192961a38858521 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sun, 30 Jun 2024 14:35:34 -0700 Subject: [PATCH 8/9] Fixup assembly name of WinRT component --- .../ComputeSharp.NativeLibrary.WinRT.csproj | 6 ++++++ .../ComputeSharp.NativeLibrary.WinRT/HelloWorldEffect.cs | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/samples/ComputeSharp.NativeLibrary.WinRT/ComputeSharp.NativeLibrary.WinRT.csproj b/samples/ComputeSharp.NativeLibrary.WinRT/ComputeSharp.NativeLibrary.WinRT.csproj index eb6713bab..cb6f39da5 100644 --- a/samples/ComputeSharp.NativeLibrary.WinRT/ComputeSharp.NativeLibrary.WinRT.csproj +++ b/samples/ComputeSharp.NativeLibrary.WinRT/ComputeSharp.NativeLibrary.WinRT.csproj @@ -9,6 +9,12 @@ true + + ComputeSharp.NativeLibrary + false true diff --git a/samples/ComputeSharp.NativeLibrary.WinRT/HelloWorldEffect.cs b/samples/ComputeSharp.NativeLibrary.WinRT/HelloWorldEffect.cs index f99063c17..5927c4f6b 100644 --- a/samples/ComputeSharp.NativeLibrary.WinRT/HelloWorldEffect.cs +++ b/samples/ComputeSharp.NativeLibrary.WinRT/HelloWorldEffect.cs @@ -2,7 +2,7 @@ using ComputeSharp.D2D1.WinUI; using Windows.Foundation; -namespace ComputeSharp.NativeLibrary.WinRT; +namespace ComputeSharp.NativeLibrary; /// /// A hello world effect that displays a color gradient. From 7228e935703cdaeafc4c9c68483d755bcc731360 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sun, 30 Jun 2024 14:39:57 -0700 Subject: [PATCH 9/9] Publish WinRT sample with NAOT in CI pipeline --- .github/workflows/dotnet.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index d0ba2241c..c25c59157 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -316,6 +316,13 @@ jobs: - name: Publish ComputeSharp.NativeLibrary run: dotnet publish samples\ComputeSharp.NativeLibrary\ComputeSharp.NativeLibrary.csproj -r win-${{matrix.platform}} -v n + # Publish the WinRT component with NativeAOT as well + - if: matrix.platform == 'x64' + name: Publish ComputeSharp.NativeLibrary.WinRT + run: > + msbuild samples\ComputeSharp.NativeLibrary.WinRT\ComputeSharp.NativeLibrary.WinRT.csproj /restore -t:publish + /p:Configuration=Release /p:Platform=${{matrix.platform}} /p:RuntimeIdentifier=win-${{matrix.platform}} + # Download the NuGet packages generated in the previous job and use them # to build and run the sample project referencing them. This is used as # a test to ensure the NuGet packages work in a consuming project.