From 1cf3b897b82c3e283466449bce1efcafea4fa9fb Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Thu, 11 Jun 2020 17:05:22 +0200 Subject: [PATCH] Minor code refactoring --- .../ComputeSharp.ImageProcessing.csproj | 2 +- .../HlslGaussianBlurProcessor{TPixel}.cs | 1 - .../Abstract/HlslStructuredBuffer{T}.cs | 9 ++++----- .../Buffers/ConstantBuffer{T}.cs | 1 - .../Commands/CommandList.cs | 18 ++++-------------- src/ComputeSharp.Shaders/ShaderRunner{T}.cs | 1 - 6 files changed, 9 insertions(+), 23 deletions(-) diff --git a/samples/ComputeSharp.ImageProcessing/ComputeSharp.ImageProcessing.csproj b/samples/ComputeSharp.ImageProcessing/ComputeSharp.ImageProcessing.csproj index b09ecf3d..a849bebf 100644 --- a/samples/ComputeSharp.ImageProcessing/ComputeSharp.ImageProcessing.csproj +++ b/samples/ComputeSharp.ImageProcessing/ComputeSharp.ImageProcessing.csproj @@ -16,7 +16,7 @@ - + diff --git a/samples/ComputeSharp.ImageProcessing/Processors/HlslGaussianBlurProcessor{TPixel}.cs b/samples/ComputeSharp.ImageProcessing/Processors/HlslGaussianBlurProcessor{TPixel}.cs index 25df7eaa..1cd556b2 100644 --- a/samples/ComputeSharp.ImageProcessing/Processors/HlslGaussianBlurProcessor{TPixel}.cs +++ b/samples/ComputeSharp.ImageProcessing/Processors/HlslGaussianBlurProcessor{TPixel}.cs @@ -4,7 +4,6 @@ using System.Numerics; using System.Runtime.CompilerServices; using SixLabors.ImageSharp; using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing.Processors; diff --git a/src/ComputeSharp.Graphics/Buffers/Abstract/HlslStructuredBuffer{T}.cs b/src/ComputeSharp.Graphics/Buffers/Abstract/HlslStructuredBuffer{T}.cs index c5db3eb5..15e2d11e 100644 --- a/src/ComputeSharp.Graphics/Buffers/Abstract/HlslStructuredBuffer{T}.cs +++ b/src/ComputeSharp.Graphics/Buffers/Abstract/HlslStructuredBuffer{T}.cs @@ -25,10 +25,11 @@ namespace ComputeSharp.Graphics.Buffers.Abstract public override void GetData(Span span, int offset, int count) { using Buffer transferBuffer = new Buffer(GraphicsDevice, count, count * ElementSizeInBytes, BufferType.ReadBack); - using CommandList copyCommandList = new CommandList(GraphicsDevice, CommandListType.Copy); - copyCommandList.CopyBufferRegion(this, offset * ElementSizeInBytes, transferBuffer, 0, count * ElementSizeInBytes); - copyCommandList.Flush(); + using (CommandList copyCommandList = new CommandList(GraphicsDevice, CommandListType.Copy)) + { + copyCommandList.CopyBufferRegion(this, offset * ElementSizeInBytes, transferBuffer, 0, count * ElementSizeInBytes); + } using MappedResource resource = transferBuffer.MapResource(); @@ -48,7 +49,6 @@ namespace ComputeSharp.Graphics.Buffers.Abstract using CommandList copyCommandList = new CommandList(GraphicsDevice, CommandListType.Copy); copyCommandList.CopyBufferRegion(transferBuffer, 0, this, offset * ElementSizeInBytes, count * ElementSizeInBytes); - copyCommandList.Flush(); } /// @@ -60,7 +60,6 @@ namespace ComputeSharp.Graphics.Buffers.Abstract using CommandList copyCommandList = new CommandList(GraphicsDevice, CommandListType.Copy); copyCommandList.CopyBufferRegion(buffer, 0, this, 0, SizeInBytes); - copyCommandList.Flush(); } else SetDataWithCpuBuffer(buffer); } diff --git a/src/ComputeSharp.Graphics/Buffers/ConstantBuffer{T}.cs b/src/ComputeSharp.Graphics/Buffers/ConstantBuffer{T}.cs index 75cd89cc..186a3154 100644 --- a/src/ComputeSharp.Graphics/Buffers/ConstantBuffer{T}.cs +++ b/src/ComputeSharp.Graphics/Buffers/ConstantBuffer{T}.cs @@ -99,7 +99,6 @@ namespace ComputeSharp using CommandList copyCommandList = new CommandList(GraphicsDevice, CommandListType.Copy); copyCommandList.CopyBufferRegion(buffer, 0, this, 0, SizeInBytes); - copyCommandList.Flush(); } else SetDataWithCpuBuffer(buffer); } diff --git a/src/ComputeSharp.Graphics/Commands/CommandList.cs b/src/ComputeSharp.Graphics/Commands/CommandList.cs index 413af34e..6f288bce 100644 --- a/src/ComputeSharp.Graphics/Commands/CommandList.cs +++ b/src/ComputeSharp.Graphics/Commands/CommandList.cs @@ -88,23 +88,13 @@ namespace ComputeSharp.Graphics.Commands NativeCommandList.Dispatch(threadGroupCountX, threadGroupCountY, threadGroupCountZ); } - /// - /// Executes the pending operations and waits for them to be completed - /// - public void Flush() - { - Close(); - GraphicsDevice.ExecuteCommandList(this); - } - - /// - /// Closes the current native command list - /// - public void Close() => NativeCommandList.Close(); - /// public override void Dispose() { + NativeCommandList.Close(); + + GraphicsDevice.ExecuteCommandList(this); + switch (CommandListType) { case CommandListType.Direct: diff --git a/src/ComputeSharp.Shaders/ShaderRunner{T}.cs b/src/ComputeSharp.Shaders/ShaderRunner{T}.cs index 1ebb6005..eba0bbb6 100644 --- a/src/ComputeSharp.Shaders/ShaderRunner{T}.cs +++ b/src/ComputeSharp.Shaders/ShaderRunner{T}.cs @@ -125,7 +125,6 @@ namespace ComputeSharp.Shaders // Dispatch and wait for completion commandList.Dispatch(groupsX, groupsY, groupsZ); - commandList.Flush(); } } }