Added dispatch unit tests to resource types
このコミットが含まれているのは:
1 親
b229b327b9
コミット
5fafd3d9ac
3ファイル変更
+196
-3
検索条件に一致するファイルはありません
@@ -8,7 +8,7 @@ namespace ComputeSharp.Tests
|
||||
{
|
||||
[TestClass]
|
||||
[TestCategory("Buffer")]
|
||||
public class BufferTests
|
||||
public partial class BufferTests
|
||||
{
|
||||
[TestMethod]
|
||||
[DataRow(typeof(ConstantBuffer<>))]
|
||||
@@ -201,5 +201,86 @@ namespace ComputeSharp.Tests
|
||||
|
||||
buffer.GetData(result, destinationOffset, bufferOffset, count);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Dispatch_ConstantBuffer()
|
||||
{
|
||||
int[] data = Enumerable.Range(0, 1024).ToArray();
|
||||
|
||||
using ConstantBuffer<int> source = Gpu.Default.AllocateConstantBuffer(data);
|
||||
using ReadWriteBuffer<int> destination = Gpu.Default.AllocateReadWriteBuffer<int>(data.Length);
|
||||
|
||||
Gpu.Default.For(source.Length, new ConstantBufferKernel(source, destination));
|
||||
|
||||
int[] result = destination.GetData();
|
||||
|
||||
CollectionAssert.AreEqual(data, result);
|
||||
}
|
||||
|
||||
[AutoConstructor]
|
||||
private readonly partial struct ConstantBufferKernel : IComputeShader
|
||||
{
|
||||
public readonly ConstantBuffer<int> source;
|
||||
public readonly ReadWriteBuffer<int> destination;
|
||||
|
||||
public void Execute(ThreadIds ids)
|
||||
{
|
||||
destination[ids.X] = source[ids.X];
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Dispatch_ReadOnlyBuffer()
|
||||
{
|
||||
int[] data = Enumerable.Range(0, 1024).ToArray();
|
||||
|
||||
using ReadOnlyBuffer<int> source = Gpu.Default.AllocateReadOnlyBuffer(data);
|
||||
using ReadWriteBuffer<int> destination = Gpu.Default.AllocateReadWriteBuffer<int>(data.Length);
|
||||
|
||||
Gpu.Default.For(source.Length, new ReadOnlyBufferKernel(source, destination));
|
||||
|
||||
int[] result = destination.GetData();
|
||||
|
||||
CollectionAssert.AreEqual(data, result);
|
||||
}
|
||||
|
||||
[AutoConstructor]
|
||||
private readonly partial struct ReadOnlyBufferKernel : IComputeShader
|
||||
{
|
||||
public readonly ReadOnlyBuffer<int> source;
|
||||
public readonly ReadWriteBuffer<int> destination;
|
||||
|
||||
public void Execute(ThreadIds ids)
|
||||
{
|
||||
destination[ids.X] = source[ids.X];
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Dispatch_ReadWriteBuffer()
|
||||
{
|
||||
int[] data = Enumerable.Range(0, 1024).ToArray();
|
||||
|
||||
using ReadWriteBuffer<int> source = Gpu.Default.AllocateReadWriteBuffer(data);
|
||||
using ReadWriteBuffer<int> destination = Gpu.Default.AllocateReadWriteBuffer<int>(data.Length);
|
||||
|
||||
Gpu.Default.For(source.Length, new ReadWriteBufferKernel(source, destination));
|
||||
|
||||
int[] result = destination.GetData();
|
||||
|
||||
CollectionAssert.AreEqual(data, result);
|
||||
}
|
||||
|
||||
[AutoConstructor]
|
||||
private readonly partial struct ReadWriteBufferKernel : IComputeShader
|
||||
{
|
||||
public readonly ReadWriteBuffer<int> source;
|
||||
public readonly ReadWriteBuffer<int> destination;
|
||||
|
||||
public void Execute(ThreadIds ids)
|
||||
{
|
||||
destination[ids.X] = source[ids.X];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ namespace ComputeSharp.Tests
|
||||
{
|
||||
[TestClass]
|
||||
[TestCategory("Texture2D")]
|
||||
public class Texture2DTests
|
||||
public partial class Texture2DTests
|
||||
{
|
||||
[TestMethod]
|
||||
[DataRow(typeof(ReadOnlyTexture2D<>))]
|
||||
@@ -137,5 +137,61 @@ namespace ComputeSharp.Tests
|
||||
|
||||
texture.GetData(result, x, y, width, height);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Dispatch_ReadOnlyTexture2D()
|
||||
{
|
||||
int[] data = Enumerable.Range(0, 32 * 32).ToArray();
|
||||
|
||||
using ReadOnlyTexture2D<int> source = Gpu.Default.AllocateReadOnlyTexture2D(data, 32, 32);
|
||||
using ReadWriteBuffer<int> destination = Gpu.Default.AllocateReadWriteBuffer<int>(data.Length);
|
||||
|
||||
Gpu.Default.For(source.Width, source.Height, new ReadOnlyTexture2DKernel(source, destination));
|
||||
|
||||
int[] result = destination.GetData();
|
||||
|
||||
CollectionAssert.AreEqual(data, result);
|
||||
}
|
||||
|
||||
[AutoConstructor]
|
||||
private readonly partial struct ReadOnlyTexture2DKernel : IComputeShader
|
||||
{
|
||||
public readonly ReadOnlyTexture2D<int> source;
|
||||
public readonly ReadWriteBuffer<int> destination;
|
||||
|
||||
public void Execute(ThreadIds ids)
|
||||
{
|
||||
destination[ids.Y * 32 + ids.X] = source[new((uint)ids.X, (uint)ids.Y)];
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Dispatch_ReadWriteTexture2D()
|
||||
{
|
||||
int[] data = Enumerable.Range(0, 32 * 32).ToArray();
|
||||
|
||||
using ReadWriteTexture2D<int> source = Gpu.Default.AllocateReadWriteTexture2D(data, 32, 32);
|
||||
using ReadWriteTexture2D<int> destination = Gpu.Default.AllocateReadWriteTexture2D<int>(32, 32);
|
||||
|
||||
Gpu.Default.For(source.Width, source.Height, new ReadWriteTexture2DKernel(source, destination));
|
||||
|
||||
int[] result = new int[data.Length];
|
||||
|
||||
destination.GetData(result);
|
||||
|
||||
CollectionAssert.AreEqual(data, result);
|
||||
}
|
||||
|
||||
[AutoConstructor]
|
||||
private readonly partial struct ReadWriteTexture2DKernel : IComputeShader
|
||||
{
|
||||
public readonly ReadWriteTexture2D<int> source;
|
||||
public readonly ReadWriteTexture2D<int> destination;
|
||||
|
||||
public void Execute(ThreadIds ids)
|
||||
{
|
||||
destination[new((uint)ids.X, (uint)ids.Y)] = source[new((uint)ids.X, (uint)ids.Y)];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ namespace ComputeSharp.Tests
|
||||
{
|
||||
[TestClass]
|
||||
[TestCategory("Texture3D")]
|
||||
public class Texture3DTests
|
||||
public partial class Texture3DTests
|
||||
{
|
||||
[TestMethod]
|
||||
[DataRow(typeof(ReadOnlyTexture3D<>))]
|
||||
@@ -171,5 +171,61 @@ namespace ComputeSharp.Tests
|
||||
|
||||
texture.GetData(result, x, y, z, width, height, depth);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Dispatch_ReadOnlyTexture3D()
|
||||
{
|
||||
int[] data = Enumerable.Range(0, 32 * 32 * 3).ToArray();
|
||||
|
||||
using ReadOnlyTexture3D<int> source = Gpu.Default.AllocateReadOnlyTexture3D(data, 32, 32, 3);
|
||||
using ReadWriteBuffer<int> destination = Gpu.Default.AllocateReadWriteBuffer<int>(data.Length);
|
||||
|
||||
Gpu.Default.For(source.Width, source.Height, source.Depth, new ReadOnlyTexture3DKernel(source, destination));
|
||||
|
||||
int[] result = destination.GetData();
|
||||
|
||||
CollectionAssert.AreEqual(data, result);
|
||||
}
|
||||
|
||||
[AutoConstructor]
|
||||
private readonly partial struct ReadOnlyTexture3DKernel : IComputeShader
|
||||
{
|
||||
public readonly ReadOnlyTexture3D<int> source;
|
||||
public readonly ReadWriteBuffer<int> destination;
|
||||
|
||||
public void Execute(ThreadIds ids)
|
||||
{
|
||||
destination[ids.Z * 32 * 32 + ids.Y * 32 + ids.X] = source[new((uint)ids.X, (uint)ids.Y, (uint)ids.Z)];
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Dispatch_ReadWriteTexture2D()
|
||||
{
|
||||
int[] data = Enumerable.Range(0, 32 * 32 * 3).ToArray();
|
||||
|
||||
using ReadWriteTexture3D<int> source = Gpu.Default.AllocateReadWriteTexture3D(data, 32, 32, 3);
|
||||
using ReadWriteTexture3D<int> destination = Gpu.Default.AllocateReadWriteTexture3D<int>(32, 32, 3);
|
||||
|
||||
Gpu.Default.For(source.Width, source.Height, source.Depth, new ReadWriteTexture3DKernel(source, destination));
|
||||
|
||||
int[] result = new int[data.Length];
|
||||
|
||||
destination.GetData(result);
|
||||
|
||||
CollectionAssert.AreEqual(data, result);
|
||||
}
|
||||
|
||||
[AutoConstructor]
|
||||
private readonly partial struct ReadWriteTexture3DKernel : IComputeShader
|
||||
{
|
||||
public readonly ReadWriteTexture3D<int> source;
|
||||
public readonly ReadWriteTexture3D<int> destination;
|
||||
|
||||
public void Execute(ThreadIds ids)
|
||||
{
|
||||
destination[new((uint)ids.X, (uint)ids.Y, (uint)ids.Z)] = source[new((uint)ids.X, (uint)ids.Y, (uint)ids.Z)];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする