diff --git a/src/ComputeSharp/Graphics/Extensions/GraphicsDeviceExtensions.Dispatching.cs b/src/ComputeSharp/Graphics/Extensions/GraphicsDeviceExtensions.Dispatching.cs index 25b55a2b..5bfb1ac4 100644 --- a/src/ComputeSharp/Graphics/Extensions/GraphicsDeviceExtensions.Dispatching.cs +++ b/src/ComputeSharp/Graphics/Extensions/GraphicsDeviceExtensions.Dispatching.cs @@ -1,5 +1,6 @@ using ComputeSharp.Shaders; using ComputeSharp.__Internals; +using System.Runtime.CompilerServices; #pragma warning disable CS0618 @@ -20,7 +21,7 @@ namespace ComputeSharp public static void For(this GraphicsDevice device, int x, in T shader) where T : struct, IComputeShader, IShader { - ShaderRunner.Run(device, x, 1, 1, in shader); + ShaderRunner.Run(device, x, 1, 1, ref Unsafe.AsRef(in shader)); } /// @@ -34,7 +35,7 @@ namespace ComputeSharp public static void For(this GraphicsDevice device, int x, int y, in T shader) where T : struct, IComputeShader, IShader { - ShaderRunner.Run(device, x, y, 1, in shader); + ShaderRunner.Run(device, x, y, 1, ref Unsafe.AsRef(in shader)); } /// @@ -49,7 +50,7 @@ namespace ComputeSharp public static void For(this GraphicsDevice device, int x, int y, int z, in T shader) where T : struct, IComputeShader, IShader { - ShaderRunner.Run(device, x, y, z, in shader); + ShaderRunner.Run(device, x, y, z, ref Unsafe.AsRef(in shader)); } /// @@ -67,7 +68,7 @@ namespace ComputeSharp public static void For(this GraphicsDevice device, int x, int y, int z, int threadsX, int threadsY, int threadsZ, in T shader) where T : struct, IComputeShader, IShader { - ShaderRunner.Run(device, x, y, z, threadsX, threadsY, threadsZ, in shader); + ShaderRunner.Run(device, x, y, z, threadsX, threadsY, threadsZ, ref Unsafe.AsRef(in shader)); } /// @@ -81,7 +82,7 @@ namespace ComputeSharp where T : struct, IPixelShader, IShader where TPixel : unmanaged { - ShaderRunner.Run(device, texture, default); + ShaderRunner.Run(device, texture, ref Unsafe.AsRef(default(T))); } /// @@ -96,7 +97,7 @@ namespace ComputeSharp where T : struct, IPixelShader, IShader where TPixel : unmanaged { - ShaderRunner.Run(device, texture, in shader); + ShaderRunner.Run(device, texture, ref Unsafe.AsRef(in shader)); } } } diff --git a/src/ComputeSharp/Shaders/ShaderRunner{T}.cs b/src/ComputeSharp/Shaders/ShaderRunner{T}.cs index 9fdcf83f..f545ff33 100644 --- a/src/ComputeSharp/Shaders/ShaderRunner{T}.cs +++ b/src/ComputeSharp/Shaders/ShaderRunner{T}.cs @@ -36,7 +36,7 @@ namespace ComputeSharp.Shaders /// 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. - public static unsafe void Run(GraphicsDevice device, int x, int y, int z, in T shader) + public static unsafe void Run(GraphicsDevice device, int x, int y, int z, ref T shader) { // Here we calculate the optimized [numthreads] values. Using small thread group sizes leads to the // best average performance due to better occupancy of the GPU with different shaders, using any @@ -84,7 +84,7 @@ namespace ComputeSharp.Shaders break; } - Run(device, x, y, z, threadsX, threadsY, threadsZ, in shader); + Run(device, x, y, z, threadsX, threadsY, threadsZ, ref shader); } /// @@ -106,7 +106,7 @@ namespace ComputeSharp.Shaders int threadsX, int threadsY, int threadsZ, - in T shader) + ref T shader) { device.ThrowIfDisposed(); @@ -135,7 +135,7 @@ namespace ComputeSharp.Shaders // Get or preload the shader if (!ShadersCache.TryGetValue(key, out CachedShader? shaderData)) { - LoadShader(threadsX, threadsY, threadsZ, in shader, out shaderData); + LoadShader(threadsX, threadsY, threadsZ, ref shader, out shaderData); // Cache for later use ShadersCache.Add(key, shaderData); @@ -167,7 +167,7 @@ namespace ComputeSharp.Shaders /// The to use to run the shader. /// The target texture to invoke the pixel shader upon. /// The input instance representing the pixel shader to run. - public static unsafe void Run(GraphicsDevice device, IReadWriteTexture2D texture, in T shader) + public static unsafe void Run(GraphicsDevice device, IReadWriteTexture2D texture, ref T shader) where TPixel : unmanaged { device.ThrowIfDisposed(); @@ -193,7 +193,7 @@ namespace ComputeSharp.Shaders // Get or preload the shader if (!ShadersCache.TryGetValue(key, out CachedShader? shaderData)) { - LoadShader(threadsX, threadsY, 1, in shader, out shaderData); + LoadShader(threadsX, threadsY, 1, ref shader, out shaderData); // Cache for later use ShadersCache.Add(key, shaderData); @@ -235,7 +235,7 @@ namespace ComputeSharp.Shaders /// The input instance representing the compute shader to run. /// The instance to return with the cached shader data. [MethodImpl(MethodImplOptions.NoInlining)] - private static unsafe void LoadShader(int threadsX, int threadsY, int threadsZ, in T shader, out CachedShader shaderData) + private static unsafe void LoadShader(int threadsX, int threadsY, int threadsZ, ref T shader, out CachedShader shaderData) { shader.BuildHlslString(out ArrayPoolStringBuilder builder, threadsX, threadsY, threadsZ);