diff --git a/src/ComputeSharp.Shaders/ShaderRunner{T}.cs b/src/ComputeSharp.Shaders/ShaderRunner{T}.cs index 4c900713..871a27cd 100644 --- a/src/ComputeSharp.Shaders/ShaderRunner{T}.cs +++ b/src/ComputeSharp.Shaders/ShaderRunner{T}.cs @@ -69,7 +69,7 @@ namespace ComputeSharp.Shaders else if (z == 1) threadsX = threadsY = 8; else threadsX = threadsY = threadsZ = 4; - Run(device, x, y, z, threadsX, threadsY, threadsZ, shader); + Run(device, x, y, z, threadsX, threadsY, threadsZ, in shader); } /// @@ -85,12 +85,16 @@ namespace ComputeSharp.Shaders /// The input instance representing the compute shader to run. public static void Run( GraphicsDevice device, - int x, int y, int z, - int threadsX, int threadsY, int threadsZ, + int x, + int y, + int z, + int threadsX, + int threadsY, + int threadsZ, in T shader) { // Create the shader key - ShaderKey key = new(ShaderHashCodeProvider.GetHashCode(shader), threadsX, threadsY, threadsZ); + ShaderKey key = new(ShaderHashCodeProvider.GetHashCode(in shader), threadsX, threadsY, threadsZ); CachedShader shaderData; PipelineData? pipelineData; @@ -99,7 +103,7 @@ namespace ComputeSharp.Shaders // Get or preload the shader if (!ShadersCache.TryGetValue(key, out shaderData)) { - LoadShader(threadsX, threadsY, threadsZ, shader, out shaderData); + LoadShader(threadsX, threadsY, threadsZ, in shader, out shaderData); // Cache for later use ShadersCache.Add(key, shaderData); @@ -118,7 +122,7 @@ namespace ComputeSharp.Shaders commandList.SetPipelineData(pipelineData); // Extract the dispatch data for the shader invocation - using DispatchData dispatchData = shaderData.Loader.GetDispatchData(shader, x, y, z); + using DispatchData dispatchData = shaderData.Loader.GetDispatchData(in shader, x, y, z); // Load the captured buffers ReadOnlySpan resources = dispatchData.Resources; @@ -158,7 +162,7 @@ namespace ComputeSharp.Shaders private static void LoadShader(int threadsX, int threadsY, int threadsZ, in T shader, out CachedShader shaderData) { // Load the input shader - ShaderLoader shaderLoader = ShaderLoader.Load(shader); + ShaderLoader shaderLoader = ShaderLoader.Load(in shader); // Render the loaded shader string shaderSource = ShaderRenderer.Instance.Render(new ShaderInfo diff --git a/src/ComputeSharp.Shaders/Translation/ShaderHashCodeProvider.cs b/src/ComputeSharp.Shaders/Translation/ShaderHashCodeProvider.cs index bc07e89d..775db0a9 100644 --- a/src/ComputeSharp.Shaders/Translation/ShaderHashCodeProvider.cs +++ b/src/ComputeSharp.Shaders/Translation/ShaderHashCodeProvider.cs @@ -65,7 +65,7 @@ namespace ComputeSharp.Shaders.Translation Hasher? hasher = TypeInfo.Hasher; - if (hasher != null) hash = hasher(hash, shader); + if (hasher != null) hash = hasher(hash, in shader); return hash; } diff --git a/src/ComputeSharp.Shaders/Translation/ShaderLoader{T}.IL.cs b/src/ComputeSharp.Shaders/Translation/ShaderLoader{T}.IL.cs index 53b7966b..78ab2c13 100644 --- a/src/ComputeSharp.Shaders/Translation/ShaderLoader{T}.IL.cs +++ b/src/ComputeSharp.Shaders/Translation/ShaderLoader{T}.IL.cs @@ -68,7 +68,7 @@ namespace ComputeSharp.Shaders.Translation Unsafe.Add(ref Unsafe.As(ref r1), 2) = z; // Invoke the dynamic method to extract the captured data - this.dispatchDataLoader!(shader, ref r0, ref r1); + this.dispatchDataLoader!(in shader, ref r0, ref r1); return new DispatchData(resources, this.totalResourceCount, variables, this.totalVariablesByteSize); } diff --git a/src/ComputeSharp/Extensions/GraphicsDeviceExtensions.cs b/src/ComputeSharp/Extensions/GraphicsDeviceExtensions.cs index 97ddd81e..30b91186 100644 --- a/src/ComputeSharp/Extensions/GraphicsDeviceExtensions.cs +++ b/src/ComputeSharp/Extensions/GraphicsDeviceExtensions.cs @@ -18,7 +18,7 @@ namespace ComputeSharp public static void For(this GraphicsDevice device, int x, in T shader) where T : struct, IComputeShader { - ShaderRunner.Run(device, x, 1, 1, shader); + ShaderRunner.Run(device, x, 1, 1, in shader); } /// @@ -32,7 +32,7 @@ namespace ComputeSharp public static void For(this GraphicsDevice device, int x, int y, in T shader) where T : struct, IComputeShader { - ShaderRunner.Run(device, x, y, 1, shader); + ShaderRunner.Run(device, x, y, 1, in shader); } /// @@ -47,7 +47,7 @@ namespace ComputeSharp public static void For(this GraphicsDevice device, int x, int y, int z, in T shader) where T : struct, IComputeShader { - ShaderRunner.Run(device, x, y, z, shader); + ShaderRunner.Run(device, x, y, z, in shader); } /// @@ -69,7 +69,7 @@ namespace ComputeSharp in T shader) where T : struct, IComputeShader { - ShaderRunner.Run(device, x, y, z, threadsX, threadsY, threadsZ, shader); + ShaderRunner.Run(device, x, y, z, threadsX, threadsY, threadsZ, in shader); } } }