Enabled tests for both dedicated/WARP devices
このコミットが含まれているのは:
1 親
088b46e69c
コミット
4b23773873
16ファイル変更
+643
-651
検索条件に一致するファイルはありません
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using ComputeSharp.Resources;
|
||||
using ComputeSharp.Tests.Attributes;
|
||||
using ComputeSharp.Tests.Extensions;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
@@ -10,45 +11,47 @@ namespace ComputeSharp.Tests
|
||||
[TestCategory("Buffer")]
|
||||
public partial class BufferTests
|
||||
{
|
||||
[TestMethod]
|
||||
[DataRow(typeof(ConstantBuffer<>))]
|
||||
[DataRow(typeof(ReadOnlyBuffer<>))]
|
||||
[DataRow(typeof(ReadWriteBuffer<>))]
|
||||
public void Allocate_Uninitialized_Ok(Type bufferType)
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ConstantBuffer<>))]
|
||||
[Resource(typeof(ReadOnlyBuffer<>))]
|
||||
[Resource(typeof(ReadWriteBuffer<>))]
|
||||
public void Allocate_Uninitialized_Ok(Device device, Type bufferType)
|
||||
{
|
||||
using Buffer<float> buffer = Gpu.Default.AllocateBuffer<float>(bufferType, 128);
|
||||
using Buffer<float> buffer = device.Get().AllocateBuffer<float>(bufferType, 128);
|
||||
|
||||
Assert.IsNotNull(buffer);
|
||||
Assert.AreEqual(buffer.Length, 128);
|
||||
Assert.AreSame(buffer.GraphicsDevice, Gpu.Default);
|
||||
Assert.AreSame(buffer.GraphicsDevice, device.Get());
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow(typeof(ConstantBuffer<>), -247824)]
|
||||
[DataRow(typeof(ConstantBuffer<>), -1)]
|
||||
[DataRow(typeof(ReadOnlyBuffer<>), -247824)]
|
||||
[DataRow(typeof(ReadOnlyBuffer<>), -1)]
|
||||
[DataRow(typeof(ReadWriteBuffer<>), -247824)]
|
||||
[DataRow(typeof(ReadWriteBuffer<>), -1)]
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ConstantBuffer<>))]
|
||||
[Resource(typeof(ReadOnlyBuffer<>))]
|
||||
[Resource(typeof(ReadWriteBuffer<>))]
|
||||
[Data(-247824)]
|
||||
[Data(-1)]
|
||||
[ExpectedException(typeof(ArgumentOutOfRangeException))]
|
||||
public void Allocate_Uninitialized_Fail(Type bufferType, int length)
|
||||
public void Allocate_Uninitialized_Fail(Device device, Type bufferType, int length)
|
||||
{
|
||||
using Buffer<float> buffer = Gpu.Default.AllocateBuffer<float>(bufferType, length);
|
||||
using Buffer<float> buffer = device.Get().AllocateBuffer<float>(bufferType, length);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow(typeof(ConstantBuffer<>))]
|
||||
[DataRow(typeof(ReadOnlyBuffer<>))]
|
||||
[DataRow(typeof(ReadWriteBuffer<>))]
|
||||
public void Allocate_FromArray(Type bufferType)
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ConstantBuffer<>))]
|
||||
[Resource(typeof(ReadOnlyBuffer<>))]
|
||||
[Resource(typeof(ReadWriteBuffer<>))]
|
||||
public void Allocate_FromArray(Device device, Type bufferType)
|
||||
{
|
||||
float[] data = Enumerable.Range(0, 128).Select(static i => (float)i).ToArray();
|
||||
|
||||
using Buffer<float> buffer = Gpu.Default.AllocateBuffer(bufferType, data);
|
||||
using Buffer<float> buffer = device.Get().AllocateBuffer(bufferType, data);
|
||||
|
||||
Assert.IsNotNull(buffer);
|
||||
Assert.AreEqual(buffer.Length, 128);
|
||||
Assert.AreSame(buffer.GraphicsDevice, Gpu.Default);
|
||||
Assert.AreSame(buffer.GraphicsDevice, device.Get());
|
||||
|
||||
float[] result = buffer.ToArray();
|
||||
|
||||
@@ -57,26 +60,24 @@ namespace ComputeSharp.Tests
|
||||
Assert.IsTrue(data.SequenceEqual(result));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow(typeof(ConstantBuffer<>), typeof(ConstantBuffer<>))]
|
||||
[DataRow(typeof(ConstantBuffer<>), typeof(ReadOnlyBuffer<>))]
|
||||
[DataRow(typeof(ConstantBuffer<>), typeof(ReadWriteBuffer<>))]
|
||||
[DataRow(typeof(ReadOnlyBuffer<>), typeof(ConstantBuffer<>))]
|
||||
[DataRow(typeof(ReadOnlyBuffer<>), typeof(ReadOnlyBuffer<>))]
|
||||
[DataRow(typeof(ReadOnlyBuffer<>), typeof(ReadWriteBuffer<>))]
|
||||
[DataRow(typeof(ReadWriteBuffer<>), typeof(ConstantBuffer<>))]
|
||||
[DataRow(typeof(ReadWriteBuffer<>), typeof(ReadOnlyBuffer<>))]
|
||||
[DataRow(typeof(ReadWriteBuffer<>), typeof(ReadWriteBuffer<>))]
|
||||
public void Allocate_FromBuffer(Type sourceType, Type destinationType)
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ConstantBuffer<>))]
|
||||
[Resource(typeof(ReadOnlyBuffer<>))]
|
||||
[Resource(typeof(ReadWriteBuffer<>))]
|
||||
[Data(typeof(ConstantBuffer<>))]
|
||||
[Data(typeof(ReadOnlyBuffer<>))]
|
||||
[Data(typeof(ReadWriteBuffer<>))]
|
||||
public void Allocate_FromBuffer(Device device, Type sourceType, Type destinationType)
|
||||
{
|
||||
float[] data = Enumerable.Range(0, 128).Select(static i => (float)i).ToArray();
|
||||
|
||||
using Buffer<float> source = Gpu.Default.AllocateBuffer(sourceType, data);
|
||||
using Buffer<float> destination = Gpu.Default.AllocateBuffer(destinationType, source);
|
||||
using Buffer<float> source = device.Get().AllocateBuffer(sourceType, data);
|
||||
using Buffer<float> destination = device.Get().AllocateBuffer(destinationType, source);
|
||||
|
||||
Assert.IsNotNull(destination);
|
||||
Assert.AreEqual(destination.Length, 128);
|
||||
Assert.AreSame(destination.GraphicsDevice, Gpu.Default);
|
||||
Assert.AreSame(destination.GraphicsDevice, device.Get());
|
||||
|
||||
float[] result = destination.ToArray();
|
||||
|
||||
@@ -85,35 +86,34 @@ namespace ComputeSharp.Tests
|
||||
Assert.IsTrue(data.SequenceEqual(result));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow(typeof(ConstantBuffer<>))]
|
||||
[DataRow(typeof(ReadOnlyBuffer<>))]
|
||||
[DataRow(typeof(ReadWriteBuffer<>))]
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ConstantBuffer<>))]
|
||||
[Resource(typeof(ReadOnlyBuffer<>))]
|
||||
[Resource(typeof(ReadWriteBuffer<>))]
|
||||
[ExpectedException(typeof(ObjectDisposedException))]
|
||||
public void UsageAfterDispose(Type bufferType)
|
||||
public void UsageAfterDispose(Device device, Type bufferType)
|
||||
{
|
||||
using Buffer<float> buffer = Gpu.Default.AllocateBuffer<float>(bufferType, 128);
|
||||
using Buffer<float> buffer = device.Get().AllocateBuffer<float>(bufferType, 128);
|
||||
|
||||
buffer.Dispose();
|
||||
|
||||
_ = buffer.ToArray();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow(typeof(ConstantBuffer<>), 0, 4096)]
|
||||
[DataRow(typeof(ConstantBuffer<>), 128, 512)]
|
||||
[DataRow(typeof(ConstantBuffer<>), 2048, 2048)]
|
||||
[DataRow(typeof(ReadOnlyBuffer<>), 0, 4096)]
|
||||
[DataRow(typeof(ReadOnlyBuffer<>), 128, 512)]
|
||||
[DataRow(typeof(ReadOnlyBuffer<>), 2048, 2048)]
|
||||
[DataRow(typeof(ReadWriteBuffer<>), 0, 4096)]
|
||||
[DataRow(typeof(ReadWriteBuffer<>), 128, 512)]
|
||||
[DataRow(typeof(ReadWriteBuffer<>), 2048, 2048)]
|
||||
public void CopyTo_RangeToArray_Ok(Type bufferType, int offset, int count)
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ConstantBuffer<>))]
|
||||
[Resource(typeof(ReadOnlyBuffer<>))]
|
||||
[Resource(typeof(ReadWriteBuffer<>))]
|
||||
[Data(0, 4096)]
|
||||
[Data(128, 512)]
|
||||
[Data(2048, 2048)]
|
||||
public void CopyTo_RangeToArray_Ok(Device device, Type bufferType, int offset, int count)
|
||||
{
|
||||
float[] array = Enumerable.Range(0, 4096).Select(static i => (float)i).ToArray();
|
||||
|
||||
using Buffer<float> buffer = Gpu.Default.AllocateBuffer(bufferType, array);
|
||||
using Buffer<float> buffer = device.Get().AllocateBuffer(bufferType, array);
|
||||
|
||||
float[] result = buffer.ToArray(offset, count);
|
||||
|
||||
@@ -122,47 +122,39 @@ namespace ComputeSharp.Tests
|
||||
Assert.IsTrue(array.AsSpan(offset, count).SequenceEqual(result));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow(typeof(ConstantBuffer<>), -1, 128)]
|
||||
[DataRow(typeof(ConstantBuffer<>), 8192, 128)]
|
||||
[DataRow(typeof(ConstantBuffer<>), 512, 4096)]
|
||||
[DataRow(typeof(ConstantBuffer<>), 512, -128)]
|
||||
[DataRow(typeof(ReadOnlyBuffer<>), -1, 128)]
|
||||
[DataRow(typeof(ReadOnlyBuffer<>), 8192, 128)]
|
||||
[DataRow(typeof(ReadOnlyBuffer<>), 512, 4096)]
|
||||
[DataRow(typeof(ReadOnlyBuffer<>), 512, -128)]
|
||||
[DataRow(typeof(ReadWriteBuffer<>), -1, 128)]
|
||||
[DataRow(typeof(ReadWriteBuffer<>), 8192, 128)]
|
||||
[DataRow(typeof(ReadWriteBuffer<>), 512, 4096)]
|
||||
[DataRow(typeof(ReadWriteBuffer<>), 512, -128)]
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ConstantBuffer<>))]
|
||||
[Resource(typeof(ReadOnlyBuffer<>))]
|
||||
[Resource(typeof(ReadWriteBuffer<>))]
|
||||
[Data(-1, 128)]
|
||||
[Data(8192, 128)]
|
||||
[Data(512, 4096)]
|
||||
[Data(512, -128)]
|
||||
[ExpectedException(typeof(ArgumentOutOfRangeException))]
|
||||
public void CopyTo_RangeToArray_Fail(Type bufferType, int offset, int count)
|
||||
public void CopyTo_RangeToArray_Fail(Device device, Type bufferType, int offset, int count)
|
||||
{
|
||||
float[] array = Enumerable.Range(0, 4096).Select(static i => (float)i).ToArray();
|
||||
|
||||
using Buffer<float> buffer = Gpu.Default.AllocateBuffer(bufferType, array);
|
||||
using Buffer<float> buffer = device.Get().AllocateBuffer(bufferType, array);
|
||||
|
||||
_ = buffer.ToArray(offset, count);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow(typeof(ConstantBuffer<>), 0, 0, 4096)]
|
||||
[DataRow(typeof(ConstantBuffer<>), 512, 0, 2048)]
|
||||
[DataRow(typeof(ConstantBuffer<>), 0, 512, 2048)]
|
||||
[DataRow(typeof(ConstantBuffer<>), 127, 1024, 587)]
|
||||
[DataRow(typeof(ReadOnlyBuffer<>), 0, 0, 4096)]
|
||||
[DataRow(typeof(ReadOnlyBuffer<>), 512, 0, 2048)]
|
||||
[DataRow(typeof(ReadOnlyBuffer<>), 0, 512, 2048)]
|
||||
[DataRow(typeof(ReadOnlyBuffer<>), 127, 1024, 587)]
|
||||
[DataRow(typeof(ReadWriteBuffer<>), 0, 0, 4096)]
|
||||
[DataRow(typeof(ReadWriteBuffer<>), 512, 0, 2048)]
|
||||
[DataRow(typeof(ReadWriteBuffer<>), 0, 512, 2048)]
|
||||
[DataRow(typeof(ReadWriteBuffer<>), 127, 1024, 587)]
|
||||
public void CopyTo_RangeToVoid_Ok(Type bufferType, int destinationOffset, int bufferOffset, int count)
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ConstantBuffer<>))]
|
||||
[Resource(typeof(ReadOnlyBuffer<>))]
|
||||
[Resource(typeof(ReadWriteBuffer<>))]
|
||||
[Data(0, 0, 4096)]
|
||||
[Data(512, 0, 2048)]
|
||||
[Data(0, 512, 2048)]
|
||||
[Data(127, 1024, 587)]
|
||||
public void CopyTo_RangeToVoid_Ok(Device device, Type bufferType, int destinationOffset, int bufferOffset, int count)
|
||||
{
|
||||
float[] array = Enumerable.Range(0, 4096).Select(static i => (float)i).ToArray();
|
||||
|
||||
using Buffer<float> buffer = Gpu.Default.AllocateBuffer(bufferType, array);
|
||||
using Buffer<float> buffer = device.Get().AllocateBuffer(bufferType, array);
|
||||
|
||||
float[] result = new float[4096];
|
||||
|
||||
@@ -171,46 +163,39 @@ namespace ComputeSharp.Tests
|
||||
Assert.IsTrue(array.AsSpan(bufferOffset, count).SequenceEqual(result.AsSpan(destinationOffset, count)));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow(typeof(ConstantBuffer<>), 0, 0, 8196)]
|
||||
[DataRow(typeof(ConstantBuffer<>), -12, 0, 1024)]
|
||||
[DataRow(typeof(ConstantBuffer<>), 0, -56, 1024)]
|
||||
[DataRow(typeof(ConstantBuffer<>), 512, 0, 4096)]
|
||||
[DataRow(typeof(ConstantBuffer<>), 12, 1024, 3600)]
|
||||
[DataRow(typeof(ConstantBuffer<>), 12, 1024, -2096)]
|
||||
[DataRow(typeof(ReadOnlyBuffer<>), 0, 0, 8196)]
|
||||
[DataRow(typeof(ReadOnlyBuffer<>), -12, 0, 1024)]
|
||||
[DataRow(typeof(ReadOnlyBuffer<>), 0, -56, 1024)]
|
||||
[DataRow(typeof(ReadOnlyBuffer<>), 512, 0, 4096)]
|
||||
[DataRow(typeof(ReadOnlyBuffer<>), 12, 1024, 3600)]
|
||||
[DataRow(typeof(ReadOnlyBuffer<>), 12, 1024, -2096)]
|
||||
[DataRow(typeof(ReadWriteBuffer<>), 0, 0, 8196)]
|
||||
[DataRow(typeof(ReadWriteBuffer<>), -12, 0, 1024)]
|
||||
[DataRow(typeof(ReadWriteBuffer<>), 0, -56, 1024)]
|
||||
[DataRow(typeof(ReadWriteBuffer<>), 512, 0, 4096)]
|
||||
[DataRow(typeof(ReadWriteBuffer<>), 12, 1024, 3600)]
|
||||
[DataRow(typeof(ReadWriteBuffer<>), 12, 1024, -2096)]
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ConstantBuffer<>))]
|
||||
[Resource(typeof(ReadOnlyBuffer<>))]
|
||||
[Resource(typeof(ReadWriteBuffer<>))]
|
||||
[Data(0, 0, 8196)]
|
||||
[Data(-12, 0, 1024)]
|
||||
[Data(0, -56, 1024)]
|
||||
[Data(512, 0, 4096)]
|
||||
[Data(12, 1024, 3600)]
|
||||
[Data(12, 1024, -2096)]
|
||||
[ExpectedException(typeof(ArgumentOutOfRangeException))]
|
||||
public void CopyTo_RangeToVoid_Fail(Type bufferType, int destinationOffset, int bufferOffset, int count)
|
||||
public void CopyTo_RangeToVoid_Fail(Device device, Type bufferType, int destinationOffset, int bufferOffset, int count)
|
||||
{
|
||||
float[] array = Enumerable.Range(0, 4096).Select(static i => (float)i).ToArray();
|
||||
|
||||
using Buffer<float> buffer = Gpu.Default.AllocateBuffer(bufferType, array);
|
||||
using Buffer<float> buffer = device.Get().AllocateBuffer(bufferType, array);
|
||||
|
||||
float[] result = new float[4096];
|
||||
|
||||
buffer.CopyTo(result, destinationOffset, bufferOffset, count);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Dispatch_ConstantBuffer()
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
public void Dispatch_ConstantBuffer(Device device)
|
||||
{
|
||||
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);
|
||||
using ConstantBuffer<int> source = device.Get().AllocateConstantBuffer(data);
|
||||
using ReadWriteBuffer<int> destination = device.Get().AllocateReadWriteBuffer<int>(data.Length);
|
||||
|
||||
Gpu.Default.For(source.Length, new ConstantBufferKernel(source, destination));
|
||||
device.Get().For(source.Length, new ConstantBufferKernel(source, destination));
|
||||
|
||||
int[] result = destination.ToArray();
|
||||
|
||||
@@ -229,15 +214,16 @@ namespace ComputeSharp.Tests
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Dispatch_ReadOnlyBuffer()
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
public void Dispatch_ReadOnlyBuffer(Device device)
|
||||
{
|
||||
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);
|
||||
using ReadOnlyBuffer<int> source = device.Get().AllocateReadOnlyBuffer(data);
|
||||
using ReadWriteBuffer<int> destination = device.Get().AllocateReadWriteBuffer<int>(data.Length);
|
||||
|
||||
Gpu.Default.For(source.Length, new ReadOnlyBufferKernel(source, destination));
|
||||
device.Get().For(source.Length, new ReadOnlyBufferKernel(source, destination));
|
||||
|
||||
int[] result = destination.ToArray();
|
||||
|
||||
@@ -256,15 +242,16 @@ namespace ComputeSharp.Tests
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Dispatch_ReadWriteBuffer()
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
public void Dispatch_ReadWriteBuffer(Device device)
|
||||
{
|
||||
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);
|
||||
using ReadWriteBuffer<int> source = device.Get().AllocateReadWriteBuffer(data);
|
||||
using ReadWriteBuffer<int> destination = device.Get().AllocateReadWriteBuffer<int>(data.Length);
|
||||
|
||||
Gpu.Default.For(source.Length, new ReadWriteBufferKernel(source, destination));
|
||||
device.Get().For(source.Length, new ReadWriteBufferKernel(source, destination));
|
||||
|
||||
int[] result = destination.ToArray();
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
<TargetFrameworks>net5.0</TargetFrameworks>
|
||||
<IsPackable>false</IsPackable>
|
||||
<LangVersion>9.0</LangVersion>
|
||||
<Nullable>enable</Nullable>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using ComputeSharp.Tests.Attributes;
|
||||
using ComputeSharp.Tests.Extensions;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace ComputeSharp.Tests
|
||||
@@ -7,12 +9,13 @@ namespace ComputeSharp.Tests
|
||||
[TestCategory("Dispatch")]
|
||||
public partial class DispatchTests
|
||||
{
|
||||
[TestMethod]
|
||||
public void Verify_ThreadIds()
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
public void Verify_ThreadIds(Device device)
|
||||
{
|
||||
using ReadWriteTexture3D<Int4> buffer = Gpu.Default.AllocateReadWriteTexture3D<Int4>(50, 50, 50);
|
||||
using ReadWriteTexture3D<Int4> buffer = device.Get().AllocateReadWriteTexture3D<Int4>(50, 50, 50);
|
||||
|
||||
Gpu.Default.For(buffer.Width, buffer.Height, buffer.Depth, new ThreadIdsShader(buffer));
|
||||
device.Get().For(buffer.Width, buffer.Height, buffer.Depth, new ThreadIdsShader(buffer));
|
||||
|
||||
Int4[,,] data = buffer.ToArray();
|
||||
|
||||
@@ -32,18 +35,19 @@ namespace ComputeSharp.Tests
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow(0, 8, 8)]
|
||||
[DataRow(8, 0, 8)]
|
||||
[DataRow(8, 8, 0)]
|
||||
[DataRow(8, -3, 16)]
|
||||
[DataRow(-1, -1, -1)]
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Data(0, 8, 8)]
|
||||
[Data(8, 0, 8)]
|
||||
[Data(8, 8, 0)]
|
||||
[Data(8, -3, 16)]
|
||||
[Data(-1, -1, -1)]
|
||||
[ExpectedException(typeof(ArgumentOutOfRangeException))]
|
||||
public void Verify_ThreadIds_OutOfRange(int x, int y, int z)
|
||||
public void Verify_ThreadIds_OutOfRange(Device device, int x, int y, int z)
|
||||
{
|
||||
using ReadWriteTexture3D<Int4> buffer = Gpu.Default.AllocateReadWriteTexture3D<Int4>(50, 50, 50);
|
||||
using ReadWriteTexture3D<Int4> buffer = device.Get().AllocateReadWriteTexture3D<Int4>(50, 50, 50);
|
||||
|
||||
Gpu.Default.For(x, y, z, new ThreadIdsShader(buffer));
|
||||
device.Get().For(x, y, z, new ThreadIdsShader(buffer));
|
||||
|
||||
Assert.Fail();
|
||||
}
|
||||
@@ -59,12 +63,13 @@ namespace ComputeSharp.Tests
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Verify_GroupIds()
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
public void Verify_GroupIds(Device device)
|
||||
{
|
||||
using ReadWriteTexture3D<Int4> buffer = Gpu.Default.AllocateReadWriteTexture3D<Int4>(50, 50, 50);
|
||||
using ReadWriteTexture3D<Int4> buffer = device.Get().AllocateReadWriteTexture3D<Int4>(50, 50, 50);
|
||||
|
||||
Gpu.Default.For(buffer.Width, buffer.Height, buffer.Depth, 4, 4, 4, new GroupIdsShader(buffer));
|
||||
device.Get().For(buffer.Width, buffer.Height, buffer.Depth, 4, 4, 4, new GroupIdsShader(buffer));
|
||||
|
||||
Int4[,,] data = buffer.ToArray();
|
||||
|
||||
@@ -85,21 +90,22 @@ namespace ComputeSharp.Tests
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow(0, 8, 8)]
|
||||
[DataRow(8, 0, 8)]
|
||||
[DataRow(8, 8, 0)]
|
||||
[DataRow(1025, 8, 8)]
|
||||
[DataRow(8, 2000, 8)]
|
||||
[DataRow(8, 8, 70)]
|
||||
[DataRow(8, -1, 8)]
|
||||
[DataRow(8, 15, 16)]
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Data(0, 8, 8)]
|
||||
[Data(8, 0, 8)]
|
||||
[Data(8, 8, 0)]
|
||||
[Data(1025, 8, 8)]
|
||||
[Data(8, 2000, 8)]
|
||||
[Data(8, 8, 70)]
|
||||
[Data(8, -1, 8)]
|
||||
[Data(8, 15, 16)]
|
||||
[ExpectedException(typeof(ArgumentOutOfRangeException))]
|
||||
public void Verify_GroupIds_OutOfRange(int x, int y, int z)
|
||||
public void Verify_GroupIds_OutOfRange(Device device, int x, int y, int z)
|
||||
{
|
||||
using ReadWriteTexture3D<Int4> buffer = Gpu.Default.AllocateReadWriteTexture3D<Int4>(50, 50, 50);
|
||||
using ReadWriteTexture3D<Int4> buffer = device.Get().AllocateReadWriteTexture3D<Int4>(50, 50, 50);
|
||||
|
||||
Gpu.Default.For(buffer.Width, buffer.Height, buffer.Depth, x, y, z, new GroupIdsShader(buffer));
|
||||
device.Get().For(buffer.Width, buffer.Height, buffer.Depth, x, y, z, new GroupIdsShader(buffer));
|
||||
|
||||
Assert.Fail();
|
||||
}
|
||||
@@ -116,12 +122,13 @@ namespace ComputeSharp.Tests
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Verify_GroupSize()
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
public void Verify_GroupSize(Device device)
|
||||
{
|
||||
using ReadWriteBuffer<int> buffer = Gpu.Default.AllocateReadWriteBuffer<int>(32);
|
||||
using ReadWriteBuffer<int> buffer = device.Get().AllocateReadWriteBuffer<int>(32);
|
||||
|
||||
Gpu.Default.For(1, 1, 1, 4, 15, 7, new GroupSizeShader(buffer));
|
||||
device.Get().For(1, 1, 1, 4, 15, 7, new GroupSizeShader(buffer));
|
||||
|
||||
int[] data = buffer.ToArray();
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace ComputeSharp.Tests
|
||||
[TestMethod]
|
||||
public void BokehBlur()
|
||||
{
|
||||
string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Imaging");
|
||||
string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Imaging");
|
||||
|
||||
using var original = Image.Load<ImageSharpRgba32>(Path.Combine(path, "city.jpg"));
|
||||
using var cpu = original.Clone(c => c.BokehBlur(80, 2, 3));
|
||||
@@ -38,7 +38,7 @@ namespace ComputeSharp.Tests
|
||||
[TestMethod]
|
||||
public void GaussianBlur()
|
||||
{
|
||||
string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Imaging");
|
||||
string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Imaging");
|
||||
|
||||
using var original = Image.Load<ImageSharpRgba32>(Path.Combine(path, "city.jpg"));
|
||||
using var cpu = original.Clone(c => c.GaussianBlur(30f));
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using ComputeSharp.Tests.Attributes;
|
||||
using ComputeSharp.Tests.Extensions;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace ComputeSharp.Tests
|
||||
@@ -14,23 +16,26 @@ namespace ComputeSharp.Tests
|
||||
Assert.IsTrue(Gpu.IsSupported);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void DefaultDeviceInfo()
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
public void DeviceInfo(Device device)
|
||||
{
|
||||
Assert.IsTrue(Gpu.Default.Luid != default);
|
||||
Assert.IsTrue(Gpu.Default.Name is { Length: > 0 });
|
||||
GraphicsDevice gpu = device.Get();
|
||||
|
||||
if (Gpu.Default.IsHardwareAccelerated)
|
||||
Assert.IsTrue(gpu.Luid != default);
|
||||
Assert.IsTrue(gpu.Name is { Length: > 0 });
|
||||
|
||||
if (gpu.IsHardwareAccelerated)
|
||||
{
|
||||
Assert.IsTrue(Gpu.Default.DedicatedMemorySize != 0);
|
||||
Assert.IsTrue(gpu.DedicatedMemorySize != 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.IsTrue(Gpu.Default.SharedMemorySize != 0);
|
||||
Assert.IsTrue(gpu.SharedMemorySize != 0);
|
||||
}
|
||||
|
||||
Assert.IsTrue(Gpu.Default.ComputeUnits != 0);
|
||||
Assert.IsTrue(Gpu.Default.WavefrontSize != 0);
|
||||
Assert.IsTrue(gpu.ComputeUnits != 0);
|
||||
Assert.IsTrue(gpu.WavefrontSize != 0);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Numerics;
|
||||
using System.Reflection;
|
||||
using ComputeSharp.__Internals;
|
||||
using ComputeSharp.Resources;
|
||||
using ComputeSharp.Tests.Attributes;
|
||||
using ComputeSharp.Tests.Extensions;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
@@ -12,43 +13,34 @@ namespace ComputeSharp.Tests
|
||||
{
|
||||
public partial class Texture2DTests
|
||||
{
|
||||
[TestMethod]
|
||||
[DataRow(typeof(ReadOnlyTexture2D<,>), typeof(Bgra32), typeof(Vector4))]
|
||||
[DataRow(typeof(ReadOnlyTexture2D<,>), typeof(Bgra32), typeof(Float4))]
|
||||
[DataRow(typeof(ReadOnlyTexture2D<,>), typeof(R16), typeof(float))]
|
||||
[DataRow(typeof(ReadOnlyTexture2D<,>), typeof(R8), typeof(float))]
|
||||
[DataRow(typeof(ReadOnlyTexture2D<,>), typeof(Rg16), typeof(Vector2))]
|
||||
[DataRow(typeof(ReadOnlyTexture2D<,>), typeof(Rg16), typeof(Float2))]
|
||||
[DataRow(typeof(ReadOnlyTexture2D<,>), typeof(Rg32), typeof(Vector2))]
|
||||
[DataRow(typeof(ReadOnlyTexture2D<,>), typeof(Rg32), typeof(Float2))]
|
||||
[DataRow(typeof(ReadOnlyTexture2D<,>), typeof(Rgba32), typeof(Vector4))]
|
||||
[DataRow(typeof(ReadOnlyTexture2D<,>), typeof(Rgba32), typeof(Float4))]
|
||||
[DataRow(typeof(ReadOnlyTexture2D<,>), typeof(Rgba64), typeof(Vector4))]
|
||||
[DataRow(typeof(ReadOnlyTexture2D<,>), typeof(Rgba64), typeof(Float4))]
|
||||
[DataRow(typeof(ReadWriteTexture2D<,>), typeof(Bgra32), typeof(Vector4))]
|
||||
[DataRow(typeof(ReadWriteTexture2D<,>), typeof(Bgra32), typeof(Float4))]
|
||||
[DataRow(typeof(ReadWriteTexture2D<,>), typeof(R16), typeof(float))]
|
||||
[DataRow(typeof(ReadWriteTexture2D<,>), typeof(R8), typeof(float))]
|
||||
[DataRow(typeof(ReadWriteTexture2D<,>), typeof(Rg16), typeof(Vector2))]
|
||||
[DataRow(typeof(ReadWriteTexture2D<,>), typeof(Rg16), typeof(Float2))]
|
||||
[DataRow(typeof(ReadWriteTexture2D<,>), typeof(Rg32), typeof(Vector2))]
|
||||
[DataRow(typeof(ReadWriteTexture2D<,>), typeof(Rg32), typeof(Float2))]
|
||||
[DataRow(typeof(ReadWriteTexture2D<,>), typeof(Rgba32), typeof(Vector4))]
|
||||
[DataRow(typeof(ReadWriteTexture2D<,>), typeof(Rgba32), typeof(Float4))]
|
||||
[DataRow(typeof(ReadWriteTexture2D<,>), typeof(Rgba64), typeof(Vector4))]
|
||||
[DataRow(typeof(ReadWriteTexture2D<,>), typeof(Rgba64), typeof(Float4))]
|
||||
public void Allocate_Uninitialized_Pixel_Ok(Type textureType, Type t, Type tPixel)
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ReadOnlyTexture2D<,>))]
|
||||
[Resource(typeof(ReadWriteTexture2D<,>))]
|
||||
[Data(typeof(Bgra32), typeof(Vector4))]
|
||||
[Data(typeof(Bgra32), typeof(Float4))]
|
||||
[Data(typeof(R16), typeof(float))]
|
||||
[Data(typeof(R8), typeof(float))]
|
||||
[Data(typeof(Rg16), typeof(Vector2))]
|
||||
[Data(typeof(Rg16), typeof(Float2))]
|
||||
[Data(typeof(Rg32), typeof(Vector2))]
|
||||
[Data(typeof(Rg32), typeof(Float2))]
|
||||
[Data(typeof(Rgba32), typeof(Vector4))]
|
||||
[Data(typeof(Rgba32), typeof(Float4))]
|
||||
[Data(typeof(Rgba64), typeof(Vector4))]
|
||||
[Data(typeof(Rgba64), typeof(Float4))]
|
||||
public void Allocate_Uninitialized_Pixel_Ok(Device device, Type textureType, Type t, Type tPixel)
|
||||
{
|
||||
static void Test<T, TPixel>(Type textureType)
|
||||
static void Test<T, TPixel>(Device device, Type textureType)
|
||||
where T : unmanaged, IUnorm<TPixel>
|
||||
where TPixel : unmanaged
|
||||
{
|
||||
using Texture2D<T> texture = Gpu.Default.AllocateTexture2D<T, TPixel>(textureType, 128, 128);
|
||||
using Texture2D<T> texture = device.Get().AllocateTexture2D<T, TPixel>(textureType, 128, 128);
|
||||
|
||||
Assert.IsNotNull(texture);
|
||||
Assert.AreEqual(texture.Width, 128);
|
||||
Assert.AreEqual(texture.Height, 128);
|
||||
Assert.AreSame(texture.GraphicsDevice, Gpu.Default);
|
||||
Assert.AreSame(texture.GraphicsDevice, device.Get());
|
||||
|
||||
if (textureType == typeof(ReadOnlyTexture2D<,>))
|
||||
{
|
||||
@@ -62,7 +54,7 @@ namespace ComputeSharp.Tests
|
||||
|
||||
try
|
||||
{
|
||||
new Action<Type>(Test<Rgba32, Vector4>).Method.GetGenericMethodDefinition().MakeGenericMethod(t, tPixel).Invoke(null, new[] { textureType });
|
||||
new Action<Device, Type>(Test<Rgba32, Vector4>).Method.GetGenericMethodDefinition().MakeGenericMethod(t, tPixel).Invoke(null, new object[] { device, textureType });
|
||||
}
|
||||
catch (TargetInvocationException e) when (e.InnerException is not null)
|
||||
{
|
||||
|
||||
@@ -1,109 +1,111 @@
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using ComputeSharp.Tests.Attributes;
|
||||
using ComputeSharp.Tests.Extensions;
|
||||
|
||||
namespace ComputeSharp.Tests
|
||||
{
|
||||
public partial class Texture2DTests
|
||||
{
|
||||
[TestMethod]
|
||||
[DataRow(typeof(Bgra32), typeof(Vector4))]
|
||||
[DataRow(typeof(Bgra32), typeof(Float4))]
|
||||
[DataRow(typeof(R16), typeof(float))]
|
||||
[DataRow(typeof(R8), typeof(float))]
|
||||
[DataRow(typeof(Rg16), typeof(Vector2))]
|
||||
[DataRow(typeof(Rg16), typeof(Float2))]
|
||||
[DataRow(typeof(Rg32), typeof(Vector2))]
|
||||
[DataRow(typeof(Rg32), typeof(Float2))]
|
||||
[DataRow(typeof(Rgba32), typeof(Vector4))]
|
||||
[DataRow(typeof(Rgba32), typeof(Float4))]
|
||||
[DataRow(typeof(Rgba64), typeof(Vector4))]
|
||||
[DataRow(typeof(Rgba64), typeof(Float4))]
|
||||
public void Dispatch_NormalizedTexture2D(Type t, Type tPixel)
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Data(typeof(Bgra32), typeof(Vector4))]
|
||||
[Data(typeof(Bgra32), typeof(Float4))]
|
||||
[Data(typeof(R16), typeof(float))]
|
||||
[Data(typeof(R8), typeof(float))]
|
||||
[Data(typeof(Rg16), typeof(Vector2))]
|
||||
[Data(typeof(Rg16), typeof(Float2))]
|
||||
[Data(typeof(Rg32), typeof(Vector2))]
|
||||
[Data(typeof(Rg32), typeof(Float2))]
|
||||
[Data(typeof(Rgba32), typeof(Vector4))]
|
||||
[Data(typeof(Rgba32), typeof(Float4))]
|
||||
[Data(typeof(Rgba64), typeof(Vector4))]
|
||||
[Data(typeof(Rgba64), typeof(Float4))]
|
||||
public void Dispatch_NormalizedTexture2D(Device device, Type t, Type tPixel)
|
||||
{
|
||||
if (t == typeof(Bgra32) && tPixel == typeof(Vector4))
|
||||
{
|
||||
using ReadOnlyTexture2D<Bgra32, Vector4> source = Gpu.Default.AllocateReadOnlyTexture2D<Bgra32, Vector4>(128, 128);
|
||||
using ReadWriteTexture2D<Bgra32, Vector4> destination = Gpu.Default.AllocateReadWriteTexture2D<Bgra32, Vector4>(128, 128);
|
||||
using ReadOnlyTexture2D<Bgra32, Vector4> source = device.Get().AllocateReadOnlyTexture2D<Bgra32, Vector4>(128, 128);
|
||||
using ReadWriteTexture2D<Bgra32, Vector4> destination = device.Get().AllocateReadWriteTexture2D<Bgra32, Vector4>(128, 128);
|
||||
|
||||
Gpu.Default.For(128, 128, new Shader_Unorm_Bgra32_Vector4(source, destination));
|
||||
device.Get().For(128, 128, new Shader_Unorm_Bgra32_Vector4(source, destination));
|
||||
}
|
||||
if (t == typeof(Bgra32) && tPixel == typeof(Float4))
|
||||
{
|
||||
using ReadOnlyTexture2D<Bgra32, Float4> source = Gpu.Default.AllocateReadOnlyTexture2D<Bgra32, Float4>(128, 128);
|
||||
using ReadWriteTexture2D<Bgra32, Float4> destination = Gpu.Default.AllocateReadWriteTexture2D<Bgra32, Float4>(128, 128);
|
||||
using ReadOnlyTexture2D<Bgra32, Float4> source = device.Get().AllocateReadOnlyTexture2D<Bgra32, Float4>(128, 128);
|
||||
using ReadWriteTexture2D<Bgra32, Float4> destination = device.Get().AllocateReadWriteTexture2D<Bgra32, Float4>(128, 128);
|
||||
|
||||
Gpu.Default.For(128, 128, new Shader_Unorm_Bgra32_Float4(source, destination));
|
||||
device.Get().For(128, 128, new Shader_Unorm_Bgra32_Float4(source, destination));
|
||||
}
|
||||
if (t == typeof(R16) && tPixel == typeof(float))
|
||||
{
|
||||
using ReadOnlyTexture2D<R16, float> source = Gpu.Default.AllocateReadOnlyTexture2D<R16, float>(128, 128);
|
||||
using ReadWriteTexture2D<R16, float> destination = Gpu.Default.AllocateReadWriteTexture2D<R16, float>(128, 128);
|
||||
using ReadOnlyTexture2D<R16, float> source = device.Get().AllocateReadOnlyTexture2D<R16, float>(128, 128);
|
||||
using ReadWriteTexture2D<R16, float> destination = device.Get().AllocateReadWriteTexture2D<R16, float>(128, 128);
|
||||
|
||||
Gpu.Default.For(128, 128, new Shader_Unorm_R16_float(source, destination));
|
||||
device.Get().For(128, 128, new Shader_Unorm_R16_float(source, destination));
|
||||
}
|
||||
if (t == typeof(R8) && tPixel == typeof(float))
|
||||
{
|
||||
using ReadOnlyTexture2D<R8, float> source = Gpu.Default.AllocateReadOnlyTexture2D<R8, float>(128, 128);
|
||||
using ReadWriteTexture2D<R8, float> destination = Gpu.Default.AllocateReadWriteTexture2D<R8, float>(128, 128);
|
||||
using ReadOnlyTexture2D<R8, float> source = device.Get().AllocateReadOnlyTexture2D<R8, float>(128, 128);
|
||||
using ReadWriteTexture2D<R8, float> destination = device.Get().AllocateReadWriteTexture2D<R8, float>(128, 128);
|
||||
|
||||
Gpu.Default.For(128, 128, new Shader_Unorm_R8_float(source, destination));
|
||||
device.Get().For(128, 128, new Shader_Unorm_R8_float(source, destination));
|
||||
}
|
||||
if (t == typeof(Rg16) && tPixel == typeof(Vector2))
|
||||
{
|
||||
using ReadOnlyTexture2D<Rg16, Vector2> source = Gpu.Default.AllocateReadOnlyTexture2D<Rg16, Vector2>(128, 128);
|
||||
using ReadWriteTexture2D<Rg16, Vector2> destination = Gpu.Default.AllocateReadWriteTexture2D<Rg16, Vector2>(128, 128);
|
||||
using ReadOnlyTexture2D<Rg16, Vector2> source = device.Get().AllocateReadOnlyTexture2D<Rg16, Vector2>(128, 128);
|
||||
using ReadWriteTexture2D<Rg16, Vector2> destination = device.Get().AllocateReadWriteTexture2D<Rg16, Vector2>(128, 128);
|
||||
|
||||
Gpu.Default.For(128, 128, new Shader_Unorm_Rg16_Vector2(source, destination));
|
||||
device.Get().For(128, 128, new Shader_Unorm_Rg16_Vector2(source, destination));
|
||||
}
|
||||
if (t == typeof(Rg16) && tPixel == typeof(Float2))
|
||||
{
|
||||
using ReadOnlyTexture2D<Rg16, Float2> source = Gpu.Default.AllocateReadOnlyTexture2D<Rg16, Float2>(128, 128);
|
||||
using ReadWriteTexture2D<Rg16, Float2> destination = Gpu.Default.AllocateReadWriteTexture2D<Rg16, Float2>(128, 128);
|
||||
using ReadOnlyTexture2D<Rg16, Float2> source = device.Get().AllocateReadOnlyTexture2D<Rg16, Float2>(128, 128);
|
||||
using ReadWriteTexture2D<Rg16, Float2> destination = device.Get().AllocateReadWriteTexture2D<Rg16, Float2>(128, 128);
|
||||
|
||||
Gpu.Default.For(128, 128, new Shader_Unorm_Rg16_Float2(source, destination));
|
||||
device.Get().For(128, 128, new Shader_Unorm_Rg16_Float2(source, destination));
|
||||
}
|
||||
if (t == typeof(Rg32) && tPixel == typeof(Vector2))
|
||||
{
|
||||
using ReadOnlyTexture2D<Rg32, Vector2> source = Gpu.Default.AllocateReadOnlyTexture2D<Rg32, Vector2>(128, 128);
|
||||
using ReadWriteTexture2D<Rg32, Vector2> destination = Gpu.Default.AllocateReadWriteTexture2D<Rg32, Vector2>(128, 128);
|
||||
using ReadOnlyTexture2D<Rg32, Vector2> source = device.Get().AllocateReadOnlyTexture2D<Rg32, Vector2>(128, 128);
|
||||
using ReadWriteTexture2D<Rg32, Vector2> destination = device.Get().AllocateReadWriteTexture2D<Rg32, Vector2>(128, 128);
|
||||
|
||||
Gpu.Default.For(128, 128, new Shader_Unorm_Rg32_Vector2(source, destination));
|
||||
device.Get().For(128, 128, new Shader_Unorm_Rg32_Vector2(source, destination));
|
||||
}
|
||||
if (t == typeof(Rg32) && tPixel == typeof(Float2))
|
||||
{
|
||||
using ReadOnlyTexture2D<Rg32, Float2> source = Gpu.Default.AllocateReadOnlyTexture2D<Rg32, Float2>(128, 128);
|
||||
using ReadWriteTexture2D<Rg32, Float2> destination = Gpu.Default.AllocateReadWriteTexture2D<Rg32, Float2>(128, 128);
|
||||
using ReadOnlyTexture2D<Rg32, Float2> source = device.Get().AllocateReadOnlyTexture2D<Rg32, Float2>(128, 128);
|
||||
using ReadWriteTexture2D<Rg32, Float2> destination = device.Get().AllocateReadWriteTexture2D<Rg32, Float2>(128, 128);
|
||||
|
||||
Gpu.Default.For(128, 128, new Shader_Unorm_Rg32_Float2(source, destination));
|
||||
device.Get().For(128, 128, new Shader_Unorm_Rg32_Float2(source, destination));
|
||||
}
|
||||
if (t == typeof(Rgba32) && tPixel == typeof(Vector4))
|
||||
{
|
||||
using ReadOnlyTexture2D<Rgba32, Vector4> source = Gpu.Default.AllocateReadOnlyTexture2D<Rgba32, Vector4>(128, 128);
|
||||
using ReadWriteTexture2D<Rgba32, Vector4> destination = Gpu.Default.AllocateReadWriteTexture2D<Rgba32, Vector4>(128, 128);
|
||||
using ReadOnlyTexture2D<Rgba32, Vector4> source = device.Get().AllocateReadOnlyTexture2D<Rgba32, Vector4>(128, 128);
|
||||
using ReadWriteTexture2D<Rgba32, Vector4> destination = device.Get().AllocateReadWriteTexture2D<Rgba32, Vector4>(128, 128);
|
||||
|
||||
Gpu.Default.For(128, 128, new Shader_Unorm_Rgba32_Vector4(source, destination));
|
||||
device.Get().For(128, 128, new Shader_Unorm_Rgba32_Vector4(source, destination));
|
||||
}
|
||||
if (t == typeof(Rgba32) && tPixel == typeof(Float4))
|
||||
{
|
||||
using ReadOnlyTexture2D<Rgba32, Float4> source = Gpu.Default.AllocateReadOnlyTexture2D<Rgba32, Float4>(128, 128);
|
||||
using ReadWriteTexture2D<Rgba32, Float4> destination = Gpu.Default.AllocateReadWriteTexture2D<Rgba32, Float4>(128, 128);
|
||||
using ReadOnlyTexture2D<Rgba32, Float4> source = device.Get().AllocateReadOnlyTexture2D<Rgba32, Float4>(128, 128);
|
||||
using ReadWriteTexture2D<Rgba32, Float4> destination = device.Get().AllocateReadWriteTexture2D<Rgba32, Float4>(128, 128);
|
||||
|
||||
Gpu.Default.For(128, 128, new Shader_Unorm_Rgba32_Float4(source, destination));
|
||||
device.Get().For(128, 128, new Shader_Unorm_Rgba32_Float4(source, destination));
|
||||
}
|
||||
if (t == typeof(Rgba64) && tPixel == typeof(Vector4))
|
||||
{
|
||||
using ReadOnlyTexture2D<Rgba64, Vector4> source = Gpu.Default.AllocateReadOnlyTexture2D<Rgba64, Vector4>(128, 128);
|
||||
using ReadWriteTexture2D<Rgba64, Vector4> destination = Gpu.Default.AllocateReadWriteTexture2D<Rgba64, Vector4>(128, 128);
|
||||
using ReadOnlyTexture2D<Rgba64, Vector4> source = device.Get().AllocateReadOnlyTexture2D<Rgba64, Vector4>(128, 128);
|
||||
using ReadWriteTexture2D<Rgba64, Vector4> destination = device.Get().AllocateReadWriteTexture2D<Rgba64, Vector4>(128, 128);
|
||||
|
||||
Gpu.Default.For(128, 128, new Shader_Unorm_Rgba64_Vector4(source, destination));
|
||||
device.Get().For(128, 128, new Shader_Unorm_Rgba64_Vector4(source, destination));
|
||||
}
|
||||
if (t == typeof(Rgba64) && tPixel == typeof(Float4))
|
||||
{
|
||||
using ReadOnlyTexture2D<Rgba64, Float4> source = Gpu.Default.AllocateReadOnlyTexture2D<Rgba64, Float4>(128, 128);
|
||||
using ReadWriteTexture2D<Rgba64, Float4> destination = Gpu.Default.AllocateReadWriteTexture2D<Rgba64, Float4>(128, 128);
|
||||
using ReadOnlyTexture2D<Rgba64, Float4> source = device.Get().AllocateReadOnlyTexture2D<Rgba64, Float4>(128, 128);
|
||||
using ReadWriteTexture2D<Rgba64, Float4> destination = device.Get().AllocateReadWriteTexture2D<Rgba64, Float4>(128, 128);
|
||||
|
||||
Gpu.Default.For(128, 128, new Shader_Unorm_Rgba64_Float4(source, destination));
|
||||
device.Get().For(128, 128, new Shader_Unorm_Rgba64_Float4(source, destination));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,22 +25,24 @@ IEnumerable<(string T, string TPixel)> EnumerateTypes()
|
||||
#>
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using ComputeSharp.Tests.Attributes;
|
||||
using ComputeSharp.Tests.Extensions;
|
||||
|
||||
namespace ComputeSharp.Tests
|
||||
{
|
||||
public partial class Texture2DTests
|
||||
{
|
||||
[TestMethod]
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
<#
|
||||
foreach (var (t, tPixel) in EnumerateTypes())
|
||||
{
|
||||
#>
|
||||
[DataRow(typeof(<#=t#>), typeof(<#=tPixel#>))]
|
||||
[Data(typeof(<#=t#>), typeof(<#=tPixel#>))]
|
||||
<#
|
||||
}
|
||||
#>
|
||||
public void Dispatch_NormalizedTexture2D(Type t, Type tPixel)
|
||||
public void Dispatch_NormalizedTexture2D(Device device, Type t, Type tPixel)
|
||||
{
|
||||
<#
|
||||
foreach (var (t, tPixel) in EnumerateTypes())
|
||||
@@ -48,10 +50,10 @@ foreach (var (t, tPixel) in EnumerateTypes())
|
||||
#>
|
||||
if (t == typeof(<#=t#>) && tPixel == typeof(<#=tPixel#>))
|
||||
{
|
||||
using ReadOnlyTexture2D<<#=t#>, <#=tPixel#>> source = Gpu.Default.AllocateReadOnlyTexture2D<<#=t#>, <#=tPixel#>>(128, 128);
|
||||
using ReadWriteTexture2D<<#=t#>, <#=tPixel#>> destination = Gpu.Default.AllocateReadWriteTexture2D<<#=t#>, <#=tPixel#>>(128, 128);
|
||||
using ReadOnlyTexture2D<<#=t#>, <#=tPixel#>> source = device.Get().AllocateReadOnlyTexture2D<<#=t#>, <#=tPixel#>>(128, 128);
|
||||
using ReadWriteTexture2D<<#=t#>, <#=tPixel#>> destination = device.Get().AllocateReadWriteTexture2D<<#=t#>, <#=tPixel#>>(128, 128);
|
||||
|
||||
Gpu.Default.For(128, 128, new Shader_Unorm_<#=t#>_<#=tPixel#>(source, destination));
|
||||
device.Get().For(128, 128, new Shader_Unorm_<#=t#>_<#=tPixel#>(source, destination));
|
||||
}
|
||||
<#
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using ComputeSharp.Resources;
|
||||
using ComputeSharp.Tests.Attributes;
|
||||
using ComputeSharp.Tests.Extensions;
|
||||
using Microsoft.Toolkit.HighPerformance.Memory;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
@@ -11,47 +12,48 @@ namespace ComputeSharp.Tests
|
||||
[TestCategory("Texture2D")]
|
||||
public partial class Texture2DTests
|
||||
{
|
||||
[TestMethod]
|
||||
[DataRow(typeof(ReadOnlyTexture2D<>))]
|
||||
[DataRow(typeof(ReadWriteTexture2D<>))]
|
||||
public void Allocate_Uninitialized_Ok(Type textureType)
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ReadOnlyTexture2D<>))]
|
||||
[Resource(typeof(ReadWriteTexture2D<>))]
|
||||
public void Allocate_Uninitialized_Ok(Device device, Type textureType)
|
||||
{
|
||||
using Texture2D<float> texture = Gpu.Default.AllocateTexture2D<float>(textureType, 128, 128);
|
||||
using Texture2D<float> texture = device.Get().AllocateTexture2D<float>(textureType, 128, 128);
|
||||
|
||||
Assert.IsNotNull(texture);
|
||||
Assert.AreEqual(texture.Width, 128);
|
||||
Assert.AreEqual(texture.Height, 128);
|
||||
Assert.AreSame(texture.GraphicsDevice, Gpu.Default);
|
||||
Assert.AreSame(texture.GraphicsDevice, device.Get());
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow(typeof(ReadOnlyTexture2D<>), 128, -14253)]
|
||||
[DataRow(typeof(ReadOnlyTexture2D<>), 128, -1)]
|
||||
[DataRow(typeof(ReadOnlyTexture2D<>), 0, -4314)]
|
||||
[DataRow(typeof(ReadOnlyTexture2D<>), -14, -53)]
|
||||
[DataRow(typeof(ReadWriteTexture2D<>), 128, -14253)]
|
||||
[DataRow(typeof(ReadWriteTexture2D<>), 128, -1)]
|
||||
[DataRow(typeof(ReadWriteTexture2D<>), 0, -4314)]
|
||||
[DataRow(typeof(ReadWriteTexture2D<>), -14, -53)]
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ReadOnlyTexture2D<>))]
|
||||
[Resource(typeof(ReadWriteTexture2D<>))]
|
||||
[Data(128, -14253)]
|
||||
[Data(128, -1)]
|
||||
[Data(0, -4314)]
|
||||
[Data(-14, -53)]
|
||||
[ExpectedException(typeof(ArgumentOutOfRangeException))]
|
||||
public void Allocate_Uninitialized_Fail(Type textureType, int width, int height)
|
||||
public void Allocate_Uninitialized_Fail(Device device, Type textureType, int width, int height)
|
||||
{
|
||||
using Texture2D<float> texture = Gpu.Default.AllocateTexture2D<float>(textureType, width, height);
|
||||
using Texture2D<float> texture = device.Get().AllocateTexture2D<float>(textureType, width, height);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow(typeof(ReadOnlyTexture2D<>))]
|
||||
[DataRow(typeof(ReadWriteTexture2D<>))]
|
||||
public void Allocate_FromArray(Type textureType)
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ReadOnlyTexture2D<>))]
|
||||
[Resource(typeof(ReadWriteTexture2D<>))]
|
||||
public void Allocate_FromArray(Device device, Type textureType)
|
||||
{
|
||||
float[] data = Enumerable.Range(0, 128 * 128).Select(static i => (float)i).ToArray();
|
||||
|
||||
using Texture2D<float> texture = Gpu.Default.AllocateTexture2D(textureType, data, 128, 128);
|
||||
using Texture2D<float> texture = device.Get().AllocateTexture2D(textureType, data, 128, 128);
|
||||
|
||||
Assert.IsNotNull(texture);
|
||||
Assert.AreEqual(texture.Width, 128);
|
||||
Assert.AreEqual(texture.Height, 128);
|
||||
Assert.AreSame(texture.GraphicsDevice, Gpu.Default);
|
||||
Assert.AreSame(texture.GraphicsDevice, device.Get());
|
||||
|
||||
float[,] result = texture.ToArray();
|
||||
|
||||
@@ -60,43 +62,38 @@ namespace ComputeSharp.Tests
|
||||
Assert.IsTrue(data.SequenceEqual(result.Cast<float>()));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow(typeof(ReadOnlyTexture2D<>))]
|
||||
[DataRow(typeof(ReadWriteTexture2D<>))]
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ReadOnlyTexture2D<>))]
|
||||
[Resource(typeof(ReadWriteTexture2D<>))]
|
||||
[ExpectedException(typeof(ObjectDisposedException))]
|
||||
public void UsageAfterDispose(Type textureType)
|
||||
public void UsageAfterDispose(Device device, Type textureType)
|
||||
{
|
||||
using Texture2D<float> texture = Gpu.Default.AllocateTexture2D<float>(textureType, 10, 10);
|
||||
using Texture2D<float> texture = device.Get().AllocateTexture2D<float>(textureType, 10, 10);
|
||||
|
||||
texture.Dispose();
|
||||
|
||||
_ = texture.ToArray();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow(typeof(ReadOnlyTexture2D<>), 0, 0, 64, 64)]
|
||||
[DataRow(typeof(ReadOnlyTexture2D<>), 0, 14, 64, 50)]
|
||||
[DataRow(typeof(ReadOnlyTexture2D<>), 14, 0, 50, 64)]
|
||||
[DataRow(typeof(ReadOnlyTexture2D<>), 10, 10, 54, 54)]
|
||||
[DataRow(typeof(ReadOnlyTexture2D<>), 20, 20, 32, 27)]
|
||||
[DataRow(typeof(ReadOnlyTexture2D<>), 60, 0, 4, 64)]
|
||||
[DataRow(typeof(ReadOnlyTexture2D<>), 0, 60, 64, 4)]
|
||||
[DataRow(typeof(ReadOnlyTexture2D<>), 63, 2, 1, 60)]
|
||||
[DataRow(typeof(ReadOnlyTexture2D<>), 2, 63, 60, 1)]
|
||||
[DataRow(typeof(ReadWriteTexture2D<>), 0, 0, 64, 64)]
|
||||
[DataRow(typeof(ReadWriteTexture2D<>), 0, 14, 64, 50)]
|
||||
[DataRow(typeof(ReadWriteTexture2D<>), 14, 0, 50, 64)]
|
||||
[DataRow(typeof(ReadWriteTexture2D<>), 10, 10, 54, 54)]
|
||||
[DataRow(typeof(ReadWriteTexture2D<>), 20, 20, 32, 27)]
|
||||
[DataRow(typeof(ReadWriteTexture2D<>), 60, 0, 4, 64)]
|
||||
[DataRow(typeof(ReadWriteTexture2D<>), 0, 60, 64, 4)]
|
||||
[DataRow(typeof(ReadWriteTexture2D<>), 63, 2, 1, 60)]
|
||||
[DataRow(typeof(ReadWriteTexture2D<>), 2, 63, 60, 1)]
|
||||
public void GetData_RangeToVoid_Ok(Type textureType, int x, int y, int width, int height)
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ReadOnlyTexture2D<>))]
|
||||
[Resource(typeof(ReadWriteTexture2D<>))]
|
||||
[Data(0, 0, 64, 64)]
|
||||
[Data(0, 14, 64, 50)]
|
||||
[Data(14, 0, 50, 64)]
|
||||
[Data(10, 10, 54, 54)]
|
||||
[Data(20, 20, 32, 27)]
|
||||
[Data(60, 0, 4, 64)]
|
||||
[Data(0, 60, 64, 4)]
|
||||
[Data(63, 2, 1, 60)]
|
||||
[Data(2, 63, 60, 1)]
|
||||
public void GetData_RangeToVoid_Ok(Device device, Type textureType, int x, int y, int width, int height)
|
||||
{
|
||||
float[] array = Enumerable.Range(0, 4096).Select(static i => (float)i).ToArray();
|
||||
|
||||
using Texture2D<float> texture = Gpu.Default.AllocateTexture2D(textureType, array, 64, 64);
|
||||
using Texture2D<float> texture = device.Get().AllocateTexture2D(textureType, array, 64, 64);
|
||||
|
||||
float[] result = new float[width * height];
|
||||
|
||||
@@ -109,44 +106,40 @@ namespace ComputeSharp.Tests
|
||||
CollectionAssert.AreEqual(expected.ToArray(), data.ToArray());
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow(typeof(ReadOnlyTexture2D<>), 0, -1, 50, 50)]
|
||||
[DataRow(typeof(ReadOnlyTexture2D<>), -1, 0, 50, 50)]
|
||||
[DataRow(typeof(ReadOnlyTexture2D<>), 12, 0, -1, 50)]
|
||||
[DataRow(typeof(ReadOnlyTexture2D<>), 12, 0, 20, -1)]
|
||||
[DataRow(typeof(ReadOnlyTexture2D<>), 12, 20, 20, 50)]
|
||||
[DataRow(typeof(ReadOnlyTexture2D<>), 12, 20, 60, 20)]
|
||||
[DataRow(typeof(ReadOnlyTexture2D<>), 80, 20, 40, 20)]
|
||||
[DataRow(typeof(ReadOnlyTexture2D<>), 0, 80, 40, 20)]
|
||||
[DataRow(typeof(ReadWriteTexture2D<>), 0, -1, 50, 50)]
|
||||
[DataRow(typeof(ReadWriteTexture2D<>), -1, 0, 50, 50)]
|
||||
[DataRow(typeof(ReadWriteTexture2D<>), 12, 0, -1, 50)]
|
||||
[DataRow(typeof(ReadWriteTexture2D<>), 12, 0, 20, -1)]
|
||||
[DataRow(typeof(ReadWriteTexture2D<>), 12, 20, 20, 50)]
|
||||
[DataRow(typeof(ReadWriteTexture2D<>), 12, 20, 60, 20)]
|
||||
[DataRow(typeof(ReadWriteTexture2D<>), 80, 20, 40, 20)]
|
||||
[DataRow(typeof(ReadWriteTexture2D<>), 0, 80, 40, 20)]
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ReadOnlyTexture2D<>))]
|
||||
[Resource(typeof(ReadWriteTexture2D<>))]
|
||||
[Data(0, -1, 50, 50)]
|
||||
[Data(-1, 0, 50, 50)]
|
||||
[Data(12, 0, -1, 50)]
|
||||
[Data(12, 0, 20, -1)]
|
||||
[Data(12, 20, 20, 50)]
|
||||
[Data(12, 20, 60, 20)]
|
||||
[Data(80, 20, 40, 20)]
|
||||
[Data(0, 80, 40, 20)]
|
||||
[ExpectedException(typeof(ArgumentOutOfRangeException))]
|
||||
public void GetData_RangeToVoid_Fail(Type textureType, int x, int y, int width, int height)
|
||||
public void GetData_RangeToVoid_Fail(Device device, Type textureType, int x, int y, int width, int height)
|
||||
{
|
||||
float[] array = Enumerable.Range(0, 4096).Select(static i => (float)i).ToArray();
|
||||
|
||||
using Texture2D<float> texture = Gpu.Default.AllocateTexture2D(textureType, array, 64, 64);
|
||||
using Texture2D<float> texture = device.Get().AllocateTexture2D(textureType, array, 64, 64);
|
||||
|
||||
float[] result = new float[4096];
|
||||
|
||||
texture.CopyTo(result, x, y, width, height);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Dispatch_ReadOnlyTexture2D()
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
public void Dispatch_ReadOnlyTexture2D(Device device)
|
||||
{
|
||||
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);
|
||||
using ReadOnlyTexture2D<int> source = device.Get().AllocateReadOnlyTexture2D(data, 32, 32);
|
||||
using ReadWriteBuffer<int> destination = device.Get().AllocateReadWriteBuffer<int>(data.Length);
|
||||
|
||||
Gpu.Default.For(source.Width, source.Height, new ReadOnlyTexture2DKernel(source, destination));
|
||||
device.Get().For(source.Width, source.Height, new ReadOnlyTexture2DKernel(source, destination));
|
||||
|
||||
int[] result = destination.ToArray();
|
||||
|
||||
@@ -165,15 +158,16 @@ namespace ComputeSharp.Tests
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Dispatch_ReadWriteTexture2D()
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
public void Dispatch_ReadWriteTexture2D(Device device)
|
||||
{
|
||||
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);
|
||||
using ReadWriteTexture2D<int> source = device.Get().AllocateReadWriteTexture2D(data, 32, 32);
|
||||
using ReadWriteTexture2D<int> destination = device.Get().AllocateReadWriteTexture2D<int>(32, 32);
|
||||
|
||||
Gpu.Default.For(source.Width, source.Height, new ReadWriteTexture2DKernel(source, destination));
|
||||
device.Get().For(source.Width, source.Height, new ReadWriteTexture2DKernel(source, destination));
|
||||
|
||||
int[] result = new int[data.Length];
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Numerics;
|
||||
using System.Reflection;
|
||||
using ComputeSharp.__Internals;
|
||||
using ComputeSharp.Resources;
|
||||
using ComputeSharp.Tests.Attributes;
|
||||
using ComputeSharp.Tests.Extensions;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
@@ -12,44 +13,35 @@ namespace ComputeSharp.Tests
|
||||
{
|
||||
public partial class Texture3DTests
|
||||
{
|
||||
[TestMethod]
|
||||
[DataRow(typeof(ReadOnlyTexture3D<,>), typeof(Bgra32), typeof(Vector4))]
|
||||
[DataRow(typeof(ReadOnlyTexture3D<,>), typeof(Bgra32), typeof(Float4))]
|
||||
[DataRow(typeof(ReadOnlyTexture3D<,>), typeof(R16), typeof(float))]
|
||||
[DataRow(typeof(ReadOnlyTexture3D<,>), typeof(R8), typeof(float))]
|
||||
[DataRow(typeof(ReadOnlyTexture3D<,>), typeof(Rg16), typeof(Vector2))]
|
||||
[DataRow(typeof(ReadOnlyTexture3D<,>), typeof(Rg16), typeof(Float2))]
|
||||
[DataRow(typeof(ReadOnlyTexture3D<,>), typeof(Rg32), typeof(Vector2))]
|
||||
[DataRow(typeof(ReadOnlyTexture3D<,>), typeof(Rg32), typeof(Float2))]
|
||||
[DataRow(typeof(ReadOnlyTexture3D<,>), typeof(Rgba32), typeof(Vector4))]
|
||||
[DataRow(typeof(ReadOnlyTexture3D<,>), typeof(Rgba32), typeof(Float4))]
|
||||
[DataRow(typeof(ReadOnlyTexture3D<,>), typeof(Rgba64), typeof(Vector4))]
|
||||
[DataRow(typeof(ReadOnlyTexture3D<,>), typeof(Rgba64), typeof(Float4))]
|
||||
[DataRow(typeof(ReadWriteTexture3D<,>), typeof(Bgra32), typeof(Vector4))]
|
||||
[DataRow(typeof(ReadWriteTexture3D<,>), typeof(Bgra32), typeof(Float4))]
|
||||
[DataRow(typeof(ReadWriteTexture3D<,>), typeof(R16), typeof(float))]
|
||||
[DataRow(typeof(ReadWriteTexture3D<,>), typeof(R8), typeof(float))]
|
||||
[DataRow(typeof(ReadWriteTexture3D<,>), typeof(Rg16), typeof(Vector2))]
|
||||
[DataRow(typeof(ReadWriteTexture3D<,>), typeof(Rg16), typeof(Float2))]
|
||||
[DataRow(typeof(ReadWriteTexture3D<,>), typeof(Rg32), typeof(Vector2))]
|
||||
[DataRow(typeof(ReadWriteTexture3D<,>), typeof(Rg32), typeof(Float2))]
|
||||
[DataRow(typeof(ReadWriteTexture3D<,>), typeof(Rgba32), typeof(Vector4))]
|
||||
[DataRow(typeof(ReadWriteTexture3D<,>), typeof(Rgba32), typeof(Float4))]
|
||||
[DataRow(typeof(ReadWriteTexture3D<,>), typeof(Rgba64), typeof(Vector4))]
|
||||
[DataRow(typeof(ReadWriteTexture3D<,>), typeof(Rgba64), typeof(Float4))]
|
||||
public void Allocate_Uninitialized_Pixel_Ok(Type textureType, Type t, Type tPixel)
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ReadOnlyTexture3D<,>))]
|
||||
[Resource(typeof(ReadWriteTexture3D<,>))]
|
||||
[Data(typeof(Bgra32), typeof(Vector4))]
|
||||
[Data(typeof(Bgra32), typeof(Float4))]
|
||||
[Data(typeof(R16), typeof(float))]
|
||||
[Data(typeof(R8), typeof(float))]
|
||||
[Data(typeof(Rg16), typeof(Vector2))]
|
||||
[Data(typeof(Rg16), typeof(Float2))]
|
||||
[Data(typeof(Rg32), typeof(Vector2))]
|
||||
[Data(typeof(Rg32), typeof(Float2))]
|
||||
[Data(typeof(Rgba32), typeof(Vector4))]
|
||||
[Data(typeof(Rgba32), typeof(Float4))]
|
||||
[Data(typeof(Rgba64), typeof(Vector4))]
|
||||
[Data(typeof(Rgba64), typeof(Float4))]
|
||||
public void Allocate_Uninitialized_Pixel_Ok(Device device, Type textureType, Type t, Type tPixel)
|
||||
{
|
||||
static void Test<T, TPixel>(Type textureType)
|
||||
static void Test<T, TPixel>(Device device, Type textureType)
|
||||
where T : unmanaged, IUnorm<TPixel>
|
||||
where TPixel : unmanaged
|
||||
{
|
||||
using Texture3D<T> texture = Gpu.Default.AllocateTexture3D<T, TPixel>(textureType, 128, 128, 2);
|
||||
using Texture3D<T> texture = device.Get().AllocateTexture3D<T, TPixel>(textureType, 128, 128, 2);
|
||||
|
||||
Assert.IsNotNull(texture);
|
||||
Assert.AreEqual(texture.Width, 128);
|
||||
Assert.AreEqual(texture.Height, 128);
|
||||
Assert.AreEqual(texture.Depth, 2);
|
||||
Assert.AreSame(texture.GraphicsDevice, Gpu.Default);
|
||||
Assert.AreSame(texture.GraphicsDevice, device.Get());
|
||||
|
||||
if (textureType == typeof(ReadOnlyTexture3D<,>))
|
||||
{
|
||||
@@ -63,7 +55,7 @@ namespace ComputeSharp.Tests
|
||||
|
||||
try
|
||||
{
|
||||
new Action<Type>(Test<Rgba32, Vector4>).Method.GetGenericMethodDefinition().MakeGenericMethod(t, tPixel).Invoke(null, new[] { textureType });
|
||||
new Action<Device, Type>(Test<Rgba32, Vector4>).Method.GetGenericMethodDefinition().MakeGenericMethod(t, tPixel).Invoke(null, new object[] { device, textureType });
|
||||
}
|
||||
catch (TargetInvocationException e) when (e.InnerException is not null)
|
||||
{
|
||||
|
||||
@@ -1,109 +1,111 @@
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using ComputeSharp.Tests.Attributes;
|
||||
using ComputeSharp.Tests.Extensions;
|
||||
|
||||
namespace ComputeSharp.Tests
|
||||
{
|
||||
public partial class Texture3DTests
|
||||
{
|
||||
[TestMethod]
|
||||
[DataRow(typeof(Bgra32), typeof(Vector4))]
|
||||
[DataRow(typeof(Bgra32), typeof(Float4))]
|
||||
[DataRow(typeof(R16), typeof(float))]
|
||||
[DataRow(typeof(R8), typeof(float))]
|
||||
[DataRow(typeof(Rg16), typeof(Vector2))]
|
||||
[DataRow(typeof(Rg16), typeof(Float2))]
|
||||
[DataRow(typeof(Rg32), typeof(Vector2))]
|
||||
[DataRow(typeof(Rg32), typeof(Float2))]
|
||||
[DataRow(typeof(Rgba32), typeof(Vector4))]
|
||||
[DataRow(typeof(Rgba32), typeof(Float4))]
|
||||
[DataRow(typeof(Rgba64), typeof(Vector4))]
|
||||
[DataRow(typeof(Rgba64), typeof(Float4))]
|
||||
public void Dispatch_NormalizedTexture3D(Type t, Type tPixel)
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Data(typeof(Bgra32), typeof(Vector4))]
|
||||
[Data(typeof(Bgra32), typeof(Float4))]
|
||||
[Data(typeof(R16), typeof(float))]
|
||||
[Data(typeof(R8), typeof(float))]
|
||||
[Data(typeof(Rg16), typeof(Vector2))]
|
||||
[Data(typeof(Rg16), typeof(Float2))]
|
||||
[Data(typeof(Rg32), typeof(Vector2))]
|
||||
[Data(typeof(Rg32), typeof(Float2))]
|
||||
[Data(typeof(Rgba32), typeof(Vector4))]
|
||||
[Data(typeof(Rgba32), typeof(Float4))]
|
||||
[Data(typeof(Rgba64), typeof(Vector4))]
|
||||
[Data(typeof(Rgba64), typeof(Float4))]
|
||||
public void Dispatch_NormalizedTexture3D(Device device, Type t, Type tPixel)
|
||||
{
|
||||
if (t == typeof(Bgra32) && tPixel == typeof(Vector4))
|
||||
{
|
||||
using ReadOnlyTexture3D<Bgra32, Vector4> source = Gpu.Default.AllocateReadOnlyTexture3D<Bgra32, Vector4>(128, 128, 2);
|
||||
using ReadWriteTexture3D<Bgra32, Vector4> destination = Gpu.Default.AllocateReadWriteTexture3D<Bgra32, Vector4>(128, 128, 2);
|
||||
using ReadOnlyTexture3D<Bgra32, Vector4> source = device.Get().AllocateReadOnlyTexture3D<Bgra32, Vector4>(128, 128, 2);
|
||||
using ReadWriteTexture3D<Bgra32, Vector4> destination = device.Get().AllocateReadWriteTexture3D<Bgra32, Vector4>(128, 128, 2);
|
||||
|
||||
Gpu.Default.For(128, 128, 2, new Shader_Unorm_Bgra32_Vector4(source, destination));
|
||||
device.Get().For(128, 128, 2, new Shader_Unorm_Bgra32_Vector4(source, destination));
|
||||
}
|
||||
if (t == typeof(Bgra32) && tPixel == typeof(Float4))
|
||||
{
|
||||
using ReadOnlyTexture3D<Bgra32, Float4> source = Gpu.Default.AllocateReadOnlyTexture3D<Bgra32, Float4>(128, 128, 2);
|
||||
using ReadWriteTexture3D<Bgra32, Float4> destination = Gpu.Default.AllocateReadWriteTexture3D<Bgra32, Float4>(128, 128, 2);
|
||||
using ReadOnlyTexture3D<Bgra32, Float4> source = device.Get().AllocateReadOnlyTexture3D<Bgra32, Float4>(128, 128, 2);
|
||||
using ReadWriteTexture3D<Bgra32, Float4> destination = device.Get().AllocateReadWriteTexture3D<Bgra32, Float4>(128, 128, 2);
|
||||
|
||||
Gpu.Default.For(128, 128, 2, new Shader_Unorm_Bgra32_Float4(source, destination));
|
||||
device.Get().For(128, 128, 2, new Shader_Unorm_Bgra32_Float4(source, destination));
|
||||
}
|
||||
if (t == typeof(R16) && tPixel == typeof(float))
|
||||
{
|
||||
using ReadOnlyTexture3D<R16, float> source = Gpu.Default.AllocateReadOnlyTexture3D<R16, float>(128, 128, 2);
|
||||
using ReadWriteTexture3D<R16, float> destination = Gpu.Default.AllocateReadWriteTexture3D<R16, float>(128, 128, 2);
|
||||
using ReadOnlyTexture3D<R16, float> source = device.Get().AllocateReadOnlyTexture3D<R16, float>(128, 128, 2);
|
||||
using ReadWriteTexture3D<R16, float> destination = device.Get().AllocateReadWriteTexture3D<R16, float>(128, 128, 2);
|
||||
|
||||
Gpu.Default.For(128, 128, 2, new Shader_Unorm_R16_float(source, destination));
|
||||
device.Get().For(128, 128, 2, new Shader_Unorm_R16_float(source, destination));
|
||||
}
|
||||
if (t == typeof(R8) && tPixel == typeof(float))
|
||||
{
|
||||
using ReadOnlyTexture3D<R8, float> source = Gpu.Default.AllocateReadOnlyTexture3D<R8, float>(128, 128, 2);
|
||||
using ReadWriteTexture3D<R8, float> destination = Gpu.Default.AllocateReadWriteTexture3D<R8, float>(128, 128, 2);
|
||||
using ReadOnlyTexture3D<R8, float> source = device.Get().AllocateReadOnlyTexture3D<R8, float>(128, 128, 2);
|
||||
using ReadWriteTexture3D<R8, float> destination = device.Get().AllocateReadWriteTexture3D<R8, float>(128, 128, 2);
|
||||
|
||||
Gpu.Default.For(128, 128, 2, new Shader_Unorm_R8_float(source, destination));
|
||||
device.Get().For(128, 128, 2, new Shader_Unorm_R8_float(source, destination));
|
||||
}
|
||||
if (t == typeof(Rg16) && tPixel == typeof(Vector2))
|
||||
{
|
||||
using ReadOnlyTexture3D<Rg16, Vector2> source = Gpu.Default.AllocateReadOnlyTexture3D<Rg16, Vector2>(128, 128, 2);
|
||||
using ReadWriteTexture3D<Rg16, Vector2> destination = Gpu.Default.AllocateReadWriteTexture3D<Rg16, Vector2>(128, 128, 2);
|
||||
using ReadOnlyTexture3D<Rg16, Vector2> source = device.Get().AllocateReadOnlyTexture3D<Rg16, Vector2>(128, 128, 2);
|
||||
using ReadWriteTexture3D<Rg16, Vector2> destination = device.Get().AllocateReadWriteTexture3D<Rg16, Vector2>(128, 128, 2);
|
||||
|
||||
Gpu.Default.For(128, 128, 2, new Shader_Unorm_Rg16_Vector2(source, destination));
|
||||
device.Get().For(128, 128, 2, new Shader_Unorm_Rg16_Vector2(source, destination));
|
||||
}
|
||||
if (t == typeof(Rg16) && tPixel == typeof(Float2))
|
||||
{
|
||||
using ReadOnlyTexture3D<Rg16, Float2> source = Gpu.Default.AllocateReadOnlyTexture3D<Rg16, Float2>(128, 128, 2);
|
||||
using ReadWriteTexture3D<Rg16, Float2> destination = Gpu.Default.AllocateReadWriteTexture3D<Rg16, Float2>(128, 128, 2);
|
||||
using ReadOnlyTexture3D<Rg16, Float2> source = device.Get().AllocateReadOnlyTexture3D<Rg16, Float2>(128, 128, 2);
|
||||
using ReadWriteTexture3D<Rg16, Float2> destination = device.Get().AllocateReadWriteTexture3D<Rg16, Float2>(128, 128, 2);
|
||||
|
||||
Gpu.Default.For(128, 128, 2, new Shader_Unorm_Rg16_Float2(source, destination));
|
||||
device.Get().For(128, 128, 2, new Shader_Unorm_Rg16_Float2(source, destination));
|
||||
}
|
||||
if (t == typeof(Rg32) && tPixel == typeof(Vector2))
|
||||
{
|
||||
using ReadOnlyTexture3D<Rg32, Vector2> source = Gpu.Default.AllocateReadOnlyTexture3D<Rg32, Vector2>(128, 128, 2);
|
||||
using ReadWriteTexture3D<Rg32, Vector2> destination = Gpu.Default.AllocateReadWriteTexture3D<Rg32, Vector2>(128, 128, 2);
|
||||
using ReadOnlyTexture3D<Rg32, Vector2> source = device.Get().AllocateReadOnlyTexture3D<Rg32, Vector2>(128, 128, 2);
|
||||
using ReadWriteTexture3D<Rg32, Vector2> destination = device.Get().AllocateReadWriteTexture3D<Rg32, Vector2>(128, 128, 2);
|
||||
|
||||
Gpu.Default.For(128, 128, 2, new Shader_Unorm_Rg32_Vector2(source, destination));
|
||||
device.Get().For(128, 128, 2, new Shader_Unorm_Rg32_Vector2(source, destination));
|
||||
}
|
||||
if (t == typeof(Rg32) && tPixel == typeof(Float2))
|
||||
{
|
||||
using ReadOnlyTexture3D<Rg32, Float2> source = Gpu.Default.AllocateReadOnlyTexture3D<Rg32, Float2>(128, 128, 2);
|
||||
using ReadWriteTexture3D<Rg32, Float2> destination = Gpu.Default.AllocateReadWriteTexture3D<Rg32, Float2>(128, 128, 2);
|
||||
using ReadOnlyTexture3D<Rg32, Float2> source = device.Get().AllocateReadOnlyTexture3D<Rg32, Float2>(128, 128, 2);
|
||||
using ReadWriteTexture3D<Rg32, Float2> destination = device.Get().AllocateReadWriteTexture3D<Rg32, Float2>(128, 128, 2);
|
||||
|
||||
Gpu.Default.For(128, 128, 2, new Shader_Unorm_Rg32_Float2(source, destination));
|
||||
device.Get().For(128, 128, 2, new Shader_Unorm_Rg32_Float2(source, destination));
|
||||
}
|
||||
if (t == typeof(Rgba32) && tPixel == typeof(Vector4))
|
||||
{
|
||||
using ReadOnlyTexture3D<Rgba32, Vector4> source = Gpu.Default.AllocateReadOnlyTexture3D<Rgba32, Vector4>(128, 128, 2);
|
||||
using ReadWriteTexture3D<Rgba32, Vector4> destination = Gpu.Default.AllocateReadWriteTexture3D<Rgba32, Vector4>(128, 128, 2);
|
||||
using ReadOnlyTexture3D<Rgba32, Vector4> source = device.Get().AllocateReadOnlyTexture3D<Rgba32, Vector4>(128, 128, 2);
|
||||
using ReadWriteTexture3D<Rgba32, Vector4> destination = device.Get().AllocateReadWriteTexture3D<Rgba32, Vector4>(128, 128, 2);
|
||||
|
||||
Gpu.Default.For(128, 128, 2, new Shader_Unorm_Rgba32_Vector4(source, destination));
|
||||
device.Get().For(128, 128, 2, new Shader_Unorm_Rgba32_Vector4(source, destination));
|
||||
}
|
||||
if (t == typeof(Rgba32) && tPixel == typeof(Float4))
|
||||
{
|
||||
using ReadOnlyTexture3D<Rgba32, Float4> source = Gpu.Default.AllocateReadOnlyTexture3D<Rgba32, Float4>(128, 128, 2);
|
||||
using ReadWriteTexture3D<Rgba32, Float4> destination = Gpu.Default.AllocateReadWriteTexture3D<Rgba32, Float4>(128, 128, 2);
|
||||
using ReadOnlyTexture3D<Rgba32, Float4> source = device.Get().AllocateReadOnlyTexture3D<Rgba32, Float4>(128, 128, 2);
|
||||
using ReadWriteTexture3D<Rgba32, Float4> destination = device.Get().AllocateReadWriteTexture3D<Rgba32, Float4>(128, 128, 2);
|
||||
|
||||
Gpu.Default.For(128, 128, 2, new Shader_Unorm_Rgba32_Float4(source, destination));
|
||||
device.Get().For(128, 128, 2, new Shader_Unorm_Rgba32_Float4(source, destination));
|
||||
}
|
||||
if (t == typeof(Rgba64) && tPixel == typeof(Vector4))
|
||||
{
|
||||
using ReadOnlyTexture3D<Rgba64, Vector4> source = Gpu.Default.AllocateReadOnlyTexture3D<Rgba64, Vector4>(128, 128, 2);
|
||||
using ReadWriteTexture3D<Rgba64, Vector4> destination = Gpu.Default.AllocateReadWriteTexture3D<Rgba64, Vector4>(128, 128, 2);
|
||||
using ReadOnlyTexture3D<Rgba64, Vector4> source = device.Get().AllocateReadOnlyTexture3D<Rgba64, Vector4>(128, 128, 2);
|
||||
using ReadWriteTexture3D<Rgba64, Vector4> destination = device.Get().AllocateReadWriteTexture3D<Rgba64, Vector4>(128, 128, 2);
|
||||
|
||||
Gpu.Default.For(128, 128, 2, new Shader_Unorm_Rgba64_Vector4(source, destination));
|
||||
device.Get().For(128, 128, 2, new Shader_Unorm_Rgba64_Vector4(source, destination));
|
||||
}
|
||||
if (t == typeof(Rgba64) && tPixel == typeof(Float4))
|
||||
{
|
||||
using ReadOnlyTexture3D<Rgba64, Float4> source = Gpu.Default.AllocateReadOnlyTexture3D<Rgba64, Float4>(128, 128, 2);
|
||||
using ReadWriteTexture3D<Rgba64, Float4> destination = Gpu.Default.AllocateReadWriteTexture3D<Rgba64, Float4>(128, 128, 2);
|
||||
using ReadOnlyTexture3D<Rgba64, Float4> source = device.Get().AllocateReadOnlyTexture3D<Rgba64, Float4>(128, 128, 2);
|
||||
using ReadWriteTexture3D<Rgba64, Float4> destination = device.Get().AllocateReadWriteTexture3D<Rgba64, Float4>(128, 128, 2);
|
||||
|
||||
Gpu.Default.For(128, 128, 2, new Shader_Unorm_Rgba64_Float4(source, destination));
|
||||
device.Get().For(128, 128, 2, new Shader_Unorm_Rgba64_Float4(source, destination));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,22 +25,24 @@ IEnumerable<(string T, string TPixel)> EnumerateTypes()
|
||||
#>
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using ComputeSharp.Tests.Attributes;
|
||||
using ComputeSharp.Tests.Extensions;
|
||||
|
||||
namespace ComputeSharp.Tests
|
||||
{
|
||||
public partial class Texture3DTests
|
||||
{
|
||||
[TestMethod]
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
<#
|
||||
foreach (var (t, tPixel) in EnumerateTypes())
|
||||
{
|
||||
#>
|
||||
[DataRow(typeof(<#=t#>), typeof(<#=tPixel#>))]
|
||||
[Data(typeof(<#=t#>), typeof(<#=tPixel#>))]
|
||||
<#
|
||||
}
|
||||
#>
|
||||
public void Dispatch_NormalizedTexture3D(Type t, Type tPixel)
|
||||
public void Dispatch_NormalizedTexture3D(Device device, Type t, Type tPixel)
|
||||
{
|
||||
<#
|
||||
foreach (var (t, tPixel) in EnumerateTypes())
|
||||
@@ -48,10 +50,10 @@ foreach (var (t, tPixel) in EnumerateTypes())
|
||||
#>
|
||||
if (t == typeof(<#=t#>) && tPixel == typeof(<#=tPixel#>))
|
||||
{
|
||||
using ReadOnlyTexture3D<<#=t#>, <#=tPixel#>> source = Gpu.Default.AllocateReadOnlyTexture3D<<#=t#>, <#=tPixel#>>(128, 128, 2);
|
||||
using ReadWriteTexture3D<<#=t#>, <#=tPixel#>> destination = Gpu.Default.AllocateReadWriteTexture3D<<#=t#>, <#=tPixel#>>(128, 128, 2);
|
||||
using ReadOnlyTexture3D<<#=t#>, <#=tPixel#>> source = device.Get().AllocateReadOnlyTexture3D<<#=t#>, <#=tPixel#>>(128, 128, 2);
|
||||
using ReadWriteTexture3D<<#=t#>, <#=tPixel#>> destination = device.Get().AllocateReadWriteTexture3D<<#=t#>, <#=tPixel#>>(128, 128, 2);
|
||||
|
||||
Gpu.Default.For(128, 128, 2, new Shader_Unorm_<#=t#>_<#=tPixel#>(source, destination));
|
||||
device.Get().For(128, 128, 2, new Shader_Unorm_<#=t#>_<#=tPixel#>(source, destination));
|
||||
}
|
||||
<#
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using ComputeSharp.Resources;
|
||||
using ComputeSharp.Tests.Attributes;
|
||||
using ComputeSharp.Tests.Extensions;
|
||||
using Microsoft.Toolkit.HighPerformance.Extensions;
|
||||
using Microsoft.Toolkit.HighPerformance.Memory;
|
||||
@@ -12,59 +13,56 @@ namespace ComputeSharp.Tests
|
||||
[TestCategory("Texture3D")]
|
||||
public partial class Texture3DTests
|
||||
{
|
||||
[TestMethod]
|
||||
[DataRow(typeof(ReadOnlyTexture3D<>))]
|
||||
[DataRow(typeof(ReadWriteTexture3D<>))]
|
||||
public void Allocate_Uninitialized_Ok(Type textureType)
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ReadOnlyTexture3D<>))]
|
||||
[Resource(typeof(ReadWriteTexture3D<>))]
|
||||
public void Allocate_Uninitialized_Ok(Device device, Type textureType)
|
||||
{
|
||||
using Texture3D<float> texture = Gpu.Default.AllocateTexture3D<float>(textureType, 64, 64, 12);
|
||||
using Texture3D<float> texture = device.Get().AllocateTexture3D<float>(textureType, 64, 64, 12);
|
||||
|
||||
Assert.IsNotNull(texture);
|
||||
Assert.AreEqual(texture.Width, 64);
|
||||
Assert.AreEqual(texture.Height, 64);
|
||||
Assert.AreEqual(texture.Depth, 12);
|
||||
Assert.AreSame(texture.GraphicsDevice, Gpu.Default);
|
||||
Assert.AreSame(texture.GraphicsDevice, device.Get());
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow(typeof(ReadOnlyTexture3D<>), 128, -14253, 4)]
|
||||
[DataRow(typeof(ReadOnlyTexture3D<>), 128, -1, 4)]
|
||||
[DataRow(typeof(ReadOnlyTexture3D<>), 0, -4314, 4)]
|
||||
[DataRow(typeof(ReadOnlyTexture3D<>), -14, -53, 4)]
|
||||
[DataRow(typeof(ReadOnlyTexture3D<>), 12, 12, -1)]
|
||||
[DataRow(typeof(ReadOnlyTexture3D<>), 2, 4, ushort.MaxValue + 1)]
|
||||
[DataRow(typeof(ReadWriteTexture3D<>), 128, -14253, 4)]
|
||||
[DataRow(typeof(ReadWriteTexture3D<>), 128, -1, 4)]
|
||||
[DataRow(typeof(ReadWriteTexture3D<>), 0, -4314, 4)]
|
||||
[DataRow(typeof(ReadWriteTexture3D<>), -14, -53, 4)]
|
||||
[DataRow(typeof(ReadWriteTexture3D<>), 12, 12, -1)]
|
||||
[DataRow(typeof(ReadWriteTexture3D<>), 2, 4, ushort.MaxValue + 1)]
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ReadOnlyTexture3D<>))]
|
||||
[Resource(typeof(ReadWriteTexture3D<>))]
|
||||
[Data(128, -14253, 4)]
|
||||
[Data(128, -1, 4)]
|
||||
[Data(0, -4314, 4)]
|
||||
[Data(-14, -53, 4)]
|
||||
[Data(12, 12, -1)]
|
||||
[Data(2, 4, ushort.MaxValue + 1)]
|
||||
[ExpectedException(typeof(ArgumentOutOfRangeException))]
|
||||
public void Allocate_Uninitialized_Fail(Type textureType, int width, int height, int depth)
|
||||
public void Allocate_Uninitialized_Fail(Device device, Type textureType, int width, int height, int depth)
|
||||
{
|
||||
using Texture3D<float> texture = Gpu.Default.AllocateTexture3D<float>(textureType, width, height, depth);
|
||||
using Texture3D<float> texture = device.Get().AllocateTexture3D<float>(textureType, width, height, depth);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow(typeof(ReadOnlyTexture3D<>), 12, 12, 4)]
|
||||
[DataRow(typeof(ReadOnlyTexture3D<>), 2, 12, 4)]
|
||||
[DataRow(typeof(ReadOnlyTexture3D<>), 64, 64, 1)]
|
||||
[DataRow(typeof(ReadOnlyTexture3D<>), 64, 27, 3)]
|
||||
[DataRow(typeof(ReadWriteTexture3D<>), 12, 12, 4)]
|
||||
[DataRow(typeof(ReadWriteTexture3D<>), 2, 12, 4)]
|
||||
[DataRow(typeof(ReadWriteTexture3D<>), 64, 64, 1)]
|
||||
[DataRow(typeof(ReadWriteTexture3D<>), 64, 27, 3)]
|
||||
public void Allocate_FromArray(Type textureType, int width, int height, int depth)
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ReadOnlyTexture3D<>))]
|
||||
[Resource(typeof(ReadWriteTexture3D<>))]
|
||||
[Data(12, 12, 4)]
|
||||
[Data(2, 12, 4)]
|
||||
[Data(64, 64, 1)]
|
||||
[Data(64, 27, 3)]
|
||||
public void Allocate_FromArray(Device device, Type textureType, int width, int height, int depth)
|
||||
{
|
||||
float[] data = Enumerable.Range(0, width * height * depth).Select(static i => (float)i).ToArray();
|
||||
|
||||
using Texture3D<float> texture = Gpu.Default.AllocateTexture3D(textureType, data, width, height, depth);
|
||||
using Texture3D<float> texture = device.Get().AllocateTexture3D(textureType, data, width, height, depth);
|
||||
|
||||
Assert.IsNotNull(texture);
|
||||
Assert.AreEqual(texture.Width, width);
|
||||
Assert.AreEqual(texture.Height, height);
|
||||
Assert.AreEqual(texture.Depth, depth);
|
||||
Assert.AreSame(texture.GraphicsDevice, Gpu.Default);
|
||||
Assert.AreSame(texture.GraphicsDevice, device.Get());
|
||||
|
||||
float[,,] result = texture.ToArray();
|
||||
|
||||
@@ -84,48 +82,42 @@ namespace ComputeSharp.Tests
|
||||
CollectionAssert.AreEqual(flat, data);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow(typeof(ReadOnlyTexture3D<>))]
|
||||
[DataRow(typeof(ReadWriteTexture3D<>))]
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ReadOnlyTexture3D<>))]
|
||||
[Resource(typeof(ReadWriteTexture3D<>))]
|
||||
[ExpectedException(typeof(ObjectDisposedException))]
|
||||
public void UsageAfterDispose(Type textureType)
|
||||
public void UsageAfterDispose(Device device, Type textureType)
|
||||
{
|
||||
using Texture3D<float> texture = Gpu.Default.AllocateTexture3D<float>(textureType, 10, 10, 4);
|
||||
using Texture3D<float> texture = device.Get().AllocateTexture3D<float>(textureType, 10, 10, 4);
|
||||
|
||||
texture.Dispose();
|
||||
|
||||
_ = texture.ToArray();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow(typeof(ReadOnlyTexture3D<>), 0, 0, 0, 64, 64, 3)]
|
||||
[DataRow(typeof(ReadOnlyTexture3D<>), 0, 14, 0, 64, 50, 3)]
|
||||
[DataRow(typeof(ReadOnlyTexture3D<>), 0, 14, 1, 64, 50, 2)]
|
||||
[DataRow(typeof(ReadOnlyTexture3D<>), 14, 0, 1, 50, 64, 2)]
|
||||
[DataRow(typeof(ReadOnlyTexture3D<>), 10, 10, 2, 54, 54, 1)]
|
||||
[DataRow(typeof(ReadOnlyTexture3D<>), 20, 20, 0, 32, 27, 3)]
|
||||
[DataRow(typeof(ReadOnlyTexture3D<>), 60, 0, 0, 4, 64, 3)]
|
||||
[DataRow(typeof(ReadOnlyTexture3D<>), 0, 60, 2, 64, 4, 1)]
|
||||
[DataRow(typeof(ReadOnlyTexture3D<>), 63, 2, 0, 1, 60, 2)]
|
||||
[DataRow(typeof(ReadOnlyTexture3D<>), 2, 63, 1, 60, 1, 2)]
|
||||
[DataRow(typeof(ReadWriteTexture3D<>), 0, 0, 0, 64, 64, 3)]
|
||||
[DataRow(typeof(ReadWriteTexture3D<>), 0, 14, 0, 64, 50, 3)]
|
||||
[DataRow(typeof(ReadWriteTexture3D<>), 0, 14, 1, 64, 50, 2)]
|
||||
[DataRow(typeof(ReadWriteTexture3D<>), 14, 0, 1, 50, 64, 2)]
|
||||
[DataRow(typeof(ReadWriteTexture3D<>), 10, 10, 2, 54, 54, 1)]
|
||||
[DataRow(typeof(ReadWriteTexture3D<>), 20, 20, 0, 32, 27, 3)]
|
||||
[DataRow(typeof(ReadWriteTexture3D<>), 60, 0, 0, 4, 64, 3)]
|
||||
[DataRow(typeof(ReadWriteTexture3D<>), 0, 60, 2, 64, 4, 1)]
|
||||
[DataRow(typeof(ReadWriteTexture3D<>), 63, 2, 0, 1, 60, 2)]
|
||||
[DataRow(typeof(ReadWriteTexture3D<>), 2, 63, 1, 60, 1, 2)]
|
||||
public void GetData_RangeToVoid_Ok(Type textureType, int x, int y, int z, int width, int height, int depth)
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ReadOnlyTexture3D<>))]
|
||||
[Resource(typeof(ReadWriteTexture3D<>))]
|
||||
[Data(0, 0, 0, 64, 64, 3)]
|
||||
[Data(0, 14, 0, 64, 50, 3)]
|
||||
[Data(0, 14, 1, 64, 50, 2)]
|
||||
[Data(14, 0, 1, 50, 64, 2)]
|
||||
[Data(10, 10, 2, 54, 54, 1)]
|
||||
[Data(20, 20, 0, 32, 27, 3)]
|
||||
[Data(60, 0, 0, 4, 64, 3)]
|
||||
[Data(0, 60, 2, 64, 4, 1)]
|
||||
[Data(63, 2, 0, 1, 60, 2)]
|
||||
[Data(2, 63, 1, 60, 1, 2)]
|
||||
public void GetData_RangeToVoid_Ok(Device device, Type textureType, int x, int y, int z, int width, int height, int depth)
|
||||
{
|
||||
int[,,] array = new int[3, 64, 64];
|
||||
|
||||
foreach (var item in array.AsSpan().Enumerate())
|
||||
item.Value = item.Index;
|
||||
|
||||
using Texture3D<int> texture = Gpu.Default.AllocateTexture3D(textureType, array);
|
||||
using Texture3D<int> texture = device.Get().AllocateTexture3D(textureType, array);
|
||||
|
||||
int[,,] result = new int[depth, height, width];
|
||||
|
||||
@@ -141,46 +133,41 @@ namespace ComputeSharp.Tests
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow(typeof(ReadOnlyTexture3D<>), 0, -1, 0, 50, 50, 2)]
|
||||
[DataRow(typeof(ReadOnlyTexture3D<>), -1, 0, 0, 50, 50, 3)]
|
||||
[DataRow(typeof(ReadOnlyTexture3D<>), 12, 0, 0, -1, 50, 1)]
|
||||
[DataRow(typeof(ReadOnlyTexture3D<>), 12, 0, 0, 20, 50, 0)]
|
||||
[DataRow(typeof(ReadOnlyTexture3D<>), 12, 0, 1, 20, -1, 2)]
|
||||
[DataRow(typeof(ReadOnlyTexture3D<>), 12, 20, 2, 20, 50, 1)]
|
||||
[DataRow(typeof(ReadOnlyTexture3D<>), 12, 20, 0, 60, 20, 3)]
|
||||
[DataRow(typeof(ReadOnlyTexture3D<>), 80, 20, 2, 40, 20, 1)]
|
||||
[DataRow(typeof(ReadOnlyTexture3D<>), 0, 80, 2, 40, 20, 1)]
|
||||
[DataRow(typeof(ReadWriteTexture3D<>), 0, -1, 0, 50, 50, 2)]
|
||||
[DataRow(typeof(ReadWriteTexture3D<>), -1, 0, 0, 50, 50, 3)]
|
||||
[DataRow(typeof(ReadWriteTexture3D<>), 12, 0, 0, -1, 50, 1)]
|
||||
[DataRow(typeof(ReadWriteTexture3D<>), 12, 0, 0, 20, 50, 0)]
|
||||
[DataRow(typeof(ReadWriteTexture3D<>), 12, 0, 1, 20, -1, 2)]
|
||||
[DataRow(typeof(ReadWriteTexture3D<>), 12, 20, 2, 20, 50, 1)]
|
||||
[DataRow(typeof(ReadWriteTexture3D<>), 12, 20, 0, 60, 20, 3)]
|
||||
[DataRow(typeof(ReadWriteTexture3D<>), 80, 20, 2, 40, 20, 1)]
|
||||
[DataRow(typeof(ReadWriteTexture3D<>), 0, 80, 2, 40, 20, 1)]
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ReadOnlyTexture3D<>))]
|
||||
[Resource(typeof(ReadWriteTexture3D<>))]
|
||||
[Data(0, -1, 0, 50, 50, 2)]
|
||||
[Data(-1, 0, 0, 50, 50, 3)]
|
||||
[Data(12, 0, 0, -1, 50, 1)]
|
||||
[Data(12, 0, 0, 20, 50, 0)]
|
||||
[Data(12, 0, 1, 20, -1, 2)]
|
||||
[Data(12, 20, 2, 20, 50, 1)]
|
||||
[Data(12, 20, 0, 60, 20, 3)]
|
||||
[Data(80, 20, 2, 40, 20, 1)]
|
||||
[Data(0, 80, 2, 40, 20, 1)]
|
||||
[ExpectedException(typeof(ArgumentOutOfRangeException))]
|
||||
public void GetData_RangeToVoid_Fail(Type textureType, int x, int y, int z, int width, int height, int depth)
|
||||
public void GetData_RangeToVoid_Fail(Device device, Type textureType, int x, int y, int z, int width, int height, int depth)
|
||||
{
|
||||
float[] array = Enumerable.Range(0, 64 * 64 * 3).Select(static i => (float)i).ToArray();
|
||||
|
||||
using Texture3D<float> texture = Gpu.Default.AllocateTexture3D(textureType, array, 64, 64, 3);
|
||||
using Texture3D<float> texture = device.Get().AllocateTexture3D(textureType, array, 64, 64, 3);
|
||||
|
||||
float[] result = new float[array.Length];
|
||||
|
||||
texture.CopyTo(result, x, y, z, width, height, depth);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Dispatch_ReadOnlyTexture3D()
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
public void Dispatch_ReadOnlyTexture3D(Device device)
|
||||
{
|
||||
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);
|
||||
using ReadOnlyTexture3D<int> source = device.Get().AllocateReadOnlyTexture3D(data, 32, 32, 3);
|
||||
using ReadWriteBuffer<int> destination = device.Get().AllocateReadWriteBuffer<int>(data.Length);
|
||||
|
||||
Gpu.Default.For(source.Width, source.Height, source.Depth, new ReadOnlyTexture3DKernel(source, destination));
|
||||
device.Get().For(source.Width, source.Height, source.Depth, new ReadOnlyTexture3DKernel(source, destination));
|
||||
|
||||
int[] result = destination.ToArray();
|
||||
|
||||
@@ -199,15 +186,16 @@ namespace ComputeSharp.Tests
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Dispatch_ReadWriteTexture2D()
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
public void Dispatch_ReadWriteTexture2D(Device device)
|
||||
{
|
||||
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);
|
||||
using ReadWriteTexture3D<int> source = device.Get().AllocateReadWriteTexture3D(data, 32, 32, 3);
|
||||
using ReadWriteTexture3D<int> destination = device.Get().AllocateReadWriteTexture3D<int>(32, 32, 3);
|
||||
|
||||
Gpu.Default.For(source.Width, source.Height, source.Depth, new ReadWriteTexture3DKernel(source, destination));
|
||||
device.Get().For(source.Width, source.Height, source.Depth, new ReadWriteTexture3DKernel(source, destination));
|
||||
|
||||
int[] result = new int[data.Length];
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using ComputeSharp.Resources;
|
||||
using ComputeSharp.Tests.Attributes;
|
||||
using ComputeSharp.Tests.Extensions;
|
||||
using Microsoft.Toolkit.HighPerformance.Extensions;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
@@ -12,12 +13,13 @@ namespace ComputeSharp.Tests
|
||||
[TestCategory("TransferBuffer")]
|
||||
public partial class TransferBufferTests
|
||||
{
|
||||
[TestMethod]
|
||||
[DataRow(typeof(UploadBuffer<>))]
|
||||
[DataRow(typeof(ReadBackBuffer<>))]
|
||||
public unsafe void Allocate_Uninitialized_Ok(Type bufferType)
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(UploadBuffer<>))]
|
||||
[Resource(typeof(ReadBackBuffer<>))]
|
||||
public unsafe void Allocate_Uninitialized_Ok(Device device, Type bufferType)
|
||||
{
|
||||
using TransferBuffer<float> buffer = Gpu.Default.AllocateTransferBuffer<float>(bufferType, 128);
|
||||
using TransferBuffer<float> buffer = device.Get().AllocateTransferBuffer<float>(bufferType, 128);
|
||||
|
||||
Assert.IsNotNull(buffer);
|
||||
Assert.AreEqual(buffer.Length, 128);
|
||||
@@ -25,41 +27,44 @@ namespace ComputeSharp.Tests
|
||||
Assert.AreEqual(buffer.Span.Length, 128);
|
||||
Assert.IsTrue(Unsafe.AreSame(ref buffer.Memory.Span[0], ref buffer.Span[0]));
|
||||
Assert.IsTrue(Unsafe.AreSame(ref *(float*)buffer.Memory.Pin().Pointer, ref buffer.Span[0]));
|
||||
Assert.AreSame(buffer.GraphicsDevice, Gpu.Default);
|
||||
Assert.AreSame(buffer.GraphicsDevice, device.Get());
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow(typeof(UploadBuffer<>), -247824)]
|
||||
[DataRow(typeof(UploadBuffer<>), -1)]
|
||||
[DataRow(typeof(ReadBackBuffer<>), -247824)]
|
||||
[DataRow(typeof(ReadBackBuffer<>), -1)]
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(UploadBuffer<>))]
|
||||
[Resource(typeof(ReadBackBuffer<>))]
|
||||
[Data(-247824)]
|
||||
[Data(-1)]
|
||||
[ExpectedException(typeof(ArgumentOutOfRangeException))]
|
||||
public void Allocate_Uninitialized_Fail(Type bufferType, int length)
|
||||
public void Allocate_Uninitialized_Fail(Device device, Type bufferType, int length)
|
||||
{
|
||||
using TransferBuffer<float> buffer = Gpu.Default.AllocateTransferBuffer<float>(bufferType, length);
|
||||
using TransferBuffer<float> buffer = device.Get().AllocateTransferBuffer<float>(bufferType, length);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow(typeof(UploadBuffer<>))]
|
||||
[DataRow(typeof(ReadBackBuffer<>))]
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(UploadBuffer<>))]
|
||||
[Resource(typeof(ReadBackBuffer<>))]
|
||||
[ExpectedException(typeof(ObjectDisposedException))]
|
||||
public void UsageAfterDispose(Type bufferType)
|
||||
public void UsageAfterDispose(Device device, Type bufferType)
|
||||
{
|
||||
using TransferBuffer<float> buffer = Gpu.Default.AllocateTransferBuffer<float>(bufferType, 128);
|
||||
using TransferBuffer<float> buffer = device.Get().AllocateTransferBuffer<float>(bufferType, 128);
|
||||
|
||||
buffer.Dispose();
|
||||
|
||||
_ = buffer.Span;
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Allocate_UploadBuffer_Copy_Full()
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
public void Allocate_UploadBuffer_Copy_Full(Device device)
|
||||
{
|
||||
using UploadBuffer<int> uploadBuffer = Gpu.Default.AllocateUploadBuffer<int>(4096);
|
||||
using UploadBuffer<int> uploadBuffer = device.Get().AllocateUploadBuffer<int>(4096);
|
||||
|
||||
new Random(42).NextBytes(uploadBuffer.Span.AsBytes());
|
||||
|
||||
using ReadOnlyBuffer<int> readOnlyBuffer = Gpu.Default.AllocateReadOnlyBuffer<int>(uploadBuffer.Length);
|
||||
using ReadOnlyBuffer<int> readOnlyBuffer = device.Get().AllocateReadOnlyBuffer<int>(uploadBuffer.Length);
|
||||
|
||||
uploadBuffer.CopyTo(readOnlyBuffer);
|
||||
|
||||
@@ -69,18 +74,19 @@ namespace ComputeSharp.Tests
|
||||
Assert.IsTrue(uploadBuffer.Span.SequenceEqual(result));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow(0, 0, 4096)]
|
||||
[DataRow(128, 0, 2048)]
|
||||
[DataRow(0, 128, 2048)]
|
||||
[DataRow(97, 33, 512)]
|
||||
public void Allocate_UploadBuffer_Copy_Range(int destinationOffset, int bufferOffset, int count)
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Data(0, 0, 4096)]
|
||||
[Data(128, 0, 2048)]
|
||||
[Data(0, 128, 2048)]
|
||||
[Data(97, 33, 512)]
|
||||
public void Allocate_UploadBuffer_Copy_Range(Device device, int destinationOffset, int bufferOffset, int count)
|
||||
{
|
||||
using UploadBuffer<int> uploadBuffer = Gpu.Default.AllocateUploadBuffer<int>(4096);
|
||||
using UploadBuffer<int> uploadBuffer = device.Get().AllocateUploadBuffer<int>(4096);
|
||||
|
||||
new Random(42).NextBytes(uploadBuffer.Span.AsBytes());
|
||||
|
||||
using ReadOnlyBuffer<int> readOnlyBuffer = Gpu.Default.AllocateReadOnlyBuffer<int>(uploadBuffer.Length);
|
||||
using ReadOnlyBuffer<int> readOnlyBuffer = device.Get().AllocateReadOnlyBuffer<int>(uploadBuffer.Length);
|
||||
|
||||
uploadBuffer.CopyTo(readOnlyBuffer, destinationOffset, bufferOffset, count);
|
||||
|
||||
@@ -90,15 +96,16 @@ namespace ComputeSharp.Tests
|
||||
Assert.IsTrue(uploadBuffer.Span.Slice(bufferOffset, count).SequenceEqual(result));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Allocate_ReadBackBuffer_Copy_Full()
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
public void Allocate_ReadBackBuffer_Copy_Full(Device device)
|
||||
{
|
||||
int[] source = new int[4096];
|
||||
|
||||
new Random(42).NextBytes(source.AsSpan().AsBytes());
|
||||
|
||||
using ReadOnlyBuffer<int> readOnlyBuffer = Gpu.Default.AllocateReadOnlyBuffer(source);
|
||||
using ReadBackBuffer<int> readBackBuffer = Gpu.Default.AllocateReadBackBuffer<int>(readOnlyBuffer.Length);
|
||||
using ReadOnlyBuffer<int> readOnlyBuffer = device.Get().AllocateReadOnlyBuffer(source);
|
||||
using ReadBackBuffer<int> readBackBuffer = device.Get().AllocateReadBackBuffer<int>(readOnlyBuffer.Length);
|
||||
|
||||
readOnlyBuffer.CopyTo(readBackBuffer);
|
||||
|
||||
@@ -106,19 +113,20 @@ namespace ComputeSharp.Tests
|
||||
Assert.IsTrue(source.AsSpan().SequenceEqual(readBackBuffer.Span));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow(0, 0, 4096)]
|
||||
[DataRow(128, 0, 2048)]
|
||||
[DataRow(0, 128, 2048)]
|
||||
[DataRow(97, 33, 512)]
|
||||
public void Allocate_ReadBackBuffer_Copy_Range(int destinationOffset, int bufferOffset, int count)
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Data(0, 0, 4096)]
|
||||
[Data(128, 0, 2048)]
|
||||
[Data(0, 128, 2048)]
|
||||
[Data(97, 33, 512)]
|
||||
public void Allocate_ReadBackBuffer_Copy_Range(Device device, int destinationOffset, int bufferOffset, int count)
|
||||
{
|
||||
int[] source = new int[4096];
|
||||
|
||||
new Random(42).NextBytes(source.AsSpan().AsBytes());
|
||||
|
||||
using ReadOnlyBuffer<int> readOnlyBuffer = Gpu.Default.AllocateReadOnlyBuffer(source);
|
||||
using ReadBackBuffer<int> readBackBuffer = Gpu.Default.AllocateReadBackBuffer<int>(readOnlyBuffer.Length);
|
||||
using ReadOnlyBuffer<int> readOnlyBuffer = device.Get().AllocateReadOnlyBuffer(source);
|
||||
using ReadBackBuffer<int> readBackBuffer = device.Get().AllocateReadBackBuffer<int>(readOnlyBuffer.Length);
|
||||
|
||||
readOnlyBuffer.CopyTo(readBackBuffer, destinationOffset, bufferOffset, count);
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using ComputeSharp.Resources;
|
||||
using ComputeSharp.Tests.Attributes;
|
||||
using ComputeSharp.Tests.Extensions;
|
||||
using Microsoft.Toolkit.HighPerformance.Extensions;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
@@ -11,60 +12,62 @@ namespace ComputeSharp.Tests
|
||||
[TestCategory("TransferTexture2D")]
|
||||
public partial class TransferTexture2DTests
|
||||
{
|
||||
[TestMethod]
|
||||
[DataRow(typeof(UploadTexture2D<>))]
|
||||
[DataRow(typeof(ReadBackTexture2D<>))]
|
||||
public unsafe void Allocate_Uninitialized_Ok(Type bufferType)
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(UploadTexture2D<>))]
|
||||
[Resource(typeof(ReadBackTexture2D<>))]
|
||||
public unsafe void Allocate_Uninitialized_Ok(Device device, Type bufferType)
|
||||
{
|
||||
using TransferTexture2D<float> buffer = Gpu.Default.AllocateTransferTexture2D<float>(bufferType, 128, 256);
|
||||
using TransferTexture2D<float> buffer = device.Get().AllocateTransferTexture2D<float>(bufferType, 128, 256);
|
||||
|
||||
Assert.IsNotNull(buffer);
|
||||
Assert.AreEqual(buffer.Width, 128);
|
||||
Assert.AreEqual(buffer.Height, 256);
|
||||
Assert.AreEqual(buffer.View.Width, 128);
|
||||
Assert.AreEqual(buffer.View.Height, 256);
|
||||
Assert.AreSame(buffer.GraphicsDevice, Gpu.Default);
|
||||
Assert.AreSame(buffer.GraphicsDevice, device.Get());
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow(typeof(UploadTexture2D<>), 128, -14253)]
|
||||
[DataRow(typeof(UploadTexture2D<>), 128, -1)]
|
||||
[DataRow(typeof(UploadTexture2D<>), 0, -4314)]
|
||||
[DataRow(typeof(UploadTexture2D<>), -14, -53)]
|
||||
[DataRow(typeof(ReadBackTexture2D<>), 128, -14253)]
|
||||
[DataRow(typeof(ReadBackTexture2D<>), 128, -1)]
|
||||
[DataRow(typeof(ReadBackTexture2D<>), 0, -4314)]
|
||||
[DataRow(typeof(ReadBackTexture2D<>), -14, -53)]
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(UploadTexture2D<>))]
|
||||
[Resource(typeof(ReadBackTexture2D<>))]
|
||||
[Data(128, -14253)]
|
||||
[Data(128, -1)]
|
||||
[Data(0, -4314)]
|
||||
[Data(-14, -53)]
|
||||
[ExpectedException(typeof(ArgumentOutOfRangeException))]
|
||||
public void Allocate_Uninitialized_Fail(Type bufferType, int width, int height)
|
||||
public void Allocate_Uninitialized_Fail(Device device, Type bufferType, int width, int height)
|
||||
{
|
||||
using TransferTexture2D<float> buffer = Gpu.Default.AllocateTransferTexture2D<float>(bufferType, width, height);
|
||||
using TransferTexture2D<float> buffer = device.Get().AllocateTransferTexture2D<float>(bufferType, width, height);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow(typeof(UploadTexture2D<>))]
|
||||
[DataRow(typeof(ReadBackTexture2D<>))]
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(UploadTexture2D<>))]
|
||||
[Resource(typeof(ReadBackTexture2D<>))]
|
||||
[ExpectedException(typeof(ObjectDisposedException))]
|
||||
public void UsageAfterDispose(Type bufferType)
|
||||
public void UsageAfterDispose(Device device, Type bufferType)
|
||||
{
|
||||
using TransferTexture2D<float> buffer = Gpu.Default.AllocateTransferTexture2D<float>(bufferType, 32, 32);
|
||||
using TransferTexture2D<float> buffer = device.Get().AllocateTransferTexture2D<float>(bufferType, 32, 32);
|
||||
|
||||
buffer.Dispose();
|
||||
|
||||
_ = buffer.View;
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Allocate_UploadTexture2D_Copy_Full()
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
public void Allocate_UploadTexture2D_Copy_Full(Device device)
|
||||
{
|
||||
using UploadTexture2D<int> uploadTexture2D = Gpu.Default.AllocateUploadTexture2D<int>(256, 256);
|
||||
using UploadTexture2D<int> uploadTexture2D = device.Get().AllocateUploadTexture2D<int>(256, 256);
|
||||
|
||||
for (int i = 0; i < uploadTexture2D.Height; i++)
|
||||
{
|
||||
new Random(i).NextBytes(uploadTexture2D.View.GetRowSpan(i).AsBytes());
|
||||
}
|
||||
|
||||
using ReadOnlyTexture2D<int> readOnlyTexture2D = Gpu.Default.AllocateReadOnlyTexture2D<int>(uploadTexture2D.Width, uploadTexture2D.Height);
|
||||
using ReadOnlyTexture2D<int> readOnlyTexture2D = device.Get().AllocateReadOnlyTexture2D<int>(uploadTexture2D.Width, uploadTexture2D.Height);
|
||||
|
||||
uploadTexture2D.CopyTo(readOnlyTexture2D);
|
||||
|
||||
@@ -79,21 +82,22 @@ namespace ComputeSharp.Tests
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow(0, 0, 2048, 2048)]
|
||||
[DataRow(128, 0, 1813, 2048)]
|
||||
[DataRow(0, 128, 2000, 944)]
|
||||
[DataRow(97, 33, 512, 794)]
|
||||
public void Allocate_UploadTexture2D_Copy_Range(int x, int y, int width, int height)
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Data(0, 0, 2048, 2048)]
|
||||
[Data(128, 0, 1813, 2048)]
|
||||
[Data(0, 128, 2000, 944)]
|
||||
[Data(97, 33, 512, 794)]
|
||||
public void Allocate_UploadTexture2D_Copy_Range(Device device, int x, int y, int width, int height)
|
||||
{
|
||||
using UploadTexture2D<int> uploadTexture2D = Gpu.Default.AllocateUploadTexture2D<int>(2048, 2048);
|
||||
using UploadTexture2D<int> uploadTexture2D = device.Get().AllocateUploadTexture2D<int>(2048, 2048);
|
||||
|
||||
for (int i = 0; i < uploadTexture2D.Height; i++)
|
||||
{
|
||||
new Random(i).NextBytes(uploadTexture2D.View.GetRowSpan(i).AsBytes());
|
||||
}
|
||||
|
||||
using ReadOnlyTexture2D<int> readOnlyTexture2D = Gpu.Default.AllocateReadOnlyTexture2D<int>(uploadTexture2D.Width, uploadTexture2D.Height);
|
||||
using ReadOnlyTexture2D<int> readOnlyTexture2D = device.Get().AllocateReadOnlyTexture2D<int>(uploadTexture2D.Width, uploadTexture2D.Height);
|
||||
|
||||
uploadTexture2D.CopyTo(readOnlyTexture2D, x, y, width, height);
|
||||
|
||||
@@ -108,8 +112,9 @@ namespace ComputeSharp.Tests
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Allocate_ReadBackTexture2D_Copy_Full()
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
public void Allocate_ReadBackTexture2D_Copy_Full(Device device)
|
||||
{
|
||||
int[,] source = new int[256, 256];
|
||||
|
||||
@@ -118,8 +123,8 @@ namespace ComputeSharp.Tests
|
||||
new Random(42).NextBytes(source.GetRowSpan(i).AsBytes());
|
||||
}
|
||||
|
||||
using ReadOnlyTexture2D<int> readOnlyTexture2D = Gpu.Default.AllocateReadOnlyTexture2D(source);
|
||||
using ReadBackTexture2D<int> readBackTexture2D = Gpu.Default.AllocateReadBackTexture2D<int>(256, 256);
|
||||
using ReadOnlyTexture2D<int> readOnlyTexture2D = device.Get().AllocateReadOnlyTexture2D(source);
|
||||
using ReadBackTexture2D<int> readBackTexture2D = device.Get().AllocateReadBackTexture2D<int>(256, 256);
|
||||
|
||||
readOnlyTexture2D.CopyTo(readBackTexture2D);
|
||||
|
||||
@@ -132,12 +137,13 @@ namespace ComputeSharp.Tests
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow(0, 0, 2048, 2048)]
|
||||
[DataRow(128, 0, 1813, 2048)]
|
||||
[DataRow(0, 128, 2000, 944)]
|
||||
[DataRow(97, 33, 512, 794)]
|
||||
public void Allocate_ReadBackTexture2D_Copy_Range(int x, int y, int width, int height)
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Data(0, 0, 2048, 2048)]
|
||||
[Data(128, 0, 1813, 2048)]
|
||||
[Data(0, 128, 2000, 944)]
|
||||
[Data(97, 33, 512, 794)]
|
||||
public void Allocate_ReadBackTexture2D_Copy_Range(Device device, int x, int y, int width, int height)
|
||||
{
|
||||
int[,] source = new int[2048, 2048];
|
||||
|
||||
@@ -146,8 +152,8 @@ namespace ComputeSharp.Tests
|
||||
new Random(42).NextBytes(source.GetRowSpan(i).AsBytes());
|
||||
}
|
||||
|
||||
using ReadOnlyTexture2D<int> readOnlyTexture2D = Gpu.Default.AllocateReadOnlyTexture2D(source);
|
||||
using ReadBackTexture2D<int> readBackTexture2D = Gpu.Default.AllocateReadBackTexture2D<int>(2048, 2048);
|
||||
using ReadOnlyTexture2D<int> readOnlyTexture2D = device.Get().AllocateReadOnlyTexture2D(source);
|
||||
using ReadBackTexture2D<int> readBackTexture2D = device.Get().AllocateReadBackTexture2D<int>(2048, 2048);
|
||||
|
||||
readOnlyTexture2D.CopyTo(readBackTexture2D, x, y, width, height);
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using ComputeSharp.Resources;
|
||||
using ComputeSharp.Tests.Attributes;
|
||||
using ComputeSharp.Tests.Extensions;
|
||||
using Microsoft.Toolkit.HighPerformance.Extensions;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
@@ -11,12 +12,13 @@ namespace ComputeSharp.Tests
|
||||
[TestCategory("TransferTexture3D")]
|
||||
public partial class TransferTexture3DTests
|
||||
{
|
||||
[TestMethod]
|
||||
[DataRow(typeof(UploadTexture3D<>))]
|
||||
[DataRow(typeof(ReadBackTexture3D<>))]
|
||||
public unsafe void Allocate_Uninitialized_Ok(Type bufferType)
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(UploadTexture3D<>))]
|
||||
[Resource(typeof(ReadBackTexture3D<>))]
|
||||
public unsafe void Allocate_Uninitialized_Ok(Device device, Type bufferType)
|
||||
{
|
||||
using TransferTexture3D<float> buffer = Gpu.Default.AllocateTransferTexture3D<float>(bufferType, 128, 256, 32);
|
||||
using TransferTexture3D<float> buffer = device.Get().AllocateTransferTexture3D<float>(bufferType, 128, 256, 32);
|
||||
|
||||
Assert.IsNotNull(buffer);
|
||||
Assert.AreEqual(buffer.Width, 128);
|
||||
@@ -25,45 +27,44 @@ namespace ComputeSharp.Tests
|
||||
Assert.AreEqual(buffer.View.Width, 128);
|
||||
Assert.AreEqual(buffer.View.Height, 256);
|
||||
Assert.AreEqual(buffer.View.Depth, 32);
|
||||
Assert.AreSame(buffer.GraphicsDevice, Gpu.Default);
|
||||
Assert.AreSame(buffer.GraphicsDevice, device.Get());
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow(typeof(UploadTexture3D<>), 128, -14253, 4)]
|
||||
[DataRow(typeof(UploadTexture3D<>), 128, -1, 4)]
|
||||
[DataRow(typeof(UploadTexture3D<>), 0, -4314, 4)]
|
||||
[DataRow(typeof(UploadTexture3D<>), -14, -53, 4)]
|
||||
[DataRow(typeof(UploadTexture3D<>), 12, 12, -1)]
|
||||
[DataRow(typeof(UploadTexture3D<>), 2, 4, ushort.MaxValue + 1)]
|
||||
[DataRow(typeof(ReadBackTexture3D<>), 128, -14253, 4)]
|
||||
[DataRow(typeof(ReadBackTexture3D<>), 128, -1, 4)]
|
||||
[DataRow(typeof(ReadBackTexture3D<>), 0, -4314, 4)]
|
||||
[DataRow(typeof(ReadBackTexture3D<>), -14, -53, 4)]
|
||||
[DataRow(typeof(ReadBackTexture3D<>), 12, 12, -1)]
|
||||
[DataRow(typeof(ReadBackTexture3D<>), 2, 4, ushort.MaxValue + 1)]
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(UploadTexture3D<>))]
|
||||
[Resource(typeof(ReadBackTexture3D<>))]
|
||||
[Data(128, -14253, 4)]
|
||||
[Data(128, -1, 4)]
|
||||
[Data(0, -4314, 4)]
|
||||
[Data(-14, -53, 4)]
|
||||
[Data(12, 12, -1)]
|
||||
[Data(2, 4, ushort.MaxValue + 1)]
|
||||
[ExpectedException(typeof(ArgumentOutOfRangeException))]
|
||||
public void Allocate_Uninitialized_Fail(Type bufferType, int width, int height, int depth)
|
||||
public void Allocate_Uninitialized_Fail(Device device, Type bufferType, int width, int height, int depth)
|
||||
{
|
||||
using TransferTexture3D<float> buffer = Gpu.Default.AllocateTransferTexture3D<float>(bufferType, width, height, depth);
|
||||
using TransferTexture3D<float> buffer = device.Get().AllocateTransferTexture3D<float>(bufferType, width, height, depth);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow(typeof(UploadTexture3D<>))]
|
||||
[DataRow(typeof(ReadBackTexture3D<>))]
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(UploadTexture3D<>))]
|
||||
[Resource(typeof(ReadBackTexture3D<>))]
|
||||
[ExpectedException(typeof(ObjectDisposedException))]
|
||||
public void UsageAfterDispose(Type bufferType)
|
||||
public void UsageAfterDispose(Device device, Type bufferType)
|
||||
{
|
||||
using TransferTexture3D<float> buffer = Gpu.Default.AllocateTransferTexture3D<float>(bufferType, 32, 32, 16);
|
||||
using TransferTexture3D<float> buffer = device.Get().AllocateTransferTexture3D<float>(bufferType, 32, 32, 16);
|
||||
|
||||
buffer.Dispose();
|
||||
|
||||
_ = buffer.View;
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Allocate_UploadTexture3D_Copy_Full()
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
public void Allocate_UploadTexture3D_Copy_Full(Device device)
|
||||
{
|
||||
using UploadTexture3D<int> uploadTexture3D = Gpu.Default.AllocateUploadTexture3D<int>(256, 256, 16);
|
||||
using UploadTexture3D<int> uploadTexture3D = device.Get().AllocateUploadTexture3D<int>(256, 256, 16);
|
||||
|
||||
for (int i = 0; i < uploadTexture3D.Depth; i++)
|
||||
{
|
||||
@@ -73,7 +74,7 @@ namespace ComputeSharp.Tests
|
||||
}
|
||||
}
|
||||
|
||||
using ReadOnlyTexture3D<int> readOnlyTexture3D = Gpu.Default.AllocateReadOnlyTexture3D<int>(uploadTexture3D.Width, uploadTexture3D.Height, uploadTexture3D.Depth);
|
||||
using ReadOnlyTexture3D<int> readOnlyTexture3D = device.Get().AllocateReadOnlyTexture3D<int>(uploadTexture3D.Width, uploadTexture3D.Height, uploadTexture3D.Depth);
|
||||
|
||||
uploadTexture3D.CopyTo(readOnlyTexture3D);
|
||||
|
||||
@@ -95,15 +96,16 @@ namespace ComputeSharp.Tests
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow(0, 0, 0, 256, 256, 16)]
|
||||
[DataRow(128, 0, 0, 72, 256, 16)]
|
||||
[DataRow(0, 128, 0, 189, 67, 8)]
|
||||
[DataRow(0, 0, 15, 32, 64, 1)]
|
||||
[DataRow(97, 33, 4, 128, 99, 7)]
|
||||
public void Allocate_UploadTexture3D_Copy_Range(int x, int y, int z, int width, int height, int depth)
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Data(0, 0, 0, 256, 256, 16)]
|
||||
[Data(128, 0, 0, 72, 256, 16)]
|
||||
[Data(0, 128, 0, 189, 67, 8)]
|
||||
[Data(0, 0, 15, 32, 64, 1)]
|
||||
[Data(97, 33, 4, 128, 99, 7)]
|
||||
public void Allocate_UploadTexture3D_Copy_Range(Device device, int x, int y, int z, int width, int height, int depth)
|
||||
{
|
||||
using UploadTexture3D<int> uploadTexture3D = Gpu.Default.AllocateUploadTexture3D<int>(256, 256, 16);
|
||||
using UploadTexture3D<int> uploadTexture3D = device.Get().AllocateUploadTexture3D<int>(256, 256, 16);
|
||||
|
||||
for (int i = 0; i < uploadTexture3D.Depth; i++)
|
||||
{
|
||||
@@ -113,7 +115,7 @@ namespace ComputeSharp.Tests
|
||||
}
|
||||
}
|
||||
|
||||
using ReadOnlyTexture3D<int> readOnlyTexture3D = Gpu.Default.AllocateReadOnlyTexture3D<int>(uploadTexture3D.Width, uploadTexture3D.Height, uploadTexture3D.Depth);
|
||||
using ReadOnlyTexture3D<int> readOnlyTexture3D = device.Get().AllocateReadOnlyTexture3D<int>(uploadTexture3D.Width, uploadTexture3D.Height, uploadTexture3D.Depth);
|
||||
|
||||
uploadTexture3D.CopyTo(readOnlyTexture3D, x, y, z, width, height, depth);
|
||||
|
||||
@@ -131,8 +133,9 @@ namespace ComputeSharp.Tests
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Allocate_ReadBackTexture3D_Copy_Full()
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
public void Allocate_ReadBackTexture3D_Copy_Full(Device device)
|
||||
{
|
||||
int[,,] source = new int[16, 256, 256];
|
||||
|
||||
@@ -144,8 +147,8 @@ namespace ComputeSharp.Tests
|
||||
}
|
||||
}
|
||||
|
||||
using ReadOnlyTexture3D<int> readOnlyTexture3D = Gpu.Default.AllocateReadOnlyTexture3D(source);
|
||||
using ReadBackTexture3D<int> readBackTexture3D = Gpu.Default.AllocateReadBackTexture3D<int>(256, 256, 16);
|
||||
using ReadOnlyTexture3D<int> readOnlyTexture3D = device.Get().AllocateReadOnlyTexture3D(source);
|
||||
using ReadBackTexture3D<int> readBackTexture3D = device.Get().AllocateReadBackTexture3D<int>(256, 256, 16);
|
||||
|
||||
readOnlyTexture3D.CopyTo(readBackTexture3D);
|
||||
|
||||
@@ -165,13 +168,14 @@ namespace ComputeSharp.Tests
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow(0, 0, 0, 256, 256, 16)]
|
||||
[DataRow(128, 0, 0, 72, 256, 16)]
|
||||
[DataRow(0, 128, 0, 189, 67, 8)]
|
||||
[DataRow(0, 0, 15, 32, 64, 1)]
|
||||
[DataRow(97, 33, 4, 128, 99, 7)]
|
||||
public void Allocate_ReadBackTexture3D_Copy_Range(int x, int y, int z, int width, int height, int depth)
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Data(0, 0, 0, 256, 256, 16)]
|
||||
[Data(128, 0, 0, 72, 256, 16)]
|
||||
[Data(0, 128, 0, 189, 67, 8)]
|
||||
[Data(0, 0, 15, 32, 64, 1)]
|
||||
[Data(97, 33, 4, 128, 99, 7)]
|
||||
public void Allocate_ReadBackTexture3D_Copy_Range(Device device, int x, int y, int z, int width, int height, int depth)
|
||||
{
|
||||
int[,,] source = new int[16, 256, 256];
|
||||
|
||||
@@ -183,8 +187,8 @@ namespace ComputeSharp.Tests
|
||||
}
|
||||
}
|
||||
|
||||
using ReadOnlyTexture3D<int> readOnlyTexture3D = Gpu.Default.AllocateReadOnlyTexture3D(source);
|
||||
using ReadBackTexture3D<int> readBackTexture3D = Gpu.Default.AllocateReadBackTexture3D<int>(256, 256, 16);
|
||||
using ReadOnlyTexture3D<int> readOnlyTexture3D = device.Get().AllocateReadOnlyTexture3D(source);
|
||||
using ReadBackTexture3D<int> readBackTexture3D = device.Get().AllocateReadBackTexture3D<int>(256, 256, 16);
|
||||
|
||||
readOnlyTexture3D.CopyTo(readBackTexture3D, x, y, z, width, height, depth);
|
||||
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする