Added tests for sample shaders

このコミットが含まれているのは:
Sergio Pedri committed 2021-02-25 04:05:05 +01:00
1 親 4f689d0a18
コミット 6784750179
8ファイル変更
+100 -1

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

+1
ファイルの表示
@@ -43,6 +43,7 @@
}
color.XYZ = Hlsl.Pow(color.XYZ, new Float3(0.7f, 0.8f, 0.5f));
color.W = 1.0f;
texture[ThreadIds.XY] = color;
}
バイナリファイルは表示されません。

変更後

幅:  |  高さ:  |  サイズ: 872 KiB

バイナリファイルは表示されません。

変更後

幅:  |  高さ:  |  サイズ: 984 KiB

バイナリファイルは表示されません。

変更後

幅:  |  高さ:  |  サイズ: 2.0 MiB

バイナリファイルは表示されません。

変更後

幅:  |  高さ:  |  サイズ: 410 KiB

+16
ファイルの表示
@@ -27,6 +27,10 @@
<Compile Include="..\..\samples\ComputeSharp.ImageProcessing\Processors\HlslBokehBlurProcessor{TPixel}.cs" Link="Imaging\Processors\HlslBokehBlurProcessor{TPixel}.cs" />
<Compile Include="..\..\samples\ComputeSharp.ImageProcessing\Processors\HlslGaussianBlurProcessor.cs" Link="Imaging\Processors\HlslGaussianBlurProcessor.cs" />
<Compile Include="..\..\samples\ComputeSharp.ImageProcessing\Processors\HlslGaussianBlurProcessor{TPixel}.cs" Link="Imaging\Processors\HlslGaussianBlurProcessor{TPixel}.cs" />
<Compile Include="..\..\samples\ComputeSharp.SwapChain\Shaders\ColorfulInfinity.cs" Link="Shaders\ColorfulInfinity.cs" />
<Compile Include="..\..\samples\ComputeSharp.SwapChain\Shaders\FractalTiling.cs" Link="Shaders\FractalTiling.cs" />
<Compile Include="..\..\samples\ComputeSharp.SwapChain\Shaders\MengerJourney.cs" Link="Shaders\MengerJourney.cs" />
<Compile Include="..\..\samples\ComputeSharp.SwapChain\Shaders\TwoTiledTruchet.cs" Link="Shaders\TwoTiledTruchet.cs" />
</ItemGroup>
<ItemGroup>
@@ -34,6 +38,18 @@
</ItemGroup>
<ItemGroup>
<None Update="Assets\ColorfulInfinity.jpg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Assets\FractalTiling.jpg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Assets\MengerJourney.jpg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Assets\TwoTiledTruchet.jpg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Texture2DTests.Pixels.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>Texture2DTests.Pixels.g.cs</LastGenOutput>
+1 -1
ファイルの表示
@@ -67,7 +67,7 @@ namespace ComputeSharp.Tests
/// <summary>
/// An tolerant image comparer type, from <see href="https://github.com/SixLabors/ImageSharp">ImageSharp</see>.
/// </summary>
private static class TolerantImageComparer
internal static class TolerantImageComparer
{
/// <summary>
/// Asserts that two images are equal.
+82
ファイルの表示
@@ -0,0 +1,82 @@
using System;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using ComputeSharp.SwapChain.Shaders;
using ComputeSharp.Tests.Attributes;
using ComputeSharp.Tests.Extensions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SixLabors.ImageSharp;
using ImageSharpRgba32 = SixLabors.ImageSharp.PixelFormats.Rgba32;
namespace ComputeSharp.Tests
{
[TestClass]
[TestCategory("Shaders")]
public class ShadersTests
{
[CombinatorialTestMethod]
[AllDevices]
public void ColorfulInfinity(Device device)
{
RunAndCompareShader(device, static texture => new ColorfulInfinity(texture, 0), 0.0000193f);
}
[CombinatorialTestMethod]
[AllDevices]
public void FractalTiling(Device device)
{
RunAndCompareShader(device, static texture => new FractalTiling(texture, 0), 0.0000282f);
}
[CombinatorialTestMethod]
[AllDevices]
public void MengerJourney(Device device)
{
RunAndCompareShader(device, static texture => new MengerJourney(texture, 0), 0.0000864f);
}
[CombinatorialTestMethod]
[AllDevices]
public void TwoTiledTruchet(Device device)
{
RunAndCompareShader(device, static texture => new TwoTiledTruchet(texture, 0), 0.00033f);
}
/// <summary>
/// Executes a given test for a specified shader.
/// </summary>
/// <typeparam name="T">The type of shader to test.</typeparam>
/// <param name="device">The device to use.</param>
/// <param name="factory">A producer to create an instance of the shader to run.</param>
/// <param name="delta">The comparison delta.</param>
private static void RunAndCompareShader<T>(Device device, Func<ReadWriteTexture2D<Rgba32, Float4>, T> factory, float delta)
where T : struct, IComputeShader
{
_ = device.Get();
string expectedPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Assets", $"{typeof(T).Name}.jpg");
IImageInfo imageInfo = Image.Identify(expectedPath);
using Image<ImageSharpRgba32> image = new(imageInfo.Width, imageInfo.Height);
using (ReadWriteTexture2D<Rgba32, Float4> texture = device.Get().AllocateReadWriteTexture2D<Rgba32, Float4>(imageInfo.Width, imageInfo.Height))
{
device.Get().For(texture.Width, texture.Height, factory(texture));
_ = image.TryGetSinglePixelSpan(out Span<ImageSharpRgba32> span);
texture.CopyTo(MemoryMarshal.Cast<ImageSharpRgba32, Rgba32>(span));
}
string actualPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Shaders", $"{typeof(T).Name}.jpg");
_ = Directory.CreateDirectory(Path.GetDirectoryName(actualPath)!);
image.Save(actualPath);
ImagingTests.TolerantImageComparer.AssertEqual(expectedPath, actualPath, delta);
}
}
}