diff --git a/build/Directory.Build.props b/build/Directory.Build.props index 425e9414..24e29a9f 100644 --- a/build/Directory.Build.props +++ b/build/Directory.Build.props @@ -46,7 +46,7 @@ This is used eg. to replace Unsafe.SizeOf() calls with just sizeof(T). The warning is not necessary since in order to use these APIs the caller already has to be in an unsafe context. --> - $(NoWarn);CS8500;IDE0290;IDE0305;IDE0028;IDE0300;IDE0301;IDE0302 + $(NoWarn);CS8500 diff --git a/samples/ComputeSharp.ImageProcessing/Primitives/Complex64.cs b/samples/ComputeSharp.ImageProcessing/Primitives/Complex64.cs index 03c2ab44..e630a091 100644 --- a/samples/ComputeSharp.ImageProcessing/Primitives/Complex64.cs +++ b/samples/ComputeSharp.ImageProcessing/Primitives/Complex64.cs @@ -11,28 +11,19 @@ namespace SixLabors.ImageSharp; /// /// This is a more efficient version of the type. /// -internal readonly struct Complex64 +/// The real part in the complex number. +/// The imaginary part in the complex number. +internal readonly struct Complex64(float real, float imaginary) { /// /// The real part of the complex number. /// - public readonly float Real; + public readonly float Real = real; /// /// The imaginary part of the complex number. /// - public readonly float Imaginary; - - /// - /// Initializes a new instance of the struct. - /// - /// The real part in the complex number. - /// The imaginary part in the complex number. - public Complex64(float real, float imaginary) - { - this.Real = real; - this.Imaginary = imaginary; - } + public readonly float Imaginary = imaginary; /// /// Performs the multiplication operation between a instance and a scalar. diff --git a/samples/ComputeSharp.ImageProcessing/Processors/HlslBokehBlurProcessor.Implementation.cs b/samples/ComputeSharp.ImageProcessing/Processors/HlslBokehBlurProcessor.Implementation.cs index 2db0049c..8aaef293 100644 --- a/samples/ComputeSharp.ImageProcessing/Processors/HlslBokehBlurProcessor.Implementation.cs +++ b/samples/ComputeSharp.ImageProcessing/Processors/HlslBokehBlurProcessor.Implementation.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Concurrent; -using System.Collections.Generic; using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -58,7 +57,61 @@ public sealed partial class HlslBokehBlurProcessor /// /// The mapping of initialized complex kernels and parameters, to speed up the initialization of new instances. /// - private static readonly ConcurrentDictionary<(int Radius, int ComponentsCount), (Vector4[] Parameters, float Scale, Complex64[][] Kernels)> Cache = new(); + private static readonly ConcurrentDictionary<(int Radius, int ComponentsCount), (Vector4[] Parameters, float Scale, Complex64[][] Kernels)> Cache = []; + + /// + /// The kernel scales to adjust the component values in each kernel. + /// + private static readonly float[] KernelScales = [1.4f, 1.2f, 1.2f, 1.2f, 1.2f, 1.2f]; + + /// + /// The available bokeh blur kernel parameters. + /// + private static readonly Vector4[][] KernelComponents = + [ + // 1 component + [new Vector4(0.862325f, 1.624835f, 0.767583f, 1.862321f)], + + // 2 components + [ + new Vector4(0.886528f, 5.268909f, 0.411259f, -0.548794f), + new Vector4(1.960518f, 1.558213f, 0.513282f, 4.56111f) + ], + + // 3 components + [ + new Vector4(2.17649f, 5.043495f, 1.621035f, -2.105439f), + new Vector4(1.019306f, 9.027613f, -0.28086f, -0.162882f), + new Vector4(2.81511f, 1.597273f, -0.366471f, 10.300301f) + ], + + // 4 components + [ + new Vector4(4.338459f, 1.553635f, -5.767909f, 46.164397f), + new Vector4(3.839993f, 4.693183f, 9.795391f, -15.227561f), + new Vector4(2.791880f, 8.178137f, -3.048324f, 0.302959f), + new Vector4(1.342190f, 12.328289f, 0.010001f, 0.244650f) + ], + + // 5 components + [ + new Vector4(4.892608f, 1.685979f, -22.356787f, 85.91246f), + new Vector4(4.71187f, 4.998496f, 35.918936f, -28.875618f), + new Vector4(4.052795f, 8.244168f, -13.212253f, -1.578428f), + new Vector4(2.929212f, 11.900859f, 0.507991f, 1.816328f), + new Vector4(1.512961f, 16.116382f, 0.138051f, -0.01f) + ], + + // 6 components + [ + new Vector4(5.143778f, 2.079813f, -82.326596f, 111.231024f), + new Vector4(5.612426f, 6.153387f, 113.878661f, 58.004879f), + new Vector4(5.982921f, 9.802895f, 39.479083f, -162.028887f), + new Vector4(6.505167f, 11.059237f, -71.286026f, 95.027069f), + new Vector4(3.869579f, 14.81052f, 1.405746f, -3.704914f), + new Vector4(2.201904f, 19.032909f, -0.152784f, -0.107988f) + ] + ]; /// /// Initializes a new instance of the class. @@ -97,72 +150,13 @@ public sealed partial class HlslBokehBlurProcessor } } - /// - /// Gets the kernel scales to adjust the component values in each kernel. - /// - private static IReadOnlyList KernelScales { get; } = new[] { 1.4f, 1.2f, 1.2f, 1.2f, 1.2f, 1.2f }; - - /// - /// Gets the available bokeh blur kernel parameters. - /// - private static IReadOnlyList KernelComponents { get; } = new[] - { - // 1 component - new[] { new Vector4(0.862325f, 1.624835f, 0.767583f, 1.862321f) }, - - // 2 components - new[] - { - new Vector4(0.886528f, 5.268909f, 0.411259f, -0.548794f), - new Vector4(1.960518f, 1.558213f, 0.513282f, 4.56111f) - }, - - // 3 components - new[] - { - new Vector4(2.17649f, 5.043495f, 1.621035f, -2.105439f), - new Vector4(1.019306f, 9.027613f, -0.28086f, -0.162882f), - new Vector4(2.81511f, 1.597273f, -0.366471f, 10.300301f) - }, - - // 4 components - new[] - { - new Vector4(4.338459f, 1.553635f, -5.767909f, 46.164397f), - new Vector4(3.839993f, 4.693183f, 9.795391f, -15.227561f), - new Vector4(2.791880f, 8.178137f, -3.048324f, 0.302959f), - new Vector4(1.342190f, 12.328289f, 0.010001f, 0.244650f) - }, - - // 5 components - new[] - { - new Vector4(4.892608f, 1.685979f, -22.356787f, 85.91246f), - new Vector4(4.71187f, 4.998496f, 35.918936f, -28.875618f), - new Vector4(4.052795f, 8.244168f, -13.212253f, -1.578428f), - new Vector4(2.929212f, 11.900859f, 0.507991f, 1.816328f), - new Vector4(1.512961f, 16.116382f, 0.138051f, -0.01f) - }, - - // 6 components - new[] - { - new Vector4(5.143778f, 2.079813f, -82.326596f, 111.231024f), - new Vector4(5.612426f, 6.153387f, 113.878661f, 58.004879f), - new Vector4(5.982921f, 9.802895f, 39.479083f, -162.028887f), - new Vector4(6.505167f, 11.059237f, -71.286026f, 95.027069f), - new Vector4(3.869579f, 14.81052f, 1.405746f, -3.704914f), - new Vector4(2.201904f, 19.032909f, -0.152784f, -0.107988f) - } - }; - /// /// Gets the kernel parameters and scaling factor for the current count value in the current instance. /// private (Vector4[] Parameters, float Scale) GetParameters() { // Prepare the kernel components - int index = Math.Max(0, Math.Min(this.componentsCount - 1, KernelComponents.Count)); + int index = Math.Max(0, Math.Min(this.componentsCount - 1, KernelComponents.Length)); return (KernelComponents[index], KernelScales[index]); } diff --git a/samples/ComputeSharp.ImageProcessing/Processors/HlslBokehBlurProcessor.cs b/samples/ComputeSharp.ImageProcessing/Processors/HlslBokehBlurProcessor.cs index f6435bbc..f1aac6fb 100644 --- a/samples/ComputeSharp.ImageProcessing/Processors/HlslBokehBlurProcessor.cs +++ b/samples/ComputeSharp.ImageProcessing/Processors/HlslBokehBlurProcessor.cs @@ -5,6 +5,8 @@ using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing.Processors; using ImageSharpRgba32 = SixLabors.ImageSharp.PixelFormats.Rgba32; +#pragma warning disable IDE0290 + namespace ComputeSharp.BokehBlur.Processors; /// diff --git a/samples/ComputeSharp.ImageProcessing/Processors/HlslGaussianBlurProcessor.cs b/samples/ComputeSharp.ImageProcessing/Processors/HlslGaussianBlurProcessor.cs index c2e67e9d..3aa51825 100644 --- a/samples/ComputeSharp.ImageProcessing/Processors/HlslGaussianBlurProcessor.cs +++ b/samples/ComputeSharp.ImageProcessing/Processors/HlslGaussianBlurProcessor.cs @@ -5,6 +5,8 @@ using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing.Processors; using ImageSharpRgba32 = SixLabors.ImageSharp.PixelFormats.Rgba32; +#pragma warning disable IDE0290 + namespace ComputeSharp.BokehBlur.Processors; /// diff --git a/samples/ComputeSharp.SwapChain.D2D1.Cli/Backend/PixelShaderEffect.cs b/samples/ComputeSharp.SwapChain.D2D1.Cli/Backend/PixelShaderEffect.cs index c31a4a82..d8d8501e 100644 --- a/samples/ComputeSharp.SwapChain.D2D1.Cli/Backend/PixelShaderEffect.cs +++ b/samples/ComputeSharp.SwapChain.D2D1.Cli/Backend/PixelShaderEffect.cs @@ -56,7 +56,8 @@ internal abstract class PixelShaderEffect : CanvasEffect /// An effect for an animated pixel shader. /// /// The type of pixel shader to render. - public sealed class For : PixelShaderEffect + /// The input factory. + public sealed class For(For.Factory factory) : PixelShaderEffect where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor { /// @@ -64,20 +65,6 @@ internal abstract class PixelShaderEffect : CanvasEffect /// private static readonly EffectNode> Effect = new(); - /// - /// The factory to use. - /// - private readonly Factory factory; - - /// - /// Creates a new instance with the specified parameters. - /// - /// The input factory. - public For(Factory factory) - { - this.factory = factory; - } - /// protected override void BuildEffectGraph(EffectGraph effectGraph) { @@ -87,7 +74,7 @@ internal abstract class PixelShaderEffect : CanvasEffect /// protected override void ConfigureEffectGraph(EffectGraph effectGraph) { - effectGraph.GetNode(Effect).ConstantBuffer = this.factory(ElapsedTime, ScreenWidth, ScreenHeight); + effectGraph.GetNode(Effect).ConstantBuffer = factory(ElapsedTime, ScreenWidth, ScreenHeight); } /// diff --git a/samples/ComputeSharp.SwapChain.WinUI/Shaders/PixelShaderEffect.cs b/samples/ComputeSharp.SwapChain.WinUI/Shaders/PixelShaderEffect.cs index 62e38acb..3d61ad23 100644 --- a/samples/ComputeSharp.SwapChain.WinUI/Shaders/PixelShaderEffect.cs +++ b/samples/ComputeSharp.SwapChain.WinUI/Shaders/PixelShaderEffect.cs @@ -56,7 +56,8 @@ public abstract class PixelShaderEffect : CanvasEffect /// An effect for an animated pixel shader. /// /// The type of pixel shader to render. - public sealed class For : PixelShaderEffect + /// The input factory. + public sealed class For(For.Factory factory) : PixelShaderEffect where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor { /// @@ -64,20 +65,6 @@ public abstract class PixelShaderEffect : CanvasEffect /// private static readonly EffectNode> Effect = new(); - /// - /// The factory to use. - /// - private readonly Factory factory; - - /// - /// Creates a new instance with the specified parameters. - /// - /// The input factory. - public For(Factory factory) - { - this.factory = factory; - } - /// protected override void BuildEffectGraph(EffectGraph effectGraph) { @@ -87,7 +74,7 @@ public abstract class PixelShaderEffect : CanvasEffect /// protected override void ConfigureEffectGraph(EffectGraph effectGraph) { - effectGraph.GetNode(Effect).ConstantBuffer = this.factory(ElapsedTime, ScreenWidth, ScreenHeight); + effectGraph.GetNode(Effect).ConstantBuffer = factory(ElapsedTime, ScreenWidth, ScreenHeight); } /// diff --git a/samples/ComputeSharp.SwapChain.WinUI/Shaders/Runners/D2D1ContouredLayersRunner.cs b/samples/ComputeSharp.SwapChain.WinUI/Shaders/Runners/D2D1ContouredLayersRunner.cs index 4cd7ab18..54fb3a3c 100644 --- a/samples/ComputeSharp.SwapChain.WinUI/Shaders/Runners/D2D1ContouredLayersRunner.cs +++ b/samples/ComputeSharp.SwapChain.WinUI/Shaders/Runners/D2D1ContouredLayersRunner.cs @@ -40,13 +40,13 @@ public sealed class D2D1ContouredLayersEffect : PixelShaderEffect // Create the resource texture manager to use in the shader D2D1ResourceTextureManager resourceTextureManager = new( - extents: stackalloc uint[] { (uint)readBackTexture.Height, (uint)readBackTexture.Width }, + extents: [(uint)readBackTexture.Height, (uint)readBackTexture.Width], bufferPrecision: D2D1BufferPrecision.UInt8Normalized, channelDepth: D2D1ChannelDepth.Four, filter: D2D1Filter.MinMagMipLinear, - extendModes: stackalloc D2D1ExtendMode[] { D2D1ExtendMode.Mirror, D2D1ExtendMode.Mirror }, + extendModes: [D2D1ExtendMode.Mirror, D2D1ExtendMode.Mirror], data: new ReadOnlySpan(dataBuffer, bufferSize), - strides: stackalloc uint[] { (uint)strideInBytes }); + strides: [(uint)strideInBytes]); // Create the new pixel shader effect PixelShaderEffect pixelShaderEffect = new() { ResourceTextureManagers = { [0] = resourceTextureManager } }; diff --git a/samples/ComputeSharp.SwapChain.WinUI/ViewModels/ShaderRunnerViewModel.cs b/samples/ComputeSharp.SwapChain.WinUI/ViewModels/ShaderRunnerViewModel.cs index db930863..443689ec 100644 --- a/samples/ComputeSharp.SwapChain.WinUI/ViewModels/ShaderRunnerViewModel.cs +++ b/samples/ComputeSharp.SwapChain.WinUI/ViewModels/ShaderRunnerViewModel.cs @@ -7,35 +7,28 @@ namespace ComputeSharp.SwapChain.Core.ViewModels; /// /// A viewmodel for a compute shader. /// -public sealed partial class ShaderRunnerViewModel : ObservableObject +/// The name of the shader type to execute. +/// The instance to execute. +/// The instance to execute. +public sealed partial class ShaderRunnerViewModel( + string shaderType, + IShaderRunner shaderRunner, + PixelShaderEffect pixelShaderEffect) : ObservableObject { - /// - /// Creates a new instance. - /// - /// The name of the shader type to execute. - /// The instance to execute. - /// The instance to execute. - public ShaderRunnerViewModel(string shaderType, IShaderRunner shaderRunner, PixelShaderEffect pixelShaderEffect) - { - ShaderType = shaderType; - ShaderRunner = shaderRunner; - PixelShaderEffect = pixelShaderEffect; - } - /// /// Gets the name of the shader type to execute. /// - public string ShaderType { get; } + public string ShaderType => shaderType; /// /// Gets the instance to execute. /// - public IShaderRunner ShaderRunner { get; } + public IShaderRunner ShaderRunner => shaderRunner; /// /// Gets the instance to execute. /// - public PixelShaderEffect PixelShaderEffect { get; } + public PixelShaderEffect PixelShaderEffect => pixelShaderEffect; /// /// Gets or sets whether the current shader is selected. diff --git a/samples/ComputeSharp.SwapChain.WinUI/Views/MainWindow.xaml.cs b/samples/ComputeSharp.SwapChain.WinUI/Views/MainWindow.xaml.cs index 009ab8eb..a0c93a4d 100644 --- a/samples/ComputeSharp.SwapChain.WinUI/Views/MainWindow.xaml.cs +++ b/samples/ComputeSharp.SwapChain.WinUI/Views/MainWindow.xaml.cs @@ -16,7 +16,7 @@ public sealed partial class MainWindow : Window /// /// The mapping of currently alive shader panels. /// - private readonly ConditionalWeakTable shaderPanels = new(); + private readonly ConditionalWeakTable shaderPanels = []; public MainWindow() { diff --git a/samples/ComputeSharp.SwapChain/Backend/Win32Application.cs b/samples/ComputeSharp.SwapChain/Backend/Win32Application.cs index d56ae268..080820a5 100644 --- a/samples/ComputeSharp.SwapChain/Backend/Win32Application.cs +++ b/samples/ComputeSharp.SwapChain/Backend/Win32Application.cs @@ -8,13 +8,9 @@ namespace ComputeSharp.SwapChain.Backend; /// /// A class representing a simple Win32 application. /// -internal sealed unsafe class Win32Application +/// The function pointer used to run a shader on a target texture. +internal sealed unsafe class Win32Application(delegate*, TimeSpan, void> shaderCallback) { - /// - /// The function pointer used to run a shader on a target texture. - /// - private readonly delegate*, TimeSpan, void> shaderCallback; - /// /// The pointer for the device currently in use. /// @@ -75,15 +71,6 @@ internal sealed unsafe class Win32Application /// private volatile bool isResizePending; - /// - /// Creates a new instance with the specified parameters. - /// - /// The function pointer used to run a shader on a target texture. - public Win32Application(delegate*, TimeSpan, void> shaderCallback) - { - this.shaderCallback = shaderCallback; - } - /// /// Initializes the current application. /// @@ -241,7 +228,7 @@ internal sealed unsafe class Win32Application } // Generate the new frame by invoking the callback - this.shaderCallback(this.texture!, time); + shaderCallback(this.texture!, time); using ComPtr d3D12Resource = default; diff --git a/src/ComputeSharp.CodeFixers/MissingComputeShaderDescriptorOnComputeShaderCodeFixer.cs b/src/ComputeSharp.CodeFixers/MissingComputeShaderDescriptorOnComputeShaderCodeFixer.cs index a2a1de41..139e1df9 100644 --- a/src/ComputeSharp.CodeFixers/MissingComputeShaderDescriptorOnComputeShaderCodeFixer.cs +++ b/src/ComputeSharp.CodeFixers/MissingComputeShaderDescriptorOnComputeShaderCodeFixer.cs @@ -16,11 +16,11 @@ public sealed class MissingComputeShaderDescriptorOnComputeShaderCodeFixer : Mis /// /// The set of type names for all attributes that can be over shader types. /// - private static readonly string[] D2DAttributeTypeNames = new[] - { + private static readonly string[] D2DAttributeTypeNames = + [ "ComputeSharp.EmbeddedBytecodeAttribute", "ComputeSharp.GroupSharedAttribute" - }; + ]; /// /// Creates a new instance with the specified parameters. diff --git a/src/ComputeSharp.CodeFixing/MissingAttributeCodeFixer.cs b/src/ComputeSharp.CodeFixing/MissingAttributeCodeFixer.cs index 20a485e4..a4f59729 100644 --- a/src/ComputeSharp.CodeFixing/MissingAttributeCodeFixer.cs +++ b/src/ComputeSharp.CodeFixing/MissingAttributeCodeFixer.cs @@ -184,22 +184,9 @@ public abstract class MissingAttributeCodeFixer : CodeFixProvider /// /// A custom with the logic from . /// - private sealed class FixAllProvider : DocumentBasedFixAllProvider + /// The owning instance. + private sealed class FixAllProvider(MissingAttributeCodeFixer codeFixer) : DocumentBasedFixAllProvider { - /// - /// The owning instance. - /// - private readonly MissingAttributeCodeFixer codeFixer; - - /// - /// Creates a new instance with the specified parameters. - /// - /// The owning instance. - public FixAllProvider(MissingAttributeCodeFixer codeFixer) - { - this.codeFixer = codeFixer; - } - /// protected override async Task FixAllAsync(FixAllContext fixAllContext, Document document, ImmutableArray diagnostics) { @@ -220,7 +207,7 @@ public abstract class MissingAttributeCodeFixer : CodeFixProvider } // Get the syntax node with the updated declaration - SyntaxNode updatedStructDeclaration = await this.codeFixer.AddMissingAttribute( + SyntaxNode updatedStructDeclaration = await codeFixer.AddMissingAttribute( document, structDeclaration, fixAllContext.CancellationToken); diff --git a/src/ComputeSharp.Core.SourceGenerators/AutoConstructorGenerator.cs b/src/ComputeSharp.Core.SourceGenerators/AutoConstructorGenerator.cs index 8b713980..0b980bc7 100644 --- a/src/ComputeSharp.Core.SourceGenerators/AutoConstructorGenerator.cs +++ b/src/ComputeSharp.Core.SourceGenerators/AutoConstructorGenerator.cs @@ -9,7 +9,7 @@ using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory; -#pragma warning disable CS0618 +#pragma warning disable CS0618, IDE0300 namespace ComputeSharp.Core.SourceGenerators; diff --git a/src/ComputeSharp.Core/Attributes/Internals/AutoConstructorBehaviorAttribute.cs b/src/ComputeSharp.Core/Attributes/Internals/AutoConstructorBehaviorAttribute.cs index b9dbbb8a..3c1c696a 100644 --- a/src/ComputeSharp.Core/Attributes/Internals/AutoConstructorBehaviorAttribute.cs +++ b/src/ComputeSharp.Core/Attributes/Internals/AutoConstructorBehaviorAttribute.cs @@ -1,5 +1,7 @@ using System; +#pragma warning disable IDE0290 + namespace ComputeSharp; /// diff --git a/src/ComputeSharp.Core/Intrinsics/Attributes/HlslIntrinsicNameAttribute.cs b/src/ComputeSharp.Core/Intrinsics/Attributes/HlslIntrinsicNameAttribute.cs index ffc2fdad..8d847093 100644 --- a/src/ComputeSharp.Core/Intrinsics/Attributes/HlslIntrinsicNameAttribute.cs +++ b/src/ComputeSharp.Core/Intrinsics/Attributes/HlslIntrinsicNameAttribute.cs @@ -6,23 +6,15 @@ namespace ComputeSharp.Core.Intrinsics.Attributes; /// /// An attribute indicating the native member name of a given HLSL intrinsic. /// +/// The name of the HLSL intrinsic. [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] [Conditional("SOURCE_GENERATOR")] -internal sealed class HlslIntrinsicNameAttribute : Attribute +internal sealed class HlslIntrinsicNameAttribute(string name) : Attribute { - /// - /// Creates a new instance with the specified parameters. - /// - /// The name of the HLSL intrinsic. - public HlslIntrinsicNameAttribute(string name) - { - Name = name; - } - /// /// Gets the name of the HLSL intrinsic. /// - public string Name { get; } + public string Name { get; } = name; /// /// Gets whether or not matching parameters is also required to extract the name of this intrinsic. diff --git a/src/ComputeSharp.Core/Primitives/Bool/Bool2.cs b/src/ComputeSharp.Core/Primitives/Bool/Bool2.cs index 5ae6f9dd..91eb282d 100644 --- a/src/ComputeSharp.Core/Primitives/Bool/Bool2.cs +++ b/src/ComputeSharp.Core/Primitives/Bool/Bool2.cs @@ -1,4 +1,4 @@ -#pragma warning disable CS0660, CS0661 +#pragma warning disable CS0660, CS0661, IDE0290 namespace ComputeSharp; diff --git a/src/ComputeSharp.Core/Primitives/Double/Double2.cs b/src/ComputeSharp.Core/Primitives/Double/Double2.cs index 4df36386..1b5196ca 100644 --- a/src/ComputeSharp.Core/Primitives/Double/Double2.cs +++ b/src/ComputeSharp.Core/Primitives/Double/Double2.cs @@ -1,4 +1,4 @@ -#pragma warning disable CS0660, CS0661 +#pragma warning disable CS0660, CS0661, IDE0290 namespace ComputeSharp; diff --git a/src/ComputeSharp.Core/Primitives/Float/Float2.cs b/src/ComputeSharp.Core/Primitives/Float/Float2.cs index bae3c788..8b4f6183 100644 --- a/src/ComputeSharp.Core/Primitives/Float/Float2.cs +++ b/src/ComputeSharp.Core/Primitives/Float/Float2.cs @@ -1,6 +1,6 @@ using System.Numerics; -#pragma warning disable CS0660, CS0661 +#pragma warning disable CS0660, CS0661, IDE0290 namespace ComputeSharp; diff --git a/src/ComputeSharp.Core/Primitives/Int/Int2.cs b/src/ComputeSharp.Core/Primitives/Int/Int2.cs index b9ce5e58..12ff5b0c 100644 --- a/src/ComputeSharp.Core/Primitives/Int/Int2.cs +++ b/src/ComputeSharp.Core/Primitives/Int/Int2.cs @@ -1,4 +1,4 @@ -#pragma warning disable CS0660, CS0661 +#pragma warning disable CS0660, CS0661, IDE0290 namespace ComputeSharp; diff --git a/src/ComputeSharp.Core/Primitives/UInt/UInt2.cs b/src/ComputeSharp.Core/Primitives/UInt/UInt2.cs index 48ef484e..219ced4a 100644 --- a/src/ComputeSharp.Core/Primitives/UInt/UInt2.cs +++ b/src/ComputeSharp.Core/Primitives/UInt/UInt2.cs @@ -1,4 +1,4 @@ -#pragma warning disable CS0660, CS0661 +#pragma warning disable CS0660, CS0661, IDE0290 namespace ComputeSharp; diff --git a/src/ComputeSharp.D2D1.CodeFixers/MissingPixelShaderDescriptorOnPixelShaderCodeFixer.cs b/src/ComputeSharp.D2D1.CodeFixers/MissingPixelShaderDescriptorOnPixelShaderCodeFixer.cs index 69b0a7dc..2b613055 100644 --- a/src/ComputeSharp.D2D1.CodeFixers/MissingPixelShaderDescriptorOnPixelShaderCodeFixer.cs +++ b/src/ComputeSharp.D2D1.CodeFixers/MissingPixelShaderDescriptorOnPixelShaderCodeFixer.cs @@ -16,8 +16,8 @@ public sealed class MissingPixelShaderDescriptorOnPixelShaderCodeFixer : Missing /// /// The set of type names for all D2D attributes that can be over shader types. /// - private static readonly string[] D2DAttributeTypeNames = new[] - { + private static readonly string[] D2DAttributeTypeNames = + [ "ComputeSharp.D2D1.D2DCompileOptionsAttribute", "ComputeSharp.D2D1.D2DEffectAuthorAttribute", "ComputeSharp.D2D1.D2DEffectCategoryAttribute", @@ -32,7 +32,7 @@ public sealed class MissingPixelShaderDescriptorOnPixelShaderCodeFixer : Missing "ComputeSharp.D2D1.D2DPixelOptionsAttribute", "ComputeSharp.D2D1.D2DRequiresScenePositionAttribute", "ComputeSharp.D2D1.D2DShaderProfileAttribute" - }; + ]; /// /// Creates a new instance with the specified parameters. diff --git a/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.HlslBytecode.cs b/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.HlslBytecode.cs index 6ff9b7a0..3a594262 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.HlslBytecode.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.HlslBytecode.cs @@ -216,14 +216,14 @@ partial class D2DPixelShaderDescriptorGenerator diagnostic = DiagnosticInfo.Create( EmbeddedBytecodeFailedWithWin32Exception, structDeclarationSymbol, - new object[] { structDeclarationSymbol, win32Error.HResult, win32Error.Message }); + [structDeclarationSymbol, win32Error.HResult, win32Error.Message]); } else if (info is HlslBytecodeInfo.CompilerError fxcError) { diagnostic = DiagnosticInfo.Create( EmbeddedBytecodeFailedWithFxcCompilationException, structDeclarationSymbol, - new object[] { structDeclarationSymbol, fxcError.Message }); + [structDeclarationSymbol, fxcError.Message]); } if (diagnostic is not null) diff --git a/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderSourceGenerator.Execute.cs b/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderSourceGenerator.Execute.cs index 813e40ac..cdf09651 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderSourceGenerator.Execute.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderSourceGenerator.Execute.cs @@ -140,14 +140,14 @@ partial class D2DPixelShaderSourceGenerator diagnostic = DiagnosticInfo.Create( D2DPixelShaderSourceCompilationFailedWithWin32Exception, methodSymbol, - new object[] { methodSymbol, methodSymbol.ContainingType, win32Error.HResult, win32Error.Message }); + [methodSymbol, methodSymbol.ContainingType, win32Error.HResult, win32Error.Message]); } else if (info is HlslBytecodeInfo.CompilerError fxcError) { diagnostic = DiagnosticInfo.Create( D2DPixelShaderSourceCompilationFailedWithFxcCompilationException, methodSymbol, - new object[] { methodSymbol, methodSymbol.ContainingType, fxcError.Message }); + [methodSymbol, methodSymbol.ContainingType, fxcError.Message]); } if (diagnostic is not null) diff --git a/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderSourceGenerator.cs b/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderSourceGenerator.cs index 2d4bffd6..cb3686f2 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderSourceGenerator.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderSourceGenerator.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Immutable; using System.Linq; using ComputeSharp.D2D1.SourceGenerators.Models; @@ -94,7 +93,7 @@ public sealed partial class D2DPixelShaderSourceGenerator : IIncrementalGenerato item.Hierarchy.WriteSyntax( state: item, writer: writer, - baseTypes: ReadOnlySpan.Empty, + baseTypes: [], memberCallbacks: new IndentedTextWriter.Callback[] { Execute.WriteSyntax }); context.AddSource($"{item.Hierarchy.FullyQualifiedMetadataName}.{item.MethodName}.g.cs", writer.ToString()); diff --git a/src/ComputeSharp.D2D1.WinUI/ABI.Microsoft.Graphics.Canvas/ICanvasEffectFactoryNative.cs b/src/ComputeSharp.D2D1.WinUI/ABI.Microsoft.Graphics.Canvas/ICanvasEffectFactoryNative.cs index 7275b492..881ee765 100644 --- a/src/ComputeSharp.D2D1.WinUI/ABI.Microsoft.Graphics.Canvas/ICanvasEffectFactoryNative.cs +++ b/src/ComputeSharp.D2D1.WinUI/ABI.Microsoft.Graphics.Canvas/ICanvasEffectFactoryNative.cs @@ -118,7 +118,7 @@ internal unsafe struct ICanvasEffectFactoryNative private delegate* unmanaged[Stdcall] CreateWrapper; /// - [UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })] + [UnmanagedCallersOnly(CallConvs = [typeof(CallConvStdcall)])] [return: NativeTypeName("HRESULT")] private static int CreateWrapperFromAbi(IntPtr thisPtr, ICanvasDevice* device, ID2D1Effect* resource, float dpi, IInspectable** wrapper) { diff --git a/src/ComputeSharp.D2D1.WinUI/ABI.Microsoft.Graphics.Canvas/ICanvasImageInterop.cs b/src/ComputeSharp.D2D1.WinUI/ABI.Microsoft.Graphics.Canvas/ICanvasImageInterop.cs index 4e64aa82..2fe62f4d 100644 --- a/src/ComputeSharp.D2D1.WinUI/ABI.Microsoft.Graphics.Canvas/ICanvasImageInterop.cs +++ b/src/ComputeSharp.D2D1.WinUI/ABI.Microsoft.Graphics.Canvas/ICanvasImageInterop.cs @@ -142,7 +142,7 @@ internal unsafe struct ICanvasImageInterop private delegate* unmanaged[Stdcall] GetD2DImage; /// - [UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })] + [UnmanagedCallersOnly(CallConvs = [typeof(CallConvStdcall)])] [return: NativeTypeName("HRESULT")] private static int GetDeviceFromAbi(IntPtr thisPtr, ICanvasDevice** device, WIN2D_GET_DEVICE_ASSOCIATION_TYPE* type) { @@ -159,7 +159,7 @@ internal unsafe struct ICanvasImageInterop } /// - [UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })] + [UnmanagedCallersOnly(CallConvs = [typeof(CallConvStdcall)])] [return: NativeTypeName("HRESULT")] private static int GetD2DImageFromAbi( IntPtr thisPtr, diff --git a/src/ComputeSharp.D2D1.WinUI/CanvasEffect.cs b/src/ComputeSharp.D2D1.WinUI/CanvasEffect.cs index b138a98d..e08c903b 100644 --- a/src/ComputeSharp.D2D1.WinUI/CanvasEffect.cs +++ b/src/ComputeSharp.D2D1.WinUI/CanvasEffect.cs @@ -17,7 +17,7 @@ public abstract partial class CanvasEffect : ICanvasImage, ICanvasImageInterop.I /// /// When not empty (ie. when an effect graph has been built), this will always also include . /// - private readonly Dictionary transformNodes = new(); + private readonly Dictionary transformNodes = []; /// /// The current cached result for , if available. diff --git a/src/ComputeSharp.D2D1.WinUI/PixelShaderEffect{T}.Properties.ResourceTextureManagerCollection.cs b/src/ComputeSharp.D2D1.WinUI/PixelShaderEffect{T}.Properties.ResourceTextureManagerCollection.cs index cfd1947b..f801de9a 100644 --- a/src/ComputeSharp.D2D1.WinUI/PixelShaderEffect{T}.Properties.ResourceTextureManagerCollection.cs +++ b/src/ComputeSharp.D2D1.WinUI/PixelShaderEffect{T}.Properties.ResourceTextureManagerCollection.cs @@ -244,7 +244,7 @@ partial class PixelShaderEffect // Skip the array allocation if there are no resource texture descriptions if (descriptions.IsEmpty) { - return ImmutableArray.Empty; + return []; } int[] indices = new int[descriptions.Length]; diff --git a/src/ComputeSharp.D2D1.WinUI/PixelShaderEffect{T}.Properties.SourceCollection.cs b/src/ComputeSharp.D2D1.WinUI/PixelShaderEffect{T}.Properties.SourceCollection.cs index 688292de..4dd3e49d 100644 --- a/src/ComputeSharp.D2D1.WinUI/PixelShaderEffect{T}.Properties.SourceCollection.cs +++ b/src/ComputeSharp.D2D1.WinUI/PixelShaderEffect{T}.Properties.SourceCollection.cs @@ -213,7 +213,7 @@ partial class PixelShaderEffect if (inputCount == 0) { - return ImmutableArray.Empty; + return []; } int[] indices = new int[inputCount]; diff --git a/src/ComputeSharp.D2D1/Attributes/D2DCompileOptionsAttribute.cs b/src/ComputeSharp.D2D1/Attributes/D2DCompileOptionsAttribute.cs index fe4568a0..9bd4c07f 100644 --- a/src/ComputeSharp.D2D1/Attributes/D2DCompileOptionsAttribute.cs +++ b/src/ComputeSharp.D2D1/Attributes/D2DCompileOptionsAttribute.cs @@ -24,20 +24,12 @@ namespace ComputeSharp.D2D1; /// This attribute can also be added to a whole assembly, and will be used by default if not overridden by a shader type. /// /// +/// The compiler options to use to compile the shader. [AttributeUsage(AttributeTargets.Struct | AttributeTargets.Assembly | AttributeTargets.Method, AllowMultiple = false)] -public sealed class D2DCompileOptionsAttribute : Attribute +public sealed class D2DCompileOptionsAttribute(D2D1CompileOptions options) : Attribute { - /// - /// Creates a new instance with the specified parameters. - /// - /// The compiler options to use to compile the shader. - public D2DCompileOptionsAttribute(D2D1CompileOptions options) - { - Options = options; - } - /// /// Gets the number of threads in each thread group for the X axis /// - public D2D1CompileOptions Options { get; } + public D2D1CompileOptions Options { get; } = options; } \ No newline at end of file diff --git a/src/ComputeSharp.D2D1/Attributes/D2DEffectAuthorAttribute.cs b/src/ComputeSharp.D2D1/Attributes/D2DEffectAuthorAttribute.cs index 8e589eea..924bc6d9 100644 --- a/src/ComputeSharp.D2D1/Attributes/D2DEffectAuthorAttribute.cs +++ b/src/ComputeSharp.D2D1/Attributes/D2DEffectAuthorAttribute.cs @@ -8,20 +8,12 @@ namespace ComputeSharp.D2D1; /// /// This only applies to effects created from . /// +/// The value for the author. [AttributeUsage(AttributeTargets.Struct | AttributeTargets.Assembly, AllowMultiple = false)] -public sealed class D2DEffectAuthorAttribute : Attribute +public sealed class D2DEffectAuthorAttribute(string value) : Attribute { - /// - /// Creates a new instance of the type with the specified arguments. - /// - /// The value for the author. - public D2DEffectAuthorAttribute(string value) - { - Value = value; - } - /// /// Gets the author value. /// - public string Value { get; } + public string Value { get; } = value; } \ No newline at end of file diff --git a/src/ComputeSharp.D2D1/Attributes/D2DEffectCategoryAttribute.cs b/src/ComputeSharp.D2D1/Attributes/D2DEffectCategoryAttribute.cs index 53708f6c..646672d0 100644 --- a/src/ComputeSharp.D2D1/Attributes/D2DEffectCategoryAttribute.cs +++ b/src/ComputeSharp.D2D1/Attributes/D2DEffectCategoryAttribute.cs @@ -8,20 +8,12 @@ namespace ComputeSharp.D2D1; /// /// This only applies to effects created from . /// +/// The value for the category. [AttributeUsage(AttributeTargets.Struct | AttributeTargets.Assembly, AllowMultiple = false)] -public sealed class D2DEffectCategoryAttribute : Attribute +public sealed class D2DEffectCategoryAttribute(string value) : Attribute { - /// - /// Creates a new instance of the type with the specified arguments. - /// - /// The value for the category. - public D2DEffectCategoryAttribute(string value) - { - Value = value; - } - /// /// Gets the category value. /// - public string Value { get; } + public string Value { get; } = value; } \ No newline at end of file diff --git a/src/ComputeSharp.D2D1/Attributes/D2DEffectDescriptionAttribute.cs b/src/ComputeSharp.D2D1/Attributes/D2DEffectDescriptionAttribute.cs index 7bbb2c1d..19bd37e9 100644 --- a/src/ComputeSharp.D2D1/Attributes/D2DEffectDescriptionAttribute.cs +++ b/src/ComputeSharp.D2D1/Attributes/D2DEffectDescriptionAttribute.cs @@ -8,20 +8,12 @@ namespace ComputeSharp.D2D1; /// /// This only applies to effects created from . /// +/// The value for the description. [AttributeUsage(AttributeTargets.Struct, AllowMultiple = false)] -public sealed class D2DEffectDescriptionAttribute : Attribute +public sealed class D2DEffectDescriptionAttribute(string value) : Attribute { - /// - /// Creates a new instance of the type with the specified arguments. - /// - /// The value for the description. - public D2DEffectDescriptionAttribute(string value) - { - Value = value; - } - /// /// Gets the description value. /// - public string Value { get; } + public string Value { get; } = value; } \ No newline at end of file diff --git a/src/ComputeSharp.D2D1/Attributes/D2DEffectDisplayNameAttribute.cs b/src/ComputeSharp.D2D1/Attributes/D2DEffectDisplayNameAttribute.cs index 5b68b638..35046822 100644 --- a/src/ComputeSharp.D2D1/Attributes/D2DEffectDisplayNameAttribute.cs +++ b/src/ComputeSharp.D2D1/Attributes/D2DEffectDisplayNameAttribute.cs @@ -8,20 +8,12 @@ namespace ComputeSharp.D2D1; /// /// This only applies to effects created from . /// +/// The value for the display name. [AttributeUsage(AttributeTargets.Struct, AllowMultiple = false)] -public sealed class D2DEffectDisplayNameAttribute : Attribute +public sealed class D2DEffectDisplayNameAttribute(string value) : Attribute { - /// - /// Creates a new instance of the type with the specified arguments. - /// - /// The value for the display name. - public D2DEffectDisplayNameAttribute(string value) - { - Value = value; - } - /// /// Gets the display name value. /// - public string Value { get; } + public string Value { get; } = value; } \ No newline at end of file diff --git a/src/ComputeSharp.D2D1/Attributes/D2DEffectIdAttribute.cs b/src/ComputeSharp.D2D1/Attributes/D2DEffectIdAttribute.cs index c64e8bb8..46b0eccf 100644 --- a/src/ComputeSharp.D2D1/Attributes/D2DEffectIdAttribute.cs +++ b/src/ComputeSharp.D2D1/Attributes/D2DEffectIdAttribute.cs @@ -8,20 +8,12 @@ namespace ComputeSharp.D2D1; /// /// This only applies to effects created from . /// +/// The value for the effect id. [AttributeUsage(AttributeTargets.Struct, AllowMultiple = false)] -public sealed class D2DEffectIdAttribute : Attribute +public sealed class D2DEffectIdAttribute(string value) : Attribute { - /// - /// Creates a new instance of the type with the specified arguments. - /// - /// The value for the effect id. - public D2DEffectIdAttribute(string value) - { - Value = Guid.Parse(value); - } - /// /// Gets the effect id value. /// - public Guid Value { get; } + public Guid Value { get; } = Guid.Parse(value); } \ No newline at end of file diff --git a/src/ComputeSharp.D2D1/Attributes/D2DInputComplexAttribute.cs b/src/ComputeSharp.D2D1/Attributes/D2DInputComplexAttribute.cs index 36f26fcc..de52a0b1 100644 --- a/src/ComputeSharp.D2D1/Attributes/D2DInputComplexAttribute.cs +++ b/src/ComputeSharp.D2D1/Attributes/D2DInputComplexAttribute.cs @@ -10,20 +10,12 @@ namespace ComputeSharp.D2D1; /// This attribute directly maps to #define D2D_INPUT<N>_COMPLEX. /// For more info, see . /// +/// The index of the resource to declare as using complex sampling. [AttributeUsage(AttributeTargets.Struct, AllowMultiple = true)] -public sealed class D2DInputComplexAttribute : Attribute +public sealed class D2DInputComplexAttribute(int index) : Attribute { - /// - /// Creates a new instance of the type with the specified arguments. - /// - /// The index of the resource to declare as using complex sampling. - public D2DInputComplexAttribute(int index) - { - Index = index; - } - /// /// Gets the index of the resource declared as using complex sampling. /// - public int Index { get; } + public int Index { get; } = index; } \ No newline at end of file diff --git a/src/ComputeSharp.D2D1/Attributes/D2DInputCountAttribute.cs b/src/ComputeSharp.D2D1/Attributes/D2DInputCountAttribute.cs index 125e759f..db472c14 100644 --- a/src/ComputeSharp.D2D1/Attributes/D2DInputCountAttribute.cs +++ b/src/ComputeSharp.D2D1/Attributes/D2DInputCountAttribute.cs @@ -10,20 +10,12 @@ namespace ComputeSharp.D2D1; /// This attribute directly maps to #define D2D_INPUT_COUNT <N>. /// For more info, see . /// +/// The number of texture inputs for the shader. [AttributeUsage(AttributeTargets.Struct, AllowMultiple = false)] -public sealed class D2DInputCountAttribute : Attribute +public sealed class D2DInputCountAttribute(int count) : Attribute { - /// - /// Creates a new instance of the type with the specified arguments. - /// - /// The number of texture inputs for the shader. - public D2DInputCountAttribute(int count) - { - Count = count; - } - /// /// Gets the number of texture inputs for the shader. /// - public int Count { get; } + public int Count { get; } = count; } \ No newline at end of file diff --git a/src/ComputeSharp.D2D1/Attributes/D2DInputDescriptionAttribute.cs b/src/ComputeSharp.D2D1/Attributes/D2DInputDescriptionAttribute.cs index fdcd8d41..b2ea705a 100644 --- a/src/ComputeSharp.D2D1/Attributes/D2DInputDescriptionAttribute.cs +++ b/src/ComputeSharp.D2D1/Attributes/D2DInputDescriptionAttribute.cs @@ -10,29 +10,20 @@ namespace ComputeSharp.D2D1; /// This attribute exposes the options that can be set via D2D1_INPUT_DESCRIPTION. /// For more info, see . /// +/// The index of the resource to declare the description for. +/// The type of filter to apply to the input texture. [AttributeUsage(AttributeTargets.Struct, AllowMultiple = true)] -public sealed class D2DInputDescriptionAttribute : Attribute +public sealed class D2DInputDescriptionAttribute(int index, D2D1Filter filter) : Attribute { - /// - /// Creates a new instance of the type with the specified arguments. - /// - /// The index of the resource to declare the description for. - /// The type of filter to apply to the input texture. - public D2DInputDescriptionAttribute(int index, D2D1Filter filter) - { - Index = index; - Filter = filter; - } - /// /// Gets the index of the resource to declare the description for. /// - public int Index { get; } + public int Index { get; } = index; /// /// Gets the type of filter to apply to the input texture. /// - public D2D1Filter Filter { get; } + public D2D1Filter Filter { get; } = filter; /// /// Gets the mip level to retrieve from the upstream transform, if specified. diff --git a/src/ComputeSharp.D2D1/Attributes/D2DInputSimpleAttribute.cs b/src/ComputeSharp.D2D1/Attributes/D2DInputSimpleAttribute.cs index 77750358..484ed9ee 100644 --- a/src/ComputeSharp.D2D1/Attributes/D2DInputSimpleAttribute.cs +++ b/src/ComputeSharp.D2D1/Attributes/D2DInputSimpleAttribute.cs @@ -10,20 +10,12 @@ namespace ComputeSharp.D2D1; /// This attribute directly maps to #define D2D_INPUT<N>_SIMPLE. /// For more info, see . /// +/// The index of the resource to declare as using simple sampling. [AttributeUsage(AttributeTargets.Struct, AllowMultiple = true)] -public sealed class D2DInputSimpleAttribute : Attribute +public sealed class D2DInputSimpleAttribute(int index) : Attribute { - /// - /// Creates a new instance of the type with the specified arguments. - /// - /// The index of the resource to declare as using simple sampling. - public D2DInputSimpleAttribute(int index) - { - Index = index; - } - /// /// Gets the index of the resource declared as using simple sampling. /// - public int Index { get; } + public int Index { get; } = index; } \ No newline at end of file diff --git a/src/ComputeSharp.D2D1/Attributes/D2DPixelOptionsAttribute.cs b/src/ComputeSharp.D2D1/Attributes/D2DPixelOptionsAttribute.cs index 459eced3..f410980a 100644 --- a/src/ComputeSharp.D2D1/Attributes/D2DPixelOptionsAttribute.cs +++ b/src/ComputeSharp.D2D1/Attributes/D2DPixelOptionsAttribute.cs @@ -9,20 +9,12 @@ namespace ComputeSharp.D2D1; /// /// For more info, see . /// +/// The options to specify for the shader. [AttributeUsage(AttributeTargets.Struct, AllowMultiple = false)] -public sealed class D2DPixelOptionsAttribute : Attribute +public sealed class D2DPixelOptionsAttribute(D2D1PixelOptions options) : Attribute { - /// - /// Creates a new instance of the type with the specified arguments. - /// - /// The options to specify for the shader. - public D2DPixelOptionsAttribute(D2D1PixelOptions options) - { - Options = options; - } - /// /// Gets the options to specify for the shader. /// - public D2D1PixelOptions Options { get; } + public D2D1PixelOptions Options { get; } = options; } \ No newline at end of file diff --git a/src/ComputeSharp.D2D1/Attributes/D2DPixelShaderSourceAttribute.cs b/src/ComputeSharp.D2D1/Attributes/D2DPixelShaderSourceAttribute.cs index 1eb515e9..da780e56 100644 --- a/src/ComputeSharp.D2D1/Attributes/D2DPixelShaderSourceAttribute.cs +++ b/src/ComputeSharp.D2D1/Attributes/D2DPixelShaderSourceAttribute.cs @@ -32,20 +32,12 @@ namespace ComputeSharp.D2D1; /// to further customize the shader profile to use when compiling the HLSL source, and the compile options to use. /// /// +/// The number of texture inputs for the shader. [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] -public sealed class D2DPixelShaderSourceAttribute : Attribute +public sealed class D2DPixelShaderSourceAttribute([StringSyntax("Hlsl")] string hlslSource) : Attribute { - /// - /// Creates a new instance of the type with the specified arguments. - /// - /// The number of texture inputs for the shader. - public D2DPixelShaderSourceAttribute([StringSyntax("Hlsl")] string hlslSource) - { - HlslSource = hlslSource; - } - /// /// Gets the number of texture inputs for the shader. /// - public string HlslSource { get; } + public string HlslSource { get; } = hlslSource; } \ No newline at end of file diff --git a/src/ComputeSharp.D2D1/Attributes/D2DResourceTextureIndexAttribute.cs b/src/ComputeSharp.D2D1/Attributes/D2DResourceTextureIndexAttribute.cs index 60b6e2a5..fa487717 100644 --- a/src/ComputeSharp.D2D1/Attributes/D2DResourceTextureIndexAttribute.cs +++ b/src/ComputeSharp.D2D1/Attributes/D2DResourceTextureIndexAttribute.cs @@ -9,20 +9,12 @@ namespace ComputeSharp.D2D1; /// /// For more info, see . /// +/// The index of the annotated resource field. [AttributeUsage(AttributeTargets.Field, AllowMultiple = false)] -public sealed class D2DResourceTextureIndexAttribute : Attribute +public sealed class D2DResourceTextureIndexAttribute(int index) : Attribute { - /// - /// Creates a new instance of the type with the specified arguments. - /// - /// The index of the annotated resource field. - public D2DResourceTextureIndexAttribute(int index) - { - Index = index; - } - /// /// Gets the index of the annotated resource field. /// - public int Index { get; } + public int Index { get; } = index; } \ No newline at end of file diff --git a/src/ComputeSharp.D2D1/Attributes/D2DShaderProfileAttribute.cs b/src/ComputeSharp.D2D1/Attributes/D2DShaderProfileAttribute.cs index 5ae6332f..93c30a5e 100644 --- a/src/ComputeSharp.D2D1/Attributes/D2DShaderProfileAttribute.cs +++ b/src/ComputeSharp.D2D1/Attributes/D2DShaderProfileAttribute.cs @@ -24,20 +24,12 @@ namespace ComputeSharp.D2D1; /// This attribute can also be added to a whole assembly, and will be used by default if not overridden by a shader type. /// /// +/// The target shader profile to use to compile the shader. [AttributeUsage(AttributeTargets.Struct | AttributeTargets.Assembly | AttributeTargets.Method, AllowMultiple = false)] -public sealed class D2DShaderProfileAttribute : Attribute +public sealed class D2DShaderProfileAttribute(D2D1ShaderProfile shaderProfile) : Attribute { - /// - /// Creates a new instance with the specified parameters. - /// - /// The target shader profile to use to compile the shader. - public D2DShaderProfileAttribute(D2D1ShaderProfile shaderProfile) - { - ShaderProfile = shaderProfile; - } - /// /// The shader profile used to compile the annotated D2D1 pixel shader. /// - public D2D1ShaderProfile ShaderProfile { get; } + public D2D1ShaderProfile ShaderProfile { get; } = shaderProfile; } \ No newline at end of file diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/Buffers/ArrayPoolBinaryWriter.cs b/src/ComputeSharp.D2D1/Shaders/Interop/Buffers/ArrayPoolBinaryWriter.cs index e2c08b74..d27451af 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/Buffers/ArrayPoolBinaryWriter.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/Buffers/ArrayPoolBinaryWriter.cs @@ -10,7 +10,8 @@ namespace ComputeSharp.D2D1.Shaders.Interop.Buffers; /// /// Represents a heap-based, array-backed output sink into which binary data can be written. /// -internal ref struct ArrayPoolBinaryWriter +/// The initial capacity of the writer object. +internal ref struct ArrayPoolBinaryWriter(int capacity) { /// /// The default buffer size to use to expand empty arrays. @@ -20,21 +21,12 @@ internal ref struct ArrayPoolBinaryWriter /// /// The underlying array. /// - private byte[]? array; + private byte[]? array = ArrayPool.Shared.Rent(capacity); /// /// The starting offset within . /// - private int index; - - /// - /// Initializes a new instance of the type. - /// - public ArrayPoolBinaryWriter(int capacity) - { - this.array = ArrayPool.Shared.Rent(capacity); - this.index = 0; - } + private int index = 0; /// /// Gets the data written to the underlying buffer so far, as a . diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1InputDescription.cs b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1InputDescription.cs index 9a563844..9482e9af 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1InputDescription.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1InputDescription.cs @@ -1,5 +1,7 @@ using System.Runtime.InteropServices; +#pragma warning disable IDE0290 + namespace ComputeSharp.D2D1.Interop; /// diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1ResourceTextureDescription.cs b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1ResourceTextureDescription.cs index 93977ca7..75e6f9b7 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1ResourceTextureDescription.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1ResourceTextureDescription.cs @@ -1,5 +1,7 @@ using System.Runtime.InteropServices; +#pragma warning disable IDE0290 + namespace ComputeSharp.D2D1.Interop; /// diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1ResourceTextureManager.cs b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1ResourceTextureManager.cs index 4517c4f5..2909a1af 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1ResourceTextureManager.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1ResourceTextureManager.cs @@ -140,8 +140,8 @@ public sealed unsafe class D2D1ResourceTextureManager : ICustomQueryInterface channelDepth, filter, extendModes, - ReadOnlySpan.Empty, - ReadOnlySpan.Empty) + [], + []) { } @@ -180,8 +180,8 @@ public sealed unsafe class D2D1ResourceTextureManager : ICustomQueryInterface channelDepth, filter, extendModes, - ReadOnlySpan.Empty, - ReadOnlySpan.Empty) + [], + []) { } diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/Helpers/Point64.cs b/src/ComputeSharp.D2D1/Shaders/Interop/Helpers/Point64.cs index 53352867..a71978bc 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/Helpers/Point64.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/Helpers/Point64.cs @@ -8,36 +8,17 @@ namespace ComputeSharp.D2D1.Shaders.Interop.Helpers; /// /// A 64-bit version of the type. /// -internal readonly struct Point64 +/// The horizontal coordinate of the point. +/// The vertical coordinate of the point. +internal readonly struct Point64(long x, long y) { - /// - /// The left coordinate of the current point. - /// - private readonly long x; - - /// - /// The top coordinate of the current point. - /// - private readonly long y; - - /// - /// Creates a new instance with the specified parameters. - /// - /// The horizontal coordinate of the point. - /// The vertical coordinate of the point. - public Point64(long x, long y) - { - this.x = x; - this.y = y; - } - /// /// Gets the horizontal coordinate of the current point. /// public readonly long X { [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => this.x; + get => x; } /// @@ -46,7 +27,7 @@ internal readonly struct Point64 public readonly long Y { [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => this.y; + get => y; } /// @@ -77,7 +58,7 @@ internal readonly struct Point64 // [ M21, M22 ] // [ x, y] [ M31, M32 ] = [ x * M11 + y * M21 + M31, x * M12 + y * M22 + m32] return ( - Math.Round(((double)this.x * matrix.M11) + ((double)this.y * matrix.M21) + matrix.M31), - Math.Round(((double)this.x * matrix.M12) + ((double)this.y * matrix.M22) + matrix.M32)); + Math.Round(((double)x * matrix.M11) + ((double)y * matrix.M21) + matrix.M31), + Math.Round(((double)x * matrix.M12) + ((double)y * matrix.M22) + matrix.M32)); } } \ No newline at end of file diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/Helpers/Rectangle64.cs b/src/ComputeSharp.D2D1/Shaders/Interop/Helpers/Rectangle64.cs index c72945b1..6c5af07e 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/Helpers/Rectangle64.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/Helpers/Rectangle64.cs @@ -7,42 +7,21 @@ namespace ComputeSharp.D2D1.Shaders.Interop.Helpers; /// /// A 64-bit version of the type. /// -internal struct Rectangle64 +/// The left coordinate of the rectangle. +/// The top coordinate of the rectangle. +/// The width of the rectangle. +/// The height of the rectangle. +internal struct Rectangle64(long x, long y, long width, long height) { /// /// The left coordinate of the current rectangle. /// - private long x; + private long x = x; /// /// The top coordinate of the current rectangle. /// - private long y; - - /// - /// The width of the current rectangle. - /// - private long width; - - /// - /// The height of the current rectangle. - /// - private long height; - - /// - /// Creates a new instance with the specified parameters. - /// - /// The left coordinate of the rectangle. - /// The top coordinate of the rectangle. - /// The width of the rectangle. - /// The height of the rectangle. - public Rectangle64(long x, long y, long width, long height) - { - this.x = x; - this.y = y; - this.width = width; - this.height = height; - } + private long y = y; /// /// Gets the left coordinate of the current rectangle. @@ -68,7 +47,7 @@ internal struct Rectangle64 public readonly long Right { [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => this.x + this.width; + get => this.x + width; } /// @@ -77,7 +56,7 @@ internal struct Rectangle64 public readonly long Bottom { [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => this.y + this.height; + get => this.y + height; } /// @@ -102,8 +81,9 @@ internal struct Rectangle64 this.x = left; this.y = top; - this.width = right - left; - this.height = bottom - top; + + width = right - left; + height = bottom - top; } /// @@ -119,8 +99,9 @@ internal struct Rectangle64 this.x = left; this.y = top; - this.width = Math.Max(right - left, 0); - this.height = Math.Max(bottom - top, 0); + + width = Math.Max(right - left, 0); + height = Math.Max(bottom - top, 0); } /// @@ -134,8 +115,9 @@ internal struct Rectangle64 { this.x -= left; this.y -= top; - this.width += left + right; - this.height += top + bottom; + + width += left + right; + height += top + bottom; } /// @@ -146,7 +128,7 @@ internal struct Rectangle64 { Intersect(new Rectangle64(int.MinValue / 2, int.MinValue / 2, int.MaxValue, int.MaxValue)); - return new((int)this.x, (int)this.y, (int)this.width, (int)this.height); + return new((int)this.x, (int)this.y, (int)width, (int)height); } /// diff --git a/src/ComputeSharp.SourceGeneration.Hlsl/Helpers/SemanticModelProvider.cs b/src/ComputeSharp.SourceGeneration.Hlsl/Helpers/SemanticModelProvider.cs index ad657a04..95a019a3 100644 --- a/src/ComputeSharp.SourceGeneration.Hlsl/Helpers/SemanticModelProvider.cs +++ b/src/ComputeSharp.SourceGeneration.Hlsl/Helpers/SemanticModelProvider.cs @@ -6,27 +6,13 @@ namespace ComputeSharp.SourceGeneration.Helpers; /// /// A type providing instances for nodes. /// -internal sealed class SemanticModelProvider +/// The source instance. +internal sealed class SemanticModelProvider(Compilation compilation) { - /// - /// The source instance. - /// - private readonly Compilation compilation; - /// /// The map of loaded instances. /// - private readonly Dictionary semanticModelsMap; - - /// - /// Creates a new instance with the specified parameters. - /// - /// The source instance. - public SemanticModelProvider(Compilation compilation) - { - this.compilation = compilation; - this.semanticModelsMap = new Dictionary(); - } + private readonly Dictionary semanticModelsMap = []; /// /// Gets a instance with info on a given . @@ -37,7 +23,7 @@ internal sealed class SemanticModelProvider { if (!this.semanticModelsMap.TryGetValue(syntaxNode.SyntaxTree, out SemanticModel semanticModel)) { - semanticModel = this.compilation.GetSemanticModel(syntaxNode.SyntaxTree); + semanticModel = compilation.GetSemanticModel(syntaxNode.SyntaxTree); this.semanticModelsMap.Add(syntaxNode.SyntaxTree, semanticModel); } diff --git a/src/ComputeSharp.SourceGeneration.Hlsl/Helpers/SyntaxFormattingHelper.cs b/src/ComputeSharp.SourceGeneration.Hlsl/Helpers/SyntaxFormattingHelper.cs index 7d630da4..c6f3b680 100644 --- a/src/ComputeSharp.SourceGeneration.Hlsl/Helpers/SyntaxFormattingHelper.cs +++ b/src/ComputeSharp.SourceGeneration.Hlsl/Helpers/SyntaxFormattingHelper.cs @@ -1,5 +1,7 @@ using System; +#pragma warning disable IDE0055 + namespace ComputeSharp.SourceGeneration.Helpers; /// @@ -11,7 +13,7 @@ internal static class SyntaxFormattingHelper /// A mapping of precomputed literals for all values. /// private static readonly string[] FormattedBytes = - { + [ "0x00", "0x01", "0x02", "0x03", "0x04", "0x05", "0x06", "0x07", "0x08", "0x09", "0x0A", "0x0B", "0x0C", "0x0D", "0x0E", "0x0F", "0x10", "0x11", "0x12", "0x13", "0x14", "0x15", "0x16", "0x17", "0x18", "0x19", "0x1A", "0x1B", "0x1C", "0x1D", "0x1E", "0x1F", "0x20", "0x21", "0x22", "0x23", "0x24", "0x25", "0x26", "0x27", "0x28", "0x29", "0x2A", "0x2B", "0x2C", "0x2D", "0x2E", "0x2F", @@ -28,7 +30,7 @@ internal static class SyntaxFormattingHelper "0xD0", "0xD1", "0xD2", "0xD3", "0xD4", "0xD5", "0xD6", "0xD7", "0xD8", "0xD9", "0xDA", "0xDB", "0xDC", "0xDD", "0xDE", "0xDF", "0xE0", "0xE1", "0xE2", "0xE3", "0xE4", "0xE5", "0xE6", "0xE7", "0xE8", "0xE9", "0xEA", "0xEB", "0xEC", "0xED", "0xEE", "0xEF", "0xF0", "0xF1", "0xF2", "0xF3", "0xF4", "0xF5", "0xF6", "0xF7", "0xF8", "0xF9", "0xFA", "0xFB", "0xFC", "0xFD", "0xFE", "0xFF" - }; + ]; /// /// Gets an expression representing a single byte. diff --git a/src/ComputeSharp.SourceGeneration.Hlsl/Mappings/HlslKnownMethods.cs b/src/ComputeSharp.SourceGeneration.Hlsl/Mappings/HlslKnownMethods.cs index 38ff6e74..c47faa54 100644 --- a/src/ComputeSharp.SourceGeneration.Hlsl/Mappings/HlslKnownMethods.cs +++ b/src/ComputeSharp.SourceGeneration.Hlsl/Mappings/HlslKnownMethods.cs @@ -166,7 +166,7 @@ internal static partial class HlslKnownMethods { ILookup methodsLookup = typeof(Hlsl).GetMethods(BindingFlags.Public | BindingFlags.Static).ToLookup(static method => method.Name); - Dictionary knownMethods = new(); + Dictionary knownMethods = []; // Go through the previously discovered methods to find the ones requiring parameters mapping foreach (KeyValuePair pair in KnownMethods) diff --git a/src/ComputeSharp.SourceGeneration.Hlsl/Mappings/HlslKnownOperators.cs b/src/ComputeSharp.SourceGeneration.Hlsl/Mappings/HlslKnownOperators.cs index 826fd3c2..08c22239 100644 --- a/src/ComputeSharp.SourceGeneration.Hlsl/Mappings/HlslKnownOperators.cs +++ b/src/ComputeSharp.SourceGeneration.Hlsl/Mappings/HlslKnownOperators.cs @@ -21,7 +21,7 @@ internal static partial class HlslKnownOperators /// private static IReadOnlyDictionary BuildKnownOperatorsMap() { - Dictionary knownOperators = new(); + Dictionary knownOperators = []; // Programmatically load mappings for the intrinsic operators on each HLSL primitive type foreach ((Type Type, MethodInfo Operator, string IntrinsicName, bool RequiresParametersMatching) item in diff --git a/src/ComputeSharp.SourceGeneration.Hlsl/SyntaxRewriters/HlslSourceRewriter.cs b/src/ComputeSharp.SourceGeneration.Hlsl/SyntaxRewriters/HlslSourceRewriter.cs index ee44570d..52452865 100644 --- a/src/ComputeSharp.SourceGeneration.Hlsl/SyntaxRewriters/HlslSourceRewriter.cs +++ b/src/ComputeSharp.SourceGeneration.Hlsl/SyntaxRewriters/HlslSourceRewriter.cs @@ -24,7 +24,7 @@ internal abstract partial class HlslSourceRewriter : CSharpSyntaxRewriter /// /// An array with the '.' and 'E' characters. /// - private static readonly char[] FloatLiteralSpecialCharacters = { '.', 'E' }; + private static readonly char[] FloatLiteralSpecialCharacters = ['.', 'E']; /// /// Creates a new instance with the specified parameters. diff --git a/src/ComputeSharp.SourceGeneration.Hlsl/SyntaxRewriters/ShaderSourceRewriter.cs b/src/ComputeSharp.SourceGeneration.Hlsl/SyntaxRewriters/ShaderSourceRewriter.cs index 3e41bb7f..af5faf55 100644 --- a/src/ComputeSharp.SourceGeneration.Hlsl/SyntaxRewriters/ShaderSourceRewriter.cs +++ b/src/ComputeSharp.SourceGeneration.Hlsl/SyntaxRewriters/ShaderSourceRewriter.cs @@ -87,8 +87,8 @@ internal sealed partial class ShaderSourceRewriter : HlslSourceRewriter this.shaderType = shaderType; this.staticMethods = staticMethods; this.instanceMethods = instanceMethods; - this.localFunctions = new(); - this.implicitVariables = new(); + this.localFunctions = []; + this.implicitVariables = []; this.isEntryPoint = isEntryPoint; } @@ -112,8 +112,8 @@ internal sealed partial class ShaderSourceRewriter : HlslSourceRewriter { this.staticMethods = staticMethods; this.instanceMethods = instanceMethods; - this.implicitVariables = new(); - this.localFunctions = new(); + this.implicitVariables = []; + this.localFunctions = []; } /// @@ -150,7 +150,7 @@ internal sealed partial class ShaderSourceRewriter : HlslSourceRewriter BlockSyntax implicitBlock = Block(this.implicitVariables.Select(static v => LocalDeclarationStatement(v)).ToArray()); // Add the tracked implicit declarations (at the start of the body) - updatedNode = updatedNode.WithBody(implicitBlock).AddBodyStatements(updatedNode.Body!.Statements.ToArray()); + updatedNode = updatedNode.WithBody(implicitBlock).AddBodyStatements([.. updatedNode.Body!.Statements]); } return updatedNode; @@ -184,7 +184,7 @@ internal sealed partial class ShaderSourceRewriter : HlslSourceRewriter { BlockSyntax implicitBlock = Block(this.implicitVariables.Select(static v => LocalDeclarationStatement(v)).ToArray()); - updatedNode = updatedNode.WithBody(implicitBlock).AddBodyStatements(updatedNode.Body!.Statements.ToArray()); + updatedNode = updatedNode.WithBody(implicitBlock).AddBodyStatements([.. updatedNode.Body!.Statements]); } return updatedNode; diff --git a/src/ComputeSharp.SourceGeneration.Hlsl/SyntaxRewriters/StaticFieldRewriter.cs b/src/ComputeSharp.SourceGeneration.Hlsl/SyntaxRewriters/StaticFieldRewriter.cs index 7abe4fb7..2ce06ff4 100644 --- a/src/ComputeSharp.SourceGeneration.Hlsl/SyntaxRewriters/StaticFieldRewriter.cs +++ b/src/ComputeSharp.SourceGeneration.Hlsl/SyntaxRewriters/StaticFieldRewriter.cs @@ -19,24 +19,16 @@ namespace ComputeSharp.SourceGeneration.SyntaxRewriters; /// /// A custom type that processes C# static field to convert to HLSL static fields (possibly constant). /// -internal sealed partial class StaticFieldRewriter : HlslSourceRewriter +/// The instance for the target syntax tree. +/// The set of discovered custom types. +/// The collection of discovered constant definitions. +/// The collection of produced instances. +internal sealed partial class StaticFieldRewriter( + SemanticModelProvider semanticModel, + ICollection discoveredTypes, + IDictionary constantDefinitions, + ImmutableArrayBuilder diagnostics) : HlslSourceRewriter(semanticModel, discoveredTypes, constantDefinitions, diagnostics) { - /// - /// Creates a new instance with the specified parameters. - /// - /// The instance for the target syntax tree. - /// The set of discovered custom types. - /// The collection of discovered constant definitions. - /// The collection of produced instances. - public StaticFieldRewriter( - SemanticModelProvider semanticModel, - ICollection discoveredTypes, - IDictionary constantDefinitions, - ImmutableArrayBuilder diagnostics) - : base(semanticModel, discoveredTypes, constantDefinitions, diagnostics) - { - } - /// public ExpressionSyntax? Visit(VariableDeclaratorSyntax? node) { diff --git a/src/ComputeSharp.SourceGeneration/Helpers/DynamicCache{TKey,TValue}.cs b/src/ComputeSharp.SourceGeneration/Helpers/DynamicCache{TKey,TValue}.cs index 11d2f932..f56ce3fe 100644 --- a/src/ComputeSharp.SourceGeneration/Helpers/DynamicCache{TKey,TValue}.cs +++ b/src/ComputeSharp.SourceGeneration/Helpers/DynamicCache{TKey,TValue}.cs @@ -148,17 +148,18 @@ internal sealed class DynamicCache /// /// An entry to use in . /// - private sealed class Entry + /// The key to use for the entry. + private sealed class Entry(TKey key) { /// /// A weak reference to the actual entry instance. /// - private readonly WeakReference reference; + private readonly WeakReference reference = new(key); /// /// The hashcode of the target key (so it's available even after the key is gone). /// - private readonly int hashCode; + private readonly int hashCode = EqualityComparer.Default.GetHashCode(key); /// /// The last key matched from , if available. @@ -170,16 +171,6 @@ internal sealed class DynamicCache /// private bool isPerformingLookup; - /// - /// Creates a new instance with the specified parameters. - /// - /// The key to use for the entry. - public Entry(TKey key) - { - this.reference = new WeakReference(key); - this.hashCode = EqualityComparer.Default.GetHashCode(key); - } - /// /// Gets whether or not the current entry is alive. /// @@ -265,33 +256,19 @@ internal sealed class DynamicCache /// /// An object reponsible for removing dead instance from the table. /// - private sealed class EntryRemover + /// + /// Creates a new instance with the specified parameters. + /// + /// + /// The target instance to remove from . + private sealed class EntryRemover(ConcurrentDictionary map, Entry entry) { - /// - private readonly ConcurrentDictionary map; - /// - /// The target instance to remove from . - /// - private readonly Entry entry; - - /// - /// Creates a new instance with the specified parameters. - /// - /// - /// - public EntryRemover(ConcurrentDictionary map, Entry entry) - { - this.map = map; - this.entry = entry; - } - - /// - /// Removes from when the current instance is finalized. + /// Removes the target entry from the map when the current instance is finalized. /// ~EntryRemover() { - _ = this.map.TryRemove(this.entry, out _); + _ = map.TryRemove(entry, out _); } } } diff --git a/src/ComputeSharp.SourceGeneration/Helpers/EquatableArray{T}.cs b/src/ComputeSharp.SourceGeneration/Helpers/EquatableArray{T}.cs index 6ef3d6b8..1f1088de 100644 --- a/src/ComputeSharp.SourceGeneration/Helpers/EquatableArray{T}.cs +++ b/src/ComputeSharp.SourceGeneration/Helpers/EquatableArray{T}.cs @@ -34,22 +34,14 @@ internal static class EquatableArray /// An imutable, equatable array. This is equivalent to but with value equality support. /// /// The type of values in the array. -internal readonly struct EquatableArray : IEquatable>, IEnumerable +/// The input to wrap. +internal readonly struct EquatableArray(ImmutableArray array) : IEquatable>, IEnumerable where T : IEquatable { /// /// The underlying array. /// - private readonly T[]? array; - - /// - /// Creates a new instance. - /// - /// The input to wrap. - public EquatableArray(ImmutableArray array) - { - this.array = Unsafe.As, T[]?>(ref array); - } + private readonly T[]? array = Unsafe.As, T[]?>(ref array); /// /// Gets a reference to an item at a specified position within the array. @@ -170,7 +162,7 @@ internal readonly struct EquatableArray : IEquatable>, IEnu /// The newly instantiated array. public T[] ToArray() { - return AsImmutableArray().ToArray(); + return [.. AsImmutableArray()]; } /// diff --git a/src/ComputeSharp.SourceGeneration/Helpers/ImmutableHashSetBuilder{T}.cs b/src/ComputeSharp.SourceGeneration/Helpers/ImmutableHashSetBuilder{T}.cs index fe6a92a7..21209d6e 100644 --- a/src/ComputeSharp.SourceGeneration/Helpers/ImmutableHashSetBuilder{T}.cs +++ b/src/ComputeSharp.SourceGeneration/Helpers/ImmutableHashSetBuilder{T}.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.Collections.Immutable; -using System.Linq; using System.Runtime.CompilerServices; namespace ComputeSharp.SourceGeneration.Helpers; @@ -64,7 +63,7 @@ internal struct ImmutableHashSetBuilder : IDisposable /// public readonly ImmutableArray ToImmutable() { - T[] array = this.set!.ToArray(); + T[] array = [.. this.set!]; return Unsafe.As>(ref array); } @@ -72,7 +71,7 @@ internal struct ImmutableHashSetBuilder : IDisposable /// public readonly T[] ToArray() { - return this.set!.ToArray(); + return [.. this.set!]; } /// diff --git a/src/ComputeSharp.SourceGeneration/Helpers/IndentedTextWriter.cs b/src/ComputeSharp.SourceGeneration/Helpers/IndentedTextWriter.cs index d095a16c..84498903 100644 --- a/src/ComputeSharp.SourceGeneration/Helpers/IndentedTextWriter.cs +++ b/src/ComputeSharp.SourceGeneration/Helpers/IndentedTextWriter.cs @@ -8,6 +8,8 @@ using System.Globalization; using System.Runtime.CompilerServices; using System.Text; +#pragma warning disable IDE0290 + namespace ComputeSharp.SourceGeneration.Helpers; /// @@ -351,21 +353,13 @@ internal sealed class IndentedTextWriter : IDisposable /// /// Represents an indented block that needs to be closed. /// - public struct Block : IDisposable + /// The input instance to wrap. + public struct Block(IndentedTextWriter writer) : IDisposable { /// /// The instance to write to. /// - private IndentedTextWriter? writer; - - /// - /// Creates a new instance with the specified parameters. - /// - /// The input instance to wrap. - public Block(IndentedTextWriter writer) - { - this.writer = writer; - } + private IndentedTextWriter? writer = writer; /// public void Dispose() diff --git a/src/ComputeSharp.SourceGeneration/Helpers/ObjectPool{T}.cs b/src/ComputeSharp.SourceGeneration/Helpers/ObjectPool{T}.cs index 55648e0e..43076111 100644 --- a/src/ComputeSharp.SourceGeneration/Helpers/ObjectPool{T}.cs +++ b/src/ComputeSharp.SourceGeneration/Helpers/ObjectPool{T}.cs @@ -37,19 +37,19 @@ namespace ComputeSharp.SourceGeneration.Helpers; /// /// /// The type of objects to pool. -internal sealed class ObjectPool +/// The input factory to produce items. +/// +/// The factory is stored for the lifetime of the pool. We will call this only when pool needs to +/// expand. compared to "new T()", Func gives more flexibility to implementers and faster than "new T()". +/// +/// The pool size to use. +internal sealed class ObjectPool(Func factory, int size) where T : class { - /// - /// The factory is stored for the lifetime of the pool. We will call this only when pool needs to - /// expand. compared to "new T()", Func gives more flexibility to implementers and faster than "new T()". - /// - private readonly Func factory; - /// /// The array of cached items. /// - private readonly Element[] items; + private readonly Element[] items = new Element[size - 1]; /// /// Storage for the pool objects. The first item is stored in a dedicated field @@ -66,17 +66,6 @@ internal sealed class ObjectPool { } - /// - /// Creates a new instance with the specified parameters. - /// - /// The input factory to produce items. - /// The pool size to use. - public ObjectPool(Func factory, int size) - { - this.factory = factory; - this.items = new Element[size - 1]; - } - /// /// Produces a instance. /// @@ -131,7 +120,7 @@ internal sealed class ObjectPool } } - return this.factory(); + return factory(); } /// diff --git a/src/ComputeSharp.SourceGeneration/Models/HierarchyInfo.cs b/src/ComputeSharp.SourceGeneration/Models/HierarchyInfo.cs index 5127fbcd..82c5d47f 100644 --- a/src/ComputeSharp.SourceGeneration/Models/HierarchyInfo.cs +++ b/src/ComputeSharp.SourceGeneration/Models/HierarchyInfo.cs @@ -143,7 +143,7 @@ internal sealed partial record HierarchyInfo(string FullyQualifiedMetadataName, /// A instance for the current hierarchy. public CompilationUnitSyntax GetSyntax(params MemberDeclarationSyntax[] memberDeclarations) { - return GetSyntax(memberDeclarations, Array.Empty()); + return GetSyntax(memberDeclarations, []); } /// diff --git a/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.HlslBytecode.cs b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.HlslBytecode.cs index 6883c166..6ce9b023 100644 --- a/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.HlslBytecode.cs +++ b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.HlslBytecode.cs @@ -90,14 +90,14 @@ partial class ComputeShaderDescriptorGenerator diagnostic = DiagnosticInfo.Create( EmbeddedBytecodeFailedWithWin32Exception, structDeclarationSymbol, - new object[] { structDeclarationSymbol, win32Error.HResult, win32Error.Message }); + [structDeclarationSymbol, win32Error.HResult, win32Error.Message]); } else if (info is HlslBytecodeInfo.CompilerError dxcError) { diagnostic = DiagnosticInfo.Create( EmbeddedBytecodeFailedWithDxcCompilationException, structDeclarationSymbol, - new object[] { structDeclarationSymbol, dxcError.Message }); + [structDeclarationSymbol, dxcError.Message]); } if (diagnostic is not null) diff --git a/src/ComputeSharp.SourceGenerators/Dxc/DxcCompilationException.cs b/src/ComputeSharp.SourceGenerators/Dxc/DxcCompilationException.cs index 446a975f..d514831a 100644 --- a/src/ComputeSharp.SourceGenerators/Dxc/DxcCompilationException.cs +++ b/src/ComputeSharp.SourceGenerators/Dxc/DxcCompilationException.cs @@ -1,5 +1,7 @@ using System; +#pragma warning disable IDE0290 + namespace ComputeSharp.SourceGenerators.Dxc; /// diff --git a/src/ComputeSharp.SourceGenerators/Dxc/DxcShaderCompiler.cs b/src/ComputeSharp.SourceGenerators/Dxc/DxcShaderCompiler.cs index 37636a9e..255b29a5 100644 --- a/src/ComputeSharp.SourceGenerators/Dxc/DxcShaderCompiler.cs +++ b/src/ComputeSharp.SourceGenerators/Dxc/DxcShaderCompiler.cs @@ -121,7 +121,7 @@ internal sealed unsafe class DxcShaderCompiler pEntryPoint: "Execute", pTargetProfile: "cs_6_0", pArguments: arguments.AsSpan(0, 3), - pDefines: ReadOnlySpan.Empty, + pDefines: [], pIncludeHandler: this.dxcIncludeHandler.Get(), ppResult: dxcOperationResult.GetAddressOf()); diff --git a/src/ComputeSharp.SourceGenerators/SyntaxRewriters/ExecuteMethodRewriter.cs b/src/ComputeSharp.SourceGenerators/SyntaxRewriters/ExecuteMethodRewriter.cs index 597869e4..4fdb0251 100644 --- a/src/ComputeSharp.SourceGenerators/SyntaxRewriters/ExecuteMethodRewriter.cs +++ b/src/ComputeSharp.SourceGenerators/SyntaxRewriters/ExecuteMethodRewriter.cs @@ -9,21 +9,13 @@ namespace ComputeSharp.SourceGenerators.SyntaxRewriters; /// /// A custom type that does postprocessing fixups on the shader main method. /// -internal abstract class ExecuteMethodRewriter : CSharpSyntaxRewriter +/// The instance used to process the input tree. +internal abstract class ExecuteMethodRewriter(ShaderSourceRewriter shaderSourceRewriter) : CSharpSyntaxRewriter { - /// - /// Creates a new instance with the specified parameters. - /// - /// The instance used to process the input tree. - public ExecuteMethodRewriter(ShaderSourceRewriter shaderSourceRewriter) - { - ShaderSourceRewriter = shaderSourceRewriter; - } - /// /// Gets the instance used to process the input tree. /// - protected ShaderSourceRewriter ShaderSourceRewriter { get; } + protected ShaderSourceRewriter ShaderSourceRewriter => shaderSourceRewriter; /// public TNode? Visit(TNode? node) @@ -60,17 +52,12 @@ internal abstract class ExecuteMethodRewriter : CSharpSyntaxRewriter /// /// A custom type specialized for compute shaders. /// - public sealed class Compute : ExecuteMethodRewriter + /// + /// Creates a new instance with the specified parameters. + /// + /// The instance used to process the input tree. + public sealed class Compute(ShaderSourceRewriter shaderSourceRewriter) : ExecuteMethodRewriter(shaderSourceRewriter) { - /// - /// Creates a new instance with the specified parameters. - /// - /// The instance used to process the input tree. - public Compute(ShaderSourceRewriter shaderSourceRewriter) - : base(shaderSourceRewriter) - { - } - /// public override SyntaxNode? VisitMethodDeclaration(MethodDeclarationSyntax node) { @@ -115,17 +102,9 @@ internal abstract class ExecuteMethodRewriter : CSharpSyntaxRewriter /// /// A custom type specialized for compute shaders. /// - public sealed class Pixel : ExecuteMethodRewriter + /// The instance used to process the input tree. + public sealed class Pixel(ShaderSourceRewriter shaderSourceRewriter) : ExecuteMethodRewriter(shaderSourceRewriter) { - /// - /// Creates a new instance with the specified parameters. - /// - /// The instance used to process the input tree. - public Pixel(ShaderSourceRewriter shaderSourceRewriter) - : base(shaderSourceRewriter) - { - } - /// public override SyntaxNode? VisitReturnStatement(ReturnStatementSyntax node) { diff --git a/src/ComputeSharp.Win32.D2D1/.editorconfig b/src/ComputeSharp.Win32.D2D1/.editorconfig index 3418bdfa..e66e478f 100644 --- a/src/ComputeSharp.Win32.D2D1/.editorconfig +++ b/src/ComputeSharp.Win32.D2D1/.editorconfig @@ -38,4 +38,5 @@ dotnet_diagnostic.IDE0060.severity = none dotnet_diagnostic.IDE0090.severity = none dotnet_diagnostic.IDE0160.severity = none dotnet_diagnostic.IDE0180.severity = none +dotnet_diagnostic.IDE0290.severity = none dotnet_diagnostic.IDE1006.severity = none \ No newline at end of file diff --git a/src/ComputeSharp.Win32.D3D12/.editorconfig b/src/ComputeSharp.Win32.D3D12/.editorconfig index 3418bdfa..e66e478f 100644 --- a/src/ComputeSharp.Win32.D3D12/.editorconfig +++ b/src/ComputeSharp.Win32.D3D12/.editorconfig @@ -38,4 +38,5 @@ dotnet_diagnostic.IDE0060.severity = none dotnet_diagnostic.IDE0090.severity = none dotnet_diagnostic.IDE0160.severity = none dotnet_diagnostic.IDE0180.severity = none +dotnet_diagnostic.IDE0290.severity = none dotnet_diagnostic.IDE1006.severity = none \ No newline at end of file diff --git a/src/ComputeSharp.WinUI/Extensions/SemaphoreSlimExtensions.cs b/src/ComputeSharp.WinUI/Extensions/SemaphoreSlimExtensions.cs index 33db32fd..65ba7cf9 100644 --- a/src/ComputeSharp.WinUI/Extensions/SemaphoreSlimExtensions.cs +++ b/src/ComputeSharp.WinUI/Extensions/SemaphoreSlimExtensions.cs @@ -3,7 +3,7 @@ using System.ComponentModel; using System.Threading; using System.Threading.Tasks; -#pragma warning disable CS0618 +#pragma warning disable CS0618, IDE0290 namespace ComputeSharp.WinUI.Extensions; diff --git a/src/ComputeSharp/Core/Imaging/R16.cs b/src/ComputeSharp/Core/Imaging/R16.cs index f898ab70..7c6969af 100644 --- a/src/ComputeSharp/Core/Imaging/R16.cs +++ b/src/ComputeSharp/Core/Imaging/R16.cs @@ -2,6 +2,8 @@ using System; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; +#pragma warning disable IDE0290 + namespace ComputeSharp; /// diff --git a/src/ComputeSharp/Core/Imaging/R8.cs b/src/ComputeSharp/Core/Imaging/R8.cs index c6f1c169..729e2794 100644 --- a/src/ComputeSharp/Core/Imaging/R8.cs +++ b/src/ComputeSharp/Core/Imaging/R8.cs @@ -2,6 +2,8 @@ using System; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; +#pragma warning disable IDE0290 + namespace ComputeSharp; /// diff --git a/src/ComputeSharp/Core/Imaging/Rg16.cs b/src/ComputeSharp/Core/Imaging/Rg16.cs index 19092181..7d81e5c0 100644 --- a/src/ComputeSharp/Core/Imaging/Rg16.cs +++ b/src/ComputeSharp/Core/Imaging/Rg16.cs @@ -2,6 +2,8 @@ using System; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; +#pragma warning disable IDE0290 + namespace ComputeSharp; /// diff --git a/src/ComputeSharp/Core/Imaging/Rg32.cs b/src/ComputeSharp/Core/Imaging/Rg32.cs index 45d63aee..2686c1f9 100644 --- a/src/ComputeSharp/Core/Imaging/Rg32.cs +++ b/src/ComputeSharp/Core/Imaging/Rg32.cs @@ -2,6 +2,8 @@ using System; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; +#pragma warning disable IDE0290 + namespace ComputeSharp; /// diff --git a/src/ComputeSharp/Graphics/Commands/Interop/ID3D12CommandListPool.cs b/src/ComputeSharp/Graphics/Commands/Interop/ID3D12CommandListPool.cs index 8a78d6d6..09336922 100644 --- a/src/ComputeSharp/Graphics/Commands/Interop/ID3D12CommandListPool.cs +++ b/src/ComputeSharp/Graphics/Commands/Interop/ID3D12CommandListPool.cs @@ -10,27 +10,13 @@ namespace ComputeSharp.Graphics.Commands.Interop; /// /// A type that acts as a pool to get new instances wheen needed. /// -internal readonly unsafe struct ID3D12CommandListPool : IDisposable +/// The command list type to use. +internal readonly unsafe struct ID3D12CommandListPool(D3D12_COMMAND_LIST_TYPE d3D12CommandListType) : IDisposable { - /// - /// The command list type being used by the current instance. - /// - private readonly D3D12_COMMAND_LIST_TYPE d3D12CommandListType; - /// /// The queue of items with the available command lists. /// - private readonly Queue d3D12CommandListBundleQueue; - - /// - /// Creates a new instance with the specified parameters. - /// - /// The command list type to use. - public ID3D12CommandListPool(D3D12_COMMAND_LIST_TYPE d3D12CommandListType) - { - this.d3D12CommandListType = d3D12CommandListType; - this.d3D12CommandListBundleQueue = new Queue(); - } + private readonly Queue d3D12CommandListBundleQueue = new(); /// /// Rents a and pair. @@ -107,8 +93,8 @@ internal readonly unsafe struct ID3D12CommandListPool : IDisposable [MethodImpl(MethodImplOptions.NoInlining)] private void CreateCommandListAndAllocator(ID3D12Device* d3D12Device, ID3D12PipelineState* d3D12PipelineState, out ID3D12GraphicsCommandList* d3D12CommandList, out ID3D12CommandAllocator* d3D12CommandAllocator) { - using ComPtr d3D12CommandAllocatorComPtr = d3D12Device->CreateCommandAllocator(this.d3D12CommandListType); - using ComPtr d3D12CommandListComPtr = d3D12Device->CreateCommandList(this.d3D12CommandListType, d3D12CommandAllocatorComPtr.Get(), d3D12PipelineState); + using ComPtr d3D12CommandAllocatorComPtr = d3D12Device->CreateCommandAllocator(d3D12CommandListType); + using ComPtr d3D12CommandListComPtr = d3D12Device->CreateCommandList(d3D12CommandListType, d3D12CommandAllocatorComPtr.Get(), d3D12PipelineState); fixed (ID3D12GraphicsCommandList** d3D12CommandListPtr = &d3D12CommandList) fixed (ID3D12CommandAllocator** d3D12CommandAllocatorPtr = &d3D12CommandAllocator) @@ -121,27 +107,18 @@ internal readonly unsafe struct ID3D12CommandListPool : IDisposable /// /// A type representing a bundle of a cached command list and related allocator. /// - private readonly struct D3D12CommandListBundle + /// The value to wrap. + /// The value to wrap. + private readonly struct D3D12CommandListBundle(ID3D12GraphicsCommandList* d3D12CommandList, ID3D12CommandAllocator* d3D12CommandAllocator) { /// /// The value for the current entry. /// - public readonly ID3D12GraphicsCommandList* D3D12CommandList; + public readonly ID3D12GraphicsCommandList* D3D12CommandList = d3D12CommandList; /// /// The value for the current entry. /// - public readonly ID3D12CommandAllocator* D3D12CommandAllocator; - - /// - /// Creates a new instance with the given parameters. - /// - /// The value to wrap. - /// The value to wrap. - public D3D12CommandListBundle(ID3D12GraphicsCommandList* d3D12CommandList, ID3D12CommandAllocator* d3D12CommandAllocator) - { - this.D3D12CommandList = d3D12CommandList; - this.D3D12CommandAllocator = d3D12CommandAllocator; - } + public readonly ID3D12CommandAllocator* D3D12CommandAllocator = d3D12CommandAllocator; } } \ No newline at end of file diff --git a/src/ComputeSharp/Graphics/Commands/Interop/ID3D12ResourceDescriptorHandles.cs b/src/ComputeSharp/Graphics/Commands/Interop/ID3D12ResourceDescriptorHandles.cs index dcbaa12c..3413242a 100644 --- a/src/ComputeSharp/Graphics/Commands/Interop/ID3D12ResourceDescriptorHandles.cs +++ b/src/ComputeSharp/Graphics/Commands/Interop/ID3D12ResourceDescriptorHandles.cs @@ -5,36 +5,26 @@ namespace ComputeSharp.Graphics.Commands.Interop; /// /// A type representing a bundle of reusable resource descriptor handles. /// -internal readonly struct ID3D12ResourceDescriptorHandles +/// The value to wrap. +/// The value to wrap. +/// The non shader visible value to wrap. +internal readonly struct ID3D12ResourceDescriptorHandles( + D3D12_CPU_DESCRIPTOR_HANDLE d3D12CpuDescriptorHandle, + D3D12_GPU_DESCRIPTOR_HANDLE d3D12GpuDescriptorHandle, + D3D12_CPU_DESCRIPTOR_HANDLE d3D12CpuDescriptorHandleNonShaderVisible) { /// /// The value for the current entry. /// - public readonly D3D12_CPU_DESCRIPTOR_HANDLE D3D12CpuDescriptorHandle; + public readonly D3D12_CPU_DESCRIPTOR_HANDLE D3D12CpuDescriptorHandle = d3D12CpuDescriptorHandle; /// /// The value for the current entry. /// - public readonly D3D12_GPU_DESCRIPTOR_HANDLE D3D12GpuDescriptorHandle; + public readonly D3D12_GPU_DESCRIPTOR_HANDLE D3D12GpuDescriptorHandle = d3D12GpuDescriptorHandle; /// /// The value for the current entry, non shader visible. /// - public readonly D3D12_CPU_DESCRIPTOR_HANDLE D3D12CpuDescriptorHandleNonShaderVisible; - - /// - /// Creates a new instance with the given parameters. - /// - /// The value to wrap. - /// The value to wrap. - /// The non shader visible value to wrap. - public ID3D12ResourceDescriptorHandles( - D3D12_CPU_DESCRIPTOR_HANDLE d3D12CpuDescriptorHandle, - D3D12_GPU_DESCRIPTOR_HANDLE d3D12GpuDescriptorHandle, - D3D12_CPU_DESCRIPTOR_HANDLE d3D12CpuDescriptorHandleNonShaderVisible) - { - this.D3D12CpuDescriptorHandle = d3D12CpuDescriptorHandle; - this.D3D12GpuDescriptorHandle = d3D12GpuDescriptorHandle; - this.D3D12CpuDescriptorHandleNonShaderVisible = d3D12CpuDescriptorHandleNonShaderVisible; - } + public readonly D3D12_CPU_DESCRIPTOR_HANDLE D3D12CpuDescriptorHandleNonShaderVisible = d3D12CpuDescriptorHandleNonShaderVisible; } \ No newline at end of file diff --git a/src/ComputeSharp/Graphics/GraphicsDevice.cs b/src/ComputeSharp/Graphics/GraphicsDevice.cs index 0b9c4dd4..aec8a836 100644 --- a/src/ComputeSharp/Graphics/GraphicsDevice.cs +++ b/src/ComputeSharp/Graphics/GraphicsDevice.cs @@ -170,7 +170,7 @@ public sealed unsafe partial class GraphicsDevice : IReferenceTrackedObject IsCacheCoherentUMA = d3D12Architecture1Data.CacheCoherentUMA != 0; this.deviceRemovedReason = S.S_OK; - this.cachedPipelineData = new List(); + this.cachedPipelineData = []; RegisterDeviceLostCallback(this, out this.deviceHandle, out this.deviceRemovedEvent, out this.deviceRemovedWaitHandle); } diff --git a/src/ComputeSharp/Graphics/Helpers/DeviceHelper.Enumerator.cs b/src/ComputeSharp/Graphics/Helpers/DeviceHelper.Enumerator.cs index e18a1dd0..111f519a 100644 --- a/src/ComputeSharp/Graphics/Helpers/DeviceHelper.Enumerator.cs +++ b/src/ComputeSharp/Graphics/Helpers/DeviceHelper.Enumerator.cs @@ -19,21 +19,13 @@ partial class DeviceHelper /// /// A custom query type that iterates through devices matching a given predicate. /// - public sealed unsafe class DeviceQuery : IEnumerable + /// The input predicate to select devices to create. + public sealed unsafe class DeviceQuery(Predicate? predicate) : IEnumerable { /// /// The instance to use to select devices to create. /// - private readonly Predicate? predicate; - - /// - /// Creates a new instance for the given predicate. - /// - /// The input predicate to select devices to create. - public DeviceQuery(Predicate? predicate) - { - this.predicate = predicate; - } + private readonly Predicate? predicate = predicate; /// public IEnumerator GetEnumerator() @@ -50,12 +42,13 @@ partial class DeviceHelper /// /// The enumerator type for a instance. /// - private sealed unsafe class Enumerator : ReferenceTrackedObject, IEnumerator + /// The input predicate to select devices to create. + private sealed unsafe class Enumerator(Predicate? predicate) : ReferenceTrackedObject, IEnumerator { /// /// The instance to use to select devices to create, if present. /// - private readonly Predicate? predicate; + private readonly Predicate? predicate = predicate; /// /// The instance used to enumerate devices. @@ -82,15 +75,6 @@ partial class DeviceHelper /// private GraphicsDevice? graphicsDevice; - /// - /// Creates a new instance for the given predicate. - /// - /// The input predicate to select devices to create. - public Enumerator(Predicate? predicate) - { - this.predicate = predicate; - } - /// public GraphicsDevice Current => this.graphicsDevice!; diff --git a/src/ComputeSharp/Graphics/Helpers/DeviceHelper.Factory.cs b/src/ComputeSharp/Graphics/Helpers/DeviceHelper.Factory.cs index 1bfc44d7..57e889e1 100644 --- a/src/ComputeSharp/Graphics/Helpers/DeviceHelper.Factory.cs +++ b/src/ComputeSharp/Graphics/Helpers/DeviceHelper.Factory.cs @@ -14,12 +14,12 @@ unsafe partial class DeviceHelper /// /// The local cache of instances that are currently usable. /// - internal static readonly Dictionary DevicesCache = new(); + internal static readonly Dictionary DevicesCache = []; /// /// The local map of instances for the existing devices. /// - private static readonly Dictionary> D3D12InfoQueueMap = new(); + private static readonly Dictionary> D3D12InfoQueueMap = []; /// /// The cached default instance, if any. diff --git a/src/ComputeSharp/Graphics/Interop/ReferenceTracker.cs b/src/ComputeSharp/Graphics/Interop/ReferenceTracker.cs index e3f866c6..08932093 100644 --- a/src/ComputeSharp/Graphics/Interop/ReferenceTracker.cs +++ b/src/ComputeSharp/Graphics/Interop/ReferenceTracker.cs @@ -2,9 +2,9 @@ using System; using System.Runtime.CompilerServices; using System.Threading; -namespace ComputeSharp.Interop; +#pragma warning disable CS0618, IDE0290 -#pragma warning disable CS0618 +namespace ComputeSharp.Interop; /// /// An object acting as reference tracked for a given managed object. diff --git a/src/ComputeSharp/Graphics/Interop/ResourceDescriptorRange.cs b/src/ComputeSharp/Graphics/Interop/ResourceDescriptorRange.cs index ed5dc8dc..26e706e4 100644 --- a/src/ComputeSharp/Graphics/Interop/ResourceDescriptorRange.cs +++ b/src/ComputeSharp/Graphics/Interop/ResourceDescriptorRange.cs @@ -1,5 +1,7 @@ using System.Runtime.InteropServices; +#pragma warning disable IDE0290 + namespace ComputeSharp.Interop; /// diff --git a/src/ComputeSharp/Graphics/Resources/Abstract/TransferBuffer{T}.cs b/src/ComputeSharp/Graphics/Resources/Abstract/TransferBuffer{T}.cs index 59a8e7ed..f4c4d7d3 100644 --- a/src/ComputeSharp/Graphics/Resources/Abstract/TransferBuffer{T}.cs +++ b/src/ComputeSharp/Graphics/Resources/Abstract/TransferBuffer{T}.cs @@ -10,7 +10,7 @@ using ComputeSharp.Win32; using static ComputeSharp.Win32.D3D12_FEATURE; using ResourceType = ComputeSharp.Graphics.Resources.Enums.ResourceType; -#pragma warning disable CA1063 +#pragma warning disable CA1063, CA2213 namespace ComputeSharp.Resources; @@ -147,21 +147,13 @@ public abstract unsafe partial class TransferBuffer : IReferenceTrackedObject /// /// A implementation wrapping a instance. /// - private sealed class MemoryManager : MemoryManager + /// The in use. + private sealed class MemoryManager(TransferBuffer buffer) : MemoryManager { /// /// The in use. /// - private readonly TransferBuffer buffer; - - /// - /// Creates a new instance for a given buffer. - /// - /// The in use. - public MemoryManager(TransferBuffer buffer) - { - this.buffer = buffer; - } + private readonly TransferBuffer buffer = buffer; /// public override Memory Memory diff --git a/src/ComputeSharp/Graphics/Resources/Abstract/TransferTexture1D{T}.cs b/src/ComputeSharp/Graphics/Resources/Abstract/TransferTexture1D{T}.cs index 7db61087..78e83019 100644 --- a/src/ComputeSharp/Graphics/Resources/Abstract/TransferTexture1D{T}.cs +++ b/src/ComputeSharp/Graphics/Resources/Abstract/TransferTexture1D{T}.cs @@ -9,7 +9,7 @@ using ComputeSharp.Win32; using static ComputeSharp.Win32.D3D12_FORMAT_SUPPORT1; using ResourceType = ComputeSharp.Graphics.Resources.Enums.ResourceType; -#pragma warning disable CA1063 +#pragma warning disable CA1063, CA2213 namespace ComputeSharp.Resources; @@ -152,21 +152,13 @@ public abstract unsafe partial class TransferTexture1D : IReferenceTrackedObj /// /// A implementation wrapping a instance. /// - private sealed class MemoryManager : MemoryManager + /// The in use. + private sealed class MemoryManager(TransferTexture1D buffer) : MemoryManager { /// /// The in use. /// - private readonly TransferTexture1D buffer; - - /// - /// Creates a new instance for a given buffer. - /// - /// The in use. - public MemoryManager(TransferTexture1D buffer) - { - this.buffer = buffer; - } + private readonly TransferTexture1D buffer = buffer; /// public override Memory Memory diff --git a/src/ComputeSharp/Graphics/Resources/Debug/TransferTexture1DDebugView{T}.cs b/src/ComputeSharp/Graphics/Resources/Debug/TransferTexture1DDebugView{T}.cs index c37b4d45..75252dcd 100644 --- a/src/ComputeSharp/Graphics/Resources/Debug/TransferTexture1DDebugView{T}.cs +++ b/src/ComputeSharp/Graphics/Resources/Debug/TransferTexture1DDebugView{T}.cs @@ -6,21 +6,13 @@ namespace ComputeSharp.Resources.Debug; /// A debug proxy used to display items in a instance. /// /// The type of items to display. -internal sealed class TransferTexture1DDebugView +/// The input instance with the items to display. +internal sealed class TransferTexture1DDebugView(TransferTexture1D? texture) where T : unmanaged { - /// - /// Initializes a new instance of the class with the specified parameters. - /// - /// The input instance with the items to display. - public TransferTexture1DDebugView(TransferTexture1D? texture) - { - Items = texture?.Span.ToArray(); - } - /// /// Gets the items to display for the current instance. /// [DebuggerBrowsable(DebuggerBrowsableState.Collapsed)] - public T[]? Items { get; } + public T[]? Items { get; } = texture?.Span.ToArray(); } \ No newline at end of file diff --git a/src/ComputeSharp/Graphics/Resources/Debug/TransferTexture2DDebugView{T}.cs b/src/ComputeSharp/Graphics/Resources/Debug/TransferTexture2DDebugView{T}.cs index bedecbc8..6b71754e 100644 --- a/src/ComputeSharp/Graphics/Resources/Debug/TransferTexture2DDebugView{T}.cs +++ b/src/ComputeSharp/Graphics/Resources/Debug/TransferTexture2DDebugView{T}.cs @@ -6,21 +6,13 @@ namespace ComputeSharp.Resources.Debug; /// A debug proxy used to display items in a instance. /// /// The type of items to display. -internal sealed class TransferTexture2DDebugView +/// The input instance with the items to display. +internal sealed class TransferTexture2DDebugView(TransferTexture2D? texture) where T : unmanaged { - /// - /// Initializes a new instance of the class with the specified parameters. - /// - /// The input instance with the items to display. - public TransferTexture2DDebugView(TransferTexture2D? texture) - { - Items = texture?.View.ToArray(); - } - /// /// Gets the items to display for the current instance. /// [DebuggerBrowsable(DebuggerBrowsableState.Collapsed)] - public T[,]? Items { get; } + public T[,]? Items { get; } = texture?.View.ToArray(); } \ No newline at end of file diff --git a/src/ComputeSharp/Graphics/Resources/Debug/TransferTexture3DDebugView{T}.cs b/src/ComputeSharp/Graphics/Resources/Debug/TransferTexture3DDebugView{T}.cs index 2ad6c3b5..3f0e122a 100644 --- a/src/ComputeSharp/Graphics/Resources/Debug/TransferTexture3DDebugView{T}.cs +++ b/src/ComputeSharp/Graphics/Resources/Debug/TransferTexture3DDebugView{T}.cs @@ -6,21 +6,13 @@ namespace ComputeSharp.Resources.Debug; /// A debug proxy used to display items in a instance. /// /// The type of items to display. -internal sealed class TransferTexture3DDebugView +/// The input instance with the items to display. +internal sealed class TransferTexture3DDebugView(TransferTexture3D? texture) where T : unmanaged { - /// - /// Initializes a new instance of the class with the specified parameters. - /// - /// The input instance with the items to display. - public TransferTexture3DDebugView(TransferTexture3D? texture) - { - Items = texture?.View.ToArray(); - } - /// /// Gets the items to display for the current instance. /// [DebuggerBrowsable(DebuggerBrowsableState.Collapsed)] - public T[,,]? Items { get; } + public T[,,]? Items { get; } = texture?.View.ToArray(); } \ No newline at end of file diff --git a/src/ComputeSharp/Graphics/Resources/Interop/ID3D12ResourceMap.cs b/src/ComputeSharp/Graphics/Resources/Interop/ID3D12ResourceMap.cs index afc3b8f2..b99dda56 100644 --- a/src/ComputeSharp/Graphics/Resources/Interop/ID3D12ResourceMap.cs +++ b/src/ComputeSharp/Graphics/Resources/Interop/ID3D12ResourceMap.cs @@ -8,35 +8,20 @@ namespace ComputeSharp.Graphics.Resources.Interop; /// /// A type representing a mapped memory resource. /// -internal readonly unsafe ref struct ID3D12ResourceMap +/// The input instance to map. +/// The pointer to the mapped resource. +[method: MethodImpl(MethodImplOptions.AggressiveInlining)] +internal readonly unsafe ref struct ID3D12ResourceMap(ID3D12Resource* d3D12Resource, void* pointer) { - /// - /// The target to map. - /// - private readonly ID3D12Resource* d3D12Resource; - /// /// The pointer to the mapped resource. /// - public readonly void* Pointer; - - /// - /// Creates a new instance for a given value. - /// - /// The input instance to map. - /// The pointer to the mapped resource. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ID3D12ResourceMap(ID3D12Resource* d3D12Resource, void* pointer) - { - this.d3D12Resource = d3D12Resource; - - this.Pointer = pointer; - } + public readonly void* Pointer = pointer; /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Dispose() { - this.d3D12Resource->Unmap(); + d3D12Resource->Unmap(); } } \ No newline at end of file diff --git a/src/ComputeSharp/Shaders/Loading/PipelineDataLoader{T}.cs b/src/ComputeSharp/Shaders/Loading/PipelineDataLoader{T}.cs index 72438276..ff559581 100644 --- a/src/ComputeSharp/Shaders/Loading/PipelineDataLoader{T}.cs +++ b/src/ComputeSharp/Shaders/Loading/PipelineDataLoader{T}.cs @@ -19,7 +19,7 @@ internal static unsafe class PipelineDataLoader /// /// The map of cached instances for each GPU in use. /// - private static readonly ConditionalWeakTable CachedPipelines = new(); + private static readonly ConditionalWeakTable CachedPipelines = []; /// /// Gets the instance for a given shader. diff --git a/tests/ComputeSharp.D2D1.Tests/D2D1PixelShaderEffectTests.cs b/tests/ComputeSharp.D2D1.Tests/D2D1PixelShaderEffectTests.cs index 9df99f1d..f0d927bd 100644 --- a/tests/ComputeSharp.D2D1.Tests/D2D1PixelShaderEffectTests.cs +++ b/tests/ComputeSharp.D2D1.Tests/D2D1PixelShaderEffectTests.cs @@ -69,11 +69,11 @@ public partial class D2D1PixelShaderEffectTests public unsafe void SetResourceTextureManagerForD2D1Effect_RCW_NullD2D1Effect() { D2D1ResourceTextureManager resourceTextureManager = new( - extents: stackalloc uint[] { 64 }, + extents: [64], bufferPrecision: D2D1BufferPrecision.UInt8Normalized, channelDepth: D2D1ChannelDepth.One, filter: D2D1Filter.MinLinearMagMipPoint, - extendModes: stackalloc D2D1ExtendMode[] { D2D1ExtendMode.Clamp }); + extendModes: [D2D1ExtendMode.Clamp]); D2D1PixelShaderEffect.SetResourceTextureManagerForD2D1Effect(null, resourceTextureManager, 0); } diff --git a/tests/ComputeSharp.D2D1.Tests/D2D1PixelShaderTests.cs b/tests/ComputeSharp.D2D1.Tests/D2D1PixelShaderTests.cs index 2f2a43ff..f367e736 100644 --- a/tests/ComputeSharp.D2D1.Tests/D2D1PixelShaderTests.cs +++ b/tests/ComputeSharp.D2D1.Tests/D2D1PixelShaderTests.cs @@ -629,9 +629,7 @@ namespace ComputeSharp.D2D1.Tests { ShaderWithNoCapturedValues shader = default; - byte[] buffer = Array.Empty(); - - int bytesWritten = D2D1PixelShader.GetConstantBuffer(in shader, buffer); + int bytesWritten = D2D1PixelShader.GetConstantBuffer(in shader, []); Assert.AreEqual(bytesWritten, 0); } diff --git a/tests/ComputeSharp.D2D1.Tests/D2D1ResourceTextureManagerTests.cs b/tests/ComputeSharp.D2D1.Tests/D2D1ResourceTextureManagerTests.cs index b3001bc0..44fdd57b 100644 --- a/tests/ComputeSharp.D2D1.Tests/D2D1ResourceTextureManagerTests.cs +++ b/tests/ComputeSharp.D2D1.Tests/D2D1ResourceTextureManagerTests.cs @@ -66,11 +66,11 @@ public partial class D2D1ResourceTextureManagerTests public unsafe void VerifyInterfaces_RCW() { D2D1ResourceTextureManager resourceTextureManager = new( - extents: stackalloc uint[] { 64 }, + extents: [64], bufferPrecision: D2D1BufferPrecision.UInt8Normalized, channelDepth: D2D1ChannelDepth.Four, filter: D2D1Filter.MinLinearMagMipPoint, - extendModes: stackalloc D2D1ExtendMode[] { D2D1ExtendMode.Clamp }); + extendModes: [D2D1ExtendMode.Clamp]); using ComPtr unknown = default; using ComPtr resourceTextureManager2 = default; @@ -153,13 +153,13 @@ public partial class D2D1ResourceTextureManagerTests D2D1PixelShaderEffect.RegisterForD2D1Factory1(d2D1Factory2.Get(), out _); D2D1ResourceTextureManager resourceTextureManager = new( - extents: stackalloc uint[] { 128, 128 }, + extents: [128, 128], bufferPrecision: D2D1BufferPrecision.UInt8Normalized, channelDepth: D2D1ChannelDepth.Four, filter: D2D1Filter.MinMagMipPoint, - extendModes: stackalloc[] { D2D1ExtendMode.Clamp, D2D1ExtendMode.Clamp }, - data: ReadOnlySpan.Empty, - strides: ReadOnlySpan.Empty); + extendModes: [D2D1ExtendMode.Clamp, D2D1ExtendMode.Clamp], + data: [], + strides: []); using ComPtr d2D1Effect = default; @@ -218,13 +218,13 @@ public partial class D2D1ResourceTextureManagerTests D2D1ResourceTextureManager.Initialize( resourceTextureManager: resourceTextureManager.Get(), resourceId: Guid.NewGuid(), - extents: stackalloc[] { (uint)expected.Width, (uint)expected.Height }, + extents: [(uint)expected.Width, (uint)expected.Height], bufferPrecision: D2D1BufferPrecision.UInt8Normalized, channelDepth: D2D1ChannelDepth.Four, filter: D2D1Filter.MinMagMipPoint, - extendModes: stackalloc[] { D2D1ExtendMode.Clamp, D2D1ExtendMode.Clamp }, + extendModes: [D2D1ExtendMode.Clamp, D2D1ExtendMode.Clamp], data: MemoryMarshal.AsBytes(pixels.Span), - strides: stackalloc[] { (uint)(sizeof(Rgba32) * expected.Width) }); + strides: [(uint)(sizeof(Rgba32) * expected.Width)]); using ComPtr d2D1BitmapTarget = D2D1Helper.CreateD2D1BitmapAndSetAsTarget(d2D1DeviceContext.Get(), (uint)expected.Width, (uint)expected.Height); @@ -277,13 +277,13 @@ public partial class D2D1ResourceTextureManagerTests D2D1ResourceTextureManager.Initialize( resourceTextureManager: resourceTextureManager.Get(), resourceId: Guid.NewGuid(), - extents: stackalloc[] { (uint)expected.Width, (uint)expected.Height }, + extents: [(uint)expected.Width, (uint)expected.Height], bufferPrecision: D2D1BufferPrecision.UInt8Normalized, channelDepth: D2D1ChannelDepth.Four, filter: D2D1Filter.MinMagMipPoint, - extendModes: stackalloc[] { D2D1ExtendMode.Clamp, D2D1ExtendMode.Clamp }, + extendModes: [D2D1ExtendMode.Clamp, D2D1ExtendMode.Clamp], data: MemoryMarshal.AsBytes(pixels.Span), - strides: stackalloc[] { (uint)(sizeof(Rgba32) * expected.Width) }); + strides: [(uint)(sizeof(Rgba32) * expected.Width)]); for (int i = 0; i < drawCount; i++) { @@ -334,13 +334,13 @@ public partial class D2D1ResourceTextureManagerTests D2D1ResourceTextureManager resourceTextureManager = new( resourceId: Guid.NewGuid(), - extents: stackalloc[] { (uint)expected.Width, (uint)expected.Height }, + extents: [(uint)expected.Width, (uint)expected.Height], bufferPrecision: D2D1BufferPrecision.UInt8Normalized, channelDepth: D2D1ChannelDepth.Four, filter: D2D1Filter.MinMagMipPoint, - extendModes: stackalloc[] { D2D1ExtendMode.Clamp, D2D1ExtendMode.Clamp }, + extendModes: [D2D1ExtendMode.Clamp, D2D1ExtendMode.Clamp], data: MemoryMarshal.AsBytes(pixels.Span), - strides: stackalloc[] { (uint)(sizeof(Rgba32) * expected.Width) }); + strides: [(uint)(sizeof(Rgba32) * expected.Width)]); using ComPtr unknown = default; @@ -399,24 +399,24 @@ public partial class D2D1ResourceTextureManagerTests D2D1ResourceTextureManager.Initialize( resourceTextureManager: resourceTextureManager0.Get(), resourceId: Guid.NewGuid(), - extents: stackalloc[] { (uint)expected0.Width, (uint)expected0.Height }, + extents: [(uint)expected0.Width, (uint)expected0.Height], bufferPrecision: D2D1BufferPrecision.UInt8Normalized, channelDepth: D2D1ChannelDepth.Four, filter: D2D1Filter.MinMagMipPoint, - extendModes: stackalloc[] { D2D1ExtendMode.Clamp, D2D1ExtendMode.Clamp }, + extendModes: [D2D1ExtendMode.Clamp, D2D1ExtendMode.Clamp], data: MemoryMarshal.AsBytes(pixels0.Span), - strides: stackalloc[] { (uint)(sizeof(Rgba32) * expected0.Width) }); + strides: [(uint)(sizeof(Rgba32) * expected0.Width)]); D2D1ResourceTextureManager.Initialize( resourceTextureManager: resourceTextureManager1.Get(), resourceId: Guid.NewGuid(), - extents: stackalloc[] { (uint)expected0.Width, (uint)expected0.Height }, + extents: [(uint)expected0.Width, (uint)expected0.Height], bufferPrecision: D2D1BufferPrecision.UInt8Normalized, channelDepth: D2D1ChannelDepth.Four, filter: D2D1Filter.MinMagMipPoint, - extendModes: stackalloc[] { D2D1ExtendMode.Clamp, D2D1ExtendMode.Clamp }, + extendModes: [D2D1ExtendMode.Clamp, D2D1ExtendMode.Clamp], data: MemoryMarshal.AsBytes(pixels1.Span), - strides: stackalloc[] { (uint)(sizeof(Rgba32) * expected0.Width) }); + strides: [(uint)(sizeof(Rgba32) * expected0.Width)]); using (ComPtr d2D1Effect = default) { @@ -509,13 +509,13 @@ public partial class D2D1ResourceTextureManagerTests D2D1ResourceTextureManager.Initialize( resourceTextureManager: resourceTextureManager.Get(), resourceId: Guid.NewGuid(), - extents: stackalloc[] { (uint)expected.Width, (uint)(expected.Height / 4), 4u }, + extents: [(uint)expected.Width, (uint)(expected.Height / 4), 4u], bufferPrecision: D2D1BufferPrecision.UInt8Normalized, channelDepth: D2D1ChannelDepth.Four, filter: D2D1Filter.MinMagMipPoint, - extendModes: stackalloc[] { D2D1ExtendMode.Clamp, D2D1ExtendMode.Clamp, D2D1ExtendMode.Clamp }, + extendModes: [D2D1ExtendMode.Clamp, D2D1ExtendMode.Clamp, D2D1ExtendMode.Clamp], data: MemoryMarshal.AsBytes(pixels.Span), - strides: stackalloc[] { (uint)(sizeof(Rgba32) * expected.Width), (uint)(sizeof(Rgba32) * expected.Width * (expected.Height / 4)) }); + strides: [(uint)(sizeof(Rgba32) * expected.Width), (uint)(sizeof(Rgba32) * expected.Width * (expected.Height / 4))]); using ComPtr d2D1BitmapTarget = D2D1Helper.CreateD2D1BitmapAndSetAsTarget(d2D1DeviceContext.Get(), (uint)expected.Width, (uint)expected.Height); @@ -581,11 +581,11 @@ public partial class D2D1ResourceTextureManagerTests byte[] texture = new byte[width]; D2D1ResourceTextureManager resourceTextureManager = new( - extents: stackalloc[] { (uint)width }, + extents: [(uint)width], bufferPrecision: D2D1BufferPrecision.UInt8Normalized, channelDepth: D2D1ChannelDepth.One, filter: D2D1Filter.MinMagMipPoint, - extendModes: stackalloc[] { D2D1ExtendMode.Clamp }, + extendModes: [D2D1ExtendMode.Clamp], data: texture, strides: null); @@ -594,9 +594,9 @@ public partial class D2D1ResourceTextureManagerTests RandomNumberGenerator.Create().GetBytes(data); resourceTextureManager.Update( - minimumExtents: stackalloc uint[] { (uint)startOffset }, - maximimumExtents: stackalloc uint[] { (uint)(startOffset + updateLength) }, - strides: ReadOnlySpan.Empty, + minimumExtents: [(uint)startOffset], + maximimumExtents: [(uint)(startOffset + updateLength)], + strides: [], data: data); data.CopyTo(texture.AsSpan(startOffset)); @@ -668,22 +668,22 @@ public partial class D2D1ResourceTextureManagerTests byte[] texture = new byte[width * height]; D2D1ResourceTextureManager resourceTextureManager = new( - extents: stackalloc[] { (uint)width, (uint)height }, + extents: [(uint)width, (uint)height], bufferPrecision: D2D1BufferPrecision.UInt8Normalized, channelDepth: D2D1ChannelDepth.One, filter: D2D1Filter.MinMagMipPoint, - extendModes: stackalloc[] { D2D1ExtendMode.Clamp, D2D1ExtendMode.Clamp }, + extendModes: [D2D1ExtendMode.Clamp, D2D1ExtendMode.Clamp], data: texture, - strides: stackalloc uint[] { (uint)width }); + strides: [(uint)width]); byte[] data = new byte[updateLengthX * updateLengthY]; RandomNumberGenerator.Create().GetBytes(data); resourceTextureManager.Update( - minimumExtents: stackalloc uint[] { (uint)startOffsetX, (uint)startOffsetY }, - maximimumExtents: stackalloc uint[] { (uint)(startOffsetX + updateLengthX), (uint)(startOffsetY + updateLengthY) }, - strides: stackalloc uint[] { (uint)updateLengthX }, + minimumExtents: [(uint)startOffsetX, (uint)startOffsetY], + maximimumExtents: [(uint)(startOffsetX + updateLengthX), (uint)(startOffsetY + updateLengthY)], + strides: [(uint)updateLengthX], data: data); for (int y = 0; y < updateLengthY; y++) @@ -740,13 +740,13 @@ public partial class D2D1ResourceTextureManagerTests byte[] texture = new byte[width * height]; D2D1ResourceTextureManager resourceTextureManager = new( - extents: stackalloc[] { (uint)width, (uint)height }, + extents: [(uint)width, (uint)height], bufferPrecision: D2D1BufferPrecision.UInt8Normalized, channelDepth: D2D1ChannelDepth.One, filter: D2D1Filter.MinMagMipPoint, - extendModes: stackalloc[] { D2D1ExtendMode.Clamp, D2D1ExtendMode.Clamp }, + extendModes: [D2D1ExtendMode.Clamp, D2D1ExtendMode.Clamp], data: texture, - strides: stackalloc uint[] { width }); + strides: [width]); D2D1PixelShaderEffect.SetResourceTextureManagerForD2D1Effect(d2D1Effect.Get(), resourceTextureManager, 0); @@ -755,9 +755,9 @@ public partial class D2D1ResourceTextureManagerTests // Thread As are constantly updating the resource texture void UpdateResourceTexture() { - ReadOnlySpan minimumExtents = stackalloc uint[] { 0, 0 }; - ReadOnlySpan maximumExtents = stackalloc uint[] { width, height }; - ReadOnlySpan strides = stackalloc uint[] { width }; + ReadOnlySpan minimumExtents = [0, 0]; + ReadOnlySpan maximumExtents = [width, height]; + ReadOnlySpan strides = [width]; while (!cancellationTokenSource.IsCancellationRequested) { @@ -841,22 +841,22 @@ public partial class D2D1ResourceTextureManagerTests byte[] texture = new byte[width * height * depth]; D2D1ResourceTextureManager resourceTextureManager = new( - extents: stackalloc[] { (uint)width, (uint)height, (uint)depth }, + extents: [(uint)width, (uint)height, (uint)depth], bufferPrecision: D2D1BufferPrecision.UInt8Normalized, channelDepth: D2D1ChannelDepth.One, filter: D2D1Filter.MinMagMipPoint, - extendModes: stackalloc[] { D2D1ExtendMode.Clamp, D2D1ExtendMode.Clamp, D2D1ExtendMode.Clamp }, + extendModes: [D2D1ExtendMode.Clamp, D2D1ExtendMode.Clamp, D2D1ExtendMode.Clamp], data: texture, - strides: stackalloc uint[] { (uint)width, (uint)(width * height) }); + strides: [(uint)width, (uint)(width * height)]); byte[] data = new byte[updateLengthX * updateLengthY * updateLengthZ]; RandomNumberGenerator.Create().GetBytes(data); resourceTextureManager.Update( - minimumExtents: stackalloc uint[] { (uint)startOffsetX, (uint)startOffsetY, (uint)startOffsetZ }, - maximimumExtents: stackalloc uint[] { (uint)(startOffsetX + updateLengthX), (uint)(startOffsetY + updateLengthY), (uint)(startOffsetZ + updateLengthZ) }, - strides: stackalloc uint[] { (uint)updateLengthX, (uint)(updateLengthX * updateLengthY) }, + minimumExtents: [(uint)startOffsetX, (uint)startOffsetY, (uint)startOffsetZ], + maximimumExtents: [(uint)(startOffsetX + updateLengthX), (uint)(startOffsetY + updateLengthY), (uint)(startOffsetZ + updateLengthZ)], + strides: [(uint)updateLengthX, (uint)(updateLengthX * updateLengthY)], data: data); for (int z = 0; z < updateLengthZ; z++) diff --git a/tests/ComputeSharp.D2D1.Tests/Effects/BokehBlurEffect.cs b/tests/ComputeSharp.D2D1.Tests/Effects/BokehBlurEffect.cs index 7dd4ea6e..283f6c6e 100644 --- a/tests/ComputeSharp.D2D1.Tests/Effects/BokehBlurEffect.cs +++ b/tests/ComputeSharp.D2D1.Tests/Effects/BokehBlurEffect.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Concurrent; -using System.Collections.Generic; using System.IO; using System.Numerics; using System.Runtime.CompilerServices; @@ -22,7 +21,61 @@ public sealed partial class BokehBlurEffect /// /// The mapping of initialized complex kernels and parameters, to speed up the initialization of new instances. /// - private static readonly ConcurrentDictionary<(int Radius, int ComponentsCount), (Vector4[] Parameters, float Scale, (float[] Real, float[] Imaginary)[] Kernels)> Cache = new(); + private static readonly ConcurrentDictionary<(int Radius, int ComponentsCount), (Vector4[] Parameters, float Scale, (float[] Real, float[] Imaginary)[] Kernels)> Cache = []; + + /// + /// The kernel scales to adjust the component values in each kernel. + /// + private static readonly float[] KernelScales = [1.4f, 1.2f, 1.2f, 1.2f, 1.2f, 1.2f]; + + /// + /// The available bokeh blur kernel parameters. + /// + private static readonly Vector4[][] KernelComponents = + [ + // 1 component + [new Vector4(0.862325f, 1.624835f, 0.767583f, 1.862321f)], + + // 2 components + [ + new Vector4(0.886528f, 5.268909f, 0.411259f, -0.548794f), + new Vector4(1.960518f, 1.558213f, 0.513282f, 4.56111f) + ], + + // 3 components + [ + new Vector4(2.17649f, 5.043495f, 1.621035f, -2.105439f), + new Vector4(1.019306f, 9.027613f, -0.28086f, -0.162882f), + new Vector4(2.81511f, 1.597273f, -0.366471f, 10.300301f) + ], + + // 4 components + [ + new Vector4(4.338459f, 1.553635f, -5.767909f, 46.164397f), + new Vector4(3.839993f, 4.693183f, 9.795391f, -15.227561f), + new Vector4(2.791880f, 8.178137f, -3.048324f, 0.302959f), + new Vector4(1.342190f, 12.328289f, 0.010001f, 0.244650f) + ], + + // 5 components + [ + new Vector4(4.892608f, 1.685979f, -22.356787f, 85.91246f), + new Vector4(4.71187f, 4.998496f, 35.918936f, -28.875618f), + new Vector4(4.052795f, 8.244168f, -13.212253f, -1.578428f), + new Vector4(2.929212f, 11.900859f, 0.507991f, 1.816328f), + new Vector4(1.512961f, 16.116382f, 0.138051f, -0.01f) + ], + + // 6 components + [ + new Vector4(5.143778f, 2.079813f, -82.326596f, 111.231024f), + new Vector4(5.612426f, 6.153387f, 113.878661f, 58.004879f), + new Vector4(5.982921f, 9.802895f, 39.479083f, -162.028887f), + new Vector4(6.505167f, 11.059237f, -71.286026f, 95.027069f), + new Vector4(3.869579f, 14.81052f, 1.405746f, -3.704914f), + new Vector4(2.201904f, 19.032909f, -0.152784f, -0.107988f) + ] + ]; /// /// The kernel radius. @@ -90,72 +143,13 @@ public sealed partial class BokehBlurEffect } } - /// - /// Gets the kernel scales to adjust the component values in each kernel. - /// - private static IReadOnlyList KernelScales { get; } = new[] { 1.4f, 1.2f, 1.2f, 1.2f, 1.2f, 1.2f }; - - /// - /// Gets the available bokeh blur kernel parameters. - /// - private static IReadOnlyList KernelComponents { get; } = new[] - { - // 1 component - new[] { new Vector4(0.862325f, 1.624835f, 0.767583f, 1.862321f) }, - - // 2 components - new[] - { - new Vector4(0.886528f, 5.268909f, 0.411259f, -0.548794f), - new Vector4(1.960518f, 1.558213f, 0.513282f, 4.56111f) - }, - - // 3 components - new[] - { - new Vector4(2.17649f, 5.043495f, 1.621035f, -2.105439f), - new Vector4(1.019306f, 9.027613f, -0.28086f, -0.162882f), - new Vector4(2.81511f, 1.597273f, -0.366471f, 10.300301f) - }, - - // 4 components - new[] - { - new Vector4(4.338459f, 1.553635f, -5.767909f, 46.164397f), - new Vector4(3.839993f, 4.693183f, 9.795391f, -15.227561f), - new Vector4(2.791880f, 8.178137f, -3.048324f, 0.302959f), - new Vector4(1.342190f, 12.328289f, 0.010001f, 0.244650f) - }, - - // 5 components - new[] - { - new Vector4(4.892608f, 1.685979f, -22.356787f, 85.91246f), - new Vector4(4.71187f, 4.998496f, 35.918936f, -28.875618f), - new Vector4(4.052795f, 8.244168f, -13.212253f, -1.578428f), - new Vector4(2.929212f, 11.900859f, 0.507991f, 1.816328f), - new Vector4(1.512961f, 16.116382f, 0.138051f, -0.01f) - }, - - // 6 components - new[] - { - new Vector4(5.143778f, 2.079813f, -82.326596f, 111.231024f), - new Vector4(5.612426f, 6.153387f, 113.878661f, 58.004879f), - new Vector4(5.982921f, 9.802895f, 39.479083f, -162.028887f), - new Vector4(6.505167f, 11.059237f, -71.286026f, 95.027069f), - new Vector4(3.869579f, 14.81052f, 1.405746f, -3.704914f), - new Vector4(2.201904f, 19.032909f, -0.152784f, -0.107988f) - } - }; - /// /// Gets the kernel parameters and scaling factor for the current count value in the current instance. /// private (Vector4[] Parameters, float Scale) GetParameters() { // Prepare the kernel components - int index = Math.Max(0, Math.Min(this.componentsCount - 1, KernelComponents.Count)); + int index = Math.Max(0, Math.Min(this.componentsCount - 1, KernelComponents.Length)); return (KernelComponents[index], KernelScales[index]); } @@ -383,9 +377,9 @@ public sealed partial class BokehBlurEffect bufferPrecision: D2D1BufferPrecision.Float32, channelDepth: D2D1ChannelDepth.One, filter: D2D1Filter.MinMagMipPoint, - extendModes: stackalloc[] { D2D1ExtendMode.Clamp }, + extendModes: [D2D1ExtendMode.Clamp], data: MemoryMarshal.AsBytes(this.kernels[i].Real.AsSpan()), - strides: ReadOnlySpan.Empty); + strides: []); // Also create the one for the imaginary kernel D2D1ResourceTextureManager kernelImaginary = new( @@ -393,9 +387,9 @@ public sealed partial class BokehBlurEffect bufferPrecision: D2D1BufferPrecision.Float32, channelDepth: D2D1ChannelDepth.One, filter: D2D1Filter.MinMagMipPoint, - extendModes: stackalloc[] { D2D1ExtendMode.Clamp }, + extendModes: [D2D1ExtendMode.Clamp], data: MemoryMarshal.AsBytes(this.kernels[i].Imaginary.AsSpan()), - strides: ReadOnlySpan.Empty); + strides: []); kernels[i] = (kernelReals, kernelImaginary); } diff --git a/tests/ComputeSharp.D2D1.Tests/ShadersTests.cs b/tests/ComputeSharp.D2D1.Tests/ShadersTests.cs index c171a6fb..8982bf79 100644 --- a/tests/ComputeSharp.D2D1.Tests/ShadersTests.cs +++ b/tests/ComputeSharp.D2D1.Tests/ShadersTests.cs @@ -94,13 +94,13 @@ public class ShadersTests } resourceTextureManager = new D2D1ResourceTextureManager( - extents: stackalloc uint[] { (uint)texture.Width, (uint)texture.Height }, + extents: [(uint)texture.Width, (uint)texture.Height], bufferPrecision: D2D1BufferPrecision.UInt8Normalized, channelDepth: D2D1ChannelDepth.Four, filter: D2D1Filter.MinMagMipLinear, - extendModes: stackalloc D2D1ExtendMode[] { D2D1ExtendMode.Mirror, D2D1ExtendMode.Mirror }, + extendModes: [D2D1ExtendMode.Mirror, D2D1ExtendMode.Mirror], data: MemoryMarshal.AsBytes(pixels.Span), - strides: stackalloc uint[] { (uint)(texture.Width * sizeof(Rgba32)) }); + strides: [(uint)(texture.Width * sizeof(Rgba32))]); } ContouredLayers shader = new(0f, new int2(1280, 720)); diff --git a/tests/ComputeSharp.D2D1.WinUI.Tests/Helpers/TolerantImageComparer.cs b/tests/ComputeSharp.D2D1.WinUI.Tests/Helpers/TolerantImageComparer.cs index 8017b876..c220ead5 100644 --- a/tests/ComputeSharp.D2D1.WinUI.Tests/Helpers/TolerantImageComparer.cs +++ b/tests/ComputeSharp.D2D1.WinUI.Tests/Helpers/TolerantImageComparer.cs @@ -87,31 +87,17 @@ internal static class TolerantImageComparer /// /// A simple model repressenting info about a difference between two pixels. /// - private readonly struct PixelDifference + private readonly struct PixelDifference(Point position, Color expected, Color actual) { - public PixelDifference(Point position, Color expected, Color actual) - { - this.Position = position; - this.RedDifference = actual.R - expected.R; - this.GreenDifference = actual.G - expected.G; - this.BlueDifference = actual.B - expected.B; - this.AlphaDifference = actual.A - expected.A; - } - - public readonly Point Position; - - public readonly int RedDifference; - - public readonly int GreenDifference; - - public readonly int BlueDifference; - - public readonly int AlphaDifference; + private readonly int redDifference = actual.R - expected.R; + private readonly int greenDifference = actual.G - expected.G; + private readonly int blueDifference = actual.B - expected.B; + private readonly int alphaDifference = actual.A - expected.A; /// public override string ToString() { - return $"[delta({this.RedDifference},{this.GreenDifference},{this.BlueDifference},{this.AlphaDifference}) @ ({this.Position.X},{this.Position.Y})]"; + return $"[delta({this.redDifference},{this.greenDifference},{this.blueDifference},{this.alphaDifference}) @ ({position.X},{position.Y})]"; } } } \ No newline at end of file diff --git a/tests/ComputeSharp.D2D1.WinUI.Tests/Tests/CanvasEffectTests.cs b/tests/ComputeSharp.D2D1.WinUI.Tests/Tests/CanvasEffectTests.cs index 25e1e08c..2c853e65 100644 --- a/tests/ComputeSharp.D2D1.WinUI.Tests/Tests/CanvasEffectTests.cs +++ b/tests/ComputeSharp.D2D1.WinUI.Tests/Tests/CanvasEffectTests.cs @@ -644,9 +644,9 @@ public partial class CanvasEffectTests private static readonly EffectNode EffectNode1 = new(); private static readonly EffectNode EffectNode2 = new(); private static readonly EffectNode EffectNode3 = new(); - public readonly List Effects1 = new(); - public readonly List Effects2 = new(); - public readonly List Effects3 = new(); + public readonly List Effects1 = []; + public readonly List Effects2 = []; + public readonly List Effects3 = []; public void InvalidateCreation() { diff --git a/tests/ComputeSharp.Tests.DeviceLost/DeviceLostTests.cs b/tests/ComputeSharp.Tests.DeviceLost/DeviceLostTests.cs index 5a59f3f7..6c471952 100644 --- a/tests/ComputeSharp.Tests.DeviceLost/DeviceLostTests.cs +++ b/tests/ComputeSharp.Tests.DeviceLost/DeviceLostTests.cs @@ -24,7 +24,7 @@ public class DeviceLostTests { GraphicsDeviceHelper.GetD3D12Device(graphicsDevice, in d3D12Device); - List<(object? Sender, DeviceLostEventArgs Args)> args = new(); + List<(object? Sender, DeviceLostEventArgs Args)> args = []; // Register the device lost callback graphicsDevice.DeviceLost += (s, e) => args.Add((s, e)); diff --git a/tests/ComputeSharp.Tests.Internals/Helpers/DebugDispatchDataLoader.cs b/tests/ComputeSharp.Tests.Internals/Helpers/DebugDispatchDataLoader.cs index 57d537d3..a7d0ebac 100644 --- a/tests/ComputeSharp.Tests.Internals/Helpers/DebugDispatchDataLoader.cs +++ b/tests/ComputeSharp.Tests.Internals/Helpers/DebugDispatchDataLoader.cs @@ -17,7 +17,7 @@ internal struct DebugDispatchDataLoader : IConstantBufferLoader, IGraphicsResour /// /// The list of loaded resources. /// - private readonly List<(IGraphicsResource Resource, uint Index)> graphicsResources = new(); + private readonly List<(IGraphicsResource Resource, uint Index)> graphicsResources = []; /// /// Creates a new instance. diff --git a/tests/ComputeSharp.Tests.SourceGenerators/DiagnosticsTests.cs b/tests/ComputeSharp.Tests.SourceGenerators/DiagnosticsTests.cs index 98c6bacc..da18456f 100644 --- a/tests/ComputeSharp.Tests.SourceGenerators/DiagnosticsTests.cs +++ b/tests/ComputeSharp.Tests.SourceGenerators/DiagnosticsTests.cs @@ -1,7 +1,6 @@ extern alias Core; extern alias D3D12; -using System; using System.Collections.Generic; using System.Collections.Immutable; using System.Linq; @@ -1421,19 +1420,13 @@ public class DiagnosticsTests private static void VerifyGeneratedDiagnostics(string source, params string[] diagnosticsIds) where TGenerator : class, IIncrementalGenerator, new() { - // Ensure ComputeSharp.Core and ComputeSharp are loaded - Type hlslType = typeof(Core::ComputeSharp.Hlsl); - Type computeShaderType = typeof(D3D12::ComputeSharp.IComputeShader); - - // Prepare the two additional metadata references - IEnumerable additionalReferences = new[] - { - MetadataReference.CreateFromFile(hlslType.Assembly.Location), - MetadataReference.CreateFromFile(computeShaderType.Assembly.Location) - }; - - // Get all assembly references for the loaded assemblies (easy way to pull in all necessary dependencies) - IEnumerable metadataReferences = Net80.References.All.Concat(additionalReferences); + // Get all assembly references for the .NET TFM and ComputeSharp + IEnumerable metadataReferences = + [ + .. Net80.References.All, + MetadataReference.CreateFromFile(typeof(Core::ComputeSharp.Hlsl).Assembly.Location), + MetadataReference.CreateFromFile(typeof(D3D12::ComputeSharp.IComputeShader).Assembly.Location) + ]; // Parse the source text (C# 11) SyntaxTree sourceTree = CSharpSyntaxTree.ParseText( @@ -1466,8 +1459,5 @@ public class DiagnosticsTests Assert.IsTrue(outputCompilationDiagnostics.Count == 0, $"resultingIds: {string.Join(", ", outputCompilationDiagnostics)}"); } - - GC.KeepAlive(hlslType); - GC.KeepAlive(computeShaderType); } } \ No newline at end of file diff --git a/tests/ComputeSharp.Tests/Attributes/AdditionalDataAttribute.cs b/tests/ComputeSharp.Tests/Attributes/AdditionalDataAttribute.cs index 1014107b..e8980964 100644 --- a/tests/ComputeSharp.Tests/Attributes/AdditionalDataAttribute.cs +++ b/tests/ComputeSharp.Tests/Attributes/AdditionalDataAttribute.cs @@ -5,20 +5,12 @@ namespace ComputeSharp.Tests.Attributes; /// /// An attribute to use with adding additional arbitrary input data. /// +/// The additional input data. [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] -public sealed class AdditionalDataAttribute : Attribute +public sealed class AdditionalDataAttribute(params object[] data) : Attribute { - /// - /// Creates a new instance with the specified parameters. - /// - /// The additional input data. - public AdditionalDataAttribute(params object[] data) - { - Data = data; - } - /// /// Gets the additional input data for the current attribute. /// - public object[] Data { get; } + public object[] Data { get; } = data; } \ No newline at end of file diff --git a/tests/ComputeSharp.Tests/Attributes/AdditionalResourceAttribute.cs b/tests/ComputeSharp.Tests/Attributes/AdditionalResourceAttribute.cs index 70936ae0..2340ead2 100644 --- a/tests/ComputeSharp.Tests/Attributes/AdditionalResourceAttribute.cs +++ b/tests/ComputeSharp.Tests/Attributes/AdditionalResourceAttribute.cs @@ -5,20 +5,12 @@ namespace ComputeSharp.Tests.Attributes; /// /// An attribute to use with targeting an additional specific resource type. /// +/// The additional resource type. [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] -public sealed class AdditionalResourceAttribute : Attribute +public sealed class AdditionalResourceAttribute(Type type) : Attribute { - /// - /// Creates a new instance with the specified parameters. - /// - /// The additional resource type. - public AdditionalResourceAttribute(Type type) - { - Type = type; - } - /// /// Gets the additional resource type for the current attribute. /// - public Type Type { get; } + public Type Type { get; } = type; } \ No newline at end of file diff --git a/tests/ComputeSharp.Tests/Attributes/CombinatorialTestMethodAttribute.cs b/tests/ComputeSharp.Tests/Attributes/CombinatorialTestMethodAttribute.cs index d883ea96..c401f390 100644 --- a/tests/ComputeSharp.Tests/Attributes/CombinatorialTestMethodAttribute.cs +++ b/tests/ComputeSharp.Tests/Attributes/CombinatorialTestMethodAttribute.cs @@ -29,17 +29,17 @@ public sealed class CombinatorialTestMethodAttribute : TestMethodAttribute, ITes } else if (methodInfo.GetCustomAttributes().ToArray() is { Length: > 0 } values) { - devices = values.Select(static value => value.Device).ToArray(); + devices = [.. values.Select(static value => value.Device)]; } else { - devices = Array.Empty(); + devices = []; } - Type[] resources = methodInfo.GetCustomAttributes().Select(static value => value.Type).ToArray(); - Type[] additionalResources = methodInfo.GetCustomAttributes().Select(static value => value.Type).ToArray(); - object[][] data = methodInfo.GetCustomAttributes().Select(static value => value.Data).ToArray(); - object[][] additionalData = methodInfo.GetCustomAttributes().Select(static value => value.Data).ToArray(); + Type[] resources = [.. methodInfo.GetCustomAttributes().Select(static value => value.Type)]; + Type[] additionalResources = [.. methodInfo.GetCustomAttributes().Select(static value => value.Type)]; + object[][] data = [.. methodInfo.GetCustomAttributes().Select(static value => value.Data)]; + object[][] additionalData = [.. methodInfo.GetCustomAttributes().Select(static value => value.Data)]; if (devices.Length > 0) { @@ -60,7 +60,7 @@ public sealed class CombinatorialTestMethodAttribute : TestMethodAttribute, ITes Assert.Fail("Invalid usage of [AdditionalData]"); } - yield return new object[] { device, type, additionalType }; + yield return [device, type, additionalType]; } else { @@ -70,7 +70,7 @@ public sealed class CombinatorialTestMethodAttribute : TestMethodAttribute, ITes { foreach (object[] additionalItems in additionalData) { - yield return new object[] { device, type, additionalType }.Concat(items).Concat(additionalItems).ToArray(); + yield return [device, type, additionalType, .. items, .. additionalItems]; } } } @@ -78,7 +78,7 @@ public sealed class CombinatorialTestMethodAttribute : TestMethodAttribute, ITes { foreach (object[] items in data) { - yield return new object[] { device, type, additionalType }.Concat(items).ToArray(); + yield return [device, type, additionalType, .. items]; } } } @@ -93,7 +93,7 @@ public sealed class CombinatorialTestMethodAttribute : TestMethodAttribute, ITes Assert.Fail("Invalid usage of [AdditionalData]"); } - yield return new object[] { device, type }; + yield return [device, type]; } else { @@ -103,7 +103,7 @@ public sealed class CombinatorialTestMethodAttribute : TestMethodAttribute, ITes { foreach (object[] additionalItems in additionalData) { - yield return new object[] { device, type }.Concat(items).Concat(additionalItems).ToArray(); + yield return [device, type, .. items, .. additionalItems]; } } } @@ -111,7 +111,7 @@ public sealed class CombinatorialTestMethodAttribute : TestMethodAttribute, ITes { foreach (object[] items in data) { - yield return new object[] { device, type }.Concat(items).ToArray(); + yield return [device, type, .. items]; } } } @@ -132,7 +132,7 @@ public sealed class CombinatorialTestMethodAttribute : TestMethodAttribute, ITes Assert.Fail("Invalid usage of [AdditionalData]"); } - yield return new object[] { device }; + yield return [device]; } else { @@ -142,7 +142,7 @@ public sealed class CombinatorialTestMethodAttribute : TestMethodAttribute, ITes { foreach (object[] additionalItems in additionalData) { - yield return new object[] { device }.Concat(items).Concat(additionalItems).ToArray(); + yield return [device, .. items, .. additionalItems]; } } } @@ -150,7 +150,7 @@ public sealed class CombinatorialTestMethodAttribute : TestMethodAttribute, ITes { foreach (object[] items in data) { - yield return new object[] { device }.Concat(items).ToArray(); + yield return [device, .. items]; } } } @@ -172,7 +172,7 @@ public sealed class CombinatorialTestMethodAttribute : TestMethodAttribute, ITes Assert.Fail("Invalid usage of [AdditionalData]"); } - yield return new object[] { type, additionalType }; + yield return [type, additionalType]; } else { @@ -182,7 +182,7 @@ public sealed class CombinatorialTestMethodAttribute : TestMethodAttribute, ITes { foreach (object[] additionalItems in additionalData) { - yield return new object[] { type, additionalType }.Concat(items).Concat(additionalItems).ToArray(); + yield return [type, additionalType, .. items, .. additionalItems]; } } } @@ -190,7 +190,7 @@ public sealed class CombinatorialTestMethodAttribute : TestMethodAttribute, ITes { foreach (object[] items in data) { - yield return new object[] { type, additionalType }.Concat(items).ToArray(); + yield return [type, additionalType, .. items]; } } } @@ -205,7 +205,7 @@ public sealed class CombinatorialTestMethodAttribute : TestMethodAttribute, ITes Assert.Fail("Invalid usage of [AdditionalData]"); } - yield return new object[] { type }; + yield return [type]; } else { @@ -215,7 +215,7 @@ public sealed class CombinatorialTestMethodAttribute : TestMethodAttribute, ITes { foreach (object[] additionalItems in additionalData) { - yield return new object[] { type }.Concat(items).Concat(additionalItems).ToArray(); + yield return [type, .. items, .. additionalItems]; } } } @@ -223,7 +223,7 @@ public sealed class CombinatorialTestMethodAttribute : TestMethodAttribute, ITes { foreach (object[] items in data) { - yield return new object[] { type }.Concat(items).ToArray(); + yield return [type, .. items]; } } } @@ -244,7 +244,7 @@ public sealed class CombinatorialTestMethodAttribute : TestMethodAttribute, ITes Assert.Fail("Invalid usage of [AdditionalData]"); } - yield return Array.Empty(); + yield return []; } else { @@ -254,7 +254,7 @@ public sealed class CombinatorialTestMethodAttribute : TestMethodAttribute, ITes { foreach (object[] additionalItems in additionalData) { - yield return items.Concat(additionalItems).ToArray(); + yield return [.. items, .. additionalItems]; } } } @@ -272,6 +272,6 @@ public sealed class CombinatorialTestMethodAttribute : TestMethodAttribute, ITes /// string? ITestDataSource.GetDisplayName(MethodInfo methodInfo, object?[]? data) { - return $"{methodInfo.Name} ({string.Join(", ", data ?? Array.Empty())})"; + return $"{methodInfo.Name} ({string.Join(", ", data ?? [])})"; } } \ No newline at end of file diff --git a/tests/ComputeSharp.Tests/Attributes/DataAttribute.cs b/tests/ComputeSharp.Tests/Attributes/DataAttribute.cs index c8a133b3..191e4dd4 100644 --- a/tests/ComputeSharp.Tests/Attributes/DataAttribute.cs +++ b/tests/ComputeSharp.Tests/Attributes/DataAttribute.cs @@ -5,20 +5,12 @@ namespace ComputeSharp.Tests.Attributes; /// /// An attribute to use with adding arbitrary input data. /// +/// The input data. [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] -public sealed class DataAttribute : Attribute +public sealed class DataAttribute(params object[] data) : Attribute { - /// - /// Creates a new instance with the specified parameters. - /// - /// The input data. - public DataAttribute(params object[] data) - { - Data = data; - } - /// /// Gets the input data for the current attribute. /// - public object[] Data { get; } + public object[] Data { get; } = data; } \ No newline at end of file diff --git a/tests/ComputeSharp.Tests/Attributes/DeviceAttribute.cs b/tests/ComputeSharp.Tests/Attributes/DeviceAttribute.cs index 2aad8c70..8c09c075 100644 --- a/tests/ComputeSharp.Tests/Attributes/DeviceAttribute.cs +++ b/tests/ComputeSharp.Tests/Attributes/DeviceAttribute.cs @@ -6,20 +6,12 @@ namespace ComputeSharp.Tests.Attributes; /// /// An attribute to use with adding a specific input. /// +/// The target device type to use.. [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] -public sealed class DeviceAttribute : Attribute +public sealed class DeviceAttribute(Device device) : Attribute { - /// - /// Creates a new instance with the specified parameters. - /// - /// The target device type to use.. - public DeviceAttribute(Device device) - { - Device = device; - } - /// /// Gets the target to use. /// - public Device Device { get; } + public Device Device { get; } = device; } \ No newline at end of file diff --git a/tests/ComputeSharp.Tests/Attributes/ResourceAttribute.cs b/tests/ComputeSharp.Tests/Attributes/ResourceAttribute.cs index 1498ebf9..87db2586 100644 --- a/tests/ComputeSharp.Tests/Attributes/ResourceAttribute.cs +++ b/tests/ComputeSharp.Tests/Attributes/ResourceAttribute.cs @@ -5,20 +5,12 @@ namespace ComputeSharp.Tests.Attributes; /// /// An attribute to use with targeting a specific resource type. /// +/// The resource type. [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] -public sealed class ResourceAttribute : Attribute +public sealed class ResourceAttribute(Type type) : Attribute { - /// - /// Creates a new instance with the specified parameters. - /// - /// The resource type. - public ResourceAttribute(Type type) - { - Type = type; - } - /// /// Gets the resource type for the current attribute. /// - public Type Type { get; } + public Type Type { get; } = type; } \ No newline at end of file diff --git a/tests/ComputeSharp.Tests/Helpers/TolerantImageComparer.cs b/tests/ComputeSharp.Tests/Helpers/TolerantImageComparer.cs index 904a0997..9e84f79d 100644 --- a/tests/ComputeSharp.Tests/Helpers/TolerantImageComparer.cs +++ b/tests/ComputeSharp.Tests/Helpers/TolerantImageComparer.cs @@ -117,31 +117,17 @@ internal static class TolerantImageComparer /// /// A simple model repressenting info about a difference between two pixels. /// - private readonly struct PixelDifference + private readonly struct PixelDifference(Point position, ImageSharpRgba32 expected, ImageSharpRgba32 actual) { - public PixelDifference(Point position, ImageSharpRgba32 expected, ImageSharpRgba32 actual) - { - this.Position = position; - this.RedDifference = actual.R - expected.R; - this.GreenDifference = actual.G - expected.G; - this.BlueDifference = actual.B - expected.B; - this.AlphaDifference = actual.A - expected.A; - } - - public readonly Point Position; - - public readonly int RedDifference; - - public readonly int GreenDifference; - - public readonly int BlueDifference; - - public readonly int AlphaDifference; + private readonly int redDifference = actual.R - expected.R; + private readonly int greenDifference = actual.G - expected.G; + private readonly int blueDifference = actual.B - expected.B; + private readonly int alphaDifference = actual.A - expected.A; /// public override string ToString() { - return $"[delta({this.RedDifference},{this.GreenDifference},{this.BlueDifference},{this.AlphaDifference}) @ ({this.Position.X},{this.Position.Y})]"; + return $"[delta({this.redDifference},{this.greenDifference},{this.blueDifference},{this.alphaDifference}) @ ({position.X},{position.Y})]"; } } } \ No newline at end of file diff --git a/tests/ComputeSharp.Tests/ShaderRewriterTests.cs b/tests/ComputeSharp.Tests/ShaderRewriterTests.cs index efb9bfe5..6004a1fe 100644 --- a/tests/ComputeSharp.Tests/ShaderRewriterTests.cs +++ b/tests/ComputeSharp.Tests/ShaderRewriterTests.cs @@ -95,7 +95,7 @@ public partial class ShaderRewriterTests [AllDevices] public void CustomHlslOperators(Device device) { - float[] data = { 1, 6, 7, 3, 5, 2, 8, 4 }; + float[] data = [1, 6, 7, 3, 5, 2, 8, 4]; using ReadWriteBuffer buffer = device.Get().AllocateReadWriteBuffer(data); @@ -143,7 +143,7 @@ public partial class ShaderRewriterTests [AllDevices] public void BitwiseHlslOperators(Device device) { - int[] data = { 186456131, 215486738, unchecked((int)416439712738), unchecked((int)1437124371243), 0, 0, 0, 0, 0, 0, 0, 0 }; + int[] data = [186456131, 215486738, unchecked((int)416439712738), unchecked((int)1437124371243), 0, 0, 0, 0, 0, 0, 0, 0]; using ReadWriteBuffer buffer = device.Get().AllocateReadWriteBuffer(data); @@ -217,7 +217,7 @@ public partial class ShaderRewriterTests [AllDevices] public void BooleanHlslOperators(Device device) { - int[] data = { 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + int[] data = [1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; using ReadWriteBuffer buffer = device.Get().AllocateReadWriteBuffer(data); @@ -265,8 +265,8 @@ public partial class ShaderRewriterTests [AllDevices] public void ToBooleanConversionHlslIntrinsics(Device device) { - float[] data1 = new[] { 3.14f, 0, 1.44f, 0, 0, 0.4445f }; - int[] data2 = new[] { 3, 0, 1, 0, 0, 156 }; + float[] data1 = [3.14f, 0, 1.44f, 0, 0, 0.4445f]; + int[] data2 = [3, 0, 1, 0, 0, 156]; using ReadOnlyBuffer buffer1 = device.Get().AllocateReadOnlyBuffer(data1); using ReadOnlyBuffer buffer2 = device.Get().AllocateReadOnlyBuffer(data2); @@ -340,7 +340,7 @@ public partial class ShaderRewriterTests [AllDevices] public void FromBooleanConversionHlslIntrinsics(Device device) { - int[] data = new[] { 1, 0, 1, 0, 0, 1 }; + int[] data = [1, 0, 1, 0, 0, 1]; using ReadOnlyBuffer buffer1 = device.Get().AllocateReadOnlyBuffer(data); using ReadWriteBuffer buffer2 = device.Get().AllocateReadWriteBuffer(6, AllocationMode.Clear); @@ -616,8 +616,8 @@ public partial class ShaderRewriterTests [AllDevices] public void GlslStyleMulOperators(Device device) { - float[] data1 = { 0.727829933f, 0.6413954f, 0.9373726f, 0.7044427f, 0.46349f, 0.8098116f, 0.604649544f, 0.309247822f, 0.470999569f, 0.7374923f, 0.6993038f, 0.518516064f, 0.44598946f }; - int[] data2 = { 287, 295, 953, 465, 1011, 308, 982, 186, 323, 325, 156, 454, 580 }; + float[] data1 = [0.727829933f, 0.6413954f, 0.9373726f, 0.7044427f, 0.46349f, 0.8098116f, 0.604649544f, 0.309247822f, 0.470999569f, 0.7374923f, 0.6993038f, 0.518516064f, 0.44598946f]; + int[] data2 = [287, 295, 953, 465, 1011, 308, 982, 186, 323, 325, 156, 454, 580]; using ReadOnlyBuffer buffer1 = device.Get().AllocateReadOnlyBuffer(data1); using ReadOnlyBuffer buffer2 = device.Get().AllocateReadOnlyBuffer(data2); @@ -798,8 +798,8 @@ public partial class ShaderRewriterTests [AllDevices] public void MiscHlslIntrinsics(Device device) { - float[] data1 = { 1, 2, 0.4f, 3.14f, 2.4f, 0.8f, 0, 0 }; - int[] data2 = { 111, 222, 333, 2, 4, 8, 63, 42, 77, 0, 0, 0 }; + float[] data1 = [1, 2, 0.4f, 3.14f, 2.4f, 0.8f, 0, 0]; + int[] data2 = [111, 222, 333, 2, 4, 8, 63, 42, 77, 0, 0, 0]; using ReadWriteBuffer buffer1 = device.Get().AllocateReadWriteBuffer(data1); using ReadWriteBuffer buffer2 = device.Get().AllocateReadWriteBuffer(data2); @@ -852,7 +852,7 @@ public partial class ShaderRewriterTests [AllDevices] public void ReadonlyModifierInMethods(Device device) { - int[] data = { 0 }; + int[] data = [0]; using ReadWriteBuffer buffer = device.Get().AllocateReadWriteBuffer(data);