Fix PixelateEffect tests and switch to built-in transform

このコミットが含まれているのは:
Sergio Pedri committed 2022-09-06 02:32:57 +02:00
1 親 743a5999b3
コミット 7925952e07
4ファイル変更
+35 -66

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

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

変更前

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

変更後

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

+3 -3
ファイルの表示
@@ -15,7 +15,7 @@ public partial class D2D1PixelShaderTests
public unsafe void GetInputCount()
{
Assert.AreEqual(D2D1PixelShader.GetInputCount<InvertEffect>(), 1);
Assert.AreEqual(D2D1PixelShader.GetInputCount<PixelateEffect.Shader>(), 1);
Assert.AreEqual(D2D1PixelShader.GetInputCount<PixelateEffect>(), 1);
Assert.AreEqual(D2D1PixelShader.GetInputCount<ZonePlateEffect>(), 0);
Assert.AreEqual(D2D1PixelShader.GetInputCount<ShaderWithMultipleInputs>(), 7);
}
@@ -109,7 +109,7 @@ public partial class D2D1PixelShaderTests
Assert.AreEqual(D2D1PixelShader.GetInputDescriptions<CheckerboardClipEffect>().Length, 0);
Assert.AreEqual(D2D1PixelShader.GetInputDescriptions<InvertEffect>().Length, 0);
Assert.AreEqual(D2D1PixelShader.GetInputDescriptions<InvertWithThresholdEffect>().Length, 0);
Assert.AreEqual(D2D1PixelShader.GetInputDescriptions<PixelateEffect.Shader>().Length, 0);
Assert.AreEqual(D2D1PixelShader.GetInputDescriptions<PixelateEffect>().Length, 0);
Assert.AreEqual(D2D1PixelShader.GetInputDescriptions<ZonePlateEffect>().Length, 0);
Assert.AreEqual(D2D1PixelShader.GetInputDescriptions<ShaderWithMultipleInputs>().Length, 0);
@@ -175,7 +175,7 @@ public partial class D2D1PixelShaderTests
Assert.AreEqual(D2D1PixelShader.GetResourceTextureDescriptions<CheckerboardClipEffect>().Length, 0);
Assert.AreEqual(D2D1PixelShader.GetResourceTextureDescriptions<InvertEffect>().Length, 0);
Assert.AreEqual(D2D1PixelShader.GetResourceTextureDescriptions<InvertWithThresholdEffect>().Length, 0);
Assert.AreEqual(D2D1PixelShader.GetResourceTextureDescriptions<PixelateEffect.Shader>().Length, 0);
Assert.AreEqual(D2D1PixelShader.GetResourceTextureDescriptions<PixelateEffect>().Length, 0);
Assert.AreEqual(D2D1PixelShader.GetResourceTextureDescriptions<ZonePlateEffect>().Length, 0);
Assert.AreEqual(D2D1PixelShader.GetResourceTextureDescriptions<ShaderWithMultipleInputs>().Length, 0);
+30 -61
ファイルの表示
@@ -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<PixelateEffect.Shader>, ID2D1TransformMapper<PixelateEffect.Shader>
[D2DInputCount(1)]
[D2DInputComplex(0)]
[D2DRequiresScenePosition]
[D2DShaderProfile(D2D1ShaderProfile.PixelShader40)]
[AutoConstructor]
public partial struct PixelateEffect : ID2D1PixelShader
{
/// <inheritdoc/>
public ID2D1TransformMapper<Shader> Create()
{
return new PixelateEffect();
}
/// <inheritdoc/>
void ID2D1TransformMapper<Shader>.MapInputsToOutput(in Shader shader, ReadOnlySpan<Rectangle> inputs, ReadOnlySpan<Rectangle> opaqueInputs, out Rectangle output, out Rectangle opaqueOutput)
{
output = inputs[0];
opaqueOutput = Rectangle.Empty;
}
/// <inheritdoc/>
void ID2D1TransformMapper<Shader>.MapInvalidOutput(int inputIndex, Rectangle invalidInput, out Rectangle invalidOutput)
{
invalidOutput = invalidInput;
}
/// <inheritdoc/>
void ID2D1TransformMapper<Shader>.MapOutputToInputs(in Rectangle output, Span<Rectangle> 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;
}
}
+2 -2
ファイルの表示
@@ -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<PixelateEffect>.Inflate(16),
"Landscape.png",
"Landscape_Pixelate.png");
}