From 0b6d2b0ddf14e8d63fb4ad4c3586043fa86b3c8e Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 29 Aug 2022 00:58:59 +0200 Subject: [PATCH] Add readback and upload transfer texture 1D types --- .../Debug/TransferTexture1DDebugView{T}.cs | 26 +++++++++++++++ .../Resources/ReadBackTexture1D{T}.cs | 33 +++++++++++++++++++ .../Graphics/Resources/UploadTexture1D{T}.cs | 33 +++++++++++++++++++ 3 files changed, 92 insertions(+) create mode 100644 src/ComputeSharp/Graphics/Resources/Debug/TransferTexture1DDebugView{T}.cs create mode 100644 src/ComputeSharp/Graphics/Resources/ReadBackTexture1D{T}.cs create mode 100644 src/ComputeSharp/Graphics/Resources/UploadTexture1D{T}.cs diff --git a/src/ComputeSharp/Graphics/Resources/Debug/TransferTexture1DDebugView{T}.cs b/src/ComputeSharp/Graphics/Resources/Debug/TransferTexture1DDebugView{T}.cs new file mode 100644 index 00000000..7b277889 --- /dev/null +++ b/src/ComputeSharp/Graphics/Resources/Debug/TransferTexture1DDebugView{T}.cs @@ -0,0 +1,26 @@ +using System.Diagnostics; + +namespace ComputeSharp.Resources.Debug; + +/// +/// A debug proxy used to display items in a instance. +/// +/// The type of items to display. +internal sealed class TransferTexture1DDebugView + where T : unmanaged +{ + /// + /// Initializes a new instance of the class with the specified parameters. + /// + /// The input instance with the items to display. + public TransferTexture1DDebugView(TransferTexture1D? texture) + { + Items = texture?.Span.ToArray(); + } + + /// + /// Gets the items to display for the current instance. + /// + [DebuggerBrowsable(DebuggerBrowsableState.Collapsed)] + public T[]? Items { get; } +} diff --git a/src/ComputeSharp/Graphics/Resources/ReadBackTexture1D{T}.cs b/src/ComputeSharp/Graphics/Resources/ReadBackTexture1D{T}.cs new file mode 100644 index 00000000..7ee3a5f9 --- /dev/null +++ b/src/ComputeSharp/Graphics/Resources/ReadBackTexture1D{T}.cs @@ -0,0 +1,33 @@ +using System.Diagnostics; +using ComputeSharp.Graphics.Resources.Enums; +using ComputeSharp.Resources; +using ComputeSharp.Resources.Debug; + +namespace ComputeSharp; + +/// +/// A representing a typed 1D texture stored on CPU memory, that can be used to transfer back from the GPU. +/// +/// The type of items stored on the texture. +[DebuggerTypeProxy(typeof(TransferTexture1DDebugView<>))] +[DebuggerDisplay("{ToString(),raw}")] +public sealed class ReadBackTexture1D : TransferTexture1D + where T : unmanaged +{ + /// + /// Creates a new instance with the specified parameters. + /// + /// The associated with the current instance. + /// The width of the texture. + /// The allocation mode to use for the new resource. + internal ReadBackTexture1D(GraphicsDevice device, int width, AllocationMode allocationMode) + : base(device, width, ResourceType.ReadBack, allocationMode) + { + } + + /// + public override string ToString() + { + return $"ComputeSharp.ReadBackTexture1D<{typeof(T)}>[{Width}]"; + } +} diff --git a/src/ComputeSharp/Graphics/Resources/UploadTexture1D{T}.cs b/src/ComputeSharp/Graphics/Resources/UploadTexture1D{T}.cs new file mode 100644 index 00000000..53f6a43d --- /dev/null +++ b/src/ComputeSharp/Graphics/Resources/UploadTexture1D{T}.cs @@ -0,0 +1,33 @@ +using System.Diagnostics; +using ComputeSharp.Graphics.Resources.Enums; +using ComputeSharp.Resources; +using ComputeSharp.Resources.Debug; + +namespace ComputeSharp; + +/// +/// A representing a typed 1D texture stored on CPU memory, that can be used to transfer data to the GPU. +/// +/// The type of items stored on the texture. +[DebuggerTypeProxy(typeof(TransferTexture1DDebugView<>))] +[DebuggerDisplay("{ToString(),raw}")] +public sealed class UploadTexture1D : TransferTexture1D + where T : unmanaged +{ + /// + /// Creates a new instance with the specified parameters. + /// + /// The associated with the current instance. + /// The width of the texture. + /// The allocation mode to use for the new resource. + internal UploadTexture1D(GraphicsDevice device, int width, AllocationMode allocationMode) + : base(device, width, ResourceType.Upload, allocationMode) + { + } + + /// + public override string ToString() + { + return $"ComputeSharp.UploadTexture1D<{typeof(T)}>[{Width}]"; + } +}