From 49475dcd776cb9bea7d60a27cadc7a634b6b8363 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 27 Dec 2021 20:15:03 +0100 Subject: [PATCH] Minor bug fixes in ComputeContext extensions --- src/ComputeSharp/Shaders/ComputeContext.cs | 10 +++++----- .../Shaders/Extensions/ComputeContextExtensions.cs | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/ComputeSharp/Shaders/ComputeContext.cs b/src/ComputeSharp/Shaders/ComputeContext.cs index c228e9c0..133b34fb 100644 --- a/src/ComputeSharp/Shaders/ComputeContext.cs +++ b/src/ComputeSharp/Shaders/ComputeContext.cs @@ -129,7 +129,7 @@ public ref struct ComputeContext PipelineData pipelineData = ShaderRunner.GetPipelineData(this.device, threadsX, threadsY, threadsZ, ref shader); - ref CommandList commandList = ref GetCommandList(in this, this.device, pipelineData.D3D12PipelineState); + ref CommandList commandList = ref GetCommandList(in this, pipelineData.D3D12PipelineState); commandList.D3D12GraphicsCommandList->SetComputeRootSignature(pipelineData.D3D12RootSignature); @@ -166,7 +166,7 @@ public ref struct ComputeContext PipelineData pipelineData = ShaderRunner.GetPipelineData(this.device, threadsX, threadsY, threadsZ, ref shader); - ref CommandList commandList = ref GetCommandList(in this, this.device, pipelineData.D3D12PipelineState); + ref CommandList commandList = ref GetCommandList(in this, pipelineData.D3D12PipelineState); commandList.D3D12GraphicsCommandList->SetComputeRootSignature(pipelineData.D3D12RootSignature); @@ -183,6 +183,7 @@ public ref struct ComputeContext } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Dispose() { ThrowInvalidOperationExceptionIfDeviceIsNull(); @@ -199,11 +200,10 @@ public ref struct ComputeContext /// Gets the current instance, and initializes it as needed. /// /// The current instance. - /// The to use to run the shader. /// The input to load. /// A reference to the instance to use. [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static unsafe ref CommandList GetCommandList(in ComputeContext @this, GraphicsDevice device, ID3D12PipelineState* pipelineState) + private static unsafe ref CommandList GetCommandList(in ComputeContext @this, ID3D12PipelineState* pipelineState) { // This method has to take the context by readonly reference to allow callers to be marked as readonly. // This is needed to skip the hidden copies done by Roslyn, which would break the dispatching, as the @@ -217,7 +217,7 @@ public ref struct ComputeContext } else { - context.commandList = new CommandList(device, pipelineState); + context.commandList = new CommandList(context.device, pipelineState); } return ref context.commandList; diff --git a/src/ComputeSharp/Shaders/Extensions/ComputeContextExtensions.cs b/src/ComputeSharp/Shaders/Extensions/ComputeContextExtensions.cs index 29347582..0852b281 100644 --- a/src/ComputeSharp/Shaders/Extensions/ComputeContextExtensions.cs +++ b/src/ComputeSharp/Shaders/Extensions/ComputeContextExtensions.cs @@ -28,7 +28,7 @@ public static partial class ComputeContextExtensions /// 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. - public static void For(this ComputeContext context, int x, int y, in T shader) + public static void For(this in ComputeContext context, int x, int y, in T shader) where T : struct, IComputeShader { context.Run(x, y, 1, ref Unsafe.AsRef(in shader)); @@ -43,7 +43,7 @@ public static partial class ComputeContextExtensions /// 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 void For(this ComputeContext context, int x, int y, int z, in T shader) + public static void For(this in ComputeContext context, int x, int y, int z, in T shader) where T : struct, IComputeShader { context.Run(x, y, z, ref Unsafe.AsRef(in shader)); @@ -61,7 +61,7 @@ public static partial class ComputeContextExtensions /// The number of threads in each thread group for the Y axis. /// The number of threads in each thread group for the Z axis. /// The input instance representing the compute shader to run. - public static void For(this ComputeContext context, int x, int y, int z, int threadsX, int threadsY, int threadsZ, in T shader) + public static void For(this in ComputeContext context, int x, int y, int z, int threadsX, int threadsY, int threadsZ, in T shader) where T : struct, IComputeShader { context.Run(x, y, z, threadsX, threadsY, threadsZ, ref Unsafe.AsRef(in shader)); @@ -74,7 +74,7 @@ public static partial class ComputeContextExtensions /// The type of pixels being processed by the shader. /// The to use to run the shader. /// The target texture to apply the pixel shader to. - public static void ForEach(this ComputeContext context, IReadWriteTexture2D texture) + public static void ForEach(this in ComputeContext context, IReadWriteTexture2D texture) where T : struct, IPixelShader where TPixel : unmanaged { @@ -89,7 +89,7 @@ public static partial class ComputeContextExtensions /// The to use to run the shader. /// The target texture to apply the pixel shader to. /// The input instance representing the pixel shader to run. - public static void ForEach(this ComputeContext context, IReadWriteTexture2D texture, in T shader) + public static void ForEach(this in ComputeContext context, IReadWriteTexture2D texture, in T shader) where T : struct, IPixelShader where TPixel : unmanaged {