From 55b696ffd6aa2798e4d232dce7c3d0c6dc8cd3ab Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Thu, 19 Oct 2023 23:55:33 +0200 Subject: [PATCH] Remove unnecessary ref parameters (change to in) --- .../GraphicsDeviceExtensions.Dispatching.cs | 13 +++++-------- src/ComputeSharp/Shaders/ComputeContext.cs | 14 ++++++-------- .../Shaders/Extensions/ComputeContextExtensions.cs | 12 +++++------- 3 files changed, 16 insertions(+), 23 deletions(-) diff --git a/src/ComputeSharp/Graphics/Extensions/GraphicsDeviceExtensions.Dispatching.cs b/src/ComputeSharp/Graphics/Extensions/GraphicsDeviceExtensions.Dispatching.cs index b0ebb8fd..837d4357 100644 --- a/src/ComputeSharp/Graphics/Extensions/GraphicsDeviceExtensions.Dispatching.cs +++ b/src/ComputeSharp/Graphics/Extensions/GraphicsDeviceExtensions.Dispatching.cs @@ -1,5 +1,4 @@ using System; -using System.Runtime.CompilerServices; using ComputeSharp.Descriptors; using ComputeSharp.Interop; @@ -24,7 +23,7 @@ public static partial class GraphicsDeviceExtensions using ComputeContext context = device.CreateComputeContext(); - context.Run(x, ref Unsafe.AsRef(in shader)); + context.Run(x, in shader); } /// @@ -42,7 +41,7 @@ public static partial class GraphicsDeviceExtensions using ComputeContext context = device.CreateComputeContext(); - context.Run(x, y, ref Unsafe.AsRef(in shader)); + context.Run(x, y, in shader); } /// @@ -61,7 +60,7 @@ public static partial class GraphicsDeviceExtensions using ComputeContext context = device.CreateComputeContext(); - context.Run(x, y, z, ref Unsafe.AsRef(in shader)); + context.Run(x, y, z, in shader); } /// @@ -80,9 +79,7 @@ public static partial class GraphicsDeviceExtensions using ComputeContext context = device.CreateComputeContext(); - Unsafe.SkipInit(out T shader); - - context.Run(texture, ref shader); + context.Run(texture, default(T)); } /// @@ -102,7 +99,7 @@ public static partial class GraphicsDeviceExtensions using ComputeContext context = device.CreateComputeContext(); - context.Run(texture, ref Unsafe.AsRef(in shader)); + context.Run(texture, in shader); } /// diff --git a/src/ComputeSharp/Shaders/ComputeContext.cs b/src/ComputeSharp/Shaders/ComputeContext.cs index cc50e76b..bd978e18 100644 --- a/src/ComputeSharp/Shaders/ComputeContext.cs +++ b/src/ComputeSharp/Shaders/ComputeContext.cs @@ -121,11 +121,10 @@ public struct ComputeContext : IDisposable, IAsyncDisposable /// /// The number of iterations to run on the X axis. /// The input instance representing the compute shader to run. - internal readonly unsafe void Run(int x, ref T shader) + internal readonly unsafe void Run(int x, in T shader) where T : struct, IComputeShader, IComputeShaderDescriptor { - - Run(x, 1, 1, ref shader); + Run(x, 1, 1, in shader); } /// @@ -134,11 +133,10 @@ public struct ComputeContext : IDisposable, IAsyncDisposable /// The number of iterations to run on the X axis. /// The number of iterations to run on the Y axis. /// The input instance representing the compute shader to run. - internal readonly unsafe void Run(int x, int y, ref T shader) + internal readonly unsafe void Run(int x, int y, in T shader) where T : struct, IComputeShader, IComputeShaderDescriptor { - - Run(x, y, 1, ref shader); + Run(x, y, 1, in shader); } /// @@ -149,7 +147,7 @@ public struct ComputeContext : IDisposable, IAsyncDisposable /// The number of iterations to run on the Y axis. /// The number of iterations to run on the Z axis. /// The input instance representing the compute shader to run. - internal readonly unsafe void Run(int x, int y, int z, ref T shader) + internal readonly unsafe void Run(int x, int y, int z, in T shader) where T : struct, IComputeShader, IComputeShaderDescriptor { default(InvalidOperationException).ThrowIf(this.device is null); @@ -189,7 +187,7 @@ public struct ComputeContext : IDisposable, IAsyncDisposable /// The type of pixel to work on. /// The target texture to invoke the pixel shader upon. /// The input instance representing the pixel shader to run. - internal readonly unsafe void Run(IReadWriteNormalizedTexture2D texture, ref T shader) + internal readonly unsafe void Run(IReadWriteNormalizedTexture2D texture, in T shader) where T : struct, IComputeShader, IComputeShaderDescriptor where TPixel : unmanaged { diff --git a/src/ComputeSharp/Shaders/Extensions/ComputeContextExtensions.cs b/src/ComputeSharp/Shaders/Extensions/ComputeContextExtensions.cs index 8e38f4a6..be26aeca 100644 --- a/src/ComputeSharp/Shaders/Extensions/ComputeContextExtensions.cs +++ b/src/ComputeSharp/Shaders/Extensions/ComputeContextExtensions.cs @@ -487,7 +487,7 @@ public static class ComputeContextExtensions public static void For(this in ComputeContext context, int x, in T shader) where T : struct, IComputeShader, IComputeShaderDescriptor { - context.Run(x, ref Unsafe.AsRef(in shader)); + context.Run(x, in shader); } /// @@ -501,7 +501,7 @@ public static class ComputeContextExtensions public static void For(this in ComputeContext context, int x, int y, in T shader) where T : struct, IComputeShader, IComputeShaderDescriptor { - context.Run(x, y, ref Unsafe.AsRef(in shader)); + context.Run(x, y, in shader); } /// @@ -516,7 +516,7 @@ public static class ComputeContextExtensions public static void For(this in ComputeContext context, int x, int y, int z, in T shader) where T : struct, IComputeShader, IComputeShaderDescriptor { - context.Run(x, y, z, ref Unsafe.AsRef(in shader)); + context.Run(x, y, z, in shader); } /// @@ -532,9 +532,7 @@ public static class ComputeContextExtensions { default(ArgumentNullException).ThrowIfNull(texture); - Unsafe.SkipInit(out T shader); - - context.Run(texture, ref shader); + context.Run(texture, default(T)); } /// @@ -551,7 +549,7 @@ public static class ComputeContextExtensions { default(ArgumentNullException).ThrowIfNull(texture); - context.Run(texture, ref Unsafe.AsRef(in shader)); + context.Run(texture, in shader); } ///