Minor code refactoring

このコミットが含まれているのは:
Sergio Pedri committed 2020-11-20 01:41:05 +01:00
1 親 29eedddd65
コミット aa4eca414d
7ファイル変更
+36 -36

検索条件に一致するファイルはありません

@@ -16,7 +16,7 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
/// A <see langword="class"/> representing a typed buffer stored on GPU memory.
/// </summary>
/// <typeparam name="T">The type of items stored on the buffer.</typeparam>
public unsafe abstract class HlslBuffer<T> : NativeObject
public unsafe abstract class Buffer<T> : NativeObject
where T : unmanaged
{
/// <summary>
@@ -50,18 +50,18 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
internal readonly int PaddedElementSizeInBytes;
/// <summary>
/// The buffer type for the current <see cref="HlslBuffer{T}"/> instance.
/// The buffer type for the current <see cref="Buffer{T}"/> instance.
/// </summary>
internal readonly BufferType BufferType;
/// <summary>
/// Creates a new <see cref="HlslBuffer{T}"/> instance with the specified parameters.
/// Creates a new <see cref="Buffer{T}"/> instance with the specified parameters.
/// </summary>
/// <param name="device">The <see cref="GraphicsDevice"/> associated with the current instance.</param>
/// <param name="size">The number of items to store in the current buffer.</param>
/// <param name="sizeInBytes">The size in bytes for the current buffer.</param>
/// <param name="bufferType">The buffer type for the current buffer.</param>
internal HlslBuffer(GraphicsDevice device, int size, int sizeInBytes, BufferType bufferType)
internal Buffer(GraphicsDevice device, int size, int sizeInBytes, BufferType bufferType)
{
this.d3D12Resource = device.D3D12Device->CreateCommittedResource(bufferType, sizeInBytes);
@@ -104,14 +104,14 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
internal ID3D12Resource* D3D12Resource => this.d3D12Resource;
/// <summary>
/// Reads the contents of the current <see cref="HlslBuffer{T}"/> instance and returns an array
/// Reads the contents of the current <see cref="Buffer{T}"/> instance and returns an array
/// </summary>
/// <returns>A <typeparamref name="T"/> array with the contents of the current buffer</returns>
[Pure]
public T[] GetData() => GetData(0, Size);
/// <summary>
/// Reads the contents of the current <see cref="HlslBuffer{T}"/> instance in a given range and returns an array
/// Reads the contents of the current <see cref="Buffer{T}"/> instance in a given range and returns an array
/// </summary>
/// <param name="offset">The offset to start reading data from</param>
/// <param name="count">The number of items to read</param>
@@ -126,13 +126,13 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
}
/// <summary>
/// Reads the contents of the current <see cref="HlslBuffer{T}"/> instance and writes them into a target <see cref="Span{T}"/>
/// Reads the contents of the current <see cref="Buffer{T}"/> instance and writes them into a target <see cref="Span{T}"/>
/// </summary>
/// <param name="span">The input <see cref="Span{T}"/> to write data to</param>
public void GetData(Span<T> span) => GetData(span, 0, Size);
/// <summary>
/// Reads the contents of the specified range from the current <see cref="HlslBuffer{T}"/> instance and writes them into a target <see cref="Span{T}"/>
/// Reads the contents of the specified range from the current <see cref="Buffer{T}"/> instance and writes them into a target <see cref="Span{T}"/>
/// </summary>
/// <param name="span">The input <see cref="Span{T}"/> to write data to</param>
/// <param name="offset">The offset to start reading data from</param>
@@ -140,13 +140,13 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
public abstract void GetData(Span<T> span, int offset, int count);
/// <summary>
/// Writes the contents of a given <typeparamref name="T"/> array to the current <see cref="HlslBuffer{T}"/> instance
/// Writes the contents of a given <typeparamref name="T"/> array to the current <see cref="Buffer{T}"/> instance
/// </summary>
/// <param name="array">The input <typeparamref name="T"/> array to read data from</param>
public void SetData(T[] array) => SetData(array.AsSpan());
/// <summary>
/// Writes the contents of a given <typeparamref name="T"/> array to a specified area of the current <see cref="HlslBuffer{T}"/> instance
/// Writes the contents of a given <typeparamref name="T"/> array to a specified area of the current <see cref="Buffer{T}"/> instance
/// </summary>
/// <param name="array">The input <typeparamref name="T"/> array to read data from</param>
/// <param name="offset">The offset to start writing data to</param>
@@ -154,13 +154,13 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
public void SetData(T[] array, int offset, int count) => SetData(array.AsSpan(), offset, count);
/// <summary>
/// Writes the contents of a given <see cref="ReadOnlySpan{T}"/> to the current <see cref="HlslBuffer{T}"/> instance
/// Writes the contents of a given <see cref="ReadOnlySpan{T}"/> to the current <see cref="Buffer{T}"/> instance
/// </summary>
/// <param name="span">The input <see cref="ReadOnlySpan{T}"/> to read data from</param>
public void SetData(ReadOnlySpan<T> span) => SetData(span, 0, Size);
/// <summary>
/// Writes the contents of a given <see cref="ReadOnlySpan{T}"/> to a specified area of the current <see cref="HlslBuffer{T}"/> instance
/// Writes the contents of a given <see cref="ReadOnlySpan{T}"/> to a specified area of the current <see cref="Buffer{T}"/> instance
/// </summary>
/// <param name="span">The input <see cref="ReadOnlySpan{T}"/> to read data from</param>
/// <param name="offset">The offset to start writing data to</param>
@@ -168,16 +168,16 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
public abstract void SetData(ReadOnlySpan<T> span, int offset, int count);
/// <summary>
/// Writes the contents of a given <see cref="HlslBuffer{T}"/> to the current <see cref="HlslBuffer{T}"/> instance
/// Writes the contents of a given <see cref="Buffer{T}"/> to the current <see cref="Buffer{T}"/> instance
/// </summary>
/// <param name="buffer">The input <see cref="HlslBuffer{T}"/> to read data from</param>
public abstract void SetData(HlslBuffer<T> buffer);
/// <param name="buffer">The input <see cref="Buffer{T}"/> to read data from</param>
public abstract void SetData(Buffer<T> buffer);
/// <summary>
/// Writes the contents of a given <see cref="HlslBuffer{T}"/> to the current <see cref="HlslBuffer{T}"/> instance, using a temporary CPU buffer
/// Writes the contents of a given <see cref="Buffer{T}"/> to the current <see cref="Buffer{T}"/> instance, using a temporary CPU buffer
/// </summary>
/// <param name="buffer">The input <see cref="HlslBuffer{T}"/> to read data from</param>
protected void SetDataWithCpuBuffer(HlslBuffer<T> buffer)
/// <param name="buffer">The input <see cref="Buffer{T}"/> to read data from</param>
protected void SetDataWithCpuBuffer(Buffer<T> buffer)
{
// Create a temporary array
T[] array = ArrayPool<T>.Shared.Rent(buffer.Size);
@@ -14,16 +14,16 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
/// A <see langword="class"/> representing a typed structured buffer stored on GPU memory
/// </summary>
/// <typeparam name="T">The type of items stored on the buffer</typeparam>
public abstract class HlslStructuredBuffer<T> : HlslBuffer<T>
public abstract class StructuredBuffer<T> : Buffer<T>
where T : unmanaged
{
/// <summary>
/// Creates a new <see cref="HlslStructuredBuffer{T}"/> instance with the specified parameters
/// Creates a new <see cref="StructuredBuffer{T}"/> instance with the specified parameters
/// </summary>
/// <param name="device">The <see cref="GraphicsDevice"/> associated with the current instance</param>
/// <param name="size">The number of items to store in the current buffer</param>
/// <param name="bufferType">The buffer type for the current buffer</param>
internal HlslStructuredBuffer(GraphicsDevice device, int size, BufferType bufferType)
internal StructuredBuffer(GraphicsDevice device, int size, BufferType bufferType)
: base(device, size, size * Unsafe.SizeOf<T>(), bufferType)
{
}
@@ -69,7 +69,7 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
}
/// <inheritdoc/>
public override unsafe void SetData(HlslBuffer<T> buffer)
public override unsafe void SetData(Buffer<T> buffer)
{
if (!buffer.IsPaddingPresent)
{
+2 -2
ファイルの表示
@@ -18,7 +18,7 @@ namespace ComputeSharp
/// A <see langword="class"/> representing a typed read write buffer stored on GPU memory
/// </summary>
/// <typeparam name="T">The type of items stored on the buffer</typeparam>
public sealed class ConstantBuffer<T> : HlslBuffer<T>
public sealed class ConstantBuffer<T> : Buffer<T>
where T : unmanaged
{
/// <summary>
@@ -95,7 +95,7 @@ namespace ComputeSharp
}
/// <inheritdoc/>
public override unsafe void SetData(HlslBuffer<T> buffer)
public override unsafe void SetData(Buffer<T> buffer)
{
if (buffer is ConstantBuffer<T>)
{
+9 -9
ファイルの表示
@@ -50,11 +50,11 @@ namespace ComputeSharp
/// </summary>
/// <typeparam name="T">The type of items to store in the buffer.</typeparam>
/// <param name="device">The <see cref="GraphicsDevice"/> instance to use to allocate the buffer.</param>
/// <param name="buffer">The input <see cref="HlslBuffer{T}"/> with the data to copy on the allocated buffer.</param>
/// <returns>A constant <see cref="ConstantBuffer{T}"/> instance with the contents of the input <see cref="HlslBuffer{T}"/>.</returns>
/// <param name="buffer">The input <see cref="Buffer{T}"/> with the data to copy on the allocated buffer.</param>
/// <returns>A constant <see cref="ConstantBuffer{T}"/> instance with the contents of the input <see cref="Buffer{T}"/>.</returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ConstantBuffer<T> AllocateConstantBuffer<T>(this GraphicsDevice device, HlslBuffer<T> buffer)
public static ConstantBuffer<T> AllocateConstantBuffer<T>(this GraphicsDevice device, Buffer<T> buffer)
where T : unmanaged
{
ConstantBuffer<T> constantBuffer = new(device, buffer.Size);
@@ -118,11 +118,11 @@ namespace ComputeSharp
/// </summary>
/// <typeparam name="T">The type of items to store in the buffer.</typeparam>
/// <param name="device">The <see cref="GraphicsDevice"/> instance to use to allocate the buffer.</param>
/// <param name="buffer">The input <see cref="HlslBuffer{T}"/> with the data to copy on the allocated buffer.</param>
/// <returns>A read write <see cref="ReadOnlyBuffer{T}"/> instance with the contents of the input <see cref="HlslBuffer{T}"/>.</returns>
/// <param name="buffer">The input <see cref="Buffer{T}"/> with the data to copy on the allocated buffer.</param>
/// <returns>A read write <see cref="ReadOnlyBuffer{T}"/> instance with the contents of the input <see cref="Buffer{T}"/>.</returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ReadOnlyBuffer<T> AllocateReadOnlyBuffer<T>(this GraphicsDevice device, HlslBuffer<T> buffer)
public static ReadOnlyBuffer<T> AllocateReadOnlyBuffer<T>(this GraphicsDevice device, Buffer<T> buffer)
where T : unmanaged
{
ReadOnlyBuffer<T> readWriteBuffer = new(device, buffer.Size);
@@ -186,11 +186,11 @@ namespace ComputeSharp
/// </summary>
/// <typeparam name="T">The type of items to store in the buffer.</typeparam>
/// <param name="device">The <see cref="GraphicsDevice"/> instance to use to allocate the buffer.</param>
/// <param name="buffer">The input <see cref="HlslBuffer{T}"/> with the data to copy on the allocated buffer.</param>
/// <returns>A read write <see cref="ReadWriteBuffer{T}"/> instance with the contents of the input <see cref="HlslBuffer{T}"/>.</returns>
/// <param name="buffer">The input <see cref="Buffer{T}"/> with the data to copy on the allocated buffer.</param>
/// <returns>A read write <see cref="ReadWriteBuffer{T}"/> instance with the contents of the input <see cref="Buffer{T}"/>.</returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ReadWriteBuffer<T> AllocateReadWriteBuffer<T>(this GraphicsDevice device, HlslBuffer<T> buffer)
public static ReadWriteBuffer<T> AllocateReadWriteBuffer<T>(this GraphicsDevice device, Buffer<T> buffer)
where T : unmanaged
{
ReadWriteBuffer<T> readWriteBuffer = new (device, buffer.Size);
+1 -1
ファイルの表示
@@ -9,7 +9,7 @@ namespace ComputeSharp
/// A <see langword="class"/> representing a typed readonly buffer stored on GPU memory
/// </summary>
/// <typeparam name="T">The type of items stored on the buffer</typeparam>
public sealed class ReadOnlyBuffer<T> : HlslStructuredBuffer<T>
public sealed class ReadOnlyBuffer<T> : StructuredBuffer<T>
where T : unmanaged
{
/// <summary>
+1 -1
ファイルの表示
@@ -9,7 +9,7 @@ namespace ComputeSharp
/// A <see langword="class"/> representing a typed read write buffer stored on GPU memory
/// </summary>
/// <typeparam name="T">The type of items stored on the buffer</typeparam>
public sealed class ReadWriteBuffer<T> : HlslStructuredBuffer<T>
public sealed class ReadWriteBuffer<T> : StructuredBuffer<T>
where T : unmanaged
{
/// <summary>
+1 -1
ファイルの表示
@@ -97,7 +97,7 @@ namespace ComputeSharp.Shaders.Translation
// Access Buffer<T>.D3D12GpuDescriptorHandle
FieldInfo gpuDescriptorInfo = member.MemberType.GetField(
nameof(HlslBuffer<byte>.D3D12GpuDescriptorHandle),
nameof(Buffer<byte>.D3D12GpuDescriptorHandle),
BindingFlags.NonPublic | BindingFlags.Instance)!;
il.EmitReadMember(gpuDescriptorInfo);