From 914dd052b7ffbecdd9f10657b3fdd98fccd0ff4e Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Thu, 4 Feb 2021 16:03:50 +0100 Subject: [PATCH] Added extensions for texture transfer types --- .../Resources/Abstract/Texture3D{T}.cs | 6 +-- .../Resources/StructuredBufferExtensions.cs | 4 +- .../Resources/Texture2DExtensions.cs | 28 +++++++++++++ .../Resources/Texture3DExtensions.cs | 30 ++++++++++++++ .../Resources/UploadBufferExtensions.cs | 4 +- .../Resources/UploadTexture2DExtensions.cs | 38 ++++++++++++++++++ .../Resources/UploadTexture3DExtensions.cs | 40 +++++++++++++++++++ 7 files changed, 140 insertions(+), 10 deletions(-) create mode 100644 src/ComputeSharp/Extensions/Resources/UploadTexture2DExtensions.cs create mode 100644 src/ComputeSharp/Extensions/Resources/UploadTexture3DExtensions.cs diff --git a/src/ComputeSharp.Graphics/Resources/Abstract/Texture3D{T}.cs b/src/ComputeSharp.Graphics/Resources/Abstract/Texture3D{T}.cs index 4459aea0..38ab5e29 100644 --- a/src/ComputeSharp.Graphics/Resources/Abstract/Texture3D{T}.cs +++ b/src/ComputeSharp.Graphics/Resources/Abstract/Texture3D{T}.cs @@ -214,14 +214,13 @@ namespace ComputeSharp.Resources /// Reads the contents of the specified range from the current instance and writes them into a instance. /// /// The target instance to write data to. - /// The size of the memory area to write data to. /// The horizontal offset in the source texture. /// The vertical offset in the source texture. /// The depthwise offset in the source texture. /// The width of the memory area to copy. /// The height of the memory area to copy. /// The depth of the memory area to copy. - internal void CopyTo(ReadBackTexture3D destination, int size, int x, int y, int z, int width, int height, int depth) + internal void CopyTo(ReadBackTexture3D destination, int x, int y, int z, int width, int height, int depth) { GraphicsDevice.ThrowIfDisposed(); @@ -355,14 +354,13 @@ namespace ComputeSharp.Resources /// Writes the contents of a given instance to a specified area of the current instance. /// /// The input instance to read data from. - /// The size of the memory area to read data from. /// The horizontal offset in the destination texture. /// The vertical offset in the destination texture. /// The depthwise offseet in the destination texture. /// The width of the memory area to write to. /// The height of the memory area to write to. /// The depth of the memory area to write to. - internal void CopyFrom(ReadBackTexture3D source, int size, int x, int y, int z, int width, int height, int depth) + internal void CopyFrom(UploadTexture3D source, int x, int y, int z, int width, int height, int depth) { GraphicsDevice.ThrowIfDisposed(); diff --git a/src/ComputeSharp/Extensions/Resources/StructuredBufferExtensions.cs b/src/ComputeSharp/Extensions/Resources/StructuredBufferExtensions.cs index 3e6e8a79..90288139 100644 --- a/src/ComputeSharp/Extensions/Resources/StructuredBufferExtensions.cs +++ b/src/ComputeSharp/Extensions/Resources/StructuredBufferExtensions.cs @@ -1,5 +1,4 @@ -using System.Diagnostics.Contracts; -using ComputeSharp.Resources; +using ComputeSharp.Resources; namespace ComputeSharp { @@ -14,7 +13,6 @@ namespace ComputeSharp /// The type of items stored on the buffer. /// The input instance to read data from. /// The target instance to write data to. - [Pure] public static void CopyTo(this StructuredBuffer buffer, ReadBackBuffer destination) where T : unmanaged { diff --git a/src/ComputeSharp/Extensions/Resources/Texture2DExtensions.cs b/src/ComputeSharp/Extensions/Resources/Texture2DExtensions.cs index ef7c5a96..09764937 100644 --- a/src/ComputeSharp/Extensions/Resources/Texture2DExtensions.cs +++ b/src/ComputeSharp/Extensions/Resources/Texture2DExtensions.cs @@ -176,6 +176,34 @@ namespace ComputeSharp texture.CopyTo(ref MemoryMarshal.GetReference(destination), destination.Length, x, y, width, height); } + /// + /// 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 Texture2D texture, ReadBackTexture2D destination) + where T : unmanaged + { + texture.CopyTo(destination, 0, 0, texture.Width, texture.Height); + } + + /// + /// 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 vertical offset in the source texture. + /// The width of the memory area to copy. + /// The height of the memory area to copy. + public static void CopyTo(this Texture2D texture, ReadBackTexture2D destination, int x, int y, int width, int height) + where T : unmanaged + { + texture.CopyTo(destination, x, y, width, height); + } + /// /// Writes the contents of a given array to the current instance. /// diff --git a/src/ComputeSharp/Extensions/Resources/Texture3DExtensions.cs b/src/ComputeSharp/Extensions/Resources/Texture3DExtensions.cs index fc7ab4ad..e760251c 100644 --- a/src/ComputeSharp/Extensions/Resources/Texture3DExtensions.cs +++ b/src/ComputeSharp/Extensions/Resources/Texture3DExtensions.cs @@ -150,6 +150,36 @@ namespace ComputeSharp texture.CopyTo(ref MemoryMarshal.GetReference(destination), destination.Length, x, y, z, width, height, depth); } + /// + /// 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 Texture3D texture, ReadBackTexture3D destination) + where T : unmanaged + { + texture.CopyTo(destination, 0, 0, 0, texture.Width, texture.Height, texture.Depth); + } + + /// + /// 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 vertical offset in the source texture. + /// The depthwise offset in the source texture. + /// The width of the memory area to copy. + /// The height of the memory area to copy. + /// The depth of the memory area to copy. + public static void CopyTo(this Texture3D texture, ReadBackTexture3D destination, int x, int y, int z, int width, int height, int depth) + where T : unmanaged + { + texture.CopyTo(destination, x, y, z, width, height, depth); + } + /// /// Writes the contents of a given array to the current instance. /// diff --git a/src/ComputeSharp/Extensions/Resources/UploadBufferExtensions.cs b/src/ComputeSharp/Extensions/Resources/UploadBufferExtensions.cs index e05e1fe3..113b1c43 100644 --- a/src/ComputeSharp/Extensions/Resources/UploadBufferExtensions.cs +++ b/src/ComputeSharp/Extensions/Resources/UploadBufferExtensions.cs @@ -1,5 +1,4 @@ -using System.Diagnostics.Contracts; -using ComputeSharp.Resources; +using ComputeSharp.Resources; namespace ComputeSharp { @@ -14,7 +13,6 @@ namespace ComputeSharp /// The type of items stored on the buffer. /// The input instance to read data from. /// The target instance to write data to. - [Pure] public static void CopyTo(this UploadBuffer buffer, StructuredBuffer destination) where T : unmanaged { diff --git a/src/ComputeSharp/Extensions/Resources/UploadTexture2DExtensions.cs b/src/ComputeSharp/Extensions/Resources/UploadTexture2DExtensions.cs new file mode 100644 index 00000000..a111e454 --- /dev/null +++ b/src/ComputeSharp/Extensions/Resources/UploadTexture2DExtensions.cs @@ -0,0 +1,38 @@ +using ComputeSharp.Resources; + +namespace ComputeSharp +{ + /// + /// A that contains extension methods for the type. + /// + public static class UploadTexture2DExtensions + { + /// + /// 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 UploadTexture2D texture, Texture2D destination) + where T : unmanaged + { + destination.CopyFrom(texture, 0, 0, texture.Width, texture.Height); + } + + /// + /// 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 vertical offset in the source texture. + /// The width of the memory area to copy. + /// The height of the memory area to copy. + public static void CopyTo(this UploadTexture2D texture, Texture2D destination, int x, int y, int width, int height) + where T : unmanaged + { + destination.CopyFrom(texture, x, y, width, height); + } + } +} diff --git a/src/ComputeSharp/Extensions/Resources/UploadTexture3DExtensions.cs b/src/ComputeSharp/Extensions/Resources/UploadTexture3DExtensions.cs new file mode 100644 index 00000000..ad8bf455 --- /dev/null +++ b/src/ComputeSharp/Extensions/Resources/UploadTexture3DExtensions.cs @@ -0,0 +1,40 @@ +using ComputeSharp.Resources; + +namespace ComputeSharp +{ + /// + /// A that contains extension methods for the type. + /// + public static class UploadTexture3DExtensions + { + /// + /// 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 UploadTexture3D texture, Texture3D destination) + where T : unmanaged + { + destination.CopyFrom(texture, 0, 0, 0, texture.Width, texture.Height, texture.Depth); + } + + /// + /// 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 vertical offset in the source texture. + /// The depthwise offset in the source texture. + /// The width of the memory area to copy. + /// The height of the memory area to copy. + /// The depth of the memory area to copy. + public static void CopyTo(this UploadTexture3D texture, Texture3D destination, int x, int y, int z, int width, int height, int depth) + where T : unmanaged + { + destination.CopyFrom(texture, x, y, z, width, height, depth); + } + } +}