Added tests for mutable captured delegates in a shader

このコミットが含まれているのは:
Sergio Pedri committed 2019-09-05 15:11:42 +02:00
1 親 146b98ea89
コミット acb0d2b17b
2ファイル変更
+44

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

+41
ファイルの表示
@@ -34,5 +34,46 @@ namespace ComputeSharp.Tests
Assert.IsTrue(MathF.Abs(result[0] - 9) < 0.0001f);
}
[TestMethod]
public void ChangingFuncsFromSameMethod()
{
using ReadWriteBuffer<float> buffer = Gpu.Default.AllocateReadWriteBuffer<float>(1);
Func<float, float> func = StaticMethodsContainer.Square;
Gpu.Default.For(1, id => buffer[0] = func(3));
float[] result = buffer.GetData();
Assert.IsTrue(MathF.Abs(result[0] - 9) < 0.0001f);
func = StaticMethodsContainer.Negate;
Gpu.Default.For(1, id => buffer[0] = func(3));
result = buffer.GetData();
Assert.IsTrue(MathF.Abs(result[0] + 3) < 0.0001f);
}
[TestMethod]
public void ChangingFuncsFromExternalMethod()
{
MethodRunner(StaticMethodsContainer.Square, 3, 9);
MethodRunner(StaticMethodsContainer.Negate, 3, -3);
}
private void MethodRunner(Func<float, float> func, float input, float expected)
{
using ReadWriteBuffer<float> buffer = Gpu.Default.AllocateReadWriteBuffer<float>(1);
Gpu.Default.For(1, id => buffer[0] = func(input));
float[] result = buffer.GetData();
Assert.IsTrue(MathF.Abs(result[0] - expected) < 0.0001f);
}
}
}
+3
ファイルの表示
@@ -12,6 +12,9 @@ namespace ComputeSharp.Tests
[Pure]
public static float Square(float x) => x * x;
[Pure]
public static float Negate(float x) => -x;
[Pure]
internal static float InternalSquare(float x) => x * x;