Add global shader method test

このコミットが含まれているのは:
Sergio Pedri committed 2022-09-05 01:10:45 +02:00
1 親 a576ceeb3c
コミット c2bd62d86e
2ファイル変更
+42 -2

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

@@ -6,6 +6,10 @@
<Platforms>AnyCPU;x64;ARM64</Platforms>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\ComputeSharp.Core\ComputeSharp.Core.csproj" />
+38 -2
ファイルの表示
@@ -1,2 +1,38 @@
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");
using ComputeSharp;
using Microsoft.VisualStudio.TestTools.UnitTesting;
float[] numbers = Enumerable.Range(0, 128).Select(i => (float)i).ToArray();
using GraphicsDevice device = GraphicsDevice.GetDefault();
using ReadWriteBuffer<float> buffer = device.AllocateReadWriteBuffer(numbers);
device.For(buffer.Length, new ApplyFunctionShader(buffer, AddHalf));
foreach (ref float number in numbers.AsSpan())
{
number = AddHalf(number);
}
float[] result = buffer.ToArray();
CollectionAssert.AreEqual(
expected: numbers,
actual: result);
Console.WriteLine("Test passed successfully");
// See https://github.com/Sergio0694/ComputeSharp/issues/374
[ShaderMethod]
static float AddHalf(float input) => input + 0.5f;
[AutoConstructor]
public readonly partial struct ApplyFunctionShader : IComputeShader
{
private readonly ReadWriteBuffer<float> sourceTexture;
private readonly Func<float, float> func;
public void Execute()
{
this.sourceTexture[ThreadIds.X] = this.func(this.sourceTexture[ThreadIds.X]);
}
}