From 8c5ce3a1d79112d26356393692ec0633ff4e504e Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 29 Aug 2022 01:58:51 +0200 Subject: [PATCH] Add extensions for 1D textures --- .../GraphicsDeviceExtensions.Resources.cs | 412 +++++++++++++ .../Extensions/ReadBackTexture1DExtensions.cs | 60 ++ .../ReadWriteTexture1DExtensions.cs | 144 +++++ .../Extensions/Texture1DExtensions.cs | 544 ++++++++++++++++++ .../Extensions/UploadTexture1DExtensions.cs | 60 ++ .../Extensions/ComputeContextExtensions.cs | 235 +++++++- 6 files changed, 1454 insertions(+), 1 deletion(-) create mode 100644 src/ComputeSharp/Graphics/Extensions/ReadBackTexture1DExtensions.cs create mode 100644 src/ComputeSharp/Graphics/Extensions/ReadWriteTexture1DExtensions.cs create mode 100644 src/ComputeSharp/Graphics/Extensions/Texture1DExtensions.cs create mode 100644 src/ComputeSharp/Graphics/Extensions/UploadTexture1DExtensions.cs diff --git a/src/ComputeSharp/Graphics/Extensions/GraphicsDeviceExtensions.Resources.cs b/src/ComputeSharp/Graphics/Extensions/GraphicsDeviceExtensions.Resources.cs index b8e91f45..0e2c8834 100644 --- a/src/ComputeSharp/Graphics/Extensions/GraphicsDeviceExtensions.Resources.cs +++ b/src/ComputeSharp/Graphics/Extensions/GraphicsDeviceExtensions.Resources.cs @@ -160,6 +160,196 @@ partial class GraphicsDeviceExtensions return readWriteBuffer; } + /// + /// Allocates a new readonly 1D texture with the specified parameters. + /// + /// The type of items to store in the texture. + /// The instance to use to allocate the texture. + /// The width of the texture. + /// The allocation mode to use for the new resource. + /// A zeroed instance of size []. + public static ReadOnlyTexture1D AllocateReadOnlyTexture1D(this GraphicsDevice device, int width, AllocationMode allocationMode = AllocationMode.Default) + where T : unmanaged + { + Guard.IsNotNull(device); + + return new(device, width, allocationMode); + } + + /// + /// Allocates a new readonly 1D texture with the specified parameters. + /// + /// The type of items to store in the texture. + /// The instance to use to allocate the texture. + /// The input array with the data to copy on the allocated texture. + /// The width of the texture. + /// A instance with the contents of the input array. + public static ReadOnlyTexture1D AllocateReadOnlyTexture1D(this GraphicsDevice device, T[] source, int width) + where T : unmanaged + { + Guard.IsNotNull(device); + Guard.IsNotNull(source); + + return device.AllocateReadOnlyTexture1D(source.AsSpan(0, width)); + } + + /// + /// Allocates a new readonly 1D texture with the specified parameters. + /// + /// The type of items to store in the texture. + /// The instance to use to allocate the texture. + /// The input array with the data to copy on the allocated texture. + /// The starting offset within to read data from. + /// The width of the texture. + /// A instance with the contents of the input array. + public static ReadOnlyTexture1D AllocateReadOnlyTexture1D(this GraphicsDevice device, T[] source, int offset, int width) + where T : unmanaged + { + Guard.IsNotNull(device); + Guard.IsNotNull(source); + + return device.AllocateReadOnlyTexture1D(source.AsSpan(offset, width)); + } + + /// + /// Allocates a new readonly 1D texture with the specified parameters. + /// + /// The type of items to store in the texture. + /// The instance to use to allocate the texture. + /// The input array with the data to copy on the allocated texture. + /// A read write instance with the contents of the input array. + public static ReadOnlyTexture1D AllocateReadOnlyTexture1D(this GraphicsDevice device, T[] source) + where T : unmanaged + { + Guard.IsNotNull(device); + Guard.IsNotNull(source); + + ReadOnlyTexture1D texture = new(device, source.Length, AllocationMode.Default); + + texture.CopyFrom(source); + + return texture; + } + + /// + /// Allocates a new readonly 1D texture with the specified parameters. + /// + /// The type of items to store in the texture. + /// The instance to use to allocate the texture. + /// The input with the data to copy on the allocated texture. + /// A instance with the contents of the input . + public static ReadOnlyTexture1D AllocateReadOnlyTexture1D(this GraphicsDevice device, ReadOnlySpan source) + where T : unmanaged + { + Guard.IsNotNull(device); + + ReadOnlyTexture1D texture = new(device, source.Length, AllocationMode.Default); + + texture.CopyFrom(source); + + return texture; + } + + /// + /// Allocates a new readonly 1D texture with the specified parameters. + /// + /// The type of items to store in the texture. + /// The type of pixels used on the GPU side. + /// The instance to use to allocate the texture. + /// The width of the texture. + /// The allocation mode to use for the new resource. + /// A zeroed instance of size []. + public static ReadOnlyTexture1D AllocateReadOnlyTexture1D(this GraphicsDevice device, int width, AllocationMode allocationMode = AllocationMode.Default) + where T : unmanaged, IPixel + where TPixel : unmanaged + { + Guard.IsNotNull(device); + + return new(device, width, allocationMode); + } + + /// + /// Allocates a new readonly 1D texture with the specified parameters. + /// + /// The type of items to store in the texture. + /// The type of pixels used on the GPU side. + /// The instance to use to allocate the texture. + /// The input array with the data to copy on the allocated texture. + /// The width of the texture. + /// A instance with the contents of the input array. + public static ReadOnlyTexture1D AllocateReadOnlyTexture1D(this GraphicsDevice device, T[] source, int width) + where T : unmanaged, IPixel + where TPixel : unmanaged + { + Guard.IsNotNull(device); + Guard.IsNotNull(source); + + return device.AllocateReadOnlyTexture1D(source.AsSpan(0, width)); + } + + /// + /// Allocates a new readonly 1D texture with the specified parameters. + /// + /// The type of items to store in the texture. + /// The type of pixels used on the GPU side. + /// The instance to use to allocate the texture. + /// The input array with the data to copy on the allocated texture. + /// The starting offset within to read data from. + /// The width of the texture. + /// A instance with the contents of the input array. + public static ReadOnlyTexture1D AllocateReadOnlyTexture1D(this GraphicsDevice device, T[] source, int offset, int width) + where T : unmanaged, IPixel + where TPixel : unmanaged + { + Guard.IsNotNull(device); + Guard.IsNotNull(source); + + return device.AllocateReadOnlyTexture1D(source.AsSpan(offset, width)); + } + + /// + /// Allocates a new readonly 1D texture with the specified parameters. + /// + /// The type of items to store in the texture. + /// The type of pixels used on the GPU side. + /// The instance to use to allocate the texture. + /// The input array with the data to copy on the allocated texture. + /// A read write instance with the contents of the input array. + public static ReadOnlyTexture1D AllocateReadOnlyTexture1D(this GraphicsDevice device, T[] source) + where T : unmanaged, IPixel + where TPixel : unmanaged + { + Guard.IsNotNull(device); + Guard.IsNotNull(source); + + ReadOnlyTexture1D texture = new(device, source.Length, AllocationMode.Default); + + texture.CopyFrom(source); + + return texture; + } + + /// + /// Allocates a new readonly 1D texture with the specified parameters. + /// + /// The type of items to store in the texture. + /// The type of pixels used on the GPU side. + /// The instance to use to allocate the texture. + /// The input with the data to copy on the allocated texture. + /// A instance with the contents of the input . + public static ReadOnlyTexture1D AllocateReadOnlyTexture1D(this GraphicsDevice device, ReadOnlySpan source) + where T : unmanaged, IPixel + where TPixel : unmanaged + { + Guard.IsNotNull(device); + + ReadOnlyTexture1D texture = new(device, source.Length, AllocationMode.Default); + + texture.CopyFrom(source); + + return texture; + } + /// /// Allocates a new readonly 2D texture with the specified parameters. /// @@ -651,6 +841,196 @@ partial class GraphicsDeviceExtensions return readWriteBuffer; } + /// + /// Allocates a new writeable 1D texture with the specified parameters. + /// + /// The type of items to store in the texture. + /// The instance to use to allocate the texture. + /// The width of the texture. + /// The allocation mode to use for the new resource. + /// A zeroed instance of size []. + public static ReadWriteTexture1D AllocateReadWriteTexture1D(this GraphicsDevice device, int width, AllocationMode allocationMode = AllocationMode.Default) + where T : unmanaged + { + Guard.IsNotNull(device); + + return new(device, width, allocationMode); + } + + /// + /// Allocates a new writeable 1D texture with the specified parameters. + /// + /// The type of items to store in the texture. + /// The instance to use to allocate the texture. + /// The input array with the data to copy on the allocated texture. + /// The width of the texture. + /// A instance with the contents of the input array. + public static ReadWriteTexture1D AllocateReadWriteTexture1D(this GraphicsDevice device, T[] source, int width) + where T : unmanaged + { + Guard.IsNotNull(device); + Guard.IsNotNull(source); + + return device.AllocateReadWriteTexture1D(source.AsSpan(0, width)); + } + + /// + /// Allocates a new writeable 1D texture with the specified parameters. + /// + /// The type of items to store in the texture. + /// The instance to use to allocate the texture. + /// The input array with the data to copy on the allocated texture. + /// The starting offset within to read data from. + /// The width of the texture. + /// A instance with the contents of the input array. + public static ReadWriteTexture1D AllocateReadWriteTexture1D(this GraphicsDevice device, T[] source, int offset, int width) + where T : unmanaged + { + Guard.IsNotNull(device); + Guard.IsNotNull(source); + + return device.AllocateReadWriteTexture1D(source.AsSpan(offset, width)); + } + + /// + /// Allocates a new writeable 1D texture with the specified parameters. + /// + /// The type of items to store in the texture. + /// The instance to use to allocate the texture. + /// The input array with the data to copy on the allocated texture. + /// A read write instance with the contents of the input array. + public static ReadWriteTexture1D AllocateReadWriteTexture1D(this GraphicsDevice device, T[] source) + where T : unmanaged + { + Guard.IsNotNull(device); + Guard.IsNotNull(source); + + ReadWriteTexture1D texture = new(device, source.Length, AllocationMode.Default); + + texture.CopyFrom(source); + + return texture; + } + + /// + /// Allocates a new writeable 1D texture with the specified parameters. + /// + /// The type of items to store in the texture. + /// The instance to use to allocate the texture. + /// The input with the data to copy on the allocated texture. + /// A instance with the contents of the input . + public static ReadWriteTexture1D AllocateReadWriteTexture1D(this GraphicsDevice device, ReadOnlySpan source) + where T : unmanaged + { + Guard.IsNotNull(device); + + ReadWriteTexture1D texture = new(device, source.Length, AllocationMode.Default); + + texture.CopyFrom(source); + + return texture; + } + + /// + /// Allocates a new writeable 1D texture with the specified parameters. + /// + /// The type of items to store in the texture. + /// The type of pixels used on the GPU side. + /// The instance to use to allocate the texture. + /// The width of the texture. + /// The allocation mode to use for the new resource. + /// A zeroed instance of size []. + public static ReadWriteTexture1D AllocateReadWriteTexture1D(this GraphicsDevice device, int width, AllocationMode allocationMode = AllocationMode.Default) + where T : unmanaged, IPixel + where TPixel : unmanaged + { + Guard.IsNotNull(device); + + return new(device, width, allocationMode); + } + + /// + /// Allocates a new writeable 1D texture with the specified parameters. + /// + /// The type of items to store in the texture. + /// The type of pixels used on the GPU side. + /// The instance to use to allocate the texture. + /// The input array with the data to copy on the allocated texture. + /// The width of the texture. + /// A instance with the contents of the input array. + public static ReadWriteTexture1D AllocateReadWriteTexture1D(this GraphicsDevice device, T[] source, int width) + where T : unmanaged, IPixel + where TPixel : unmanaged + { + Guard.IsNotNull(device); + Guard.IsNotNull(source); + + return device.AllocateReadWriteTexture1D(source.AsSpan(0, width)); + } + + /// + /// Allocates a new writeable 1D texture with the specified parameters. + /// + /// The type of items to store in the texture. + /// The type of pixels used on the GPU side. + /// The instance to use to allocate the texture. + /// The input array with the data to copy on the allocated texture. + /// The starting offset within to read data from. + /// The width of the texture. + /// A instance with the contents of the input array. + public static ReadWriteTexture1D AllocateReadWriteTexture1D(this GraphicsDevice device, T[] source, int offset, int width) + where T : unmanaged, IPixel + where TPixel : unmanaged + { + Guard.IsNotNull(device); + Guard.IsNotNull(source); + + return device.AllocateReadWriteTexture1D(source.AsSpan(offset, width)); + } + + /// + /// Allocates a new writeable 1D texture with the specified parameters. + /// + /// The type of items to store in the texture. + /// The type of pixels used on the GPU side. + /// The instance to use to allocate the texture. + /// The input array with the data to copy on the allocated texture. + /// A read write instance with the contents of the input array. + public static ReadWriteTexture1D AllocateReadWriteTexture1D(this GraphicsDevice device, T[] source) + where T : unmanaged, IPixel + where TPixel : unmanaged + { + Guard.IsNotNull(device); + Guard.IsNotNull(source); + + ReadWriteTexture1D texture = new(device, source.Length, AllocationMode.Default); + + texture.CopyFrom(source); + + return texture; + } + + /// + /// Allocates a new writeable 1D texture with the specified parameters. + /// + /// The type of items to store in the texture. + /// The type of pixels used on the GPU side. + /// The instance to use to allocate the texture. + /// The input with the data to copy on the allocated texture. + /// A instance with the contents of the input . + public static ReadWriteTexture1D AllocateReadWriteTexture1D(this GraphicsDevice device, ReadOnlySpan source) + where T : unmanaged, IPixel + where TPixel : unmanaged + { + Guard.IsNotNull(device); + + ReadWriteTexture1D texture = new(device, source.Length, AllocationMode.Default); + + texture.CopyFrom(source); + + return texture; + } + /// /// Allocates a new writeable 2D texture with the specified parameters. /// @@ -1084,6 +1464,22 @@ partial class GraphicsDeviceExtensions return new(device, length, allocationMode); } + /// + /// Allocates a new upload 1D texture with the specified parameters. + /// + /// The type of items to store in the buffer. + /// The instance to use to allocate the buffer. + /// The width of the texture. + /// The allocation mode to use for the new resource. + /// A instance of size []. + public static UploadTexture1D AllocateUploadTexture1D(this GraphicsDevice device, int width, AllocationMode allocationMode = AllocationMode.Default) + where T : unmanaged + { + Guard.IsNotNull(device); + + return new(device, width, allocationMode); + } + /// /// Allocates a new upload 2D texture with the specified parameters. /// @@ -1136,6 +1532,22 @@ partial class GraphicsDeviceExtensions return new(device, length, allocationMode); } + /// + /// Allocates a new readback 1D texture with the specified parameters. + /// + /// The type of items to store in the buffer. + /// The instance to use to allocate the buffer. + /// The width of the texture. + /// The allocation mode to use for the new resource. + /// A instance of size []. + public static ReadBackTexture1D AllocateReadBackTexture1D(this GraphicsDevice device, int width, AllocationMode allocationMode = AllocationMode.Default) + where T : unmanaged + { + Guard.IsNotNull(device); + + return new(device, width, allocationMode); + } + /// /// Allocates a new readback 2D texture with the specified parameters. /// diff --git a/src/ComputeSharp/Graphics/Extensions/ReadBackTexture1DExtensions.cs b/src/ComputeSharp/Graphics/Extensions/ReadBackTexture1DExtensions.cs new file mode 100644 index 00000000..1c22347a --- /dev/null +++ b/src/ComputeSharp/Graphics/Extensions/ReadBackTexture1DExtensions.cs @@ -0,0 +1,60 @@ +using CommunityToolkit.Diagnostics; +using ComputeSharp.Resources; + +namespace ComputeSharp; + +/// +/// A that contains extension methods for the type. +/// +public static class ReadBackTexture1DExtensions +{ + /// + /// Reads the contents of a instance and writes them into a target instance. + /// + /// The type of items stored on the texture. + /// The target instance to write data to. + /// The input instance to read data from. + public static void CopyFrom(this ReadBackTexture1D destination, Texture1D source) + where T : unmanaged + { + Guard.IsNotNull(destination); + Guard.IsNotNull(source); + + source.CopyTo(destination, 0, 0, source.Width); + } + + /// + /// Reads the contents of a instance and writes them into a target instance. + /// + /// The type of items stored on the texture. + /// The target instance to write data to. + /// The input instance to read data from. + /// The horizontal offset in the source texture. + /// The width of the memory area to copy. + public static void CopyFrom(this ReadBackTexture1D destination, Texture1D source, int sourceOffsetX, int width) + where T : unmanaged + { + Guard.IsNotNull(destination); + Guard.IsNotNull(source); + + source.CopyTo(destination, sourceOffsetX, 0, width); + } + + /// + /// Reads the contents of a instance and writes them into a target instance. + /// + /// The type of items stored on the texture. + /// The target instance to write data to. + /// The input instance to read data from. + /// The horizontal offset in the source texture. + /// The horizontal offset in the destination texture. + /// The width of the memory area to copy. + public static void CopyFrom(this ReadBackTexture1D destination, Texture1D source, int sourceOffsetX, int destinationOffsetX, int width) + where T : unmanaged + { + Guard.IsNotNull(destination); + Guard.IsNotNull(source); + + source.CopyTo(destination, sourceOffsetX, destinationOffsetX, width); + } +} diff --git a/src/ComputeSharp/Graphics/Extensions/ReadWriteTexture1DExtensions.cs b/src/ComputeSharp/Graphics/Extensions/ReadWriteTexture1DExtensions.cs new file mode 100644 index 00000000..5c540d7e --- /dev/null +++ b/src/ComputeSharp/Graphics/Extensions/ReadWriteTexture1DExtensions.cs @@ -0,0 +1,144 @@ +using System; +using CommunityToolkit.Diagnostics; + +namespace ComputeSharp; + +/// +/// A that contains extension methods for the and types. +/// +public static class ReadWriteTexture1DExtensions +{ + /// + /// Retrieves a wrapping instance for the input resource. + /// + /// The input instance to create a wrapper for. + /// An instance wrapping the current resource. + /// + /// The returned instance can be used in a shader to enable texture sampling. + /// + /// This is an advanced API that can only be used after the current instance has been transitioned to be in a readonly state. To do so, + /// use , + /// and specify . After that, this method can be used to get a readonly wrapper for + /// the current texture to use in a shader. This instance should not be cached or reused, but just passed directly to a shader + /// being dispatched through that same , as it will not work if the texture changes state later on. + /// Before the end of that list of operations, the texture also needs to be transitioned back to writeable state, using the same + /// API as before but specifying . Failing to do so results in undefined behavior. + /// + /// + /// Thrown if the current instance or its associated device are disposed. + /// Thrown if the current instance is not in a readonly state. + public static IReadOnlyTexture1D AsReadOnly(this ReadWriteTexture1D texture) + { + Guard.IsNotNull(texture); + + return texture.AsReadOnly(); + } + + /// + /// Retrieves a wrapping instance for the input resource. + /// + /// The input instance to create a wrapper for. + /// An instance wrapping the current resource. + /// + /// The returned instance can be used in a shader to enable texture sampling. + /// + /// This is an advanced API that can only be used after the current instance has been transitioned to be in a readonly state. To do so, + /// use , + /// and specify . After that, this method can be used to get a readonly wrapper for + /// the current texture to use in a shader. This instance should not be cached or reused, but just passed directly to a shader + /// being dispatched through that same , as it will not work if the texture changes state later on. + /// Before the end of that list of operations, the texture also needs to be transitioned back to writeable state, using the same + /// API as before but specifying . Failing to do so results in undefined behavior. + /// + /// + /// Thrown if the current instance or its associated device are disposed. + /// Thrown if the current instance is not in a readonly state. + public static IReadOnlyTexture1D AsReadOnly(this ReadWriteTexture1D texture) + { + Guard.IsNotNull(texture); + + return texture.AsReadOnly(); + } + + /// + /// Retrieves a wrapping instance for the input resource. + /// + /// The input instance to create a wrapper for. + /// An instance wrapping the current resource. + /// + /// The returned instance can be used in a shader to enable texture sampling. + /// + /// This is an advanced API that can only be used after the current instance has been transitioned to be in a readonly state. To do so, + /// use , + /// and specify . After that, this method can be used to get a readonly wrapper for + /// the current texture to use in a shader. This instance should not be cached or reused, but just passed directly to a shader + /// being dispatched through that same , as it will not work if the texture changes state later on. + /// Before the end of that list of operations, the texture also needs to be transitioned back to writeable state, using the same + /// API as before but specifying . Failing to do so results in undefined behavior. + /// + /// + /// Thrown if the current instance or its associated device are disposed. + /// Thrown if the current instance is not in a readonly state. + public static IReadOnlyTexture1D AsReadOnly(this ReadWriteTexture1D texture) + { + Guard.IsNotNull(texture); + + return texture.AsReadOnly(); + } + + /// + /// Retrieves a wrapping instance for the input resource. + /// + /// The input instance to create a wrapper for. + /// An instance wrapping the current resource. + /// + /// The returned instance can be used in a shader to enable texture sampling. + /// + /// This is an advanced API that can only be used after the current instance has been transitioned to be in a readonly state. To do so, + /// use , + /// and specify . After that, this method can be used to get a readonly wrapper for + /// the current texture to use in a shader. This instance should not be cached or reused, but just passed directly to a shader + /// being dispatched through that same , as it will not work if the texture changes state later on. + /// Before the end of that list of operations, the texture also needs to be transitioned back to writeable state, using the same + /// API as before but specifying . Failing to do so results in undefined behavior. + /// + /// + /// Thrown if the current instance or its associated device are disposed. + /// Thrown if the current instance is not in a readonly state. + public static IReadOnlyTexture1D AsReadOnly(this ReadWriteTexture1D texture) + { + Guard.IsNotNull(texture); + + return texture.AsReadOnly(); + } + + /// + /// Retrieves a wrapping instance for the input resource. + /// + /// The type of items to store in the texture. + /// The type of pixels used on the GPU side. + /// The input instance to create a wrapper for. + /// An instance wrapping the current resource. + /// + /// The returned instance can be used in a shader to enable texture sampling. + /// + /// This is an advanced API that can only be used after the current instance has been transitioned to be in a readonly state. To do so, + /// use , + /// and specify . After that, this method can be used to get a readonly wrapper for + /// the current texture to use in a shader. This instance should not be cached or reused, but just passed directly to a shader + /// being dispatched through that same , as it will not work if the texture changes state later on. + /// Before the end of that list of operations, the texture also needs to be transitioned back to writeable state, using the same + /// API as before but specifying . Failing to do so results in undefined behavior. + /// + /// + /// Thrown if the current instance or its associated device are disposed. + /// Thrown if the current instance is not in a readonly state. + public static IReadOnlyNormalizedTexture1D AsReadOnly(this ReadWriteTexture1D texture) + where T : unmanaged, IPixel + where TPixel : unmanaged + { + Guard.IsNotNull(texture); + + return texture.AsReadOnly(); + } +} diff --git a/src/ComputeSharp/Graphics/Extensions/Texture1DExtensions.cs b/src/ComputeSharp/Graphics/Extensions/Texture1DExtensions.cs new file mode 100644 index 00000000..55c7f2fe --- /dev/null +++ b/src/ComputeSharp/Graphics/Extensions/Texture1DExtensions.cs @@ -0,0 +1,544 @@ +using System; +using System.Runtime.InteropServices; +using CommunityToolkit.Diagnostics; +using ComputeSharp.Resources; + +namespace ComputeSharp; + +/// +/// A that contains extension methods for the type. +/// +public static class Texture1DExtensions +{ + /// + /// Reads the contents of the current instance and returns an array. + /// + /// The type of items stored on the texture. + /// The input instance to read data from. + /// A array with the contents of the current texture. + public static T[] ToArray(this Texture1D source) + where T : unmanaged + { + Guard.IsNotNull(source); + + T[] data = new T[source.Width]; + + source.CopyTo(data); + + return data; + } + + /// + /// Reads the contents of the current instance and returns an array. + /// + /// The type of items stored on the texture. + /// The input instance to read data from. + /// The horizontal offset in the source texture. + /// The width of the memory area to copy. + /// A array with the contents of the current texture. + public static unsafe T[] ToArray(this Texture1D source, int x, int width) + where T : unmanaged + { + Guard.IsNotNull(source); + Guard.IsGreaterThanOrEqualTo(width, 0); + + T[] data = new T[width]; + + fixed (T* p = data) + { + source.CopyTo(new Span(p, width), x, width); + } + + return data; + } + + /// + /// Reads the contents of the specified range from the current instance and writes them into a target array. + /// + /// The type of items stored on the texture. + /// The input instance to read data from. + /// The input array to write data to. + public static void CopyTo(this Texture1D source, T[] destination) + where T : unmanaged + { + Guard.IsNotNull(source); + Guard.IsNotNull(destination); + + source.CopyTo(destination.AsSpan(), 0, source.Width); + } + +#if NET6_0_OR_GREATER + /// + /// Reads the contents of the specified range from the current instance and writes them into a target array. + /// + /// The type of items stored on the texture. + /// The input instance to read data from. + /// The input array to write data to. + /// The horizontal range of items to copy. + public static void CopyTo(this Texture1D source, T[] destination, Range x) + where T : unmanaged + { + Guard.IsNotNull(source); + Guard.IsNotNull(destination); + + source.CopyTo(destination.AsSpan(), x); + } +#endif + + /// + /// Reads the contents of the specified range from the current instance and writes them into a target array. + /// + /// The type of items stored on the texture. + /// The input instance to read data from. + /// The input array to write data to. + /// The horizontal offset in the source texture. + /// The width of the memory area to copy. + public static void CopyTo(this Texture1D source, T[] destination, int sourceOffsetX, int width) + where T : unmanaged + { + Guard.IsNotNull(source); + Guard.IsNotNull(destination); + + source.CopyTo(destination.AsSpan(), sourceOffsetX, width); + } + + /// + /// Reads the contents of the specified range from the current instance and writes them into a target array. + /// + /// The type of items stored on the texture. + /// The input instance to read data from. + /// The input array to write data to. + /// The starting offset within to write data to. + public static void CopyTo(this Texture1D source, T[] destination, int destinationOffset) + where T : unmanaged + { + Guard.IsNotNull(source); + Guard.IsNotNull(destination); + + source.CopyTo(destination.AsSpan(destinationOffset), 0, source.Width); + } + +#if NET6_0_OR_GREATER + /// + /// Reads the contents of the specified range from the current instance and writes them into a target array. + /// + /// The type of items stored on the texture. + /// The input instance to read data from. + /// The input array to write data to. + /// The starting offset within to write data to. + /// The horizontal range of items to copy. + public static void CopyTo(this Texture1D source, T[] destination, int destinationOffset, Range x) + where T : unmanaged + { + Guard.IsNotNull(source); + Guard.IsNotNull(destination); + + source.CopyTo(destination.AsSpan(destinationOffset), x); + } +#endif + + /// + /// Reads the contents of the specified range from the current instance and writes them into a target array. + /// + /// The type of items stored on the texture. + /// The input instance to read data from. + /// The input array to write data to. + /// The starting offset within to write data to. + /// The horizontal offset in the source texture. + /// The width of the memory area to copy. + public static void CopyTo(this Texture1D source, T[] destination, int destinationOffset, int sourceOffsetX, int width) + where T : unmanaged + { + Guard.IsNotNull(source); + Guard.IsNotNull(destination); + + source.CopyTo(destination.AsSpan(destinationOffset), sourceOffsetX, width); + } + + /// + /// Reads the contents of the current instance and writes them into a target . + /// The input data will be read from the start of the texture. + /// + /// The type of items stored on the texture. + /// The input instance to read data from. + /// The input to write data to. + public static void CopyTo(this Texture1D source, Span destination) + where T : unmanaged + { + Guard.IsNotNull(source); + + source.CopyTo(destination, 0, source.Width); + } + +#if NET6_0_OR_GREATER + /// + /// Reads the contents of the specified range from the current instance and writes them into a target . + /// + /// The type of items stored on the texture. + /// The input instance to read data from. + /// The input to write data to. + /// The horizontal range of items to copy. + public static void CopyTo(this Texture1D source, Span destination, Range x) + where T : unmanaged + { + Guard.IsNotNull(source); + + var (offsetX, width) = x.GetOffsetAndLength(source.Width); + + source.CopyTo(destination, offsetX, width); + } +#endif + + /// + /// Reads the contents of the specified range from the current instance and writes them into a target . + /// + /// The type of items stored on the texture. + /// The input instance to read data from. + /// The input to write data to. + /// The horizontal offset in the source texture. + /// The width of the memory area to copy. + public static void CopyTo(this Texture1D source, Span destination, int sourceOffsetX, int width) + where T : unmanaged + { + Guard.IsNotNull(source); + + source.CopyTo(ref MemoryMarshal.GetReference(destination), destination.Length, sourceOffsetX, width); + } + + /// + /// Reads the contents of a instance and writes them into a target instance. + /// + /// The type of items stored on the texture. + /// The input instance to read data from. + /// The target instance to write data to. + public static void CopyTo(this Texture1D source, Texture1D destination) + where T : unmanaged + { + Guard.IsNotNull(source); + Guard.IsNotNull(destination); + + source.CopyTo(destination, 0, 0, source.Width); + } + + /// + /// Reads the contents of a instance and writes them into a target instance. + /// + /// The type of items stored on the texture. + /// The input instance to read data from. + /// The target instance to write data to. + /// The horizontal offset in the source texture. + /// The width of the memory area to copy. + public static void CopyTo(this Texture1D source, Texture1D destination, int sourceOffsetX, int width) + where T : unmanaged + { + Guard.IsNotNull(source); + Guard.IsNotNull(destination); + + source.CopyTo(destination, sourceOffsetX, 0, width); + } + + /// + /// Reads the contents of a instance and writes them into a target instance. + /// + /// The type of items stored on the texture. + /// The input instance to read data from. + /// The target instance to write data to. + /// The horizontal offset in the source texture. + /// The horizontal offset in the destination texture. + /// The width of the memory area to copy. + public static void CopyTo(this Texture1D source, Texture1D destination, int sourceOffsetX, int destinationOffsetX, int width) + where T : unmanaged + { + Guard.IsNotNull(source); + Guard.IsNotNull(destination); + + source.CopyTo(destination, sourceOffsetX, destinationOffsetX, width); + } + + /// + /// Reads the contents of a instance and writes them into a target instance. + /// + /// The type of items stored on the texture. + /// The input instance to read data from. + /// The target instance to write data to. + public static void CopyTo(this Texture1D source, ReadBackTexture1D destination) + where T : unmanaged + { + Guard.IsNotNull(source); + Guard.IsNotNull(destination); + + source.CopyTo(destination, 0, 0, source.Width); + } + + /// + /// Reads the contents of a instance and writes them into a target instance. + /// + /// The type of items stored on the texture. + /// The input instance to read data from. + /// The target instance to write data to. + /// The horizontal offset in the source texture. + /// The width of the memory area to copy. + public static void CopyTo(this Texture1D source, ReadBackTexture1D destination, int sourceOffsetX, int width) + where T : unmanaged + { + Guard.IsNotNull(source); + Guard.IsNotNull(destination); + + source.CopyTo(destination, sourceOffsetX, 0, width); + } + + /// + /// Reads the contents of a instance and writes them into a target instance. + /// + /// The type of items stored on the texture. + /// The input instance to read data from. + /// The target instance to write data to. + /// The horizontal offset in the source texture. + /// The horizontal offset in the destination texture. + /// The width of the memory area to copy. + public static void CopyTo(this Texture1D source, ReadBackTexture1D destination, int sourceOffsetX, int destinationOffsetX, int width) + where T : unmanaged + { + Guard.IsNotNull(source); + Guard.IsNotNull(destination); + + source.CopyTo(destination, sourceOffsetX, destinationOffsetX, width); + } + + /// + /// Writes the contents of a given array to the current instance. + /// + /// The type of items stored on the texture. + /// The target instance to write data to. + /// The input array to read data from. + public static void CopyFrom(this Texture1D destination, T[] source) + where T : unmanaged + { + Guard.IsNotNull(destination); + Guard.IsNotNull(source); + + destination.CopyFrom(source.AsSpan(), 0, destination.Width); + } + +#if NET6_0_OR_GREATER + /// + /// Writes the contents of a given array to a specified area of the current instance. + /// + /// The type of items stored on the texture. + /// The target instance to write data to. + /// The input array to read data from. + /// The horizontal range of items to write. + public static void CopyFrom(this Texture1D destination, T[] source, Range x) + where T : unmanaged + { + Guard.IsNotNull(destination); + Guard.IsNotNull(source); + + destination.CopyFrom(source.AsSpan(), x); + } +#endif + + /// + /// Writes the contents of a given array to a specified area of the current instance. + /// + /// The type of items stored on the texture. + /// The target instance to write data to. + /// The input array to read data from. + /// The horizontal offset in the destination texture. + /// The width of the memory area to write to. + public static void CopyFrom(this Texture1D destination, T[] source, int destinationOffsetX, int width) + where T : unmanaged + { + Guard.IsNotNull(destination); + Guard.IsNotNull(source); + + destination.CopyFrom(source.AsSpan(), destinationOffsetX, width); + } + +#if NET6_0_OR_GREATER + /// + /// Writes the contents of a given array to a specified area of the current instance. + /// + /// The type of items stored on the texture. + /// The target instance to write data to. + /// The input array to read data from. + /// The starting offset within to read data from. + /// The horizontal range of items to write. + public static void CopyFrom(this Texture1D destination, T[] source, int sourceOffset, Range x) + where T : unmanaged + { + Guard.IsNotNull(destination); + Guard.IsNotNull(source); + + destination.CopyFrom(source.AsSpan(sourceOffset), x); + } +#endif + + /// + /// Writes the contents of a given array to a specified area of the current instance. + /// + /// The type of items stored on the texture. + /// The target instance to write data to. + /// The input array to read data from. + /// The starting offset within to read data from. + /// The horizontal offset in the destination texture. + /// The width of the memory area to write to. + public static void CopyFrom(this Texture1D destination, T[] source, int sourceOffset, int destinationOffsetX, int width) + where T : unmanaged + { + Guard.IsNotNull(destination); + Guard.IsNotNull(source); + + destination.CopyFrom(source.AsSpan(sourceOffset), destinationOffsetX, width); + } + + /// + /// Writes the contents of a given to the current instance. + /// The input data will be written to the start of the texture, and all input items will be copied. + /// + /// The type of items stored on the texture. + /// The target instance to write data to. + /// The input to read data from. + public static void CopyFrom(this Texture1D destination, ReadOnlySpan source) + where T : unmanaged + { + Guard.IsNotNull(destination); + + destination.CopyFrom(source, 0, destination.Width); + } + +#if NET6_0_OR_GREATER + /// + /// Writes the contents of a given to a specified area of the current instance. + /// + /// The type of items stored on the texture. + /// The target instance to write data to. + /// The input to read data from. + /// The horizontal range of items to write. + public static void CopyFrom(this Texture1D destination, ReadOnlySpan source, Range x) + where T : unmanaged + { + Guard.IsNotNull(destination); + + var (offsetX, width) = x.GetOffsetAndLength(destination.Width); + + destination.CopyFrom(source, offsetX, width); + } +#endif + + /// + /// Writes the contents of a given to a specified area of the current instance. + /// + /// The type of items stored on the texture. + /// The target instance to write data to. + /// The input to read data from. + /// The horizontal offset in the destination texture. + /// The width of the memory area to write to. + public static void CopyFrom(this Texture1D destination, ReadOnlySpan source, int destinationOffsetX, int width) + where T : unmanaged + { + Guard.IsNotNull(destination); + + destination.CopyFrom(ref MemoryMarshal.GetReference(source), source.Length, destinationOffsetX, width); + } + + /// + /// Reads the contents of an instance and writes them into a target instance. + /// + /// The type of items stored on the texture. + /// The target instance to write data to. + /// The input instance to read data from. + public static void CopyFrom(this Texture1D destination, Texture1D source) + where T : unmanaged + { + Guard.IsNotNull(destination); + Guard.IsNotNull(source); + + destination.CopyFrom(source, 0, 0, source.Width); + } + + /// + /// Reads the contents of an instance and writes them into a target instance. + /// + /// The type of items stored on the texture. + /// The target instance to write data to. + /// The input instance to read data from. + /// The horizontal offset in the source texture. + /// The width of the memory area to copy. + public static void CopyFrom(this Texture1D destination, Texture1D source, int sourceOffsetX, int width) + where T : unmanaged + { + Guard.IsNotNull(destination); + Guard.IsNotNull(source); + + source.CopyTo(destination, sourceOffsetX, 0, width); + } + + /// + /// Reads the contents of an instance and writes them into a target instance. + /// + /// The type of items stored on the texture. + /// The target instance to write data to. + /// The input instance to read data from. + /// The horizontal offset in the source texture. + /// The horizontal offset in the destination texture. + /// The width of the memory area to copy. + public static void CopyFrom(this Texture1D destination, Texture1D source, int sourceOffsetX, int destinationOffsetX, int width) + where T : unmanaged + { + Guard.IsNotNull(destination); + Guard.IsNotNull(source); + + source.CopyTo(destination, sourceOffsetX, destinationOffsetX, width); + } + + /// + /// Reads the contents of an instance and writes them into a target instance. + /// + /// The type of items stored on the texture. + /// The target instance to write data to. + /// The input instance to read data from. + public static void CopyFrom(this Texture1D destination, UploadTexture1D source) + where T : unmanaged + { + Guard.IsNotNull(destination); + Guard.IsNotNull(source); + + source.CopyTo(destination, 0, 0, source.Width); + } + + /// + /// Reads the contents of an instance and writes them into a target instance. + /// + /// The type of items stored on the texture. + /// The target instance to write data to. + /// The input instance to read data from. + /// The horizontal offset in the source texture. + /// The width of the memory area to copy. + public static void CopyFrom(this Texture1D destination, UploadTexture1D source, int sourceOffsetX, int width) + where T : unmanaged + { + Guard.IsNotNull(destination); + Guard.IsNotNull(source); + + destination.CopyFrom(source, sourceOffsetX, 0, width); + } + + /// + /// Reads the contents of an instance and writes them into a target instance. + /// + /// The type of items stored on the texture. + /// The target instance to write data to. + /// The input instance to read data from. + /// The horizontal offset in the source texture. + /// The horizontal offset in the destination texture. + /// The width of the memory area to copy. + public static void CopyFrom(this Texture1D destination, UploadTexture1D source, int sourceOffsetX, int destinationOffsetX, int width) + where T : unmanaged + { + Guard.IsNotNull(destination); + Guard.IsNotNull(source); + + destination.CopyFrom(source, sourceOffsetX, destinationOffsetX, width); + } +} diff --git a/src/ComputeSharp/Graphics/Extensions/UploadTexture1DExtensions.cs b/src/ComputeSharp/Graphics/Extensions/UploadTexture1DExtensions.cs new file mode 100644 index 00000000..87f160f9 --- /dev/null +++ b/src/ComputeSharp/Graphics/Extensions/UploadTexture1DExtensions.cs @@ -0,0 +1,60 @@ +using CommunityToolkit.Diagnostics; +using ComputeSharp.Resources; + +namespace ComputeSharp; + +/// +/// A that contains extension methods for the type. +/// +public static class UploadTexture1DExtensions +{ + /// + /// Reads the contents of a instance and writes them into a target instance. + /// + /// The type of items stored on the texture. + /// The input instance to read data from. + /// The target instance to write data to. + public static void CopyTo(this UploadTexture1D source, Texture1D destination) + where T : unmanaged + { + Guard.IsNotNull(source); + Guard.IsNotNull(destination); + + destination.CopyFrom(source, 0, 0, source.Width); + } + + /// + /// Reads the contents of a instance and writes them into a target instance. + /// + /// The type of items stored on the texture. + /// The input instance to read data from. + /// The target instance to write data to. + /// The horizontal offset in the source texture. + /// The width of the memory area to copy. + public static void CopyTo(this UploadTexture1D source, Texture1D destination, int sourceOffsetX, int width) + where T : unmanaged + { + Guard.IsNotNull(source); + Guard.IsNotNull(destination); + + destination.CopyFrom(source, sourceOffsetX, 0, width); + } + + /// + /// Reads the contents of a instance and writes them into a target instance. + /// + /// The type of items stored on the texture. + /// The input instance to read data from. + /// The target instance to write data to. + /// The horizontal offset in the source texture. + /// The horizontal offset in the destination texture. + /// The width of the memory area to copy. + public static void CopyTo(this UploadTexture1D source, Texture1D destination, int sourceOffsetX, int destinationOffsetX, int width) + where T : unmanaged + { + Guard.IsNotNull(source); + Guard.IsNotNull(destination); + + destination.CopyFrom(source, sourceOffsetX, destinationOffsetX, width); + } +} diff --git a/src/ComputeSharp/Shaders/Extensions/ComputeContextExtensions.cs b/src/ComputeSharp/Shaders/Extensions/ComputeContextExtensions.cs index 6b6bc55f..1cc635f9 100644 --- a/src/ComputeSharp/Shaders/Extensions/ComputeContextExtensions.cs +++ b/src/ComputeSharp/Shaders/Extensions/ComputeContextExtensions.cs @@ -30,6 +30,22 @@ public static class ComputeContextExtensions context.Barrier(buffer.ValidateAndGetID3D12Resource(context.GraphicsDevice, out Unsafe.AsRef(in lease))); } + /// + /// 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 Barrier(this in ComputeContext context, ReadWriteTexture1D texture) + where T : unmanaged + { + Guard.IsNotNull(texture); + + using NativeObject.Lease lease = default; + + context.Barrier(texture.ValidateAndGetID3D12Resource(context.GraphicsDevice, out Unsafe.AsRef(in lease))); + } + /// /// Inserts a resource barrier for a specific resource. /// @@ -62,6 +78,24 @@ public static class ComputeContextExtensions context.Barrier(texture.ValidateAndGetID3D12Resource(context.GraphicsDevice, out Unsafe.AsRef(in lease))); } + /// + /// 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 Barrier(this in ComputeContext context, ReadWriteTexture1D texture) + where T : unmanaged, IPixel + where TPixel : unmanaged + { + Guard.IsNotNull(texture); + + using NativeObject.Lease lease = default; + + context.Barrier(texture.ValidateAndGetID3D12Resource(context.GraphicsDevice, out Unsafe.AsRef(in lease))); + } + /// /// Inserts a resource barrier for a specific resource. /// @@ -98,6 +132,22 @@ public static class ComputeContextExtensions context.Barrier(texture.ValidateAndGetID3D12Resource(context.GraphicsDevice, out Unsafe.AsRef(in lease))); } + /// + /// 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 Barrier(this in ComputeContext context, IReadWriteNormalizedTexture1D texture) + where TPixel : unmanaged + { + Guard.IsNotNull(texture); + + using NativeObject.Lease lease = default; + + context.Barrier(((GraphicsResourceHelper.IGraphicsResource)texture).ValidateAndGetID3D12Resource(context.GraphicsDevice, out Unsafe.AsRef(in lease))); + } + /// /// Inserts a resource barrier for a specific resource. /// @@ -146,6 +196,22 @@ public static class ComputeContextExtensions context.Clear(buffer.D3D12Resource, handles.Gpu, handles.Cpu, isNormalized: false); } + /// + /// Clears a specific resource. + /// + /// The type of items stored on the texture. + /// The to use to clear the resource. + /// The input instance to clear. + public static unsafe void Clear(this in ComputeContext context, ReadWriteTexture1D texture) + where T : unmanaged + { + Guard.IsNotNull(texture); + + var handles = texture.ValidateAndGetGpuAndCpuDescriptorHandlesForClear(context.GraphicsDevice, out bool isNormalized); + + context.Clear(texture.D3D12Resource, handles.Gpu, handles.Cpu, isNormalized); + } + /// /// Clears a specific resource. /// @@ -178,6 +244,24 @@ public static class ComputeContextExtensions context.Clear(texture.D3D12Resource, handles.Gpu, handles.Cpu, isNormalized); } + /// + /// Clears a specific resource. + /// + /// The type of items stored on the texture. + /// The type of pixels used on the GPU side. + /// The to use to clear the resource. + /// The input instance to clear. + public static unsafe void Clear(this in ComputeContext context, ReadWriteTexture1D texture) + where T : unmanaged, IPixel + where TPixel : unmanaged + { + Guard.IsNotNull(texture); + + var handles = texture.ValidateAndGetGpuAndCpuDescriptorHandlesForClear(context.GraphicsDevice, out _); + + context.Clear(texture.D3D12Resource, handles.Gpu, handles.Cpu, true); + } + /// /// Clears a specific resource. /// @@ -214,6 +298,24 @@ public static class ComputeContextExtensions context.Clear(texture.D3D12Resource, handles.Gpu, handles.Cpu, true); } + /// + /// Clears a specific resource. + /// + /// The type of pixels stored on the texture. + /// The to use to clear the resource. + /// The input instance to clear. + public static unsafe void Clear(this in ComputeContext context, IReadWriteNormalizedTexture1D texture) + where TPixel : unmanaged + { + Guard.IsNotNull(texture); + + var handles = ((GraphicsResourceHelper.IGraphicsResource)texture).ValidateAndGetGpuAndCpuDescriptorHandlesForClear(context.GraphicsDevice, out _); + + using NativeObject.Lease lease = default; + + context.Clear(((GraphicsResourceHelper.IGraphicsResource)texture).ValidateAndGetID3D12Resource(context.GraphicsDevice, out Unsafe.AsRef(in lease)), handles.Gpu, handles.Cpu, true); + } + /// /// Clears a specific resource. /// @@ -250,6 +352,25 @@ public static class ComputeContextExtensions context.Clear(((GraphicsResourceHelper.IGraphicsResource)texture).ValidateAndGetID3D12Resource(context.GraphicsDevice, out Unsafe.AsRef(in lease)), handles.Gpu, handles.Cpu, true); } + /// + /// Fills a specific texture with a given value. + /// + /// The type of items stored on the texture. + /// The type of pixels used on the GPU side. + /// The to use to fill the resource. + /// The input instance to fill. + /// The value to use to fill . + public static unsafe void Fill(this in ComputeContext context, ReadWriteTexture1D texture, T value) + where T : unmanaged, IPixel + where TPixel : unmanaged + { + Guard.IsNotNull(texture); + + var handles = texture.ValidateAndGetGpuAndCpuDescriptorHandlesForClear(context.GraphicsDevice, out _); + + context.Fill(texture.D3D12Resource, handles.Gpu, handles.Cpu, DXGIFormatHelper.ExtendToNormalizedValue(value.ToPixel())); + } + /// /// Fills a specific texture with a given value. /// @@ -288,6 +409,29 @@ public static class ComputeContextExtensions context.Fill(texture.D3D12Resource, handles.Gpu, handles.Cpu, DXGIFormatHelper.ExtendToNormalizedValue(value.ToPixel())); } + /// + /// Fills a specific texture with a given value. + /// + /// The type of pixels stored on the texture. + /// The to use to fill the resource. + /// The input instance to fill. + /// The value to use to fill . + public static unsafe void Fill(this in ComputeContext context, IReadWriteNormalizedTexture1D texture, TPixel value) + where TPixel : unmanaged + { + Guard.IsNotNull(texture); + + var handles = ((GraphicsResourceHelper.IGraphicsResource)texture).ValidateAndGetGpuAndCpuDescriptorHandlesForClear(context.GraphicsDevice, out _); + + using NativeObject.Lease lease = default; + + context.Fill( + ((GraphicsResourceHelper.IGraphicsResource)texture).ValidateAndGetID3D12Resource(context.GraphicsDevice, out Unsafe.AsRef(in lease)), + handles.Gpu, + handles.Cpu, + DXGIFormatHelper.ExtendToNormalizedValue(value)); + } + /// /// Fills a specific texture with a given value. /// @@ -427,6 +571,95 @@ public static class ComputeContextExtensions context.Run(texture, ref Unsafe.AsRef(in shader)); } + /// + /// Transitions the state of a specific resource. + /// + /// The to use to transition the resource. + /// The input instance to transition. + /// The state to transition the input resource to. + public static unsafe void Transition(this in ComputeContext context, ReadWriteTexture1D texture, ResourceState resourceState) + { + Guard.IsNotNull(texture); + + using NativeObject.Lease lease = default; + + var states = texture.ValidateAndGetID3D12ResourceAndTransitionStates(context.GraphicsDevice, resourceState, out ID3D12Resource* d3D12Resource, out Unsafe.AsRef(in lease)); + + context.Transition(d3D12Resource, states.Before, states.After); + } + + /// + /// Transitions the state of a specific resource. + /// + /// The to use to transition the resource. + /// The input instance to transition. + /// The state to transition the input resource to. + public static unsafe void Transition(this in ComputeContext context, ReadWriteTexture1D texture, ResourceState resourceState) + { + Guard.IsNotNull(texture); + + using NativeObject.Lease lease = default; + + var states = texture.ValidateAndGetID3D12ResourceAndTransitionStates(context.GraphicsDevice, resourceState, out ID3D12Resource* d3D12Resource, out Unsafe.AsRef(in lease)); + + context.Transition(d3D12Resource, states.Before, states.After); + } + + /// + /// Transitions the state of a specific resource. + /// + /// The to use to transition the resource. + /// The input instance to transition. + /// The state to transition the input resource to. + public static unsafe void Transition(this in ComputeContext context, ReadWriteTexture1D texture, ResourceState resourceState) + { + Guard.IsNotNull(texture); + + using NativeObject.Lease lease = default; + + var states = texture.ValidateAndGetID3D12ResourceAndTransitionStates(context.GraphicsDevice, resourceState, out ID3D12Resource* d3D12Resource, out Unsafe.AsRef(in lease)); + + context.Transition(d3D12Resource, states.Before, states.After); + } + + /// + /// Transitions the state of a specific resource. + /// + /// The to use to transition the resource. + /// The input instance to transition. + /// The state to transition the input resource to. + public static unsafe void Transition(this in ComputeContext context, ReadWriteTexture1D texture, ResourceState resourceState) + { + Guard.IsNotNull(texture); + + using NativeObject.Lease lease = default; + + var states = texture.ValidateAndGetID3D12ResourceAndTransitionStates(context.GraphicsDevice, resourceState, out ID3D12Resource* d3D12Resource, out Unsafe.AsRef(in lease)); + + context.Transition(d3D12Resource, states.Before, states.After); + } + + /// + /// Transitions the state of a specific resource. + /// + /// The type of items stored on the texture. + /// The type of pixels used on the GPU side. + /// The to use to transition the resource. + /// The input instance to transition. + /// The state to transition the input resource to. + public static unsafe void Transition(this in ComputeContext context, ReadWriteTexture1D texture, ResourceState resourceState) + where T : unmanaged, IPixel + where TPixel : unmanaged + { + Guard.IsNotNull(texture); + + using NativeObject.Lease lease = default; + + var states = texture.ValidateAndGetID3D12ResourceAndTransitionStates(context.GraphicsDevice, resourceState, out ID3D12Resource* d3D12Resource, out Unsafe.AsRef(in lease)); + + context.Transition(d3D12Resource, states.Before, states.After); + } + /// /// Transitions the state of a specific resource. /// @@ -590,7 +823,7 @@ public static class ComputeContextExtensions /// The type of items stored on the texture. /// The type of pixels used on the GPU side. /// The to use to transition the resource. - /// The input instance to transition. + /// The input instance to transition. /// The state to transition the input resource to. public static unsafe void Transition(this in ComputeContext context, ReadWriteTexture3D texture, ResourceState resourceState) where T : unmanaged, IPixel