From 51cd173b17853f7131907c74e18cc3d05d919d6d Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 21 Dec 2024 15:06:27 +0100 Subject: [PATCH] Use '[GeneratedCanvasEffectProperty]' in samples --- .../ComputeSharp.NativeLibrary.WinRT.csproj | 1 + .../HelloWorldEffect.cs | 26 ++++---------- .../Backend/PixelShaderEffect.cs | 36 ++++--------------- .../ComputeSharp.SwapChain.D2D1.Cli.csproj | 1 + .../Backend/PixelShaderEffect.cs | 36 ++++--------------- .../ComputeSharp.SwapChain.D2D1.Uwp.csproj | 3 +- .../Shaders/PixelShaderEffect.cs | 36 ++++--------------- .../ComputeSharp.SwapChain.Uwp.csproj | 1 + .../ComputeSharp.SwapChain.WinUI.csproj | 1 + 9 files changed, 31 insertions(+), 110 deletions(-) diff --git a/samples/ComputeSharp.NativeLibrary.WinRT/ComputeSharp.NativeLibrary.WinRT.csproj b/samples/ComputeSharp.NativeLibrary.WinRT/ComputeSharp.NativeLibrary.WinRT.csproj index 45df7ddc..87098f49 100644 --- a/samples/ComputeSharp.NativeLibrary.WinRT/ComputeSharp.NativeLibrary.WinRT.csproj +++ b/samples/ComputeSharp.NativeLibrary.WinRT/ComputeSharp.NativeLibrary.WinRT.csproj @@ -50,6 +50,7 @@ + diff --git a/samples/ComputeSharp.NativeLibrary.WinRT/HelloWorldEffect.cs b/samples/ComputeSharp.NativeLibrary.WinRT/HelloWorldEffect.cs index 282bb3ac..4c8de82a 100644 --- a/samples/ComputeSharp.NativeLibrary.WinRT/HelloWorldEffect.cs +++ b/samples/ComputeSharp.NativeLibrary.WinRT/HelloWorldEffect.cs @@ -14,29 +14,17 @@ public sealed partial class HelloWorldEffect : CanvasEffect /// 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 => SetPropertyAndInvalidateEffectGraph(ref this.time, value); - } + [GeneratedCanvasEffectProperty] + public partial float Time { get; set; } /// /// Gets or sets the dispatch area for the current output. /// - public Rect DispatchArea - { - get => this.dispatchArea; - set => SetPropertyAndInvalidateEffectGraph(ref this.dispatchArea, value); - } + [GeneratedCanvasEffectProperty] + public partial Rect DispatchArea { get; set; } /// protected override void BuildEffectGraph(CanvasEffectGraph effectGraph) @@ -48,10 +36,10 @@ public sealed partial class HelloWorldEffect : CanvasEffect protected override void ConfigureEffectGraph(CanvasEffectGraph effectGraph) { effectGraph.GetNode(EffectNode).ConstantBuffer = new Shader( - time: this.time, + time: Time, dispatchSize: new int2( - x: (int)double.Round(this.dispatchArea.Width), - y: (int)double.Round(this.dispatchArea.Height))); + x: (int)double.Round(DispatchArea.Width), + y: (int)double.Round(DispatchArea.Height))); } /// diff --git a/samples/ComputeSharp.SwapChain.D2D1.Cli/Backend/PixelShaderEffect.cs b/samples/ComputeSharp.SwapChain.D2D1.Cli/Backend/PixelShaderEffect.cs index b6abc6e3..73b56c59 100644 --- a/samples/ComputeSharp.SwapChain.D2D1.Cli/Backend/PixelShaderEffect.cs +++ b/samples/ComputeSharp.SwapChain.D2D1.Cli/Backend/PixelShaderEffect.cs @@ -10,47 +10,23 @@ namespace ComputeSharp.SwapChain.D2D1.Backend; /// internal abstract partial class PixelShaderEffect : CanvasEffect { - /// - /// The current elapsed time. - /// - private TimeSpan elapsedTime; - - /// - /// The current screen width in raw pixels. - /// - private int screenWidth; - - /// - /// The current screen height in raw pixels. - /// - private int screenHeight; - /// /// Gets or sets the total elapsed time. /// - public TimeSpan ElapsedTime - { - get => this.elapsedTime; - set => SetPropertyAndInvalidateEffectGraph(ref this.elapsedTime, value); - } + [GeneratedCanvasEffectProperty] + public partial TimeSpan ElapsedTime { get; set; } /// /// Gets or sets the screen width in raw pixels. /// - public int ScreenWidth - { - get => this.screenWidth; - set => SetPropertyAndInvalidateEffectGraph(ref this.screenWidth, value); - } + [GeneratedCanvasEffectProperty] + public partial int ScreenWidth { get; set; } /// /// Gets or sets the screen height in raw pixels. /// - public int ScreenHeight - { - get => this.screenHeight; - set => SetPropertyAndInvalidateEffectGraph(ref this.screenHeight, value); - } + [GeneratedCanvasEffectProperty] + public partial int ScreenHeight { get; set; } /// /// An effect for an animated pixel shader. diff --git a/samples/ComputeSharp.SwapChain.D2D1.Cli/ComputeSharp.SwapChain.D2D1.Cli.csproj b/samples/ComputeSharp.SwapChain.D2D1.Cli/ComputeSharp.SwapChain.D2D1.Cli.csproj index c15f2333..46de6d6a 100644 --- a/samples/ComputeSharp.SwapChain.D2D1.Cli/ComputeSharp.SwapChain.D2D1.Cli.csproj +++ b/samples/ComputeSharp.SwapChain.D2D1.Cli/ComputeSharp.SwapChain.D2D1.Cli.csproj @@ -74,6 +74,7 @@ + diff --git a/samples/ComputeSharp.SwapChain.D2D1.Uwp/Backend/PixelShaderEffect.cs b/samples/ComputeSharp.SwapChain.D2D1.Uwp/Backend/PixelShaderEffect.cs index 4472f98b..904dbe4b 100644 --- a/samples/ComputeSharp.SwapChain.D2D1.Uwp/Backend/PixelShaderEffect.cs +++ b/samples/ComputeSharp.SwapChain.D2D1.Uwp/Backend/PixelShaderEffect.cs @@ -10,47 +10,23 @@ namespace ComputeSharp.SwapChain.D2D1.Backend; /// internal abstract partial class PixelShaderEffect : CanvasEffect { - /// - /// The current elapsed time. - /// - private TimeSpan elapsedTime; - - /// - /// The current screen width in raw pixels. - /// - private int screenWidth; - - /// - /// The current screen height in raw pixels. - /// - private int screenHeight; - /// /// Gets or sets the total elapsed time. /// - public TimeSpan ElapsedTime - { - get => this.elapsedTime; - set => SetPropertyAndInvalidateEffectGraph(ref this.elapsedTime, value); - } + [GeneratedCanvasEffectProperty] + public partial TimeSpan ElapsedTime { get; set; } /// /// Gets or sets the screen width in raw pixels. /// - public int ScreenWidth - { - get => this.screenWidth; - set => SetPropertyAndInvalidateEffectGraph(ref this.screenWidth, value); - } + [GeneratedCanvasEffectProperty] + public partial int ScreenWidth { get; set; } /// /// Gets or sets the screen height in raw pixels. /// - public int ScreenHeight - { - get => this.screenHeight; - set => SetPropertyAndInvalidateEffectGraph(ref this.screenHeight, value); - } + [GeneratedCanvasEffectProperty] + public partial int ScreenHeight { get; set; } /// /// An effect for an animated pixel shader. diff --git a/samples/ComputeSharp.SwapChain.D2D1.Uwp/ComputeSharp.SwapChain.D2D1.Uwp.csproj b/samples/ComputeSharp.SwapChain.D2D1.Uwp/ComputeSharp.SwapChain.D2D1.Uwp.csproj index daba2a8e..6c5e8222 100644 --- a/samples/ComputeSharp.SwapChain.D2D1.Uwp/ComputeSharp.SwapChain.D2D1.Uwp.csproj +++ b/samples/ComputeSharp.SwapChain.D2D1.Uwp/ComputeSharp.SwapChain.D2D1.Uwp.csproj @@ -41,9 +41,10 @@ + - + diff --git a/samples/ComputeSharp.SwapChain.UI/Shaders/PixelShaderEffect.cs b/samples/ComputeSharp.SwapChain.UI/Shaders/PixelShaderEffect.cs index a66fc56a..a2ac4a69 100644 --- a/samples/ComputeSharp.SwapChain.UI/Shaders/PixelShaderEffect.cs +++ b/samples/ComputeSharp.SwapChain.UI/Shaders/PixelShaderEffect.cs @@ -14,47 +14,23 @@ namespace ComputeSharp.SwapChain.Core.Shaders; /// public abstract partial class PixelShaderEffect : CanvasEffect { - /// - /// The current elapsed time. - /// - private TimeSpan elapsedTime; - - /// - /// The current screen width in raw pixels. - /// - private int screenWidth; - - /// - /// The current screen height in raw pixels. - /// - private int screenHeight; - /// /// Gets or sets the total elapsed time. /// - public TimeSpan ElapsedTime - { - get => this.elapsedTime; - set => SetPropertyAndInvalidateEffectGraph(ref this.elapsedTime, value); - } + [GeneratedCanvasEffectProperty] + public partial TimeSpan ElapsedTime { get; set; } /// /// Gets or sets the screen width in raw pixels. /// - public int ScreenWidth - { - get => this.screenWidth; - set => SetPropertyAndInvalidateEffectGraph(ref this.screenWidth, value); - } + [GeneratedCanvasEffectProperty] + public partial int ScreenWidth { get; set; } /// /// Gets or sets the screen height in raw pixels. /// - public int ScreenHeight - { - get => this.screenHeight; - set => SetPropertyAndInvalidateEffectGraph(ref this.screenHeight, value); - } + [GeneratedCanvasEffectProperty] + public partial int ScreenHeight { get; set; } /// /// An effect for an animated pixel shader. diff --git a/samples/ComputeSharp.SwapChain.Uwp/ComputeSharp.SwapChain.Uwp.csproj b/samples/ComputeSharp.SwapChain.Uwp/ComputeSharp.SwapChain.Uwp.csproj index ae1a6160..77149a95 100644 --- a/samples/ComputeSharp.SwapChain.Uwp/ComputeSharp.SwapChain.Uwp.csproj +++ b/samples/ComputeSharp.SwapChain.Uwp/ComputeSharp.SwapChain.Uwp.csproj @@ -59,6 +59,7 @@ + diff --git a/samples/ComputeSharp.SwapChain.WinUI/ComputeSharp.SwapChain.WinUI.csproj b/samples/ComputeSharp.SwapChain.WinUI/ComputeSharp.SwapChain.WinUI.csproj index a2f34d3e..914468cc 100644 --- a/samples/ComputeSharp.SwapChain.WinUI/ComputeSharp.SwapChain.WinUI.csproj +++ b/samples/ComputeSharp.SwapChain.WinUI/ComputeSharp.SwapChain.WinUI.csproj @@ -76,6 +76,7 @@ +