Minor code refactoring
このコミットが含まれているのは:
1 親
f78d377ebf
コミット
d509db265a
3ファイル変更
+90
-84
検索条件に一致するファイルはありません
@@ -0,0 +1,19 @@
|
||||
namespace ComputeSharp.D2D1.Tests.Effects;
|
||||
|
||||
[D2DInputCount(1)]
|
||||
[D2DInputSimple(0)]
|
||||
[D2DEmbeddedBytecode(D2D1ShaderProfile.PixelShader50)]
|
||||
[AutoConstructor]
|
||||
public partial struct InvertEffect : ID2D1PixelShader
|
||||
{
|
||||
public float number;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public float4 Execute()
|
||||
{
|
||||
float4 color = D2D.GetInput(0);
|
||||
float3 rgb = Hlsl.Saturate(this.number - color.RGB);
|
||||
|
||||
return new(rgb, 1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
|
||||
namespace ComputeSharp.D2D1.Tests.Effects;
|
||||
|
||||
public sealed partial class PixelateEffect : ID2D1TransformMapper<PixelateEffect.Shader>
|
||||
{
|
||||
/// <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(in Shader shader, int inputIndex, Rectangle invalidInput, out Rectangle invalidOutput)
|
||||
{
|
||||
invalidOutput = invalidInput;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
void ID2D1TransformMapper<Shader>.MapOutputToInputs(in Shader shader, in Rectangle output, Span<Rectangle> inputs)
|
||||
{
|
||||
inputs.Fill(output);
|
||||
}
|
||||
|
||||
[D2DInputCount(1)]
|
||||
[D2DInputComplex(0)]
|
||||
[D2DRequiresScenePosition]
|
||||
[D2DEmbeddedBytecode(D2D1ShaderProfile.PixelShader40)]
|
||||
[AutoConstructor]
|
||||
public partial struct Shader : ID2D1PixelShader
|
||||
{
|
||||
[AutoConstructor]
|
||||
public partial struct Constants
|
||||
{
|
||||
public readonly int inputWidth;
|
||||
public readonly int inputHeight;
|
||||
public readonly int cellSize;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
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 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 color = (sample0 + sample1 + sample2 + sample3) / 4;
|
||||
|
||||
return color;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using ComputeSharp.D2D1.Tests.Effects;
|
||||
using ComputeSharp.D2D1.Tests.Helpers;
|
||||
using ComputeSharp.Tests.Helpers;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
@@ -16,7 +16,7 @@ public class EndToEndTests
|
||||
[TestMethod]
|
||||
public unsafe void InvertWithCustomThreshold()
|
||||
{
|
||||
RunAndCompareShader(new InvertShader(1), null, "Landscape.png", "Landscape_Inverted.png");
|
||||
RunAndCompareShader(new InvertEffect(1), null, "Landscape.png", "Landscape_Inverted.png");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -65,86 +65,4 @@ public class EndToEndTests
|
||||
// Compare the results
|
||||
TolerantImageComparer.AssertEqual(destinationPath, expectedPath, 0.00001f);
|
||||
}
|
||||
}
|
||||
|
||||
[D2DInputCount(1)]
|
||||
[D2DInputSimple(0)]
|
||||
[D2DEmbeddedBytecode(D2D1ShaderProfile.PixelShader50)]
|
||||
[AutoConstructor]
|
||||
public partial struct InvertShader : ID2D1PixelShader
|
||||
{
|
||||
public float number;
|
||||
|
||||
public float4 Execute()
|
||||
{
|
||||
float4 color = D2D.GetInput(0);
|
||||
float3 rgb = Hlsl.Saturate(this.number - color.RGB);
|
||||
|
||||
return new(rgb, 1);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed partial class PixelateEffect : ID2D1TransformMapper<PixelateEffect.Shader>
|
||||
{
|
||||
/// <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(in Shader shader, int inputIndex, Rectangle invalidInput, out Rectangle invalidOutput)
|
||||
{
|
||||
invalidOutput = invalidInput;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
void ID2D1TransformMapper<Shader>.MapOutputToInputs(in Shader shader, in Rectangle output, Span<Rectangle> inputs)
|
||||
{
|
||||
inputs.Fill(output);
|
||||
}
|
||||
|
||||
[D2DInputCount(1)]
|
||||
[D2DInputComplex(0)]
|
||||
[D2DRequiresScenePosition]
|
||||
[D2DEmbeddedBytecode(D2D1ShaderProfile.PixelShader40)]
|
||||
[AutoConstructor]
|
||||
public partial struct Shader : ID2D1PixelShader
|
||||
{
|
||||
[AutoConstructor]
|
||||
public partial struct Constants
|
||||
{
|
||||
public readonly int inputWidth;
|
||||
public readonly int inputHeight;
|
||||
public readonly int cellSize;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
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 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 color = (sample0 + sample1 + sample2 + sample3) / 4;
|
||||
|
||||
return color;
|
||||
}
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする