Add unit tests for ComputeContext.Transition API

Also test ReadWriteTexture[2D|3D]<T, TPixel>.AsReadOnly()
このコミットが含まれているのは:
Sergio Pedri committed 2022-01-17 19:52:43 +01:00
1 親 9801b500bb
コミット 40d3cd0182
3ファイル変更
+169 -12

検索条件に一致するファイルはありません

+61 -4
ファイルの表示
@@ -3,6 +3,7 @@ using System.Reflection;
using ComputeSharp.Resources;
using ComputeSharp.Tests.Attributes;
using ComputeSharp.Tests.Extensions;
using ComputeSharp.Tests.Helpers;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace ComputeSharp.Tests;
@@ -44,13 +45,69 @@ public partial class Texture3DTests
}
}
try
TestHelper.Run(Test<Rgba32, float4>, t, tPixel, device, textureType);
}
[CombinatorialTestMethod]
[AllDevices]
[Data(typeof(Bgra32), typeof(float4))]
[Data(typeof(R16), typeof(float))]
[Data(typeof(R8), typeof(float))]
[Data(typeof(Rg16), typeof(float2))]
[Data(typeof(Rg32), typeof(float2))]
[Data(typeof(Rgba32), typeof(float4))]
[Data(typeof(Rgba64), typeof(float4))]
public void AsReadOnly_MultipleCalls_SameInstance(Device device, Type t, Type tPixel)
{
static void Test<T, TPixel>(Device device)
where T : unmanaged, IPixel<T, TPixel>
where TPixel : unmanaged
{
new Action<Device, Type>(Test<Rgba32, float4>).Method.GetGenericMethodDefinition().MakeGenericMethod(t, tPixel).Invoke(null, new object[] { device, textureType });
using ReadWriteTexture3D<T, TPixel> texture = device.Get().AllocateReadWriteTexture3D<T, TPixel>(32, 32, 2);
using (var context = device.Get().CreateComputeContext())
{
context.Transition(texture, ResourceState.ReadOnly);
IReadOnlyTexture3D<TPixel> wrapper1 = texture.AsReadOnly();
Assert.IsNotNull(wrapper1);
IReadOnlyTexture3D<TPixel> wrapper2 = texture.AsReadOnly();
Assert.IsNotNull(wrapper2);
Assert.AreSame(wrapper1, wrapper2);
context.Transition(texture, ResourceState.ReadWrite);
}
}
catch (TargetInvocationException e) when (e.InnerException is not null)
TestHelper.Run(Test<Rgba32, float4>, t, tPixel, device);
}
[CombinatorialTestMethod]
[AllDevices]
[Data(typeof(Bgra32), typeof(float4))]
[Data(typeof(R16), typeof(float))]
[Data(typeof(R8), typeof(float))]
[Data(typeof(Rg16), typeof(float2))]
[Data(typeof(Rg32), typeof(float2))]
[Data(typeof(Rgba32), typeof(float4))]
[Data(typeof(Rgba64), typeof(float4))]
[ExpectedException(typeof(InvalidOperationException))]
public void AsReadOnly_InvalidState_ThrowInvalidOperationException(Device device, Type t, Type tPixel)
{
static void Test<T, TPixel>(Device device)
where T : unmanaged, IPixel<T, TPixel>
where TPixel : unmanaged
{
throw e.InnerException;
using ReadWriteTexture3D<T, TPixel> texture = device.Get().AllocateReadWriteTexture3D<T, TPixel>(32, 32, 2);
_ = texture.AsReadOnly();
Assert.Fail();
}
TestHelper.Run(Test<Rgba32, float4>, t, tPixel, device);
}
}