diff --git a/build/Directory.Build.props b/build/Directory.Build.props index 0d227034..a3173c64 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;IDE0300;IDE0301;IDE0302 + $(NoWarn);CS8500;IDE0301;IDE0302 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/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.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.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.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.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/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.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/tests/ComputeSharp.D2D1.Tests/Effects/BokehBlurEffect.cs b/tests/ComputeSharp.D2D1.Tests/Effects/BokehBlurEffect.cs index 7dd4ea6e..58cdee32 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]); } 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);