From 016d51e16151b858ce3635d6cdbd8598648ffd5b Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 4 Dec 2023 20:41:37 +0100 Subject: [PATCH 1/2] Avoid rewriting identifiers for instance methods --- .../SyntaxRewriters/ShaderSourceRewriter.cs | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/src/ComputeSharp.SourceGeneration.Hlsl/SyntaxRewriters/ShaderSourceRewriter.cs b/src/ComputeSharp.SourceGeneration.Hlsl/SyntaxRewriters/ShaderSourceRewriter.cs index dbc9b541..26e677a6 100644 --- a/src/ComputeSharp.SourceGeneration.Hlsl/SyntaxRewriters/ShaderSourceRewriter.cs +++ b/src/ComputeSharp.SourceGeneration.Hlsl/SyntaxRewriters/ShaderSourceRewriter.cs @@ -78,7 +78,7 @@ internal sealed partial class ShaderSourceRewriter : HlslSourceRewriter /// The collection of discovered constructors for custom struct types. /// The collection of discovered constant definitions. /// The collection of produced instances. - /// The value for the current operation. + /// The value for the current operation. /// Whether or not the current instance is processing a shader entry point. public ShaderSourceRewriter( INamedTypeSymbol shaderType, @@ -112,7 +112,7 @@ internal sealed partial class ShaderSourceRewriter : HlslSourceRewriter /// The collection of discovered constructors for custom struct types. /// The collection of discovered constant definitions. /// The collection of produced instances. - /// The value for the current operation. + /// The value for the current operation. private ShaderSourceRewriter( SemanticModelProvider semanticModel, ICollection discoveredTypes, @@ -581,8 +581,6 @@ internal sealed partial class ShaderSourceRewriter : HlslSourceRewriter { DiscoveredTypes.Add(structTypeSymbol); - string methodIdentifier = method.GetFullyQualifiedMetadataName().ToHlslIdentifierName(); - // Same as for static methods, ensure the method is available in source, and process it if so if (!this.instanceMethods.ContainsKey(method)) { @@ -605,18 +603,10 @@ internal sealed partial class ShaderSourceRewriter : HlslSourceRewriter MethodDeclarationSyntax processedMethod = shaderSourceRewriter.Visit(methodNode)!.WithoutTrivia(); - this.instanceMethods.Add(method, processedMethod.WithIdentifier(Identifier(methodIdentifier))); + this.instanceMethods.Add(method, processedMethod); } - // Rewrite the expression depending on its type: - // - If it's a simple member expression, change the identifier name: eg. foo.Bar(...) => foo.NewName(...) - // - If it's an identifier name, change it directly: eg. Bar(...) => NewName(...) - return updatedNode.Expression switch - { - MemberAccessExpressionSyntax memberAccess => updatedNode.WithExpression(memberAccess.WithName(IdentifierName(methodIdentifier))), - IdentifierNameSyntax identifierName => updatedNode.WithExpression(IdentifierName(methodIdentifier)), - _ => throw new NotSupportedException($"Unsupported instance method expression type \"{updatedNode.Expression.GetType()}\".") - }; + return updatedNode; } } } From 3d1a131d23062b96f9d5da6cd2f3264be1db88be Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 4 Dec 2023 20:42:31 +0100 Subject: [PATCH 2/2] Apply IDE0001 code fixers (simplify names) --- samples/ComputeSharp.Benchmark/Blas/BlasBenchmark.cs | 2 +- .../Processors/HlslGaussianBlurProcessor.Implementation.cs | 2 +- .../Processors/HlslGaussianBlurProcessor.cs | 2 +- .../ABI.Microsoft.Graphics.Canvas/ICanvasFactoryNative.cs | 4 ++-- .../ABI.Microsoft.Graphics.Canvas/ICanvasImageInterop.cs | 2 +- src/ComputeSharp.D2D1.WinUI/Helpers/ResourceManager.cs | 2 +- .../SyntaxRewriters/StaticFieldRewriter.cs | 2 +- .../Extensions/GraphicsDeviceExtensions.Dispatching.cs | 2 +- src/ComputeSharp/Graphics/Helpers/DXGIFormatHelper.cs | 4 ++-- .../Graphics/Resources/Helpers/ResourceStateHelper.cs | 2 +- .../ComputeSharp.Tests/Extensions/GraphicsDeviceExtensions.cs | 4 ++-- 11 files changed, 14 insertions(+), 14 deletions(-) diff --git a/samples/ComputeSharp.Benchmark/Blas/BlasBenchmark.cs b/samples/ComputeSharp.Benchmark/Blas/BlasBenchmark.cs index e786756b..95ed9cbd 100644 --- a/samples/ComputeSharp.Benchmark/Blas/BlasBenchmark.cs +++ b/samples/ComputeSharp.Benchmark/Blas/BlasBenchmark.cs @@ -74,7 +74,7 @@ public class BlasBenchmark : IDisposable private ReadWriteBuffer? bufferY; /// - /// A instance to initialize the tensors. + /// A instance to initialize the tensors. /// private readonly Random random = new(); diff --git a/samples/ComputeSharp.ImageProcessing/Processors/HlslGaussianBlurProcessor.Implementation.cs b/samples/ComputeSharp.ImageProcessing/Processors/HlslGaussianBlurProcessor.Implementation.cs index 7e9c8f8b..337c4de3 100644 --- a/samples/ComputeSharp.ImageProcessing/Processors/HlslGaussianBlurProcessor.Implementation.cs +++ b/samples/ComputeSharp.ImageProcessing/Processors/HlslGaussianBlurProcessor.Implementation.cs @@ -17,7 +17,7 @@ public sealed partial class HlslGaussianBlurProcessor internal sealed partial class Implementation : ImageProcessor { /// - /// The instance in use. + /// The instance in use. /// private readonly GraphicsDevice graphicsDevice; diff --git a/samples/ComputeSharp.ImageProcessing/Processors/HlslGaussianBlurProcessor.cs b/samples/ComputeSharp.ImageProcessing/Processors/HlslGaussianBlurProcessor.cs index 3aa51825..51e4294f 100644 --- a/samples/ComputeSharp.ImageProcessing/Processors/HlslGaussianBlurProcessor.cs +++ b/samples/ComputeSharp.ImageProcessing/Processors/HlslGaussianBlurProcessor.cs @@ -61,7 +61,7 @@ public sealed partial class HlslGaussianBlurProcessor : IImageProcessor } /// - /// The instance in use. + /// The instance in use. /// private readonly GraphicsDevice graphicsDevice; diff --git a/src/ComputeSharp.D2D1.WinUI/ABI.Microsoft.Graphics.Canvas/ICanvasFactoryNative.cs b/src/ComputeSharp.D2D1.WinUI/ABI.Microsoft.Graphics.Canvas/ICanvasFactoryNative.cs index 5715bd02..1f60788a 100644 --- a/src/ComputeSharp.D2D1.WinUI/ABI.Microsoft.Graphics.Canvas/ICanvasFactoryNative.cs +++ b/src/ComputeSharp.D2D1.WinUI/ABI.Microsoft.Graphics.Canvas/ICanvasFactoryNative.cs @@ -75,7 +75,7 @@ internal unsafe struct ICanvasFactoryNative /// was not previously registered, or if was already registered. /// /// - /// The method validates at runtime that is an + /// The method validates at runtime that is an /// and that is an . Additionally, /// has to implement IWeakReferenceSource for this method to be successful. /// @@ -98,7 +98,7 @@ internal unsafe struct ICanvasFactoryNative /// resource was previously registered and could be correctly unregistered, otherwise. /// /// - /// The method validates at runtime that is an . + /// The method validates at runtime that is an . /// [MethodImpl(MethodImplOptions.AggressiveInlining)] [VtblIndex(8)] 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 86a1faed..8cefb7c3 100644 --- a/src/ComputeSharp.D2D1.WinUI/ABI.Microsoft.Graphics.Canvas/ICanvasImageInterop.cs +++ b/src/ComputeSharp.D2D1.WinUI/ABI.Microsoft.Graphics.Canvas/ICanvasImageInterop.cs @@ -56,7 +56,7 @@ internal unsafe struct ICanvasImageInterop : IComObject } /// - /// Gets an from an instance. + /// Gets an from an instance. /// /// The input canvas device (as a marshalled ). /// diff --git a/src/ComputeSharp.D2D1.WinUI/Helpers/ResourceManager.cs b/src/ComputeSharp.D2D1.WinUI/Helpers/ResourceManager.cs index 5eb32a05..a024b3e4 100644 --- a/src/ComputeSharp.D2D1.WinUI/Helpers/ResourceManager.cs +++ b/src/ComputeSharp.D2D1.WinUI/Helpers/ResourceManager.cs @@ -22,7 +22,7 @@ internal static unsafe class ResourceManager /// /// Gets or creates an instance for a native resource. /// - /// The input canvas device (as a marshalled ). + /// The input canvas device (as a marshalled ). /// The input native resource to create a wrapper for. /// The realization DPIs for /// The resulting wrapper instance. diff --git a/src/ComputeSharp.SourceGeneration.Hlsl/SyntaxRewriters/StaticFieldRewriter.cs b/src/ComputeSharp.SourceGeneration.Hlsl/SyntaxRewriters/StaticFieldRewriter.cs index 9981bf5d..2d8fddcf 100644 --- a/src/ComputeSharp.SourceGeneration.Hlsl/SyntaxRewriters/StaticFieldRewriter.cs +++ b/src/ComputeSharp.SourceGeneration.Hlsl/SyntaxRewriters/StaticFieldRewriter.cs @@ -24,7 +24,7 @@ namespace ComputeSharp.SourceGeneration.SyntaxRewriters; /// The set of discovered custom types. /// The collection of discovered constant definitions. /// The collection of produced instances. -/// The value for the current operation. +/// The value for the current operation. internal sealed partial class StaticFieldRewriter( SemanticModelProvider semanticModel, ICollection discoveredTypes, diff --git a/src/ComputeSharp/Graphics/Extensions/GraphicsDeviceExtensions.Dispatching.cs b/src/ComputeSharp/Graphics/Extensions/GraphicsDeviceExtensions.Dispatching.cs index 837d4357..23357c7c 100644 --- a/src/ComputeSharp/Graphics/Extensions/GraphicsDeviceExtensions.Dispatching.cs +++ b/src/ComputeSharp/Graphics/Extensions/GraphicsDeviceExtensions.Dispatching.cs @@ -116,7 +116,7 @@ public static partial class GraphicsDeviceExtensions /// } /// /// All dispatched shaders will be executed as soon as the context goes out of scope. - /// Asynchronous execution is also supported, through the interface: + /// Asynchronous execution is also supported, through the interface: /// /// await using (var context = device.CreateComputeContext()) /// { diff --git a/src/ComputeSharp/Graphics/Helpers/DXGIFormatHelper.cs b/src/ComputeSharp/Graphics/Helpers/DXGIFormatHelper.cs index cdda88ac..b326e8fc 100644 --- a/src/ComputeSharp/Graphics/Helpers/DXGIFormatHelper.cs +++ b/src/ComputeSharp/Graphics/Helpers/DXGIFormatHelper.cs @@ -18,7 +18,7 @@ internal static class DXGIFormatHelper /// /// The input type argument to get the corresponding for. /// The value corresponding to . - /// Thrown when the input type is not supported. + /// Thrown when the input type is not supported. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static DXGI_FORMAT GetForType() where T : unmanaged @@ -54,7 +54,7 @@ internal static class DXGIFormatHelper /// /// The input type argument to check. /// Whether or not the input type corresponds to a normalized format. - /// Thrown when the input type is not supported. + /// Thrown when the input type is not supported. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsNormalizedType() where T : unmanaged diff --git a/src/ComputeSharp/Graphics/Resources/Helpers/ResourceStateHelper.cs b/src/ComputeSharp/Graphics/Resources/Helpers/ResourceStateHelper.cs index b3fd5b4a..6c356359 100644 --- a/src/ComputeSharp/Graphics/Resources/Helpers/ResourceStateHelper.cs +++ b/src/ComputeSharp/Graphics/Resources/Helpers/ResourceStateHelper.cs @@ -14,7 +14,7 @@ internal static class ResourceStateHelper /// Gets the corresponding value for the input resource state. /// /// The value corresponding to the input resource state. - /// Thrown when the input value is not valid. + /// Thrown when the input value is not valid. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static D3D12_RESOURCE_STATES GetD3D12ResourceStates(ResourceState resourceState) { diff --git a/tests/ComputeSharp.Tests/Extensions/GraphicsDeviceExtensions.cs b/tests/ComputeSharp.Tests/Extensions/GraphicsDeviceExtensions.cs index 6f10e0dc..1fa3184d 100644 --- a/tests/ComputeSharp.Tests/Extensions/GraphicsDeviceExtensions.cs +++ b/tests/ComputeSharp.Tests/Extensions/GraphicsDeviceExtensions.cs @@ -340,8 +340,8 @@ public static class GraphicsDeviceExtensions { return type switch { - _ when type == typeof(ReadOnlyTexture3D<>) => device.AllocateReadOnlyTexture3D(data), - _ when type == typeof(ReadWriteTexture3D<>) => device.AllocateReadWriteTexture3D(data), + _ when type == typeof(ReadOnlyTexture3D<>) => device.AllocateReadOnlyTexture3D(data), + _ when type == typeof(ReadWriteTexture3D<>) => device.AllocateReadWriteTexture3D(data), _ => throw new ArgumentException($"Invalid type: {type}", nameof(type)) }; }