diff --git a/src/ComputeSharp.Graphics/Buffers/Abstract/Buffer{T}.cs b/src/ComputeSharp.Graphics/Buffers/Abstract/Buffer{T}.cs index b936fb89..bec1c62b 100644 --- a/src/ComputeSharp.Graphics/Buffers/Abstract/Buffer{T}.cs +++ b/src/ComputeSharp.Graphics/Buffers/Abstract/Buffer{T}.cs @@ -106,7 +106,10 @@ namespace ComputeSharp.Graphics.Buffers.Abstract /// /// A array with the contents of the current buffer. [Pure] - public T[] GetData() => GetData(0, Length); + public T[] GetData() + { + return GetData(0, Length); + } /// /// Reads the contents of the current instance in a given range and returns an array. @@ -130,7 +133,10 @@ namespace ComputeSharp.Graphics.Buffers.Abstract /// Reads the contents of the current instance and writes them into a target array. /// /// The input array to write data to. - public void GetData(T[] destination) => GetData(destination.AsSpan(), 0); + public void GetData(T[] destination) + { + GetData(destination.AsSpan(), 0); + } /// /// Reads the contents of the specified range from the current instance and writes them into a target array. @@ -151,7 +157,10 @@ namespace ComputeSharp.Graphics.Buffers.Abstract /// The input data will be read from the start of the buffer. /// /// The input to write data to. - public void GetData(Span destination) => GetData(destination, 0); + public void GetData(Span destination) + { + GetData(destination, 0); + } /// /// Reads the contents of the specified range from the current instance and writes them into a target . @@ -164,7 +173,10 @@ namespace ComputeSharp.Graphics.Buffers.Abstract /// Writes the contents of a given array to the current instance. /// /// The input array to read data from. - public void SetData(T[] source) => SetData(source.AsSpan()); + public void SetData(T[] source) + { + SetData(source.AsSpan()); + } /// /// Writes the contents of a given array to a specified area of the current instance. @@ -185,7 +197,10 @@ namespace ComputeSharp.Graphics.Buffers.Abstract /// The input data will be written to the start of the buffer, and all input items will be copied. /// /// The input to read data from. - public void SetData(ReadOnlySpan source) => SetData(source, 0); + public void SetData(ReadOnlySpan source) + { + SetData(source, 0); + } /// /// Writes the contents of a given to a specified area of the current instance. diff --git a/src/ComputeSharp.Graphics/Buffers/Abstract/Texture2D{T}.cs b/src/ComputeSharp.Graphics/Buffers/Abstract/Texture2D{T}.cs index 1b25acfa..3c4ebe2b 100644 --- a/src/ComputeSharp.Graphics/Buffers/Abstract/Texture2D{T}.cs +++ b/src/ComputeSharp.Graphics/Buffers/Abstract/Texture2D{T}.cs @@ -1,4 +1,6 @@ -using System.Runtime.CompilerServices; +using System; +using System.Diagnostics.Contracts; +using System.Runtime.CompilerServices; using ComputeSharp.Core.Interop; using ComputeSharp.Exceptions; using ComputeSharp.Graphics.Buffers.Enums; @@ -79,6 +81,246 @@ namespace ComputeSharp.Graphics.Buffers.Abstract /// internal ID3D12Resource* D3D12Resource => this.d3D12Resource; + /// + /// Reads the contents of the current instance and returns an array. + /// + /// A array with the contents of the current buffer. + [Pure] + public T[,] GetData() + { + T[,] data = new T[Height, Width]; + + GetData(data); + + return data; + } + + /// + /// Reads the contents of the current instance and writes them into a target array. + /// + /// The input array to write data to. + public void GetData(T[,] destination) + { + fixed (T* p = destination) + { + GetData(new Span(p, destination.Length)); + } + } + + /// + /// Reads the contents of the specified range from the current instance and writes them into a target array. + /// + /// The input array to write data to. + public void GetData(T[] destination) + { + GetData(destination.AsSpan(), 0, 0, Width, Height); + } + + /// + /// Reads the contents of the specified range from the current instance and writes them into a target array. + /// + /// The input array to write data to. + /// The horizontal range of items to copy. + /// The vertical range of items to copy. + public void GetData(T[] destination, Range x, Range y) + { + GetData(destination.AsSpan(), x, y); + } + + /// + /// Reads the contents of the specified range from the current instance and writes them into a target array. + /// + /// The input array 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 void GetData(T[] destination, int x, int y, int width, int height) + { + GetData(destination.AsSpan(), x, y, width, height); + } + + /// + /// Reads the contents of the specified range from the current instance and writes them into a target array. + /// + /// The input array to write data to. + /// The starting offset within to write data to. + public void GetData(T[] destination, int offset) + { + GetData(destination.AsSpan(offset), 0, 0, Width, Height); + } + + /// + /// Reads the contents of the specified range from the current instance and writes them into a target array. + /// + /// The input array to write data to. + /// The starting offset within to write data to. + /// The horizontal range of items to copy. + /// The vertical range of items to copy. + public void GetData(T[] destination, int offset, Range x, Range y) + { + GetData(destination.AsSpan(offset), x, y); + } + + /// + /// Reads the contents of the specified range from the current instance and writes them into a target array. + /// + /// The input array to write data to. + /// The starting offset within 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 void GetData(T[] destination, int offset, int x, int y, int width, int height) + { + GetData(destination.AsSpan(offset), x, y, width, height); + } + + /// + /// 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 input to write data to. + public void GetData(Span destination) + { + GetData(destination, 0, 0, Width, Height); + } + + /// + /// Reads the contents of the specified range from the current instance and writes them into a target . + /// + /// The input to write data to. + /// The horizontal range of items to copy. + /// The vertical range of items to copy. + public void GetData(Span destination, Range x, Range y) + { + var (offsetX, width) = x.GetOffsetAndLength(Width); + var (offsetY, height) = y.GetOffsetAndLength(Height); + + GetData(destination, offsetX, offsetY, width, height); + } + + /// + /// Reads the contents of the specified range from the current instance and writes them into a target . + /// + /// The input 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 void GetData(Span destination, int x, int y, int width, int height) + { + // TODO + } + + /// + /// Writes the contents of a given array to the current instance. + /// + /// The input array to read data from. + public void SetData(T[,] source) + { + fixed (T* p = source) + { + SetData(new Span(p, source.Length)); + } + } + + /// + /// Writes the contents of a given array to the current instance. + /// + /// The input array to read data from. + public void SetData(T[] source) + { + SetData(source.AsSpan(), 0, 0, Width, Height); + } + + /// + /// Writes the contents of a given array to a specified area of the current instance. + /// + /// The input array to read data from. + /// The horizontal range of items to write. + /// The vertical range of items to write. + public void SetData(T[] source, Range x, Range y) + { + SetData(source.AsSpan(), x, y); + } + + /// + /// Writes the contents of a given array to a specified area of the current instance. + /// + /// The input array to read data from. + /// The horizontal offset in the destination texture. + /// The vertical offset in the destination texture. + /// The width of the memory area to write to. + /// The height of the memory area to write to. + public void SetData(T[] source, int x, int y, int width, int height) + { + SetData(source.AsSpan(), x, y, width, height); + } + + /// + /// Writes the contents of a given array to a specified area of the current instance. + /// + /// The input array to read data from. + /// The starting offset within to read data from. + /// The horizontal range of items to write. + /// The vertical range of items to write. + public void SetData(T[] source, int offset, Range x, Range y) + { + SetData(source.AsSpan(offset), x, y); + } + + /// + /// Writes the contents of a given array to a specified area of the current instance. + /// + /// The input array to read data from. + /// The starting offset within to read data from. + /// The horizontal offset in the destination texture. + /// The vertical offset in the destination texture. + /// The width of the memory area to write to. + /// The height of the memory area to write to. + public void SetData(T[] source, int offset, int x, int y, int width, int height) + { + SetData(source.AsSpan(offset), x, y, width, height); + } + + /// + /// 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 input to read data from. + public void SetData(ReadOnlySpan source) + { + SetData(source, 0, 0, Width, Height); + } + + /// + /// Writes the contents of a given to a specified area of the current instance. + /// + /// The input to read data from. + /// The horizontal range of items to write. + /// The vertical range of items to write. + public void SetData(ReadOnlySpan source, Range x, Range y) + { + var (offsetX, width) = x.GetOffsetAndLength(Width); + var (offsetY, height) = y.GetOffsetAndLength(Height); + + SetData(source, offsetX, offsetY, width, height); + } + + /// + /// Writes the contents of a given to a specified area of the current instance. + /// + /// The input to read data from. + /// The horizontal offset in the destination texture. + /// The vertical offset in the destination texture. + /// The width of the memory area to write to. + /// The height of the memory area to write to. + public void SetData(ReadOnlySpan source, int x, int y, int width, int height) + { + // TODO + } + /// protected override void OnDispose() {