Add unit tests for bool values in dispatch data and custom struct types

このコミットが含まれているのは:
Sergio Pedri committed 2022-08-27 23:04:12 +02:00
1 親 1e3611a060
コミット 4db6360924
1ファイル変更
+92 -1
+92 -1
ファイルの表示
@@ -1,4 +1,5 @@
using ComputeSharp.Tests.Attributes;
using System.Linq;
using ComputeSharp.Tests.Attributes;
using ComputeSharp.Tests.Extensions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
@@ -83,4 +84,94 @@ public partial class ShaderMembersTests
buffer[ThreadIds.X] = total;
}
}
// See: https://github.com/Sergio0694/ComputeSharp/issues/193
[CombinatorialTestMethod]
[AllDevices]
public void BoolInstanceFields(Device device)
{
using ReadWriteBuffer<int> buffer = device.Get().AllocateReadWriteBuffer<int>(13, AllocationMode.Clear);
device.Get().For(1, new BoolInstanceFieldsShader(buffer, true, false, 42, false, true, new int3(1, 2, 3), true, new bool2(false, true), 123, true));
int[] results = buffer.ToArray();
CollectionAssert.AreEqual(
expected: new[] { 1, 0, 42, 0, 1, 1, 2, 3, 1, 0, 1, 123, 1 },
actual: results);
}
[AutoConstructor]
internal readonly partial struct BoolInstanceFieldsShader : IComputeShader
{
public readonly ReadWriteBuffer<int> buffer;
public readonly bool a;
public readonly bool b;
public readonly int c;
public readonly bool d;
public readonly bool e;
public readonly int3 f;
public readonly bool g;
public readonly bool2 h;
public readonly int i;
public readonly bool j;
public void Execute()
{
buffer[0] = Hlsl.BoolToInt(a);
buffer[1] = Hlsl.BoolToInt(b);
buffer[2] = c;
buffer[3] = Hlsl.BoolToInt(d);
buffer[4] = Hlsl.BoolToInt(e);
buffer[5] = f.X;
buffer[6] = f.Y;
buffer[7] = f.Z;
buffer[8] = Hlsl.BoolToInt(g);
buffer[9] = Hlsl.BoolToInt(h.X);
buffer[10] = Hlsl.BoolToInt(h.Y);
buffer[11] = i;
buffer[12] = Hlsl.BoolToInt(j);
}
}
// See: https://github.com/Sergio0694/ComputeSharp/issues/193
[CombinatorialTestMethod]
[AllDevices]
public void BoolInstanceFieldInCustomStruct(Device device)
{
Int2AndBoolField[] data = Enumerable.Range(1, 100).Select(i => new Int2AndBoolField { P = new Int2(i, i) }).ToArray();
using ReadWriteBuffer<Int2AndBoolField> buffer = device.Get().AllocateReadWriteBuffer(data);
device.Get().For(100, new BoolInstanceFieldInCustomStructShader(buffer));
Int2AndBoolField[] results = buffer.ToArray();
for (int i = 0; i < results.Length; i++)
{
ref Int2AndBoolField value = ref results[i];
Assert.AreEqual(i + 1, value.P.X);
Assert.AreEqual(i + 1, value.P.Y);
Assert.AreEqual(true, (bool)value.B);
}
}
public struct Int2AndBoolField
{
public Int2 P;
public Bool B;
}
[AutoConstructor]
internal readonly partial struct BoolInstanceFieldInCustomStructShader : IComputeShader
{
public readonly ReadWriteBuffer<Int2AndBoolField> buffer;
public void Execute()
{
buffer[ThreadIds.X].B = true;
}
}
}