Code refactoring
このコミットが含まれているのは:
1 親
984d1113f8
コミット
9edbdcfdc3
3ファイル変更
+23
-48
検索条件に一致するファイルはありません
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using System.Diagnostics.Contracts;
|
||||
using SharpDX.Direct3D12;
|
||||
|
||||
@@ -48,12 +49,31 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
|
||||
/// Writes the contents of a given <see cref="ReadOnlyBuffer{T}"/> to the current <see cref="HlslBuffer{T}"/> instance
|
||||
/// </summary>
|
||||
/// <param name="buffer">The input <see cref="ReadOnlyBuffer{T}"/> to read data from</param>
|
||||
public abstract void SetData(ReadOnlyBuffer<T> buffer);
|
||||
public virtual void SetData(ReadOnlyBuffer<T> buffer) => SetDataWithCpuBuffer(buffer);
|
||||
|
||||
/// <summary>
|
||||
/// Writes the contents of a given <see cref="ReadWriteBuffer{T}"/> to the current <see cref="HlslBuffer{T}"/> instance
|
||||
/// </summary>
|
||||
/// <param name="buffer">The input <see cref="ReadWriteBuffer{T}"/> to read data from</param>
|
||||
public abstract void SetData(ReadWriteBuffer<T> buffer);
|
||||
public virtual void SetData(ReadWriteBuffer<T> buffer) => SetDataWithCpuBuffer(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
|
||||
/// </summary>
|
||||
/// <param name="buffer">The input <see cref="HlslBuffer{T}"/> to read data from</param>
|
||||
protected void SetDataWithCpuBuffer(HlslBuffer<T> buffer)
|
||||
{
|
||||
// Create a temporary array
|
||||
T[] array = ArrayPool<T>.Shared.Rent(buffer.Size);
|
||||
Span<T> span = array.AsSpan(buffer.Size);
|
||||
|
||||
// Get the unpadded data from the read write buffer
|
||||
buffer.GetData(span);
|
||||
|
||||
// Set the data, adding the padding if needed
|
||||
SetData(span);
|
||||
|
||||
ArrayPool<T>.Shared.Return(array);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -118,21 +118,5 @@ namespace ComputeSharp.Graphics.Buffers
|
||||
copyCommandList.CopyBufferRegion(buffer, 0, this, 0, SizeInBytes);
|
||||
copyCommandList.Flush(true);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void SetData(ReadWriteBuffer<T> buffer)
|
||||
{
|
||||
// Create a temporary array
|
||||
T[] array = ArrayPool<T>.Shared.Rent(buffer.Size);
|
||||
Span<T> span = array.AsSpan(buffer.Size);
|
||||
|
||||
// Get the unpadded data from the read write buffer
|
||||
buffer.GetData(span);
|
||||
|
||||
// Set the data, adding the padding if needed
|
||||
SetData(span);
|
||||
|
||||
ArrayPool<T>.Shared.Return(array);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -63,20 +63,7 @@ namespace ComputeSharp.Graphics.Buffers
|
||||
/// <inheritdoc/>
|
||||
public override void SetData(ReadOnlyBuffer<T> buffer)
|
||||
{
|
||||
if (buffer.IsPaddingPresent)
|
||||
{
|
||||
// Create a temporary array
|
||||
T[] array = ArrayPool<T>.Shared.Rent(buffer.Size);
|
||||
Span<T> span = array.AsSpan(buffer.Size);
|
||||
|
||||
// Get the data from the readonly array, removing the padding
|
||||
buffer.GetData(span);
|
||||
|
||||
// Set the data to the current buffer
|
||||
SetData(span);
|
||||
|
||||
ArrayPool<T>.Shared.Return(array);
|
||||
}
|
||||
if (buffer.IsPaddingPresent) SetDataWithCpuBuffer(buffer);
|
||||
else
|
||||
{
|
||||
// Directly copy the input buffer
|
||||
@@ -86,21 +73,5 @@ namespace ComputeSharp.Graphics.Buffers
|
||||
copyCommandList.Flush(true);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void SetData(ReadWriteBuffer<T> buffer)
|
||||
{
|
||||
// Create a temporary array
|
||||
T[] array = ArrayPool<T>.Shared.Rent(buffer.Size);
|
||||
Span<T> span = array.AsSpan(buffer.Size);
|
||||
|
||||
// Get the unpadded data from the read write buffer
|
||||
buffer.GetData(span);
|
||||
|
||||
// Set the data to the current buffer
|
||||
SetData(span);
|
||||
|
||||
ArrayPool<T>.Shared.Return(array);
|
||||
}
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする