diff --git a/src/ComputeSharp/Graphics/Resources/Debug/Texture1DDebugView{T}.cs b/src/ComputeSharp/Graphics/Resources/Debug/Texture1DDebugView{T}.cs new file mode 100644 index 00000000..a36c242d --- /dev/null +++ b/src/ComputeSharp/Graphics/Resources/Debug/Texture1DDebugView{T}.cs @@ -0,0 +1,33 @@ +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 Texture1DDebugView + where T : unmanaged +{ + /// + /// Initializes a new instance of the class with the specified parameters. + /// + /// The input instance with the items to display. + public Texture1DDebugView(Texture1D? texture) + { + if (texture is not null) + { + T[] items = new T[texture.Width]; + + texture.CopyTo(ref items[0], items.Length, 0, texture.Width); + + Items = items; + } + } + + /// + /// Gets the items to display for the current instance. + /// + [DebuggerBrowsable(DebuggerBrowsableState.Collapsed)] + public T[]? Items { get; } +} diff --git a/src/ComputeSharp/Graphics/Resources/ReadOnlyTexture1D{T}.cs b/src/ComputeSharp/Graphics/Resources/ReadOnlyTexture1D{T}.cs new file mode 100644 index 00000000..2ebbb317 --- /dev/null +++ b/src/ComputeSharp/Graphics/Resources/ReadOnlyTexture1D{T}.cs @@ -0,0 +1,42 @@ +using System.Diagnostics; +using ComputeSharp.Exceptions; +using ComputeSharp.Graphics.Resources.Enums; +using ComputeSharp.Resources; +using ComputeSharp.Resources.Debug; +using static TerraFX.Interop.DirectX.D3D12_FORMAT_SUPPORT1; + +namespace ComputeSharp; + +/// +/// A representing a typed readonly 1D texture stored on GPU memory. +/// +/// The type of items stored on the texture. +[DebuggerTypeProxy(typeof(Texture1DDebugView<>))] +[DebuggerDisplay("{ToString(),raw}")] +public sealed class ReadOnlyTexture1D : Texture1D + 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 ReadOnlyTexture1D(GraphicsDevice device, int width, AllocationMode allocationMode) + : base(device, width, ResourceType.ReadOnly, allocationMode, D3D12_FORMAT_SUPPORT1_TEXTURE1D) + { + } + + /// + /// Gets a single value from the current readonly texture. + /// + /// The horizontal offset of the value to get. + /// This API can only be used from a compute shader, and will always throw if used anywhere else. + public ref readonly T this[int x] => throw new InvalidExecutionContextException($"{typeof(ReadOnlyTexture1D)}[{typeof(int)}]"); + + /// + public override string ToString() + { + return $"ComputeSharp.ReadOnlyTexture1D<{typeof(T)}>[{Width}]"; + } +} diff --git a/src/ComputeSharp/Graphics/Resources/ReadWriteTexture1D{T}.cs b/src/ComputeSharp/Graphics/Resources/ReadWriteTexture1D{T}.cs new file mode 100644 index 00000000..4cd863ad --- /dev/null +++ b/src/ComputeSharp/Graphics/Resources/ReadWriteTexture1D{T}.cs @@ -0,0 +1,42 @@ +using System.Diagnostics; +using ComputeSharp.Exceptions; +using ComputeSharp.Graphics.Resources.Enums; +using ComputeSharp.Resources; +using ComputeSharp.Resources.Debug; +using static TerraFX.Interop.DirectX.D3D12_FORMAT_SUPPORT1; + +namespace ComputeSharp; + +/// +/// A representing a typed read write 1D texture stored on GPU memory. +/// +/// The type of items stored on the texture. +[DebuggerTypeProxy(typeof(Texture1DDebugView<>))] +[DebuggerDisplay("{ToString(),raw}")] +public sealed partial class ReadWriteTexture1D : Texture1D + 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 ReadWriteTexture1D(GraphicsDevice device, int width, AllocationMode allocationMode) + : base(device, width, ResourceType.ReadWrite, allocationMode, D3D12_FORMAT_SUPPORT1_TEXTURE1D | D3D12_FORMAT_SUPPORT1_TYPED_UNORDERED_ACCESS_VIEW) + { + } + + /// + /// Gets a single value from the current writeable texture. + /// + /// The horizontal offset of the value to get. + /// This API can only be used from a compute shader, and will always throw if used anywhere else. + public ref T this[int x] => throw new InvalidExecutionContextException($"{typeof(ReadWriteTexture1D)}[{typeof(int)}]"); + + /// + public override string ToString() + { + return $"ComputeSharp.ReadWriteTexture1D<{typeof(T)}>[{Width}]"; + } +}