Renamed ReadOnlyBuffer to ConstantBuffer
このコミットが含まれているのは:
1 親
eb44113990
コミット
51f1e3e020
9ファイル変更
+36
-36
検索条件に一致するファイルはありません
@@ -98,12 +98,12 @@ namespace ComputeSharp
|
||||
/// <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="array">The input <typeparamref name="T"/> array with the data to copy on the allocated buffer</param>
|
||||
/// <returns>A constant <see cref="ReadOnlyBuffer{T}"/> instance with the contents of the input array</returns>
|
||||
/// <returns>A constant <see cref="ConstantBuffer{T}"/> instance with the contents of the input array</returns>
|
||||
[Pure]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static ReadOnlyBuffer<T> AllocateReadOnlyBuffer<T>(this GraphicsDevice device, T[] array) where T : unmanaged
|
||||
public static ConstantBuffer<T> AllocateConstantBuffer<T>(this GraphicsDevice device, T[] array) where T : unmanaged
|
||||
{
|
||||
return device.AllocateReadOnlyBuffer(array.AsSpan());
|
||||
return device.AllocateConstantBuffer(array.AsSpan());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -112,15 +112,15 @@ namespace ComputeSharp
|
||||
/// <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="array">The input 2D <typeparamref name="T"/> array with the data to copy on the allocated buffer</param>
|
||||
/// <returns>A constant <see cref="ReadOnlyBuffer{T}"/> instance with the contents of the input 2D array</returns>
|
||||
/// <returns>A constant <see cref="ConstantBuffer{T}"/> instance with the contents of the input 2D array</returns>
|
||||
[Pure]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe ReadOnlyBuffer<T> AllocateReadOnlyBuffer<T>(this GraphicsDevice device, T[,] array) where T : unmanaged
|
||||
public static unsafe ConstantBuffer<T> AllocateConstantBuffer<T>(this GraphicsDevice device, T[,] array) where T : unmanaged
|
||||
{
|
||||
fixed (T* p = array)
|
||||
{
|
||||
Span<T> span = new Span<T>(p, array.Length);
|
||||
return device.AllocateReadOnlyBuffer(span);
|
||||
return device.AllocateConstantBuffer(span);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,12 +130,12 @@ namespace ComputeSharp
|
||||
/// <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="span">The input <see cref="Span{T}"/> with the data to copy on the allocated buffer</param>
|
||||
/// <returns>A constant <see cref="ReadOnlyBuffer{T}"/> instance with the contents of the input <see cref="Span{T}"/></returns>
|
||||
/// <returns>A constant <see cref="ConstantBuffer{T}"/> instance with the contents of the input <see cref="Span{T}"/></returns>
|
||||
[Pure]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static ReadOnlyBuffer<T> AllocateReadOnlyBuffer<T>(this GraphicsDevice device, Span<T> span) where T : unmanaged
|
||||
public static ConstantBuffer<T> AllocateConstantBuffer<T>(this GraphicsDevice device, Span<T> span) where T : unmanaged
|
||||
{
|
||||
ReadOnlyBuffer<T> buffer = new ReadOnlyBuffer<T>(device, span.Length);
|
||||
ConstantBuffer<T> buffer = new ConstantBuffer<T>(device, span.Length);
|
||||
buffer.SetData(span);
|
||||
|
||||
return buffer;
|
||||
@@ -147,15 +147,15 @@ namespace ComputeSharp
|
||||
/// <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="ReadOnlyBuffer{T}"/> instance with the contents of the input <see cref="HlslBuffer{T}"/></returns>
|
||||
/// <returns>A constant <see cref="ConstantBuffer{T}"/> instance with the contents of the input <see cref="HlslBuffer{T}"/></returns>
|
||||
[Pure]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static ReadOnlyBuffer<T> AllocateReadOnlyBuffer<T>(this GraphicsDevice device, HlslBuffer<T> buffer) where T : unmanaged
|
||||
public static ConstantBuffer<T> AllocateConstantBuffer<T>(this GraphicsDevice device, HlslBuffer<T> buffer) where T : unmanaged
|
||||
{
|
||||
ReadOnlyBuffer<T> readOnlyBuffer = new ReadOnlyBuffer<T>(device, buffer.Size);
|
||||
readOnlyBuffer.SetData(buffer);
|
||||
ConstantBuffer<T> constantBuffer = new ConstantBuffer<T>(device, buffer.Size);
|
||||
constantBuffer.SetData(buffer);
|
||||
|
||||
return readOnlyBuffer;
|
||||
return constantBuffer;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,7 @@ namespace ComputeSharp.Graphics.Buffers.Extensions
|
||||
/// </summary>
|
||||
/// <param name="device">The <see cref="GraphicsDevice"/> instance to use to allocate the buffer</param>
|
||||
/// <param name="data">The input <see cref="object"/> to copy to the allocated buffer</param>
|
||||
/// <returns>A constant <see cref="ReadOnlyBuffer{T}"/> instance (as a <see cref="GraphicsResource"/>) with the input data</returns>
|
||||
/// <returns>A constant <see cref="ConstantBuffer{T}"/> instance (as a <see cref="GraphicsResource"/>) with the input data</returns>
|
||||
[Pure]
|
||||
public static GraphicsResource AllocateReadOnlyBufferFromReflectedSingleValue(this GraphicsDevice device, object data)
|
||||
{
|
||||
@@ -31,7 +31,7 @@ namespace ComputeSharp.Graphics.Buffers.Extensions
|
||||
if (!TypeMapping.TryGetValue(dataType, out var info))
|
||||
{
|
||||
// Get the generic buffer constructor
|
||||
Type bufferType = typeof(ReadOnlyBuffer<>).MakeGenericType(dataType);
|
||||
Type bufferType = typeof(ConstantBuffer<>).MakeGenericType(dataType);
|
||||
info.Constructor = bufferType.GetConstructors(BindingFlags.Instance | BindingFlags.NonPublic).First();
|
||||
|
||||
// Create the reusable array
|
||||
|
||||
@@ -12,14 +12,14 @@ namespace ComputeSharp.Graphics.Buffers
|
||||
/// 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 ReadOnlyBuffer<T> : HlslBuffer<T> where T : unmanaged
|
||||
public sealed class ConstantBuffer<T> : HlslBuffer<T> where T : unmanaged
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="ReadOnlyBuffer{T}"/> instance with the specified parameters
|
||||
/// Creates a new <see cref="ConstantBuffer{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>
|
||||
internal ReadOnlyBuffer(GraphicsDevice device, int size) : base(device, size, size * (Unsafe.SizeOf<T>() / 16 + 1) * 16, HeapType.Upload)
|
||||
internal ConstantBuffer(GraphicsDevice device, int size) : base(device, size, size * (Unsafe.SizeOf<T>() / 16 + 1) * 16, HeapType.Upload)
|
||||
{
|
||||
PaddedElementSizeInBytes = SizeInBytes / Size;
|
||||
IsPaddingPresent = PaddedElementSizeInBytes > ElementSizeInBytes;
|
||||
@@ -114,7 +114,7 @@ namespace ComputeSharp.Graphics.Buffers
|
||||
/// <inheritdoc/>
|
||||
public override void SetData(HlslBuffer<T> buffer)
|
||||
{
|
||||
if (buffer is ReadOnlyBuffer<T>)
|
||||
if (buffer is ConstantBuffer<T>)
|
||||
{
|
||||
// Directly copy the input buffer, if possible
|
||||
using CommandList copyCommandList = new CommandList(GraphicsDevice, CommandListType.Copy);
|
||||
|
||||
@@ -63,7 +63,7 @@ namespace ComputeSharp.Graphics.Buffers
|
||||
/// <inheritdoc/>
|
||||
public override void SetData(HlslBuffer<T> buffer)
|
||||
{
|
||||
if (buffer is ReadOnlyBuffer<T> readOnlyBuffer && !readOnlyBuffer.IsPaddingPresent)
|
||||
if (buffer is ConstantBuffer<T> readOnlyBuffer && !readOnlyBuffer.IsPaddingPresent)
|
||||
{
|
||||
// Directly copy the input buffer
|
||||
using CommandList copyCommandList = new CommandList(GraphicsDevice, CommandListType.Copy);
|
||||
|
||||
@@ -63,13 +63,13 @@ namespace ComputeSharp.Shaders.Mappings
|
||||
type.GetGenericTypeDefinition() == typeof(ReadWriteBuffer<>);
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether or not the input type is a <see cref="ReadOnlyBuffer{T}"/> value
|
||||
/// Checks whether or not the input type is a <see cref="ConstantBuffer{T}"/> value
|
||||
/// </summary>
|
||||
/// <param name="type">The input <see cref="Type"/> instance to check</param>
|
||||
/// <returns>A <see langword="bool"/> indicating whether the input <see cref="Type"/> is in fact a <see cref="ReadOnlyBuffer{T}"/> instance</returns>
|
||||
/// <returns>A <see langword="bool"/> indicating whether the input <see cref="Type"/> is in fact a <see cref="ConstantBuffer{T}"/> instance</returns>
|
||||
[Pure]
|
||||
public static bool IsReadOnlyBufferType(Type type) => type.IsGenericType &&
|
||||
type.GetGenericTypeDefinition() == typeof(ReadOnlyBuffer<>);
|
||||
public static bool IsConstantBufferType(Type type) => type.IsGenericType &&
|
||||
type.GetGenericTypeDefinition() == typeof(ConstantBuffer<>);
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether or not a given <see cref="Type"/> is an HLSL known type
|
||||
|
||||
@@ -136,9 +136,9 @@ namespace ComputeSharp.Shaders.Translation
|
||||
string typeName = HlslKnownTypes.GetMappedName(fieldType);
|
||||
processedFieldInfo = new ReadWriteBufferFieldInfo(typeName, fieldName, readWriteBuffersCount++);
|
||||
}
|
||||
else if (HlslKnownTypes.IsReadOnlyBufferType(fieldType))
|
||||
else if (HlslKnownTypes.IsConstantBufferType(fieldType))
|
||||
{
|
||||
// Read only buffer
|
||||
// Constant buffer
|
||||
DescriptorRange range = new DescriptorRange(DescriptorRangeType.ConstantBufferView, 1, readOnlyBuffersCount);
|
||||
descriptorRanges.Add(range);
|
||||
|
||||
@@ -150,7 +150,7 @@ namespace ComputeSharp.Shaders.Translation
|
||||
}
|
||||
else if (HlslKnownTypes.IsKnownScalarType(fieldType))
|
||||
{
|
||||
// Read only buffer
|
||||
// Constant buffer
|
||||
DescriptorRange range = new DescriptorRange(DescriptorRangeType.ConstantBufferView, 1, readOnlyBuffersCount);
|
||||
descriptorRanges.Add(range);
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace ComputeSharp.NetCore.Tests.Internals
|
||||
{
|
||||
object value = 77;
|
||||
|
||||
using ReadOnlyBuffer<int> buffer = (ReadOnlyBuffer<int>)Gpu.Default.AllocateReadOnlyBufferFromReflectedSingleValue(value);
|
||||
using ConstantBuffer<int> buffer = (ConstantBuffer<int>)Gpu.Default.AllocateReadOnlyBufferFromReflectedSingleValue(value);
|
||||
int[] result = buffer.GetData();
|
||||
|
||||
Assert.IsTrue(result.Length == 1);
|
||||
@@ -26,7 +26,7 @@ namespace ComputeSharp.NetCore.Tests.Internals
|
||||
{
|
||||
object value = 3.14f;
|
||||
|
||||
using ReadOnlyBuffer<float> buffer = (ReadOnlyBuffer<float>)Gpu.Default.AllocateReadOnlyBufferFromReflectedSingleValue(value);
|
||||
using ConstantBuffer<float> buffer = (ConstantBuffer<float>)Gpu.Default.AllocateReadOnlyBufferFromReflectedSingleValue(value);
|
||||
float[] result = buffer.GetData();
|
||||
|
||||
Assert.IsTrue(result.Length == 1);
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace ComputeSharp.NetCore.Tests
|
||||
{
|
||||
float[] array = Enumerable.Range(0, 4096).Select(i => (float)i).ToArray();
|
||||
|
||||
using ReadOnlyBuffer<float> buffer = Gpu.Default.AllocateReadOnlyBuffer(array);
|
||||
using ConstantBuffer<float> buffer = Gpu.Default.AllocateConstantBuffer(array);
|
||||
float[] result = buffer.GetData();
|
||||
|
||||
Assert.IsTrue(array.AsSpan().ContentEquals(result));
|
||||
@@ -52,7 +52,7 @@ namespace ComputeSharp.NetCore.Tests
|
||||
{
|
||||
float[] array = Enumerable.Range(0, 4096).Select(i => (float)i).ToArray();
|
||||
|
||||
using ReadOnlyBuffer<float> sourceBuffer = Gpu.Default.AllocateReadOnlyBuffer(array);
|
||||
using ConstantBuffer<float> sourceBuffer = Gpu.Default.AllocateConstantBuffer(array);
|
||||
using ReadWriteBuffer<float> destinationBuffer = Gpu.Default.AllocateReadWriteBuffer(sourceBuffer);
|
||||
|
||||
float[] sourceResult = sourceBuffer.GetData();
|
||||
@@ -68,7 +68,7 @@ namespace ComputeSharp.NetCore.Tests
|
||||
float[] array = Enumerable.Range(0, 4096).Select(i => (float)i).ToArray();
|
||||
|
||||
using ReadWriteBuffer<float> sourceBuffer = Gpu.Default.AllocateReadWriteBuffer(array);
|
||||
using ReadOnlyBuffer<float> destinationBuffer = Gpu.Default.AllocateReadOnlyBuffer(sourceBuffer);
|
||||
using ConstantBuffer<float> destinationBuffer = Gpu.Default.AllocateConstantBuffer(sourceBuffer);
|
||||
|
||||
float[] sourceResult = sourceBuffer.GetData();
|
||||
float[] destinationResult = destinationBuffer.GetData();
|
||||
@@ -82,8 +82,8 @@ namespace ComputeSharp.NetCore.Tests
|
||||
{
|
||||
float[] array = Enumerable.Range(0, 4096).Select(i => (float)i).ToArray();
|
||||
|
||||
using ReadOnlyBuffer<float> sourceBuffer = Gpu.Default.AllocateReadOnlyBuffer(array);
|
||||
using ReadOnlyBuffer<float> destinationBuffer = Gpu.Default.AllocateReadOnlyBuffer(sourceBuffer);
|
||||
using ConstantBuffer<float> sourceBuffer = Gpu.Default.AllocateConstantBuffer(array);
|
||||
using ConstantBuffer<float> destinationBuffer = Gpu.Default.AllocateConstantBuffer(sourceBuffer);
|
||||
|
||||
float[] sourceResult = sourceBuffer.GetData();
|
||||
float[] destinationResult = destinationBuffer.GetData();
|
||||
|
||||
@@ -85,7 +85,7 @@ namespace ComputeSharp.NetCore.Tests
|
||||
{
|
||||
float[] source = Enumerable.Range(0, 100).Select(i => (float)i).ToArray();
|
||||
|
||||
using ReadOnlyBuffer<float> input = Gpu.Default.AllocateReadOnlyBuffer(source);
|
||||
using ConstantBuffer<float> input = Gpu.Default.AllocateConstantBuffer(source);
|
||||
using ReadWriteBuffer<float> buffer = Gpu.Default.AllocateReadWriteBuffer<float>(source.Length);
|
||||
|
||||
Action<ThreadIds> action = id => buffer[id.X] = input[id.X];
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする