From 0a187f64bcb5f31958bb61f18ffa0a1b9f49456e Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 15 Feb 2025 19:11:40 -0800 Subject: [PATCH] Enable 'IDE0060' warnings, fix issues --- .globalconfig | 2 -- .../ProteanClouds.cs | 4 ++-- .../ComputeSharp.SwapChain.Shaders/ProteanClouds.cs | 4 ++-- src/ComputeSharp.Core/Intrinsics/Hlsl.cs | 2 +- src/ComputeSharp.Core/Primitives/Bool/Bool.cs | 2 ++ .../CanvasEffectPropertyGenerator.Execute.cs | 2 ++ .../PixelShaderEffect{T}.ICanvasEffect.cs | 2 +- .../PixelShaderEffect.ID2D1EffectImplMethods.cs | 2 ++ .../Helpers/ImmutableArrayBuilder{T}.cs | 10 +--------- .../Helpers/IndentedTextWriter.cs | 2 +- .../ComputeShaderDescriptorGenerator.HlslSource.cs | 3 --- ...Test_D2DPixelShaderDescriptorGenerator_Analyzers.cs | 5 +---- tests/ComputeSharp.Tests/ShaderCompilerTests.cs | 2 +- .../Shaders/Compute/ProteanClouds.cs | 4 ++-- 14 files changed, 18 insertions(+), 28 deletions(-) diff --git a/.globalconfig b/.globalconfig index 06d62109..b466f2aa 100644 --- a/.globalconfig +++ b/.globalconfig @@ -69,11 +69,9 @@ dotnet_diagnostic.CA2242.severity = warning dotnet_diagnostic.IDE0010.severity = none dotnet_diagnostic.IDE0130.severity = none -dotnet_diagnostic.IDE0060.severity = none dotnet_diagnostic.IDE1006.severity = warning dotnet_diagnostic.IDE0023.severity = none dotnet_diagnostic.IDE0024.severity = none -dotnet_diagnostic.IDE0060.severity = none dotnet_diagnostic.IDE0057.severity = none dotnet_diagnostic.IDE0046.severity = none dotnet_diagnostic.IDE0072.severity = none diff --git a/samples/ComputeSharp.SwapChain.Shaders.D2D1/ProteanClouds.cs b/samples/ComputeSharp.SwapChain.Shaders.D2D1/ProteanClouds.cs index 957435b6..b77f1b67 100644 --- a/samples/ComputeSharp.SwapChain.Shaders.D2D1/ProteanClouds.cs +++ b/samples/ComputeSharp.SwapChain.Shaders.D2D1/ProteanClouds.cs @@ -67,7 +67,7 @@ internal readonly partial struct ProteanClouds(float time, int2 dispatchSize) : return new float2(d + (cl * 0.2f) + 0.25f, cl); } - private float4 Render(float3 ro, float3 rd, float time, float prm1, float2 bsMo) + private float4 Render(float3 ro, float3 rd, float prm1, float2 bsMo) { float4 rez = 0; float t = 1.5f; @@ -162,7 +162,7 @@ internal readonly partial struct ProteanClouds(float time, int2 dispatchSize) : rd.XY = Hlsl.Mul(rd.XY, Rotate((-Disp(scaledTime + 3.5f).X * 0.2f) + bsMo.X)); float prm1 = Hlsl.SmoothStep(-0.4f, 0.4f, Hlsl.Sin(time * 0.3f)); - float4 scn = Render(ro, rd, scaledTime, prm1, bsMo); + float4 scn = Render(ro, rd, prm1, bsMo); float3 col = scn.RGB; col = ILerp(col.BGR, col.RGB, Hlsl.Clamp(1.0f - prm1, 0.05f, 1.0f)); diff --git a/samples/ComputeSharp.SwapChain.Shaders/ProteanClouds.cs b/samples/ComputeSharp.SwapChain.Shaders/ProteanClouds.cs index 2c56510d..7dd21251 100644 --- a/samples/ComputeSharp.SwapChain.Shaders/ProteanClouds.cs +++ b/samples/ComputeSharp.SwapChain.Shaders/ProteanClouds.cs @@ -62,7 +62,7 @@ internal readonly partial struct ProteanClouds(float time) : IComputeShader diff --git a/src/ComputeSharp.D2D1.UI.SourceGenerators/CanvasEffectPropertyGenerator.Execute.cs b/src/ComputeSharp.D2D1.UI.SourceGenerators/CanvasEffectPropertyGenerator.Execute.cs index 169f8e97..703023e8 100644 --- a/src/ComputeSharp.D2D1.UI.SourceGenerators/CanvasEffectPropertyGenerator.Execute.cs +++ b/src/ComputeSharp.D2D1.UI.SourceGenerators/CanvasEffectPropertyGenerator.Execute.cs @@ -59,6 +59,8 @@ partial class CanvasEffectPropertyGenerator return false; } + token.ThrowIfCancellationRequested(); + // The property must be in a type with a base type (as it must derive from CanvasEffect) return node.Parent?.IsTypeDeclarationWithOrPotentiallyWithBaseTypes() == true; } diff --git a/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ICanvasEffect.cs b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ICanvasEffect.cs index 23805744..34282d13 100644 --- a/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ICanvasEffect.cs +++ b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ICanvasEffect.cs @@ -145,7 +145,7 @@ unsafe partial class PixelShaderEffect Span> canvasEffects = sourceEffects.Length <= 16 ? stackalloc ComPtr[16] : MemoryMarshal.Cast>( - canvasEffectsAbiArray = ArrayPool.Shared.Rent(sourceEffects.Length)); + (canvasEffectsAbiArray = ArrayPool.Shared.Rent(sourceEffects.Length)).AsSpan()); // Clear the span to ensure no false positives are accidentally disposed canvasEffects.Clear(); diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.ID2D1EffectImplMethods.cs b/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.ID2D1EffectImplMethods.cs index 99309334..7b442015 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.ID2D1EffectImplMethods.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.ID2D1EffectImplMethods.cs @@ -6,6 +6,8 @@ using ComputeSharp.D2D1.Shaders.Interop.Effects.ResourceManagers; using ComputeSharp.D2D1.Shaders.Interop.Extensions; using ComputeSharp.Win32; +#pragma warning disable IDE0060 + namespace ComputeSharp.D2D1.Interop.Effects; /// diff --git a/src/ComputeSharp.SourceGeneration/Helpers/ImmutableArrayBuilder{T}.cs b/src/ComputeSharp.SourceGeneration/Helpers/ImmutableArrayBuilder{T}.cs index a5663530..b721f1a1 100644 --- a/src/ComputeSharp.SourceGeneration/Helpers/ImmutableArrayBuilder{T}.cs +++ b/src/ComputeSharp.SourceGeneration/Helpers/ImmutableArrayBuilder{T}.cs @@ -229,12 +229,6 @@ internal struct ImmutableArrayBuilder : IDisposable this.index += items.Length; } - /// - public void Clear(ReadOnlySpan items) - { - this.index = 0; - } - /// public void Insert(int index, T item) { @@ -254,9 +248,7 @@ internal struct ImmutableArrayBuilder : IDisposable this.index++; } - /// - /// Clears the items in the current writer. - /// + /// public void Clear() { if (typeof(T) != typeof(byte) && diff --git a/src/ComputeSharp.SourceGeneration/Helpers/IndentedTextWriter.cs b/src/ComputeSharp.SourceGeneration/Helpers/IndentedTextWriter.cs index 9bfdb248..86181dc9 100644 --- a/src/ComputeSharp.SourceGeneration/Helpers/IndentedTextWriter.cs +++ b/src/ComputeSharp.SourceGeneration/Helpers/IndentedTextWriter.cs @@ -8,7 +8,7 @@ using System.Globalization; using System.Runtime.CompilerServices; using System.Text; -#pragma warning disable IDE0290 +#pragma warning disable IDE0060, IDE0290 namespace ComputeSharp.SourceGeneration.Helpers; diff --git a/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.HlslSource.cs b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.HlslSource.cs index 1821dbdd..066e1835 100644 --- a/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.HlslSource.cs +++ b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.HlslSource.cs @@ -84,7 +84,6 @@ partial class ComputeShaderDescriptorGenerator token.ThrowIfCancellationRequested(); ImmutableArray sharedBuffers = GetSharedBuffers( - diagnostics, structDeclarationSymbol, discoveredTypes); @@ -323,12 +322,10 @@ partial class ComputeShaderDescriptorGenerator /// /// Gets a sequence of captured members and their mapped names. /// - /// The collection of produced instances. /// The input instance to process. /// The collection of currently discovered types. /// A sequence of captured members in . private static ImmutableArray GetSharedBuffers( - ImmutableArrayBuilder diagnostics, INamedTypeSymbol structDeclarationSymbol, ICollection types) { diff --git a/tests/ComputeSharp.D2D1.Tests.SourceGenerators/Test_D2DPixelShaderDescriptorGenerator_Analyzers.cs b/tests/ComputeSharp.D2D1.Tests.SourceGenerators/Test_D2DPixelShaderDescriptorGenerator_Analyzers.cs index 71a93b3d..cc3c4a79 100644 --- a/tests/ComputeSharp.D2D1.Tests.SourceGenerators/Test_D2DPixelShaderDescriptorGenerator_Analyzers.cs +++ b/tests/ComputeSharp.D2D1.Tests.SourceGenerators/Test_D2DPixelShaderDescriptorGenerator_Analyzers.cs @@ -1003,10 +1003,7 @@ public class Test_D2DPixelShaderDescriptorGenerator_Analyzers } [TestMethod] - [DataRow(-1)] - [DataRow(6)] - [DataRow(int.MaxValue)] - public async Task OutOfRangeInputIndex_OutOfRange_BothInputTypes_WarnsOnce(int inputIndex) + public async Task OutOfRangeInputIndex_OutOfRange_BothInputTypes_WarnsOnce() { const string source = """ using ComputeSharp.D2D1; diff --git a/tests/ComputeSharp.Tests/ShaderCompilerTests.cs b/tests/ComputeSharp.Tests/ShaderCompilerTests.cs index 9ee52faf..0301f516 100644 --- a/tests/ComputeSharp.Tests/ShaderCompilerTests.cs +++ b/tests/ComputeSharp.Tests/ShaderCompilerTests.cs @@ -5,7 +5,7 @@ using ComputeSharp.Interop; using ComputeSharp.Tests.Misc; using Microsoft.VisualStudio.TestTools.UnitTesting; -#pragma warning disable IDE0008, IDE0022, IDE0009, IDE0290 +#pragma warning disable IDE0008, IDE0022, IDE0009, IDE0060, IDE0290 namespace ComputeSharp.Tests { diff --git a/tests/ComputeSharp.Tests/Shaders/Compute/ProteanClouds.cs b/tests/ComputeSharp.Tests/Shaders/Compute/ProteanClouds.cs index 4241bad0..8494a3bd 100644 --- a/tests/ComputeSharp.Tests/Shaders/Compute/ProteanClouds.cs +++ b/tests/ComputeSharp.Tests/Shaders/Compute/ProteanClouds.cs @@ -74,7 +74,7 @@ internal readonly partial struct ProteanClouds : IComputeShader return new float2(d + cl * 0.2f + 0.25f, cl); } - private float4 Render(float3 ro, float3 rd, float time, float prm1, float2 bsMo) + private float4 Render(float3 ro, float3 rd, float prm1, float2 bsMo) { float4 rez = 0; float t = 1.5f; @@ -165,7 +165,7 @@ internal readonly partial struct ProteanClouds : IComputeShader rd.XY = Hlsl.Mul(rd.XY, Rotate(-Disp(scaledTime + 3.5f).X * 0.2f + bsMo.X)); float prm1 = Hlsl.SmoothStep(-0.4f, 0.4f, Hlsl.Sin(time * 0.3f)); - float4 scn = Render(ro, rd, scaledTime, prm1, bsMo); + float4 scn = Render(ro, rd, prm1, bsMo); float3 col = scn.RGB; col = ILerp(col.BGR, col.RGB, Hlsl.Clamp(1.0f - prm1, 0.05f, 1.0f));