Add unit tests for async APIs
このコミットが含まれているのは:
1 親
ff59d3f5ad
コミット
a0c1787d10
1ファイル変更
+100
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using ComputeSharp.__Internals;
|
||||
using ComputeSharp.Tests.Attributes;
|
||||
using ComputeSharp.Tests.Extensions;
|
||||
@@ -433,6 +434,91 @@ public partial class ComputeContextTests
|
||||
}
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
public async Task ForAndForEach_Async_Batched(Device device)
|
||||
{
|
||||
int[] array = Enumerable.Range(0, 1024).ToArray();
|
||||
|
||||
using ReadWriteBuffer<int> buffer = device.Get().AllocateReadWriteBuffer(array);
|
||||
using ReadWriteTexture2D<Rgba32, float4> texture = device.Get().AllocateReadWriteTexture2D<Rgba32, float4>(128, 128);
|
||||
|
||||
await using (ComputeContext context = device.Get().CreateComputeContext())
|
||||
{
|
||||
context.For(512, new OffsetComputeShader(buffer, 0));
|
||||
context.For(64, new OffsetComputeShader(buffer, 512));
|
||||
context.ForEach(texture, default(ClearPixelShader));
|
||||
context.For(299, new OffsetComputeShader(buffer, 576));
|
||||
context.Barrier(texture);
|
||||
context.ForEach(texture, new ColorPixelShader(new float4(0.22f, 0.44f, 0.66f, 0.88f)));
|
||||
context.For(149, new OffsetComputeShader(buffer, 875));
|
||||
}
|
||||
|
||||
void Validate()
|
||||
{
|
||||
// Buffer test
|
||||
{
|
||||
int[] result = buffer.ToArray();
|
||||
|
||||
foreach (ref int x in array.AsSpan())
|
||||
{
|
||||
x *= 2;
|
||||
}
|
||||
|
||||
CollectionAssert.AreEqual(array, result);
|
||||
}
|
||||
|
||||
// Texture test
|
||||
{
|
||||
Rgba32[,] result = texture.ToArray();
|
||||
|
||||
foreach (Rgba32 pixel in result)
|
||||
{
|
||||
Assert.AreEqual(pixel.R, 56);
|
||||
Assert.AreEqual(pixel.G, 112);
|
||||
Assert.AreEqual(pixel.B, 168);
|
||||
Assert.AreEqual(pixel.A, 224);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Validate();
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
public async Task ForAndForEach_Async_Batched_Parallel(Device device)
|
||||
{
|
||||
async Task TestAsync(Device device)
|
||||
{
|
||||
for (int i = 0; i < 20; i++)
|
||||
{
|
||||
await ForAndForEach_Async_Batched(device);
|
||||
}
|
||||
}
|
||||
|
||||
await Task.WhenAll(Enumerable.Range(0, 64).Select(_ => TestAsync(device)));
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
public async Task ForAndForEach_Async_Batched_Parallel_Multiple(Device device)
|
||||
{
|
||||
async Task TestAsync(Device device)
|
||||
{
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
Task task1 = ForAndForEach_Async_Batched(device);
|
||||
Task task2 = ForAndForEach_Async_Batched(device);
|
||||
Task task3 = ForAndForEach_Async_Batched(device);
|
||||
|
||||
await Task.WhenAll(task1, task2, task3);
|
||||
}
|
||||
}
|
||||
|
||||
await Task.WhenAll(Enumerable.Range(0, 64).Select(_ => TestAsync(device)));
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[ExpectedException(typeof(InvalidOperationException), AllowDerivedTypes = false)]
|
||||
@@ -448,6 +534,13 @@ public partial class ComputeContextTests
|
||||
Assert.Fail();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(InvalidOperationException), AllowDerivedTypes = false)]
|
||||
public void DefaultContext_GetGraphicsDevice_ThrowsException()
|
||||
{
|
||||
_ = default(ComputeContext).GraphicsDevice;
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[ExpectedException(typeof(InvalidOperationException), AllowDerivedTypes = false)]
|
||||
@@ -508,6 +601,13 @@ public partial class ComputeContextTests
|
||||
using ComputeContext context = default;
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(InvalidOperationException), AllowDerivedTypes = false)]
|
||||
public async Task DefaultContext_DisposeAsync_ThrowsException()
|
||||
{
|
||||
await using ComputeContext context = default;
|
||||
}
|
||||
|
||||
[AutoConstructor]
|
||||
internal readonly partial struct OffsetComputeShader : IComputeShader
|
||||
{
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする