From 46a6b257569220378c0ca4de4ca3f181b2ba77b7 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sun, 22 Oct 2023 12:54:21 +0200 Subject: [PATCH] Use primary constructors in published projects --- build/Directory.Build.props | 2 +- .../MissingAttributeCodeFixer.cs | 19 +------ .../AutoConstructorBehaviorAttribute.cs | 2 + .../Attributes/HlslIntrinsicNameAttribute.cs | 14 +---- .../Primitives/Bool/Bool2.cs | 2 +- .../Primitives/Double/Double2.cs | 2 +- .../Primitives/Float/Float2.cs | 2 +- src/ComputeSharp.Core/Primitives/Int/Int2.cs | 2 +- .../Primitives/UInt/UInt2.cs | 2 +- .../Attributes/D2DCompileOptionsAttribute.cs | 14 +---- .../Attributes/D2DEffectAuthorAttribute.cs | 14 +---- .../Attributes/D2DEffectCategoryAttribute.cs | 14 +---- .../D2DEffectDescriptionAttribute.cs | 14 +---- .../D2DEffectDisplayNameAttribute.cs | 14 +---- .../Attributes/D2DEffectIdAttribute.cs | 14 +---- .../Attributes/D2DInputComplexAttribute.cs | 14 +---- .../Attributes/D2DInputCountAttribute.cs | 14 +---- .../D2DInputDescriptionAttribute.cs | 19 ++----- .../Attributes/D2DInputSimpleAttribute.cs | 14 +---- .../Attributes/D2DPixelOptionsAttribute.cs | 14 +---- .../D2DPixelShaderSourceAttribute.cs | 14 +---- .../D2DResourceTextureIndexAttribute.cs | 14 +---- .../Attributes/D2DShaderProfileAttribute.cs | 14 +---- .../Interop/Buffers/ArrayPoolBinaryWriter.cs | 16 ++---- .../Shaders/Interop/D2D1InputDescription.cs | 2 + .../Interop/D2D1ResourceTextureDescription.cs | 2 + .../Shaders/Interop/Helpers/Point64.cs | 33 +++-------- .../Shaders/Interop/Helpers/Rectangle64.cs | 56 +++++++------------ .../Helpers/SemanticModelProvider.cs | 22 ++------ .../SyntaxRewriters/StaticFieldRewriter.cs | 26 +++------ .../Helpers/DynamicCache{TKey,TValue}.cs | 47 ++++------------ .../Helpers/EquatableArray{T}.cs | 14 +---- .../Helpers/IndentedTextWriter.cs | 16 ++---- .../Helpers/ObjectPool{T}.cs | 29 +++------- .../Dxc/DxcCompilationException.cs | 2 + .../SyntaxRewriters/ExecuteMethodRewriter.cs | 41 ++++---------- src/ComputeSharp.Win32.D2D1/.editorconfig | 1 + src/ComputeSharp.Win32.D3D12/.editorconfig | 1 + .../Extensions/SemaphoreSlimExtensions.cs | 2 +- src/ComputeSharp/Core/Imaging/R16.cs | 2 + src/ComputeSharp/Core/Imaging/R8.cs | 2 + src/ComputeSharp/Core/Imaging/Rg16.cs | 2 + src/ComputeSharp/Core/Imaging/Rg32.cs | 2 + .../Commands/Interop/ID3D12CommandListPool.cs | 43 ++++---------- .../ID3D12ResourceDescriptorHandles.cs | 30 ++++------ .../Helpers/DeviceHelper.Enumerator.cs | 28 ++-------- .../Graphics/Interop/ReferenceTracker.cs | 4 +- .../Interop/ResourceDescriptorRange.cs | 2 + .../Resources/Abstract/TransferBuffer{T}.cs | 16 ++---- .../Abstract/TransferTexture1D{T}.cs | 16 ++---- .../Debug/TransferTexture1DDebugView{T}.cs | 14 +---- .../Debug/TransferTexture2DDebugView{T}.cs | 14 +---- .../Debug/TransferTexture3DDebugView{T}.cs | 14 +---- .../Resources/Interop/ID3D12ResourceMap.cs | 27 ++------- 54 files changed, 210 insertions(+), 564 deletions(-) diff --git a/build/Directory.Build.props b/build/Directory.Build.props index 425e9414..6ff78624 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;IDE0305;IDE0028;IDE0300;IDE0301;IDE0302 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/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..5e2cae43 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 => 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/Attributes/D2DCompileOptionsAttribute.cs b/src/ComputeSharp.D2D1/Attributes/D2DCompileOptionsAttribute.cs index fe4568a0..85d6bdd2 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 => 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..f8bf0788 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 => 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..381419fe 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 => 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..519a971b 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 => 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..788027ef 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 => 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..23fa9bcf 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 => 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..0f67dce6 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 => 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..81243509 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 => index; /// /// Gets the type of filter to apply to the input texture. /// - public D2D1Filter Filter { get; } + public D2D1Filter Filter => 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..d005eb60 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 => 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..f7e1129a 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 => 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..bd7a8c6c 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 => 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..1996f134 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 => 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..4e8cb333 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 => 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/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..cce26153 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 = new(); /// /// 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/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..7202a243 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. 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.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/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/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/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