Fixed unit test build errors
このコミットが含まれているのは:
1 親
b386c23742
コミット
2d200db5ba
5ファイル変更
+235
-138
検索条件に一致するファイルはありません
@@ -202,7 +202,7 @@ namespace ComputeSharp.SourceGenerators
|
||||
.AddArgumentListArguments(Argument(
|
||||
MemberAccessExpression(
|
||||
SyntaxKind.SimpleMemberAccessExpression,
|
||||
IdentifierName("foo"),
|
||||
IdentifierName(fieldSymbol.Name),
|
||||
IdentifierName("Method"))))));
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Runtime.CompilerServices;
|
||||
using ComputeSharp.__Internals;
|
||||
|
||||
#pragma warning disable CS0618
|
||||
|
||||
namespace ComputeSharp.Tests.Internals.Helpers
|
||||
{
|
||||
/// <summary>
|
||||
/// A debug data loader for generic shaders.
|
||||
/// </summary>
|
||||
internal readonly unsafe struct DebugDispatchDataLoader : IDispatchDataLoader
|
||||
{
|
||||
/// <summary>
|
||||
/// The backing, mutable data for <see cref="Values"/> and <see cref="Resources"/>.
|
||||
/// </summary>
|
||||
private readonly StrongBox<(uint[] Values, ulong[] Resources)> data;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the captured values.
|
||||
/// </summary>
|
||||
public uint[] Values => this.data.Value.Values;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the captured resources.
|
||||
/// </summary>
|
||||
public ulong[] Resources => this.data.Value.Resources;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="DebugDispatchDataLoader"/> instance.
|
||||
/// </summary>
|
||||
/// <returns>A new <see cref="DebugDispatchDataLoader"/> instance to use.</returns>
|
||||
[Pure]
|
||||
public static DebugDispatchDataLoader Create()
|
||||
{
|
||||
DebugDispatchDataLoader @this = default;
|
||||
|
||||
Unsafe.AsRef(in @this.data) = new StrongBox<(uint[], ulong[])>((Array.Empty<uint>(), Array.Empty<ulong>()));
|
||||
|
||||
return @this;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void LoadCapturedValues(ReadOnlySpan<uint> data)
|
||||
{
|
||||
this.data.Value.Values = data.ToArray();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void LoadCapturedResources(ReadOnlySpan<ulong> data)
|
||||
{
|
||||
this.data.Value.Resources = data.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
using ComputeSharp.__Internals;
|
||||
using ComputeSharp.Tests.Internals.Helpers;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
#pragma warning disable CS0618
|
||||
@@ -22,16 +22,19 @@ namespace ComputeSharp.Tests.Internals
|
||||
[TestMethod]
|
||||
public unsafe void CapturedResource()
|
||||
{
|
||||
ulong* p0 = stackalloc ulong[128];
|
||||
byte* p1 = stackalloc byte[256];
|
||||
|
||||
using ReadWriteBuffer<float> buffer = Gpu.Default.AllocateReadWriteBuffer<float>(16);
|
||||
|
||||
int size = DispatchDataLoader.LoadDispatchData(Gpu.Default, new CapturedResourceShader(buffer), ref *p0, ref *p1);
|
||||
DebugDispatchDataLoader dataLoader = DebugDispatchDataLoader.Create();
|
||||
|
||||
Assert.AreEqual(12, size);
|
||||
new CapturedResourceShader(buffer).LoadDispatchData(in dataLoader, Gpu.Default, 111, 222, 333);
|
||||
|
||||
Assert.AreEqual(p0[0], buffer.D3D12GpuDescriptorHandle.ptr);
|
||||
Assert.AreEqual(3, dataLoader.Values.Length);
|
||||
Assert.AreEqual(1, dataLoader.Resources.Length);
|
||||
|
||||
Assert.AreEqual(111, (int)dataLoader.Values[0]);
|
||||
Assert.AreEqual(222, (int)dataLoader.Values[1]);
|
||||
Assert.AreEqual(333, (int)dataLoader.Values[2]);
|
||||
Assert.AreEqual(buffer.D3D12GpuDescriptorHandle.ptr, dataLoader.Resources[0]);
|
||||
}
|
||||
|
||||
[AutoConstructor]
|
||||
@@ -51,22 +54,24 @@ namespace ComputeSharp.Tests.Internals
|
||||
[TestMethod]
|
||||
public unsafe void LoadMultipleResourcesAndPrimitives()
|
||||
{
|
||||
ulong* p0 = stackalloc ulong[128];
|
||||
byte* p1 = stackalloc byte[256];
|
||||
|
||||
using ReadWriteBuffer<float> buffer0 = Gpu.Default.AllocateReadWriteBuffer<float>(16);
|
||||
using ReadWriteBuffer<float> buffer1 = Gpu.Default.AllocateReadWriteBuffer<float>(16);
|
||||
|
||||
int size = DispatchDataLoader.LoadDispatchData(Gpu.Default, new MultipleResourcesAndPrimitivesShader(buffer0, buffer1, 1, 22, 77), ref *p0, ref *p1);
|
||||
DebugDispatchDataLoader dataLoader = DebugDispatchDataLoader.Create();
|
||||
|
||||
Assert.AreEqual(24, size);
|
||||
new MultipleResourcesAndPrimitivesShader(buffer0, buffer1, 1, 22, 77).LoadDispatchData(in dataLoader, Gpu.Default, 111, 222, 333);
|
||||
|
||||
Assert.AreEqual(p0[0], buffer0.D3D12GpuDescriptorHandle.ptr);
|
||||
Assert.AreEqual(p0[1], buffer1.D3D12GpuDescriptorHandle.ptr);
|
||||
Assert.AreEqual(6, dataLoader.Values.Length);
|
||||
Assert.AreEqual(2, dataLoader.Resources.Length);
|
||||
|
||||
Assert.AreEqual(1, *(int*)&p1[12]);
|
||||
Assert.AreEqual(22, *(int*)&p1[16]);
|
||||
Assert.AreEqual(77, *(int*)&p1[20]);
|
||||
Assert.AreEqual(111, (int)dataLoader.Values[0]);
|
||||
Assert.AreEqual(222, (int)dataLoader.Values[1]);
|
||||
Assert.AreEqual(333, (int)dataLoader.Values[2]);
|
||||
Assert.AreEqual(1, (int)dataLoader.Values[3]);
|
||||
Assert.AreEqual(22, (int)dataLoader.Values[4]);
|
||||
Assert.AreEqual(77, (int)dataLoader.Values[5]);
|
||||
Assert.AreEqual(buffer0.D3D12GpuDescriptorHandle.ptr, dataLoader.Resources[0]);
|
||||
Assert.AreEqual(buffer1.D3D12GpuDescriptorHandle.ptr, dataLoader.Resources[1]);
|
||||
}
|
||||
|
||||
[AutoConstructor]
|
||||
@@ -88,28 +93,36 @@ namespace ComputeSharp.Tests.Internals
|
||||
[TestMethod]
|
||||
public unsafe void LoadScalarAndVectorTypes()
|
||||
{
|
||||
ulong* p0 = stackalloc ulong[128];
|
||||
byte* p1 = stackalloc byte[256];
|
||||
|
||||
using ReadWriteBuffer<float> buffer = Gpu.Default.AllocateReadWriteBuffer<float>(16);
|
||||
|
||||
DebugDispatchDataLoader dataLoader = DebugDispatchDataLoader.Create();
|
||||
ScalarAndVectorTypesShader shader = new(buffer, new(55, 44, 888), 22, 77, new(3.14, 6.28), 42, 9999);
|
||||
|
||||
int size = DispatchDataLoader.LoadDispatchData(Gpu.Default, in shader, ref *p0, ref *p1);
|
||||
shader.LoadDispatchData(in dataLoader, Gpu.Default, 111, 222, 333);
|
||||
|
||||
Assert.AreEqual(72, size);
|
||||
Assert.AreEqual(18, dataLoader.Values.Length);
|
||||
Assert.AreEqual(1, dataLoader.Resources.Length);
|
||||
|
||||
Assert.AreEqual(p0[0], buffer.D3D12GpuDescriptorHandle.ptr);
|
||||
Assert.AreEqual(111, (int)dataLoader.Values[0]);
|
||||
Assert.AreEqual(222, (int)dataLoader.Values[1]);
|
||||
Assert.AreEqual(333, (int)dataLoader.Values[2]);
|
||||
|
||||
Assert.AreEqual(55, *(float*)&p1[16]);
|
||||
Assert.AreEqual(44, *(float*)&p1[20]);
|
||||
Assert.AreEqual(888, *(float*)&p1[24]);
|
||||
Assert.AreEqual(22, *(int*)&p1[28]);
|
||||
Assert.AreEqual(77, *(int*)&p1[32]);
|
||||
Assert.AreEqual(3.14, *(double*)&p1[48]);
|
||||
Assert.AreEqual(6.28, *(double*)&p1[56]);
|
||||
Assert.AreEqual(42, *(int*)&p1[64]);
|
||||
Assert.AreEqual(9999, *(int*)&p1[68]);
|
||||
Assert.AreEqual(buffer.D3D12GpuDescriptorHandle.ptr, dataLoader.Resources[0]);
|
||||
|
||||
fixed (void* p0 = &dataLoader.Values[0])
|
||||
{
|
||||
byte* p1 = (byte*)p0;
|
||||
|
||||
Assert.AreEqual(55, *(float*)&p1[16]);
|
||||
Assert.AreEqual(44, *(float*)&p1[20]);
|
||||
Assert.AreEqual(888, *(float*)&p1[24]);
|
||||
Assert.AreEqual(22, *(int*)&p1[28]);
|
||||
Assert.AreEqual(77, *(int*)&p1[32]);
|
||||
Assert.AreEqual(3.14, *(double*)&p1[48]);
|
||||
Assert.AreEqual(6.28, *(double*)&p1[56]);
|
||||
Assert.AreEqual(42, *(int*)&p1[64]);
|
||||
Assert.AreEqual(9999, *(int*)&p1[68]);
|
||||
}
|
||||
}
|
||||
|
||||
[AutoConstructor]
|
||||
@@ -133,11 +146,9 @@ namespace ComputeSharp.Tests.Internals
|
||||
[TestMethod]
|
||||
public unsafe void LoadScalarVectorAndMatrixTypes()
|
||||
{
|
||||
ulong* p0 = stackalloc ulong[128];
|
||||
byte* p1 = stackalloc byte[256];
|
||||
|
||||
using ReadWriteBuffer<float> buffer = Gpu.Default.AllocateReadWriteBuffer<float>(16);
|
||||
|
||||
DebugDispatchDataLoader dataLoader = DebugDispatchDataLoader.Create();
|
||||
ScalarVectorAndMatrixTypesShader shader = new(
|
||||
buffer,
|
||||
f2x3: new(55, 44, 888, 111, 222, 333),
|
||||
@@ -149,32 +160,42 @@ namespace ComputeSharp.Tests.Internals
|
||||
i2x2: new(11, 22, 33, 44),
|
||||
d: 9999);
|
||||
|
||||
int size = DispatchDataLoader.LoadDispatchData(Gpu.Default, in shader, ref *p0, ref *p1);
|
||||
shader.LoadDispatchData(in dataLoader, Gpu.Default, 111, 222, 333);
|
||||
|
||||
Assert.AreEqual(124, size);
|
||||
Assert.AreEqual(31, dataLoader.Values.Length);
|
||||
Assert.AreEqual(1, dataLoader.Resources.Length);
|
||||
|
||||
Assert.AreEqual(p0[0], buffer.D3D12GpuDescriptorHandle.ptr);
|
||||
Assert.AreEqual(111, (int)dataLoader.Values[0]);
|
||||
Assert.AreEqual(222, (int)dataLoader.Values[1]);
|
||||
Assert.AreEqual(333, (int)dataLoader.Values[2]);
|
||||
|
||||
Assert.AreEqual(55, *(float*)&p1[16]);
|
||||
Assert.AreEqual(44, *(float*)&p1[20]);
|
||||
Assert.AreEqual(888, *(float*)&p1[24]);
|
||||
Assert.AreEqual(111, *(float*)&p1[32]);
|
||||
Assert.AreEqual(222, *(float*)&p1[36]);
|
||||
Assert.AreEqual(333, *(float*)&p1[40]);
|
||||
Assert.AreEqual(22, *(int*)&p1[44]);
|
||||
Assert.AreEqual(1, *(int*)&p1[48]);
|
||||
Assert.AreEqual(2, *(int*)&p1[52]);
|
||||
Assert.AreEqual(3, *(int*)&p1[56]);
|
||||
Assert.AreEqual(3.14, *(double*)&p1[64]);
|
||||
Assert.AreEqual(6.28, *(double*)&p1[72]);
|
||||
Assert.AreEqual(42, *(int*)&p1[80]);
|
||||
Assert.AreEqual(111, *(int*)&p1[84]);
|
||||
Assert.AreEqual(222, *(int*)&p1[88]);
|
||||
Assert.AreEqual(11, *(int*)&p1[96]);
|
||||
Assert.AreEqual(22, *(int*)&p1[100]);
|
||||
Assert.AreEqual(33, *(int*)&p1[112]);
|
||||
Assert.AreEqual(44, *(int*)&p1[116]);
|
||||
Assert.AreEqual(9999, *(int*)&p1[120]);
|
||||
Assert.AreEqual(buffer.D3D12GpuDescriptorHandle.ptr, dataLoader.Resources[0]);
|
||||
|
||||
fixed (void* p0 = &dataLoader.Values[0])
|
||||
{
|
||||
byte* p1 = (byte*)p0;
|
||||
|
||||
Assert.AreEqual(55, *(float*)&p1[16]);
|
||||
Assert.AreEqual(44, *(float*)&p1[20]);
|
||||
Assert.AreEqual(888, *(float*)&p1[24]);
|
||||
Assert.AreEqual(111, *(float*)&p1[32]);
|
||||
Assert.AreEqual(222, *(float*)&p1[36]);
|
||||
Assert.AreEqual(333, *(float*)&p1[40]);
|
||||
Assert.AreEqual(22, *(int*)&p1[44]);
|
||||
Assert.AreEqual(1, *(int*)&p1[48]);
|
||||
Assert.AreEqual(2, *(int*)&p1[52]);
|
||||
Assert.AreEqual(3, *(int*)&p1[56]);
|
||||
Assert.AreEqual(3.14, *(double*)&p1[64]);
|
||||
Assert.AreEqual(6.28, *(double*)&p1[72]);
|
||||
Assert.AreEqual(42, *(int*)&p1[80]);
|
||||
Assert.AreEqual(111, *(int*)&p1[84]);
|
||||
Assert.AreEqual(222, *(int*)&p1[88]);
|
||||
Assert.AreEqual(11, *(int*)&p1[96]);
|
||||
Assert.AreEqual(22, *(int*)&p1[100]);
|
||||
Assert.AreEqual(33, *(int*)&p1[112]);
|
||||
Assert.AreEqual(44, *(int*)&p1[116]);
|
||||
Assert.AreEqual(9999, *(int*)&p1[120]);
|
||||
}
|
||||
}
|
||||
|
||||
[AutoConstructor]
|
||||
@@ -204,11 +225,9 @@ namespace ComputeSharp.Tests.Internals
|
||||
[TestMethod]
|
||||
public unsafe void LoadFlatCustomTypeShader()
|
||||
{
|
||||
ulong* p0 = stackalloc ulong[128];
|
||||
byte* p1 = stackalloc byte[256];
|
||||
|
||||
using ReadWriteBuffer<float> buffer = Gpu.Default.AllocateReadWriteBuffer<float>(16);
|
||||
|
||||
DebugDispatchDataLoader dataLoader = DebugDispatchDataLoader.Create();
|
||||
FlatCustomTypeShader shader = new(
|
||||
buffer,
|
||||
new SimpleTypes(
|
||||
@@ -221,32 +240,42 @@ namespace ComputeSharp.Tests.Internals
|
||||
i2x2: new(11, 22, 33, 44),
|
||||
d: 9999));
|
||||
|
||||
int size = DispatchDataLoader.LoadDispatchData(Gpu.Default, in shader, ref *p0, ref *p1);
|
||||
shader.LoadDispatchData(in dataLoader, Gpu.Default, 111, 222, 333);
|
||||
|
||||
Assert.AreEqual(124, size);
|
||||
Assert.AreEqual(31, dataLoader.Values.Length);
|
||||
Assert.AreEqual(1, dataLoader.Resources.Length);
|
||||
|
||||
Assert.AreEqual(p0[0], buffer.D3D12GpuDescriptorHandle.ptr);
|
||||
Assert.AreEqual(111, (int)dataLoader.Values[0]);
|
||||
Assert.AreEqual(222, (int)dataLoader.Values[1]);
|
||||
Assert.AreEqual(333, (int)dataLoader.Values[2]);
|
||||
|
||||
Assert.AreEqual(55, *(float*)&p1[16]);
|
||||
Assert.AreEqual(44, *(float*)&p1[20]);
|
||||
Assert.AreEqual(888, *(float*)&p1[24]);
|
||||
Assert.AreEqual(111, *(float*)&p1[32]);
|
||||
Assert.AreEqual(222, *(float*)&p1[36]);
|
||||
Assert.AreEqual(333, *(float*)&p1[40]);
|
||||
Assert.AreEqual(22, *(int*)&p1[44]);
|
||||
Assert.AreEqual(1, *(int*)&p1[48]);
|
||||
Assert.AreEqual(2, *(int*)&p1[52]);
|
||||
Assert.AreEqual(3, *(int*)&p1[56]);
|
||||
Assert.AreEqual(3.14, *(double*)&p1[64]);
|
||||
Assert.AreEqual(6.28, *(double*)&p1[72]);
|
||||
Assert.AreEqual(42, *(int*)&p1[80]);
|
||||
Assert.AreEqual(111, *(int*)&p1[84]);
|
||||
Assert.AreEqual(222, *(int*)&p1[88]);
|
||||
Assert.AreEqual(11, *(int*)&p1[96]);
|
||||
Assert.AreEqual(22, *(int*)&p1[100]);
|
||||
Assert.AreEqual(33, *(int*)&p1[112]);
|
||||
Assert.AreEqual(44, *(int*)&p1[116]);
|
||||
Assert.AreEqual(9999, *(int*)&p1[120]);
|
||||
Assert.AreEqual(buffer.D3D12GpuDescriptorHandle.ptr, dataLoader.Resources[0]);
|
||||
|
||||
fixed (void* p0 = &dataLoader.Values[0])
|
||||
{
|
||||
byte* p1 = (byte*)p0;
|
||||
|
||||
Assert.AreEqual(55, *(float*)&p1[16]);
|
||||
Assert.AreEqual(44, *(float*)&p1[20]);
|
||||
Assert.AreEqual(888, *(float*)&p1[24]);
|
||||
Assert.AreEqual(111, *(float*)&p1[32]);
|
||||
Assert.AreEqual(222, *(float*)&p1[36]);
|
||||
Assert.AreEqual(333, *(float*)&p1[40]);
|
||||
Assert.AreEqual(22, *(int*)&p1[44]);
|
||||
Assert.AreEqual(1, *(int*)&p1[48]);
|
||||
Assert.AreEqual(2, *(int*)&p1[52]);
|
||||
Assert.AreEqual(3, *(int*)&p1[56]);
|
||||
Assert.AreEqual(3.14, *(double*)&p1[64]);
|
||||
Assert.AreEqual(6.28, *(double*)&p1[72]);
|
||||
Assert.AreEqual(42, *(int*)&p1[80]);
|
||||
Assert.AreEqual(111, *(int*)&p1[84]);
|
||||
Assert.AreEqual(222, *(int*)&p1[88]);
|
||||
Assert.AreEqual(11, *(int*)&p1[96]);
|
||||
Assert.AreEqual(22, *(int*)&p1[100]);
|
||||
Assert.AreEqual(33, *(int*)&p1[112]);
|
||||
Assert.AreEqual(44, *(int*)&p1[116]);
|
||||
Assert.AreEqual(9999, *(int*)&p1[120]);
|
||||
}
|
||||
}
|
||||
|
||||
[AutoConstructor]
|
||||
@@ -288,11 +317,9 @@ namespace ComputeSharp.Tests.Internals
|
||||
[TestMethod]
|
||||
public unsafe void LoadNestedCustomTypes()
|
||||
{
|
||||
ulong* p0 = stackalloc ulong[128];
|
||||
byte* p1 = stackalloc byte[256];
|
||||
|
||||
using ReadWriteBuffer<float> buffer = Gpu.Default.AllocateReadWriteBuffer<float>(16);
|
||||
|
||||
DebugDispatchDataLoader dataLoader = DebugDispatchDataLoader.Create();
|
||||
NestedCustomTypesShader shader = new(
|
||||
buffer,
|
||||
new CustomType1(
|
||||
@@ -317,45 +344,55 @@ namespace ComputeSharp.Tests.Internals
|
||||
a: 888888,
|
||||
b: new(333.3f, 444.4f))));
|
||||
|
||||
int size = DispatchDataLoader.LoadDispatchData(Gpu.Default, in shader, ref *p0, ref *p1);
|
||||
shader.LoadDispatchData(in dataLoader, Gpu.Default, 111, 222, 333);
|
||||
|
||||
Assert.AreEqual(188, size);
|
||||
Assert.AreEqual(47, dataLoader.Values.Length);
|
||||
Assert.AreEqual(1, dataLoader.Resources.Length);
|
||||
|
||||
Assert.AreEqual(p0[0], buffer.D3D12GpuDescriptorHandle.ptr);
|
||||
Assert.AreEqual(111, (int)dataLoader.Values[0]);
|
||||
Assert.AreEqual(222, (int)dataLoader.Values[1]);
|
||||
Assert.AreEqual(333, (int)dataLoader.Values[2]);
|
||||
|
||||
Assert.AreEqual(3.14f, *(float*)&p1[16]);
|
||||
Assert.AreEqual(6.28f, *(float*)&p1[20]);
|
||||
Assert.AreEqual(123.4f, *(float*)&p1[24]);
|
||||
Assert.AreEqual(55, *(float*)&p1[32]);
|
||||
Assert.AreEqual(44, *(float*)&p1[36]);
|
||||
Assert.AreEqual(888, *(float*)&p1[40]);
|
||||
Assert.AreEqual(111, *(float*)&p1[48]);
|
||||
Assert.AreEqual(222, *(float*)&p1[52]);
|
||||
Assert.AreEqual(333, *(float*)&p1[56]);
|
||||
Assert.AreEqual(22, *(int*)&p1[60]);
|
||||
Assert.AreEqual(1, *(int*)&p1[64]);
|
||||
Assert.AreEqual(2, *(int*)&p1[68]);
|
||||
Assert.AreEqual(3, *(int*)&p1[72]);
|
||||
Assert.AreEqual(3.14, *(double*)&p1[80]);
|
||||
Assert.AreEqual(6.28, *(double*)&p1[88]);
|
||||
Assert.AreEqual(42, *(int*)&p1[96]);
|
||||
Assert.AreEqual(111, *(int*)&p1[100]);
|
||||
Assert.AreEqual(222, *(int*)&p1[104]);
|
||||
Assert.AreEqual(11, *(int*)&p1[112]);
|
||||
Assert.AreEqual(22, *(int*)&p1[116]);
|
||||
Assert.AreEqual(33, *(int*)&p1[128]);
|
||||
Assert.AreEqual(44, *(int*)&p1[132]);
|
||||
Assert.AreEqual(9999, *(int*)&p1[136]);
|
||||
Assert.AreEqual(42, *(int*)&p1[140]);
|
||||
Assert.AreEqual(1234567, *(int*)&p1[144]);
|
||||
Assert.AreEqual(44.4f, *(float*)&p1[148]);
|
||||
Assert.AreEqual(55.5f, *(float*)&p1[152]);
|
||||
Assert.AreEqual(7654321, *(int*)&p1[160]);
|
||||
Assert.AreEqual(111.1f, *(float*)&p1[164]);
|
||||
Assert.AreEqual(222.2f, *(float*)&p1[168]);
|
||||
Assert.AreEqual(888888, *(int*)&p1[176]);
|
||||
Assert.AreEqual(333.3f, *(float*)&p1[180]);
|
||||
Assert.AreEqual(444.4f, *(float*)&p1[184]);
|
||||
Assert.AreEqual(buffer.D3D12GpuDescriptorHandle.ptr, dataLoader.Resources[0]);
|
||||
|
||||
fixed (void* p0 = &dataLoader.Values[0])
|
||||
{
|
||||
byte* p1 = (byte*)p0;
|
||||
|
||||
Assert.AreEqual(3.14f, *(float*)&p1[16]);
|
||||
Assert.AreEqual(6.28f, *(float*)&p1[20]);
|
||||
Assert.AreEqual(123.4f, *(float*)&p1[24]);
|
||||
Assert.AreEqual(55, *(float*)&p1[32]);
|
||||
Assert.AreEqual(44, *(float*)&p1[36]);
|
||||
Assert.AreEqual(888, *(float*)&p1[40]);
|
||||
Assert.AreEqual(111, *(float*)&p1[48]);
|
||||
Assert.AreEqual(222, *(float*)&p1[52]);
|
||||
Assert.AreEqual(333, *(float*)&p1[56]);
|
||||
Assert.AreEqual(22, *(int*)&p1[60]);
|
||||
Assert.AreEqual(1, *(int*)&p1[64]);
|
||||
Assert.AreEqual(2, *(int*)&p1[68]);
|
||||
Assert.AreEqual(3, *(int*)&p1[72]);
|
||||
Assert.AreEqual(3.14, *(double*)&p1[80]);
|
||||
Assert.AreEqual(6.28, *(double*)&p1[88]);
|
||||
Assert.AreEqual(42, *(int*)&p1[96]);
|
||||
Assert.AreEqual(111, *(int*)&p1[100]);
|
||||
Assert.AreEqual(222, *(int*)&p1[104]);
|
||||
Assert.AreEqual(11, *(int*)&p1[112]);
|
||||
Assert.AreEqual(22, *(int*)&p1[116]);
|
||||
Assert.AreEqual(33, *(int*)&p1[128]);
|
||||
Assert.AreEqual(44, *(int*)&p1[132]);
|
||||
Assert.AreEqual(9999, *(int*)&p1[136]);
|
||||
Assert.AreEqual(42, *(int*)&p1[140]);
|
||||
Assert.AreEqual(1234567, *(int*)&p1[144]);
|
||||
Assert.AreEqual(44.4f, *(float*)&p1[148]);
|
||||
Assert.AreEqual(55.5f, *(float*)&p1[152]);
|
||||
Assert.AreEqual(7654321, *(int*)&p1[160]);
|
||||
Assert.AreEqual(111.1f, *(float*)&p1[164]);
|
||||
Assert.AreEqual(222.2f, *(float*)&p1[168]);
|
||||
Assert.AreEqual(888888, *(int*)&p1[176]);
|
||||
Assert.AreEqual(333.3f, *(float*)&p1[180]);
|
||||
Assert.AreEqual(444.4f, *(float*)&p1[184]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,15 @@
|
||||
using System;
|
||||
using ComputeSharp.Shaders.Translation;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
#pragma warning disable CS0618
|
||||
|
||||
namespace ComputeSharp.Tests.Internals
|
||||
{
|
||||
[TestClass]
|
||||
[TestCategory("ShaderHashCode")]
|
||||
public class ShaderHashCodeTests
|
||||
public partial class ShaderHashCodeTests
|
||||
{
|
||||
public struct Shader1 : IComputeShader
|
||||
public partial struct Shader1 : IComputeShader
|
||||
{
|
||||
public float A;
|
||||
public ReadWriteBuffer<float> B;
|
||||
@@ -28,19 +29,19 @@ namespace ComputeSharp.Tests.Internals
|
||||
Shader1 shader1 = new() { A = value, B = buffer };
|
||||
|
||||
int
|
||||
hash1 = ShaderHashCodeProvider.GetHashCode(shader1),
|
||||
hash2 = ShaderHashCodeProvider.GetHashCode(shader1);
|
||||
hash1 = shader1.GetDispatchId(),
|
||||
hash2 = shader1.GetDispatchId();
|
||||
|
||||
Assert.IsTrue(hash1 == hash2);
|
||||
|
||||
Shader1 shader2 = new() { A = value, B = buffer };
|
||||
|
||||
int hash3 = ShaderHashCodeProvider.GetHashCode(shader2);
|
||||
int hash3 = shader2.GetDispatchId();
|
||||
|
||||
Assert.IsTrue(hash1 == hash3);
|
||||
}
|
||||
|
||||
public struct Shader2 : IComputeShader
|
||||
public partial struct Shader2 : IComputeShader
|
||||
{
|
||||
public float A;
|
||||
public ReadWriteBuffer<float> B;
|
||||
@@ -62,8 +63,8 @@ namespace ComputeSharp.Tests.Internals
|
||||
Shader2 shader1 = new() { A = 1, B = buffer, F = f };
|
||||
|
||||
int
|
||||
hash1 = ShaderHashCodeProvider.GetHashCode(shader1),
|
||||
hash2 = ShaderHashCodeProvider.GetHashCode(shader1);
|
||||
hash1 = shader1.GetDispatchId(),
|
||||
hash2 = shader1.GetDispatchId();
|
||||
|
||||
Assert.IsTrue(hash1 == hash2);
|
||||
|
||||
@@ -71,7 +72,7 @@ namespace ComputeSharp.Tests.Internals
|
||||
|
||||
Shader2 shader2 = new() { A = 1, B = buffer, F = f };
|
||||
|
||||
int hash3 = ShaderHashCodeProvider.GetHashCode(shader2);
|
||||
int hash3 = shader2.GetDispatchId();
|
||||
|
||||
Assert.IsFalse(hash1 == hash3);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using ComputeSharp.__Internals;
|
||||
using ComputeSharp.SwapChain.Shaders;
|
||||
using ComputeSharp.Tests.Attributes;
|
||||
using ComputeSharp.Tests.Extensions;
|
||||
@@ -10,6 +11,8 @@ using SixLabors.ImageSharp;
|
||||
using SixLabors.ImageSharp.Formats.Png;
|
||||
using ImageSharpRgba32 = SixLabors.ImageSharp.PixelFormats.Rgba32;
|
||||
|
||||
#pragma warning disable CS0618
|
||||
|
||||
namespace ComputeSharp.Tests
|
||||
{
|
||||
[TestClass]
|
||||
@@ -137,7 +140,7 @@ namespace ComputeSharp.Tests
|
||||
if (shaderType.IsAssignableTo(typeof(IComputeShader)))
|
||||
{
|
||||
static void RunComputeShader<T>(ReadWriteTexture2D<Rgba32, Float4> texture)
|
||||
where T : struct, IComputeShader
|
||||
where T : struct, IComputeShader, IShader<T>
|
||||
{
|
||||
texture.GraphicsDevice.For(texture.Width, texture.Height, (T)Activator.CreateInstance(typeof(T), texture, 0f)!);
|
||||
}
|
||||
@@ -149,7 +152,7 @@ namespace ComputeSharp.Tests
|
||||
else
|
||||
{
|
||||
static void RunPixelShader<T>(ReadWriteTexture2D<Rgba32, Float4> texture)
|
||||
where T : struct, IPixelShader<Float4>
|
||||
where T : struct, IPixelShader<Float4>, IShader<T>
|
||||
{
|
||||
texture.GraphicsDevice.ForEach(texture, (T)Activator.CreateInstance(typeof(T), 0f)!);
|
||||
}
|
||||
@@ -188,8 +191,8 @@ namespace ComputeSharp.Tests
|
||||
Func<ReadWriteTexture2D<Rgba32, Float4>, TCompute> computeFactory,
|
||||
Func<ReadWriteTexture2D<Rgba32, Float4>, TPixel> pixelFactory,
|
||||
float delta)
|
||||
where TCompute : struct, IComputeShader
|
||||
where TPixel : struct, IPixelShader<Float4>
|
||||
where TCompute : struct, IComputeShader, IShader<TCompute>
|
||||
where TPixel : struct, IPixelShader<Float4>, IShader<TPixel>
|
||||
{
|
||||
_ = device.Get();
|
||||
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする