diff --git a/samples/ComputeSharp.Benchmark/Dispatching/DispatchingBenchmark.cs b/samples/ComputeSharp.Benchmark/Dispatching/DispatchingBenchmark.cs index 99f6bd4a..395624e0 100644 --- a/samples/ComputeSharp.Benchmark/Dispatching/DispatchingBenchmark.cs +++ b/samples/ComputeSharp.Benchmark/Dispatching/DispatchingBenchmark.cs @@ -74,7 +74,7 @@ public partial class DispatchingBenchmark : IDisposable using var context = GraphicsDevice.Default.CreateComputeContext(); context.For(64, new TestShader(Buffer!)); - context.FullBarrier(Buffer!); + context.Barrier(Buffer!); context.For(64, new TestShader(Buffer!)); } diff --git a/samples/ComputeSharp.ImageProcessing/Processors/HlslBokehBlurProcessor{TPixel}.cs b/samples/ComputeSharp.ImageProcessing/Processors/HlslBokehBlurProcessor{TPixel}.cs index 74efc9d5..25c159d1 100644 --- a/samples/ComputeSharp.ImageProcessing/Processors/HlslBokehBlurProcessor{TPixel}.cs +++ b/samples/ComputeSharp.ImageProcessing/Processors/HlslBokehBlurProcessor{TPixel}.cs @@ -293,8 +293,8 @@ public sealed partial class HlslBokehBlurProcessor source.Height, new(texture, reals, imaginaries, kernel)); - context.FullBarrier(reals); - context.FullBarrier(imaginaries); + context.Barrier(reals); + context.Barrier(imaginaries); context.For( source.Width, diff --git a/samples/ComputeSharp.ImageProcessing/Processors/HlslGaussianBlurProcessor{TPixel}.cs b/samples/ComputeSharp.ImageProcessing/Processors/HlslGaussianBlurProcessor{TPixel}.cs index 95fd3633..c993f9d2 100644 --- a/samples/ComputeSharp.ImageProcessing/Processors/HlslGaussianBlurProcessor{TPixel}.cs +++ b/samples/ComputeSharp.ImageProcessing/Processors/HlslGaussianBlurProcessor{TPixel}.cs @@ -108,7 +108,7 @@ public sealed partial class HlslGaussianBlurProcessor using (var context = GraphicsDevice.CreateComputeContext()) { context.For(source.Width, source.Height, new(sourceTexture, firstPassTexture, kernelBuffer)); - context.FullBarrier(firstPassTexture); + context.Barrier(firstPassTexture); context.For(source.Width, source.Height, new(firstPassTexture, sourceTexture, kernelBuffer)); } diff --git a/src/ComputeSharp/Graphics/Extensions/Interop/ID3D12GraphicsCommandListExtensions.cs b/src/ComputeSharp/Graphics/Extensions/Interop/ID3D12GraphicsCommandListExtensions.cs index d79cf59a..987fbf90 100644 --- a/src/ComputeSharp/Graphics/Extensions/Interop/ID3D12GraphicsCommandListExtensions.cs +++ b/src/ComputeSharp/Graphics/Extensions/Interop/ID3D12GraphicsCommandListExtensions.cs @@ -197,7 +197,7 @@ internal static unsafe class ID3D12GraphicsCommandListExtensions /// The to change state for. /// The starting value for the transition. /// The destnation value for the transition. - public static void TransitioneBarrier( + public static void TransitionBarrier( this ref ID3D12GraphicsCommandList d3D12GraphicsCommandList, ID3D12Resource* d3D12Resource, D3D12_RESOURCE_STATES d3D12ResourceStatesBefore, @@ -220,36 +220,6 @@ internal static unsafe class ID3D12GraphicsCommandListExtensions d3D12GraphicsCommandList.ResourceBarrier(1, &d3D12ResourceBarrier); } - /// - /// Starts a UAV resource barrier for a specific resource. - /// - /// The instance in use. - /// The to start the barrier for. - public static void StartUAVBarrier(this ref ID3D12GraphicsCommandList d3D12GraphicsCommandList, ID3D12Resource* d3D12Resource) - { - D3D12_RESOURCE_BARRIER d3D12ResourceBarrier = default; - d3D12ResourceBarrier.Type = D3D12_RESOURCE_BARRIER_TYPE_UAV; - d3D12ResourceBarrier.Flags = D3D12_RESOURCE_BARRIER_FLAG_BEGIN_ONLY; - d3D12ResourceBarrier.Anonymous.UAV.pResource = d3D12Resource; - - d3D12GraphicsCommandList.ResourceBarrier(1, &d3D12ResourceBarrier); - } - - /// - /// Ends a UAV resource barrier for a specific resource. - /// - /// The instance in use. - /// The to end the barrier for. - public static void EndUAVBarrier(this ref ID3D12GraphicsCommandList d3D12GraphicsCommandList, ID3D12Resource* d3D12Resource) - { - D3D12_RESOURCE_BARRIER d3D12ResourceBarrier = default; - d3D12ResourceBarrier.Type = D3D12_RESOURCE_BARRIER_TYPE_UAV; - d3D12ResourceBarrier.Flags = D3D12_RESOURCE_BARRIER_FLAG_END_ONLY; - d3D12ResourceBarrier.Anonymous.UAV.pResource = d3D12Resource; - - d3D12GraphicsCommandList.ResourceBarrier(1, &d3D12ResourceBarrier); - } - /// /// Binds an input constant buffer to the first root parameter. /// diff --git a/src/ComputeSharp/Graphics/Resources/Abstract/Texture2D{T}.cs b/src/ComputeSharp/Graphics/Resources/Abstract/Texture2D{T}.cs index a0d0e834..edd0a980 100644 --- a/src/ComputeSharp/Graphics/Resources/Abstract/Texture2D{T}.cs +++ b/src/ComputeSharp/Graphics/Resources/Abstract/Texture2D{T}.cs @@ -207,7 +207,7 @@ public unsafe abstract class Texture2D : NativeObject, GraphicsResourceHelper { if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE) { - copyCommandList.D3D12GraphicsCommandList->TransitioneBarrier(D3D12Resource, this.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_SOURCE); + copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(D3D12Resource, this.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_SOURCE); } copyCommandList.D3D12GraphicsCommandList->CopyTextureRegion( @@ -226,7 +226,7 @@ public unsafe abstract class Texture2D : NativeObject, GraphicsResourceHelper if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE) { - copyCommandList.D3D12GraphicsCommandList->TransitioneBarrier(D3D12Resource, D3D12_RESOURCE_STATE_COPY_SOURCE, this.d3D12ResourceState); + copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(D3D12Resource, D3D12_RESOURCE_STATE_COPY_SOURCE, this.d3D12ResourceState); } copyCommandList.ExecuteAndWaitForCompletion(); @@ -287,8 +287,8 @@ public unsafe abstract class Texture2D : NativeObject, GraphicsResourceHelper if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE) { - copyCommandList.D3D12GraphicsCommandList->TransitioneBarrier(D3D12Resource, this.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_SOURCE); - copyCommandList.D3D12GraphicsCommandList->TransitioneBarrier(destination.D3D12Resource, destination.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_DEST); + copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(D3D12Resource, this.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_SOURCE); + copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(destination.D3D12Resource, destination.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_DEST); } copyCommandList.D3D12GraphicsCommandList->CopyTextureRegion( @@ -306,8 +306,8 @@ public unsafe abstract class Texture2D : NativeObject, GraphicsResourceHelper if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE) { - copyCommandList.D3D12GraphicsCommandList->TransitioneBarrier(D3D12Resource, D3D12_RESOURCE_STATE_COPY_SOURCE, this.d3D12ResourceState); - copyCommandList.D3D12GraphicsCommandList->TransitioneBarrier(destination.D3D12Resource, D3D12_RESOURCE_STATE_COPY_DEST, destination.d3D12ResourceState); + copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(D3D12Resource, D3D12_RESOURCE_STATE_COPY_SOURCE, this.d3D12ResourceState); + copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(destination.D3D12Resource, D3D12_RESOURCE_STATE_COPY_DEST, destination.d3D12ResourceState); } copyCommandList.ExecuteAndWaitForCompletion(); @@ -349,7 +349,7 @@ public unsafe abstract class Texture2D : NativeObject, GraphicsResourceHelper if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE) { - copyCommandList.D3D12GraphicsCommandList->TransitioneBarrier(D3D12Resource, this.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_SOURCE); + copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(D3D12Resource, this.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_SOURCE); } fixed (D3D12_PLACED_SUBRESOURCE_FOOTPRINT* d3D12PlacedSubresourceFootprintDestination = &destination.D3D12PlacedSubresourceFootprint) @@ -371,7 +371,7 @@ public unsafe abstract class Texture2D : NativeObject, GraphicsResourceHelper if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE) { - copyCommandList.D3D12GraphicsCommandList->TransitioneBarrier(D3D12Resource, D3D12_RESOURCE_STATE_COPY_SOURCE, this.d3D12ResourceState); + copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(D3D12Resource, D3D12_RESOURCE_STATE_COPY_SOURCE, this.d3D12ResourceState); } copyCommandList.ExecuteAndWaitForCompletion(); @@ -439,7 +439,7 @@ public unsafe abstract class Texture2D : NativeObject, GraphicsResourceHelper if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE) { - copyCommandList.D3D12GraphicsCommandList->TransitioneBarrier(D3D12Resource, this.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_DEST); + copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(D3D12Resource, this.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_DEST); } copyCommandList.D3D12GraphicsCommandList->CopyTextureRegion( @@ -458,7 +458,7 @@ public unsafe abstract class Texture2D : NativeObject, GraphicsResourceHelper if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE) { - copyCommandList.D3D12GraphicsCommandList->TransitioneBarrier(D3D12Resource, D3D12_RESOURCE_STATE_COPY_DEST, this.d3D12ResourceState); + copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(D3D12Resource, D3D12_RESOURCE_STATE_COPY_DEST, this.d3D12ResourceState); } copyCommandList.ExecuteAndWaitForCompletion(); @@ -500,7 +500,7 @@ public unsafe abstract class Texture2D : NativeObject, GraphicsResourceHelper if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE) { - copyCommandList.D3D12GraphicsCommandList->TransitioneBarrier(D3D12Resource, this.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_DEST); + copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(D3D12Resource, this.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_DEST); } fixed (D3D12_PLACED_SUBRESOURCE_FOOTPRINT* d3D12PlacedSubresourceFootprintSource = &source.D3D12PlacedSubresourceFootprint) @@ -522,7 +522,7 @@ public unsafe abstract class Texture2D : NativeObject, GraphicsResourceHelper if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE) { - copyCommandList.D3D12GraphicsCommandList->TransitioneBarrier(D3D12Resource, D3D12_RESOURCE_STATE_COPY_DEST, this.d3D12ResourceState); + copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(D3D12Resource, D3D12_RESOURCE_STATE_COPY_DEST, this.d3D12ResourceState); } copyCommandList.ExecuteAndWaitForCompletion(); diff --git a/src/ComputeSharp/Graphics/Resources/Abstract/Texture3D{T}.cs b/src/ComputeSharp/Graphics/Resources/Abstract/Texture3D{T}.cs index 8121175a..7c93eacb 100644 --- a/src/ComputeSharp/Graphics/Resources/Abstract/Texture3D{T}.cs +++ b/src/ComputeSharp/Graphics/Resources/Abstract/Texture3D{T}.cs @@ -223,7 +223,7 @@ public unsafe abstract class Texture3D : NativeObject, GraphicsResourceHelper { if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE) { - copyCommandList.D3D12GraphicsCommandList->TransitioneBarrier(D3D12Resource, this.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_SOURCE); + copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(D3D12Resource, this.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_SOURCE); } copyCommandList.D3D12GraphicsCommandList->CopyTextureRegion( @@ -242,7 +242,7 @@ public unsafe abstract class Texture3D : NativeObject, GraphicsResourceHelper if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE) { - copyCommandList.D3D12GraphicsCommandList->TransitioneBarrier(D3D12Resource, D3D12_RESOURCE_STATE_COPY_SOURCE, this.d3D12ResourceState); + copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(D3D12Resource, D3D12_RESOURCE_STATE_COPY_SOURCE, this.d3D12ResourceState); } copyCommandList.ExecuteAndWaitForCompletion(); @@ -314,8 +314,8 @@ public unsafe abstract class Texture3D : NativeObject, GraphicsResourceHelper if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE) { - copyCommandList.D3D12GraphicsCommandList->TransitioneBarrier(D3D12Resource, this.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_SOURCE); - copyCommandList.D3D12GraphicsCommandList->TransitioneBarrier(destination.D3D12Resource, destination.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_DEST); + copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(D3D12Resource, this.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_SOURCE); + copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(destination.D3D12Resource, destination.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_DEST); } copyCommandList.D3D12GraphicsCommandList->CopyTextureRegion( @@ -333,8 +333,8 @@ public unsafe abstract class Texture3D : NativeObject, GraphicsResourceHelper if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE) { - copyCommandList.D3D12GraphicsCommandList->TransitioneBarrier(D3D12Resource, D3D12_RESOURCE_STATE_COPY_SOURCE, this.d3D12ResourceState); - copyCommandList.D3D12GraphicsCommandList->TransitioneBarrier(destination.D3D12Resource, D3D12_RESOURCE_STATE_COPY_DEST, destination.d3D12ResourceState); + copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(D3D12Resource, D3D12_RESOURCE_STATE_COPY_SOURCE, this.d3D12ResourceState); + copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(destination.D3D12Resource, D3D12_RESOURCE_STATE_COPY_DEST, destination.d3D12ResourceState); } copyCommandList.ExecuteAndWaitForCompletion(); @@ -385,7 +385,7 @@ public unsafe abstract class Texture3D : NativeObject, GraphicsResourceHelper if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE) { - copyCommandList.D3D12GraphicsCommandList->TransitioneBarrier(D3D12Resource, this.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_SOURCE); + copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(D3D12Resource, this.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_SOURCE); } fixed (D3D12_PLACED_SUBRESOURCE_FOOTPRINT* d3D12PlacedSubresourceFootprintDestination = &destination.D3D12PlacedSubresourceFootprint) @@ -407,7 +407,7 @@ public unsafe abstract class Texture3D : NativeObject, GraphicsResourceHelper if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE) { - copyCommandList.D3D12GraphicsCommandList->TransitioneBarrier(D3D12Resource, D3D12_RESOURCE_STATE_COPY_SOURCE, this.d3D12ResourceState); + copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(D3D12Resource, D3D12_RESOURCE_STATE_COPY_SOURCE, this.d3D12ResourceState); } copyCommandList.ExecuteAndWaitForCompletion(); @@ -483,7 +483,7 @@ public unsafe abstract class Texture3D : NativeObject, GraphicsResourceHelper if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE) { - copyCommandList.D3D12GraphicsCommandList->TransitioneBarrier(D3D12Resource, this.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_DEST); + copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(D3D12Resource, this.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_DEST); } copyCommandList.D3D12GraphicsCommandList->CopyTextureRegion( @@ -502,7 +502,7 @@ public unsafe abstract class Texture3D : NativeObject, GraphicsResourceHelper if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE) { - copyCommandList.D3D12GraphicsCommandList->TransitioneBarrier(D3D12Resource, D3D12_RESOURCE_STATE_COPY_DEST, this.d3D12ResourceState); + copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(D3D12Resource, D3D12_RESOURCE_STATE_COPY_DEST, this.d3D12ResourceState); } copyCommandList.ExecuteAndWaitForCompletion(); @@ -553,7 +553,7 @@ public unsafe abstract class Texture3D : NativeObject, GraphicsResourceHelper if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE) { - copyCommandList.D3D12GraphicsCommandList->TransitioneBarrier(D3D12Resource, this.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_DEST); + copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(D3D12Resource, this.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_DEST); } fixed (D3D12_PLACED_SUBRESOURCE_FOOTPRINT* d3D12PlacedSubresourceFootprintSource = &source.D3D12PlacedSubresourceFootprint) @@ -575,7 +575,7 @@ public unsafe abstract class Texture3D : NativeObject, GraphicsResourceHelper if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE) { - copyCommandList.D3D12GraphicsCommandList->TransitioneBarrier(D3D12Resource, D3D12_RESOURCE_STATE_COPY_DEST, this.d3D12ResourceState); + copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(D3D12Resource, D3D12_RESOURCE_STATE_COPY_DEST, this.d3D12ResourceState); } copyCommandList.ExecuteAndWaitForCompletion(); diff --git a/src/ComputeSharp/Shaders/ComputeContext.cs b/src/ComputeSharp/Shaders/ComputeContext.cs index 9df85400..17b0dcd4 100644 --- a/src/ComputeSharp/Shaders/ComputeContext.cs +++ b/src/ComputeSharp/Shaders/ComputeContext.cs @@ -43,36 +43,10 @@ public ref struct ComputeContext public GraphicsDevice GraphicsDevice => this.device; /// - /// Starts a resource barrier for a specific resource. - /// - /// The to start the barrier for. - internal readonly unsafe void StartBarrier(ID3D12Resource* d3D12Resource) - { - ThrowInvalidOperationExceptionIfDeviceIsNull(); - - ref CommandList commandList = ref GetCommandList(in this); - - commandList.D3D12GraphicsCommandList->StartUAVBarrier(d3D12Resource); - } - - /// - /// Ends a resource barrier for a specific resource. - /// - /// The to end the barrier for. - internal readonly unsafe void EndBarrier(ID3D12Resource* d3D12Resource) - { - ThrowInvalidOperationExceptionIfDeviceIsNull(); - - ref CommandList commandList = ref GetCommandList(in this); - - commandList.D3D12GraphicsCommandList->EndUAVBarrier(d3D12Resource); - } - - /// - /// Inserts a full a resource barrier for a specific resource. + /// Inserts a resource barrier for a specific resource. /// /// The to insert the barrier for. - internal readonly unsafe void FullBarrier(ID3D12Resource* d3D12Resource) + internal readonly unsafe void Barrier(ID3D12Resource* d3D12Resource) { ThrowInvalidOperationExceptionIfDeviceIsNull(); @@ -91,6 +65,8 @@ public ref struct ComputeContext internal readonly unsafe void Run(int x, int y, int z, ref T shader) where T : struct, IComputeShader { + ThrowInvalidOperationExceptionIfDeviceIsNull(); + bool xIs1 = x == 1; bool yIs1 = y == 1; bool zIs1 = z == 1; diff --git a/src/ComputeSharp/Shaders/Extensions/ComputeContextExtensions.cs b/src/ComputeSharp/Shaders/Extensions/ComputeContextExtensions.cs index df2d30ef..3fd3e302 100644 --- a/src/ComputeSharp/Shaders/Extensions/ComputeContextExtensions.cs +++ b/src/ComputeSharp/Shaders/Extensions/ComputeContextExtensions.cs @@ -11,267 +11,91 @@ namespace ComputeSharp; public static partial class ComputeContextExtensions { /// - /// Starts a resource barrier for a specific resource. - /// - /// The type of items stored on the buffer. - /// The to use to insert the resource barrier. - /// The input instance to start the barrier for. - public static unsafe void StartBarrier(this in ComputeContext context, ReadWriteBuffer buffer) - where T : unmanaged - { - context.StartBarrier(buffer.ValidateAndGetID3D12Resource(context.GraphicsDevice)); - } - - /// - /// Starts a resource barrier for a specific resource. - /// - /// The type of items stored on the texture. - /// The to use to insert the resource barrier. - /// The input instance to start the barrier for. - public static unsafe void StartBarrier(this in ComputeContext context, ReadWriteTexture2D texture) - where T : unmanaged - { - context.StartBarrier(texture.ValidateAndGetID3D12Resource(context.GraphicsDevice)); - } - - /// - /// Starts a resource barrier for a specific resource. - /// - /// The type of items stored on the texture. - /// The to use to insert the resource barrier. - /// The input instance to start the barrier for. - public static unsafe void StartBarrier(this in ComputeContext context, ReadWriteTexture3D texture) - where T : unmanaged - { - context.StartBarrier(texture.ValidateAndGetID3D12Resource(context.GraphicsDevice)); - } - - /// - /// Starts a resource barrier for a specific resource. - /// - /// The type of items stored on the texture. - /// The type of pixels used on the GPU side. - /// The to use to insert the resource barrier. - /// The input instance to start the barrier for. - public static unsafe void StartBarrier(this in ComputeContext context, ReadWriteTexture2D texture) - where T : unmanaged, IUnorm - where TPixel : unmanaged - { - context.StartBarrier(texture.ValidateAndGetID3D12Resource(context.GraphicsDevice)); - } - - /// - /// Starts a resource barrier for a specific resource. - /// - /// The type of items stored on the texture. - /// The type of pixels used on the GPU side. - /// The to use to insert the resource barrier. - /// The input instance to start the barrier for. - public static unsafe void StartBarrier(this in ComputeContext context, ReadWriteTexture3D texture) - where T : unmanaged, IUnorm - where TPixel : unmanaged - { - context.StartBarrier(texture.ValidateAndGetID3D12Resource(context.GraphicsDevice)); - } - - /// - /// Starts a resource barrier for a specific resource. - /// - /// The type of pixels stored on the texture. - /// The to use to insert the resource barrier. - /// The input instance to start the barrier for. - public static unsafe void StartBarrier(this in ComputeContext context, IReadWriteTexture2D texture) - where TPixel : unmanaged - { - context.StartBarrier(((GraphicsResourceHelper.IGraphicsResource)texture).ValidateAndGetID3D12Resource(context.GraphicsDevice)); - } - - /// - /// Starts a resource barrier for a specific resource. - /// - /// The type of pixels stored on the texture. - /// The to use to insert the resource barrier. - /// The input instance to start the barrier for. - public static unsafe void StartBarrier(this in ComputeContext context, IReadWriteTexture3D texture) - where TPixel : unmanaged - { - context.StartBarrier(((GraphicsResourceHelper.IGraphicsResource)texture).ValidateAndGetID3D12Resource(context.GraphicsDevice)); - } - - /// - /// Ends a resource barrier for a specific resource. - /// - /// The type of items stored on the buffer. - /// The to use to insert the resource barrier. - /// The input instance to end the barrier for. - public static unsafe void EndBarrier(this in ComputeContext context, ReadWriteBuffer buffer) - where T : unmanaged - { - context.EndBarrier(buffer.ValidateAndGetID3D12Resource(context.GraphicsDevice)); - } - - /// - /// Ends a resource barrier for a specific resource. - /// - /// The type of items stored on the texture. - /// The to use to insert the resource barrier. - /// The input instance to end the barrier for. - public static unsafe void EndBarrier(this in ComputeContext context, ReadWriteTexture2D texture) - where T : unmanaged - { - context.EndBarrier(texture.ValidateAndGetID3D12Resource(context.GraphicsDevice)); - } - - /// - /// Ends a resource barrier for a specific resource. - /// - /// The type of items stored on the texture. - /// The to use to insert the resource barrier. - /// The input instance to end the barrier for. - public static unsafe void EndBarrier(this in ComputeContext context, ReadWriteTexture3D texture) - where T : unmanaged - { - context.EndBarrier(texture.ValidateAndGetID3D12Resource(context.GraphicsDevice)); - } - - /// - /// Ends a resource barrier for a specific resource. - /// - /// The type of items stored on the texture. - /// The type of pixels used on the GPU side. - /// The to use to insert the resource barrier. - /// The input instance to end the barrier for. - public static unsafe void EndBarrier(this in ComputeContext context, ReadWriteTexture2D texture) - where T : unmanaged, IUnorm - where TPixel : unmanaged - { - context.EndBarrier(texture.ValidateAndGetID3D12Resource(context.GraphicsDevice)); - } - - /// - /// Ends a resource barrier for a specific resource. - /// - /// The type of items stored on the texture. - /// The type of pixels used on the GPU side. - /// The to use to insert the resource barrier. - /// The input instance to end the barrier for. - public static unsafe void EndBarrier(this in ComputeContext context, ReadWriteTexture3D texture) - where T : unmanaged, IUnorm - where TPixel : unmanaged - { - context.EndBarrier(texture.ValidateAndGetID3D12Resource(context.GraphicsDevice)); - } - - /// - /// Ends a resource barrier for a specific resource. - /// - /// The type of pixels stored on the texture. - /// The to use to insert the resource barrier. - /// The input instance to end the barrier for. - public static unsafe void EndBarrier(this in ComputeContext context, IReadWriteTexture2D texture) - where TPixel : unmanaged - { - context.EndBarrier(((GraphicsResourceHelper.IGraphicsResource)texture).ValidateAndGetID3D12Resource(context.GraphicsDevice)); - } - - /// - /// Ends a resource barrier for a specific resource. - /// - /// The type of pixels stored on the texture. - /// The to use to insert the resource barrier. - /// The input instance to end the barrier for. - public static unsafe void EndBarrier(this in ComputeContext context, IReadWriteTexture3D texture) - where TPixel : unmanaged - { - context.EndBarrier(((GraphicsResourceHelper.IGraphicsResource)texture).ValidateAndGetID3D12Resource(context.GraphicsDevice)); - } - - /// - /// Inserts a full resource barrier for a specific resource. + /// Inserts a resource barrier for a specific resource. /// /// The type of items stored on the buffer. /// The to use to insert the resource barrier. /// The input instance to insert the barrier for. - public static unsafe void FullBarrier(this in ComputeContext context, ReadWriteBuffer buffer) + public static unsafe void Barrier(this in ComputeContext context, ReadWriteBuffer buffer) where T : unmanaged { - context.FullBarrier(buffer.ValidateAndGetID3D12Resource(context.GraphicsDevice)); + context.Barrier(buffer.ValidateAndGetID3D12Resource(context.GraphicsDevice)); } /// - /// Inserts a full resource barrier for a specific resource. + /// Inserts a resource barrier for a specific resource. /// /// The type of items stored on the texture. /// The to use to insert the resource barrier. /// The input instance to insert the barrier for. - public static unsafe void FullBarrier(this in ComputeContext context, ReadWriteTexture2D texture) + public static unsafe void Barrier(this in ComputeContext context, ReadWriteTexture2D texture) where T : unmanaged { - context.FullBarrier(texture.ValidateAndGetID3D12Resource(context.GraphicsDevice)); + context.Barrier(texture.ValidateAndGetID3D12Resource(context.GraphicsDevice)); } /// - /// Inserts a full resource barrier for a specific resource. + /// Inserts a resource barrier for a specific resource. /// /// The type of items stored on the texture. /// The to use to insert the resource barrier. /// The input instance to insert the barrier for. - public static unsafe void FullBarrier(this in ComputeContext context, ReadWriteTexture3D texture) + public static unsafe void Barrier(this in ComputeContext context, ReadWriteTexture3D texture) where T : unmanaged { - context.FullBarrier(texture.ValidateAndGetID3D12Resource(context.GraphicsDevice)); + context.Barrier(texture.ValidateAndGetID3D12Resource(context.GraphicsDevice)); } /// - /// Inserts a full resource barrier for a specific resource. + /// Inserts a resource barrier for a specific resource. /// /// The type of items stored on the texture. /// The type of pixels used on the GPU side. /// The to use to insert the resource barrier. /// The input instance to insert the barrier for. - public static unsafe void FullBarrier(this in ComputeContext context, ReadWriteTexture2D texture) + public static unsafe void Barrier(this in ComputeContext context, ReadWriteTexture2D texture) where T : unmanaged, IUnorm where TPixel : unmanaged { - context.FullBarrier(texture.ValidateAndGetID3D12Resource(context.GraphicsDevice)); + context.Barrier(texture.ValidateAndGetID3D12Resource(context.GraphicsDevice)); } /// - /// Inserts a full resource barrier for a specific resource. + /// Inserts a resource barrier for a specific resource. /// /// The type of items stored on the texture. /// The type of pixels used on the GPU side. /// The to use to insert the resource barrier. /// The input instance to insert the barrier for. - public static unsafe void FullBarrier(this in ComputeContext context, ReadWriteTexture3D texture) + public static unsafe void Barrier(this in ComputeContext context, ReadWriteTexture3D texture) where T : unmanaged, IUnorm where TPixel : unmanaged { - context.FullBarrier(texture.ValidateAndGetID3D12Resource(context.GraphicsDevice)); + context.Barrier(texture.ValidateAndGetID3D12Resource(context.GraphicsDevice)); } /// - /// Inserts a full resource barrier for a specific resource. + /// Inserts a resource barrier for a specific resource. /// /// The type of pixels stored on the texture. /// The to use to insert the resource barrier. /// The input instance to insert the barrier for. - public static unsafe void FullBarrier(this in ComputeContext context, IReadWriteTexture2D texture) + public static unsafe void Barrier(this in ComputeContext context, IReadWriteTexture2D texture) where TPixel : unmanaged { - context.FullBarrier(((GraphicsResourceHelper.IGraphicsResource)texture).ValidateAndGetID3D12Resource(context.GraphicsDevice)); + context.Barrier(((GraphicsResourceHelper.IGraphicsResource)texture).ValidateAndGetID3D12Resource(context.GraphicsDevice)); } /// - /// Inserts a full resource barrier for a specific resource. + /// Inserts a resource barrier for a specific resource. /// /// The type of pixels stored on the texture. /// The to use to insert the resource barrier. /// The input instance to insert the barrier for. - public static unsafe void FullBarrier(this in ComputeContext context, IReadWriteTexture3D texture) + public static unsafe void Barrier(this in ComputeContext context, IReadWriteTexture3D texture) where TPixel : unmanaged { - context.FullBarrier(((GraphicsResourceHelper.IGraphicsResource)texture).ValidateAndGetID3D12Resource(context.GraphicsDevice)); + context.Barrier(((GraphicsResourceHelper.IGraphicsResource)texture).ValidateAndGetID3D12Resource(context.GraphicsDevice)); } /// diff --git a/tests/ComputeSharp.Tests/ComputeContextTests.cs b/tests/ComputeSharp.Tests/ComputeContextTests.cs index d16ea217..c0b48044 100644 --- a/tests/ComputeSharp.Tests/ComputeContextTests.cs +++ b/tests/ComputeSharp.Tests/ComputeContextTests.cs @@ -45,7 +45,7 @@ public partial class ComputeContextTests using (ComputeContext context = device.Get().CreateComputeContext()) { context.ForEach(texture, default(ClearPixelShader)); - context.FullBarrier(texture); + context.Barrier(texture); context.ForEach(texture, new ColorPixelShader(new float4(0.22f, 0.44f, 0.66f, 0.88f))); } @@ -74,9 +74,8 @@ public partial class ComputeContextTests context.For(512, new OffsetComputeShader(buffer, 0)); context.For(64, new OffsetComputeShader(buffer, 512)); context.ForEach(texture, default(ClearPixelShader)); - context.StartBarrier(texture); context.For(299, new OffsetComputeShader(buffer, 576)); - context.EndBarrier(texture); + context.Barrier(texture); context.ForEach(texture, new ColorPixelShader(new float4(0.22f, 0.44f, 0.66f, 0.88f))); context.For(149, new OffsetComputeShader(buffer, 875)); } @@ -107,6 +106,35 @@ public partial class ComputeContextTests } } + [CombinatorialTestMethod] + [AllDevices] + [ExpectedException(typeof(InvalidOperationException))] + public void Barrier_WithoutPreviousDispatches_ThrowsException(Device device) + { + using ReadWriteBuffer buffer = device.Get().AllocateReadWriteBuffer(64); + + using (ComputeContext context = device.Get().CreateComputeContext()) + { + context.Barrier(buffer); + } + + Assert.Fail(); + } + + [CombinatorialTestMethod] + [AllDevices] + [ExpectedException(typeof(InvalidOperationException))] + public void DefaultContext_Barrier_ThrowsException(Device device) + { + using ReadWriteBuffer buffer = device.Get().AllocateReadWriteBuffer(64); + + using ComputeContext context = default; + + context.Barrier(buffer); + + Assert.Fail(); + } + [TestMethod] [ExpectedException(typeof(InvalidOperationException))] public void DefaultContext_For_ThrowsException()