Add basic PixelShaderEffect<T> drawing and buffer tests
このコミットが含まれているのは:
1 親
92cb93cb1d
コミット
204dba3ab5
5ファイル変更
+211
-1
検索条件に一致するファイルはありません
@@ -483,6 +483,8 @@ Global
|
||||
samples\ComputeSharp.SwapChain.Shaders.D2D1.Shared\ComputeSharp.SwapChain.Shaders.D2D1.Shared.projitems*{209c95a3-fa53-431b-b688-3299ca6c29d2}*SharedItemsImports = 5
|
||||
src\TerraFX.Interop.Windows\TerraFX.Interop.Windows.projitems*{314eb353-e7e3-4146-8111-685cc83ec1de}*SharedItemsImports = 5
|
||||
tests\ComputeSharp.D2D1.UI.Tests\ComputeSharp.D2D1.UI.Tests.projitems*{346aeb10-a4ea-427e-8578-f60915db3053}*SharedItemsImports = 13
|
||||
samples\ComputeSharp.SwapChain.Shaders.D2D1.Shared\ComputeSharp.SwapChain.Shaders.D2D1.Shared.projitems*{4d4bb2f6-5653-4db5-a8dd-90d58d8fe4d3}*SharedItemsImports = 4
|
||||
tests\ComputeSharp.D2D1.UI.Tests\ComputeSharp.D2D1.UI.Tests.projitems*{4d4bb2f6-5653-4db5-a8dd-90d58d8fe4d3}*SharedItemsImports = 4
|
||||
src\TerraFX.Interop.Windows.D2D1\TerraFX.Interop.Windows.D2D1.projitems*{4d7d9ba8-a821-4b1c-9ee2-cbcf5849906e}*SharedItemsImports = 5
|
||||
src\TerraFX.Interop.Windows\TerraFX.Interop.Windows.projitems*{514ff00e-bbf0-4d55-a47c-eeeb6208adce}*SharedItemsImports = 13
|
||||
src\ComputeSharp.SourceGeneration\ComputeSharp.SourceGeneration.projitems*{51d5a422-d3a5-4c4d-8a6d-a048940bf279}*SharedItemsImports = 13
|
||||
|
||||
@@ -9,5 +9,8 @@
|
||||
<Import_RootNamespace>ComputeSharp.D2D1.UI.Tests</Import_RootNamespace>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="$(MSBuildThisFileDirectory)PixelShaderEffectTests.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)..\ComputeSharp.Tests\Helpers\TolerantImageComparer.cs" Link="Helpers\TolerantImageComparer.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)ShadersTests.cs" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
@@ -0,0 +1,76 @@
|
||||
using System;
|
||||
using ComputeSharp.D2D1.Uwp;
|
||||
using Microsoft.Graphics.Canvas;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace ComputeSharp.D2D1.UI.Tests;
|
||||
|
||||
[TestClass]
|
||||
[TestCategory("PixelShaderEffect<T>")]
|
||||
public partial class PixelShaderEffectTests
|
||||
{
|
||||
[TestMethod]
|
||||
public unsafe void ConstantBuffer_IsInitiallySetToDefault()
|
||||
{
|
||||
PixelShaderEffect<ShaderWithSomeProperties> effect = new();
|
||||
|
||||
ShaderWithSomeProperties shader = effect.ConstantBuffer;
|
||||
ShaderWithSomeProperties defaultShader = default;
|
||||
|
||||
ReadOnlySpan<byte> actual = new(&shader, sizeof(ShaderWithSomeProperties));
|
||||
ReadOnlySpan<byte> expected = new(&defaultShader, sizeof(ShaderWithSomeProperties));
|
||||
|
||||
// The default constant buffer is set to 0, and it can be retrieved correctly
|
||||
Assert.IsTrue(actual.SequenceEqual(expected));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public unsafe void ConstantBuffer_RoundTripsCorrectly()
|
||||
{
|
||||
ShaderWithSomeProperties shader = new(
|
||||
A: 3.14f,
|
||||
B: 123456,
|
||||
C: new int2(111, -222),
|
||||
D: new uint2x2(8888, 123456, 98765, 192837465),
|
||||
E: new float2(-3.14f, 6.28f));
|
||||
|
||||
PixelShaderEffect<ShaderWithSomeProperties> effect = new() { ConstantBuffer = shader };
|
||||
|
||||
ShaderWithSomeProperties roundTripShader = effect.ConstantBuffer;
|
||||
|
||||
ReadOnlySpan<byte> expected = new(&shader, sizeof(ShaderWithSomeProperties));
|
||||
ReadOnlySpan<byte> actual = new(&roundTripShader, sizeof(ShaderWithSomeProperties));
|
||||
|
||||
// The resulting constant buffer matches the source, when the effect is not realized
|
||||
Assert.IsTrue(actual.SequenceEqual(expected));
|
||||
|
||||
// Draw the effect, to force realization
|
||||
using (CanvasRenderTarget renderTarget = new(new CanvasDevice(), 128, 128, 96.0f))
|
||||
using (CanvasDrawingSession drawingSession = renderTarget.CreateDrawingSession())
|
||||
{
|
||||
drawingSession.DrawImage(effect);
|
||||
}
|
||||
|
||||
roundTripShader = effect.ConstantBuffer;
|
||||
actual = new(&roundTripShader, sizeof(ShaderWithSomeProperties));
|
||||
|
||||
// The shader also matches when retrieving it through the realized effect
|
||||
Assert.IsTrue(actual.SequenceEqual(expected));
|
||||
}
|
||||
|
||||
[D2DInputCount(0)]
|
||||
[AutoConstructor]
|
||||
private partial struct ShaderWithSomeProperties : ID2D1PixelShader
|
||||
{
|
||||
public float A;
|
||||
public int B;
|
||||
public int2 C;
|
||||
public uint2x2 D;
|
||||
public float2 E;
|
||||
|
||||
public float4 Execute()
|
||||
{
|
||||
return default;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using ComputeSharp.D2D1.Uwp;
|
||||
using ComputeSharp.SwapChain.Shaders.D2D1;
|
||||
using ComputeSharp.Tests.Helpers;
|
||||
using Microsoft.Graphics.Canvas;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using SixLabors.ImageSharp;
|
||||
using SixLabors.ImageSharp.PixelFormats;
|
||||
using Windows.Storage;
|
||||
|
||||
namespace ComputeSharp.D2D1.UI.Tests;
|
||||
|
||||
[TestClass]
|
||||
[TestCategory("Shaders")]
|
||||
public class ShadersTests
|
||||
{
|
||||
[TestMethod]
|
||||
public async Task HelloWorld()
|
||||
{
|
||||
await RunTestAsync<HelloWorld>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task ColorfulInfinity()
|
||||
{
|
||||
await RunTestAsync<ColorfulInfinity>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task FractalTiling()
|
||||
{
|
||||
await RunTestAsync<FractalTiling>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task MengerJourney()
|
||||
{
|
||||
await RunTestAsync<MengerJourney>(0.000011f);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task Octagrams()
|
||||
{
|
||||
await RunTestAsync<Octagrams>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task ProteanClouds()
|
||||
{
|
||||
await RunTestAsync<ProteanClouds>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task TerracedHills()
|
||||
{
|
||||
await RunTestAsync<TerracedHills>(0.000026f);
|
||||
}
|
||||
|
||||
private static async Task RunTestAsync<T>(float threshold = 0.00001f)
|
||||
where T : unmanaged, ID2D1PixelShader
|
||||
{
|
||||
T shader = (T)Activator.CreateInstance(typeof(T), 0f, new int2(1280, 720))!;
|
||||
PixelShaderEffect<T> effect = new() { ConstantBuffer = shader };
|
||||
|
||||
byte[] pixelBytes;
|
||||
|
||||
using (CanvasRenderTarget renderTarget = new(new CanvasDevice(), 1280, 720, 96.0f))
|
||||
{
|
||||
// Draw the shader on the render target
|
||||
using (CanvasDrawingSession drawingSession = renderTarget.CreateDrawingSession())
|
||||
{
|
||||
drawingSession.DrawImage(effect);
|
||||
}
|
||||
|
||||
// Get the BGRA32 pixel data from the render target
|
||||
pixelBytes = renderTarget.GetPixelBytes();
|
||||
}
|
||||
|
||||
StorageFile imageFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri($"ms-appx:///Assets/Shaders/{typeof(T).Name}.png"));
|
||||
|
||||
using Stream stream = await imageFile.OpenStreamForReadAsync();
|
||||
using Image<Bgra32> expected = await Image.LoadAsync<Bgra32>(stream);
|
||||
using Image<Bgra32> result = Image.WrapMemory<Bgra32>(pixelBytes, 1280, 720);
|
||||
|
||||
TolerantImageComparer.AssertEqual(expected, result, threshold);
|
||||
}
|
||||
}
|
||||
@@ -90,6 +90,34 @@
|
||||
</AppxManifest>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="..\ComputeSharp.Tests\Assets\ColorfulInfinity.png">
|
||||
<Link>Assets\Shaders\ColorfulInfinity.png</Link>
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="..\ComputeSharp.Tests\Assets\FractalTiling.png">
|
||||
<Link>Assets\Shaders\FractalTiling.png</Link>
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="..\ComputeSharp.Tests\Assets\HelloWorld.png">
|
||||
<Link>Assets\Shaders\HelloWorld.png</Link>
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="..\ComputeSharp.Tests\Assets\MengerJourney.png">
|
||||
<Link>Assets\Shaders\MengerJourney.png</Link>
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="..\ComputeSharp.Tests\Assets\Octagrams.png">
|
||||
<Link>Assets\Shaders\Octagrams.png</Link>
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="..\ComputeSharp.Tests\Assets\ProteanClouds.png">
|
||||
<Link>Assets\Shaders\ProteanClouds.png</Link>
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="..\ComputeSharp.Tests\Assets\TerracedHills.png">
|
||||
<Link>Assets\Shaders\TerracedHills.png</Link>
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Properties\Default.rd.xml" />
|
||||
<Content Include="Assets\LockScreenLogo.scale-200.png" />
|
||||
<Content Include="Assets\SplashScreen.scale-200.png" />
|
||||
@@ -109,7 +137,19 @@
|
||||
<PackageReference Include="MSTest.TestFramework">
|
||||
<Version>2.2.7</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="SixLabors.ImageSharp">
|
||||
<Version>2.1.4</Version>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\ComputeSharp.Core.SourceGenerators\ComputeSharp.Core.SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="contentfiles;build" />
|
||||
<ProjectReference Include="..\..\src\ComputeSharp.Core\ComputeSharp.Core.csproj" />
|
||||
<ProjectReference Include="..\..\src\ComputeSharp.D2D1.SourceGenerators\ComputeSharp.D2D1.SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="contentfiles;build" />
|
||||
<ProjectReference Include="..\..\src\ComputeSharp.D2D1.Uwp\ComputeSharp.D2D1.Uwp.csproj" />
|
||||
<ProjectReference Include="..\..\src\ComputeSharp.D2D1\ComputeSharp.D2D1.csproj" />
|
||||
</ItemGroup>
|
||||
<Import Project="..\ComputeSharp.D2D1.UI.Tests\ComputeSharp.D2D1.UI.Tests.projitems" Label="Shared" />
|
||||
<Import Project="..\..\samples\ComputeSharp.SwapChain.Shaders.D2D1.Shared\ComputeSharp.SwapChain.Shaders.D2D1.Shared.projitems" Label="Shared" />
|
||||
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' < '14.0' ">
|
||||
<VisualStudioVersion>14.0</VisualStudioVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする