diff --git a/tests/ComputeSharp.D2D1.Tests/Assets/Landscape_Pixelate.png b/tests/ComputeSharp.D2D1.Tests/Assets/Landscape_Pixelate.png index ef3e318b..8048c32c 100644 Binary files a/tests/ComputeSharp.D2D1.Tests/Assets/Landscape_Pixelate.png and b/tests/ComputeSharp.D2D1.Tests/Assets/Landscape_Pixelate.png differ diff --git a/tests/ComputeSharp.D2D1.Tests/D2D1PixelShaderTests.cs b/tests/ComputeSharp.D2D1.Tests/D2D1PixelShaderTests.cs index 27fea62a..ba821605 100644 --- a/tests/ComputeSharp.D2D1.Tests/D2D1PixelShaderTests.cs +++ b/tests/ComputeSharp.D2D1.Tests/D2D1PixelShaderTests.cs @@ -15,7 +15,7 @@ public partial class D2D1PixelShaderTests public unsafe void GetInputCount() { Assert.AreEqual(D2D1PixelShader.GetInputCount(), 1); - Assert.AreEqual(D2D1PixelShader.GetInputCount(), 1); + Assert.AreEqual(D2D1PixelShader.GetInputCount(), 1); Assert.AreEqual(D2D1PixelShader.GetInputCount(), 0); Assert.AreEqual(D2D1PixelShader.GetInputCount(), 7); } @@ -109,7 +109,7 @@ public partial class D2D1PixelShaderTests Assert.AreEqual(D2D1PixelShader.GetInputDescriptions().Length, 0); Assert.AreEqual(D2D1PixelShader.GetInputDescriptions().Length, 0); Assert.AreEqual(D2D1PixelShader.GetInputDescriptions().Length, 0); - Assert.AreEqual(D2D1PixelShader.GetInputDescriptions().Length, 0); + Assert.AreEqual(D2D1PixelShader.GetInputDescriptions().Length, 0); Assert.AreEqual(D2D1PixelShader.GetInputDescriptions().Length, 0); Assert.AreEqual(D2D1PixelShader.GetInputDescriptions().Length, 0); @@ -175,7 +175,7 @@ public partial class D2D1PixelShaderTests Assert.AreEqual(D2D1PixelShader.GetResourceTextureDescriptions().Length, 0); Assert.AreEqual(D2D1PixelShader.GetResourceTextureDescriptions().Length, 0); Assert.AreEqual(D2D1PixelShader.GetResourceTextureDescriptions().Length, 0); - Assert.AreEqual(D2D1PixelShader.GetResourceTextureDescriptions().Length, 0); + Assert.AreEqual(D2D1PixelShader.GetResourceTextureDescriptions().Length, 0); Assert.AreEqual(D2D1PixelShader.GetResourceTextureDescriptions().Length, 0); Assert.AreEqual(D2D1PixelShader.GetResourceTextureDescriptions().Length, 0); diff --git a/tests/ComputeSharp.D2D1.Tests/Effects/PixelateEffect.cs b/tests/ComputeSharp.D2D1.Tests/Effects/PixelateEffect.cs index 02f60a88..bf330069 100644 --- a/tests/ComputeSharp.D2D1.Tests/Effects/PixelateEffect.cs +++ b/tests/ComputeSharp.D2D1.Tests/Effects/PixelateEffect.cs @@ -1,75 +1,44 @@ -using System; -using System.Drawing; +namespace ComputeSharp.D2D1.Tests.Effects; -namespace ComputeSharp.D2D1.Tests.Effects; - -public sealed partial class PixelateEffect : ID2D1TransformMapperFactory, ID2D1TransformMapper +[D2DInputCount(1)] +[D2DInputComplex(0)] +[D2DRequiresScenePosition] +[D2DShaderProfile(D2D1ShaderProfile.PixelShader40)] +[AutoConstructor] +public partial struct PixelateEffect : ID2D1PixelShader { - /// - public ID2D1TransformMapper Create() - { - return new PixelateEffect(); - } - - /// - void ID2D1TransformMapper.MapInputsToOutput(in Shader shader, ReadOnlySpan inputs, ReadOnlySpan opaqueInputs, out Rectangle output, out Rectangle opaqueOutput) - { - output = inputs[0]; - opaqueOutput = Rectangle.Empty; - } - - /// - void ID2D1TransformMapper.MapInvalidOutput(int inputIndex, Rectangle invalidInput, out Rectangle invalidOutput) - { - invalidOutput = invalidInput; - } - - /// - void ID2D1TransformMapper.MapOutputToInputs(in Rectangle output, Span inputs) - { - inputs.Fill(output); - } - - [D2DInputCount(1)] - [D2DInputComplex(0)] - [D2DRequiresScenePosition] - [D2DShaderProfile(D2D1ShaderProfile.PixelShader40)] [AutoConstructor] - public partial struct Shader : ID2D1PixelShader + public partial struct Constants { - [AutoConstructor] - public partial struct Constants - { - public readonly int inputWidth; - public readonly int inputHeight; - public readonly int cellSize; - } + public readonly int inputWidth; + public readonly int inputHeight; + public readonly int cellSize; + } - private readonly Constants constants; + private readonly Constants constants; - public float4 Execute() - { - float2 scenePos = D2D.GetScenePosition().XY; - uint x = (uint)Hlsl.Floor(scenePos.X); - uint y = (uint)Hlsl.Floor(scenePos.Y); + public float4 Execute() + { + float2 scenePos = D2D.GetScenePosition().XY; + uint x = (uint)Hlsl.Floor(scenePos.X); + uint y = (uint)Hlsl.Floor(scenePos.Y); - int cellX = (int)Hlsl.Floor(x / this.constants.cellSize); - int cellY = (int)Hlsl.Floor(y / this.constants.cellSize); + int cellX = (int)Hlsl.Floor(x / this.constants.cellSize); + int cellY = (int)Hlsl.Floor(y / this.constants.cellSize); - int x0 = cellX * this.constants.cellSize; - int y0 = cellY * this.constants.cellSize; + int x0 = cellX * this.constants.cellSize; + int y0 = cellY * this.constants.cellSize; - int x1 = Hlsl.Min(this.constants.inputWidth, x0 + this.constants.cellSize) - 1; - int y1 = Hlsl.Min(this.constants.inputHeight, y0 + this.constants.cellSize) - 1; + int x1 = Hlsl.Min(this.constants.inputWidth, x0 + this.constants.cellSize) - 1; + int y1 = Hlsl.Min(this.constants.inputHeight, y0 + this.constants.cellSize) - 1; - float4 sample0 = D2D.SampleInputAtPosition(0, new int2(x0, y0)); - float4 sample1 = D2D.SampleInputAtPosition(0, new int2(x1, y0)); - float4 sample2 = D2D.SampleInputAtPosition(0, new int2(x0, y1)); - float4 sample3 = D2D.SampleInputAtPosition(0, new int2(x1, y1)); + float4 sample0 = D2D.SampleInputAtPosition(0, new float2(x0 + 0.5f, y0 + 0.5f)); + float4 sample1 = D2D.SampleInputAtPosition(0, new float2(x1 + 0.5f, y0 + 0.5f)); + float4 sample2 = D2D.SampleInputAtPosition(0, new float2(x0 + 0.5f, y1 + 0.5f)); + float4 sample3 = D2D.SampleInputAtPosition(0, new float2(x1 + 0.5f, y1 + 0.5f)); - float4 color = (sample0 + sample1 + sample2 + sample3) / 4; + float4 color = (sample0 + sample1 + sample2 + sample3) / 4; - return color; - } + return color; } } \ No newline at end of file diff --git a/tests/ComputeSharp.D2D1.Tests/EndToEndTests.cs b/tests/ComputeSharp.D2D1.Tests/EndToEndTests.cs index 4696b592..b5f11ff8 100644 --- a/tests/ComputeSharp.D2D1.Tests/EndToEndTests.cs +++ b/tests/ComputeSharp.D2D1.Tests/EndToEndTests.cs @@ -37,8 +37,8 @@ public class EndToEndTests public unsafe void Pixelate() { D2D1TestRunner.RunAndCompareShader( - new PixelateEffect.Shader(new PixelateEffect.Shader.Constants(1280, 840, 16)), - new PixelateEffect(), + new PixelateEffect(new PixelateEffect.Constants(1280, 840, 16)), + D2D1TransformMapperFactory.Inflate(16), "Landscape.png", "Landscape_Pixelate.png"); }