diff --git a/build/Directory.Build.props b/build/Directory.Build.props index 6545de68c..ce6cb7bc0 100644 --- a/build/Directory.Build.props +++ b/build/Directory.Build.props @@ -1,7 +1,7 @@ true - 12.0 + preview enable true diff --git a/samples/ComputeSharp.Sample.FSharp/ComputeSharp.Sample.FSharp.fsproj b/samples/ComputeSharp.Sample.FSharp/ComputeSharp.Sample.FSharp.fsproj index a89a733b7..74965e31d 100644 --- a/samples/ComputeSharp.Sample.FSharp/ComputeSharp.Sample.FSharp.fsproj +++ b/samples/ComputeSharp.Sample.FSharp/ComputeSharp.Sample.FSharp.fsproj @@ -3,7 +3,7 @@ Exe net8.0 - 8.0 + 9.0 diff --git a/samples/ComputeSharp.SwapChain.UI/ViewModels/MainViewModel.cs b/samples/ComputeSharp.SwapChain.UI/ViewModels/MainViewModel.cs index 89d42abda..93dd68cf2 100644 --- a/samples/ComputeSharp.SwapChain.UI/ViewModels/MainViewModel.cs +++ b/samples/ComputeSharp.SwapChain.UI/ViewModels/MainViewModel.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.ObjectModel; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using ComputeSharp.SwapChain.Core.Enums; @@ -25,12 +25,7 @@ public sealed partial class MainViewModel : ObservableObject /// public MainViewModel() { - this.selectedRenderingMode = RenderingMode.DirectX12; - this.isVerticalSyncEnabled = true; - this.isDynamicResolutionEnabled = true; - this.selectedResolutionScale = 100; - this.selectedComputeShader = ComputeShaderOptions[0]; - this.selectedComputeShader.IsSelected = true; + SelectedComputeShader = ComputeShaderOptions[0]; } /// @@ -38,49 +33,49 @@ public MainViewModel() /// [ObservableProperty] [NotifyPropertyChangedFor(nameof(IsResolutionScaleOptionEnabled))] - private RenderingMode selectedRenderingMode; + public partial RenderingMode SelectedRenderingMode { get; set; } = RenderingMode.DirectX12; /// /// Gets or sets whether the vertical sync is enabled. /// [ObservableProperty] - private bool isVerticalSyncEnabled; + public partial bool IsVerticalSyncEnabled { get; set; } = true; /// /// Gets or sets whether the dynamic resolution is enabled. /// [ObservableProperty] [NotifyPropertyChangedFor(nameof(IsResolutionScaleOptionEnabled))] - private bool isDynamicResolutionEnabled; + public partial bool IsDynamicResolutionEnabled { get; set; } = true; /// /// Gets the currently selected resolution scale setting (as percentage value). /// [ObservableProperty] - private int selectedResolutionScale; + public partial int SelectedResolutionScale { get; set; } = 100; /// /// Gets or sets the currently selected compute shader. /// [ObservableProperty] - private ShaderRunnerViewModel selectedComputeShader; + public partial ShaderRunnerViewModel SelectedComputeShader { get; set; } /// /// Gets or sets whether the rendering is currently paused. /// [ObservableProperty] - private bool isRenderingPaused; + public partial bool IsRenderingPaused { get; set; } /// /// Gets the available resolution scaling options (as percentage values). /// - public IList ResolutionScaleOptions { get; } = new int[] { 25, 50, 75, 100 }; + public ReadOnlyCollection ResolutionScaleOptions { get; } = new((int[])[25, 50, 75, 100]); /// /// Gets the collection of available compute shader. /// - public IReadOnlyList ComputeShaderOptions { get; } = new ShaderRunnerViewModel[] - { + public ReadOnlyCollection ComputeShaderOptions { get; } = new((ShaderRunnerViewModel[]) + [ new( nameof(ColorfulInfinity), new ShaderRunner(static time => new((float)time.TotalSeconds)), @@ -118,7 +113,7 @@ public MainViewModel() 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. @@ -153,9 +148,16 @@ private void ToggleRenderingPaused() } /// - partial void OnSelectedComputeShaderChanging(ShaderRunnerViewModel? oldValue, ShaderRunnerViewModel newValue) + partial void OnSelectedComputeShaderChanging(ShaderRunnerViewModel oldValue, ShaderRunnerViewModel newValue) { - oldValue!.IsSelected = false; + // Known issue with partial properties: while the property is marked as not nullable, assigning it in the + // constructor will suppress the warning but cause the setter to be invoked, with 'field' being 'null'. + // As such, as need to check for that scenario here to avoid an exception. Possibly fixed in C# 14. + if (oldValue is not null) + { + oldValue.IsSelected = false; + } + newValue.IsSelected = true; } } \ No newline at end of file diff --git a/samples/ComputeSharp.SwapChain.UI/ViewModels/ShaderRunnerViewModel.cs b/samples/ComputeSharp.SwapChain.UI/ViewModels/ShaderRunnerViewModel.cs index eac80e847..e3db3a2dd 100644 --- a/samples/ComputeSharp.SwapChain.UI/ViewModels/ShaderRunnerViewModel.cs +++ b/samples/ComputeSharp.SwapChain.UI/ViewModels/ShaderRunnerViewModel.cs @@ -38,5 +38,5 @@ public sealed partial class ShaderRunnerViewModel( /// Gets or sets whether the current shader is selected. /// [ObservableProperty] - private bool isSelected; + public partial bool IsSelected { get; set; } } \ No newline at end of file diff --git a/samples/ComputeSharp.SwapChain.Uwp/ComputeSharp.SwapChain.Uwp.csproj b/samples/ComputeSharp.SwapChain.Uwp/ComputeSharp.SwapChain.Uwp.csproj index 39f81549b..ae1a6160b 100644 --- a/samples/ComputeSharp.SwapChain.Uwp/ComputeSharp.SwapChain.Uwp.csproj +++ b/samples/ComputeSharp.SwapChain.Uwp/ComputeSharp.SwapChain.Uwp.csproj @@ -48,7 +48,7 @@ - + diff --git a/samples/ComputeSharp.SwapChain.WinUI/ComputeSharp.SwapChain.WinUI.csproj b/samples/ComputeSharp.SwapChain.WinUI/ComputeSharp.SwapChain.WinUI.csproj index 68864c7cc..a2f34d3e0 100644 --- a/samples/ComputeSharp.SwapChain.WinUI/ComputeSharp.SwapChain.WinUI.csproj +++ b/samples/ComputeSharp.SwapChain.WinUI/ComputeSharp.SwapChain.WinUI.csproj @@ -50,7 +50,7 @@ - + diff --git a/tests/ComputeSharp.Tests/ComputeSharp.Tests.csproj b/tests/ComputeSharp.Tests/ComputeSharp.Tests.csproj index 540e7d5e6..a031f3f04 100644 --- a/tests/ComputeSharp.Tests/ComputeSharp.Tests.csproj +++ b/tests/ComputeSharp.Tests/ComputeSharp.Tests.csproj @@ -10,7 +10,7 @@ - +