From 84da270ae81ba45ed6a99bd2c47871c6a4dda515 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Fri, 19 Aug 2022 04:17:45 +0200 Subject: [PATCH] Increase channel precision to 32 bits to fix banding --- tests/ComputeSharp.D2D1.Tests/Effects/BokehBlurEffect.cs | 9 +++++++++ tests/ComputeSharp.D2D1.Tests/EndToEndTests.cs | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/ComputeSharp.D2D1.Tests/Effects/BokehBlurEffect.cs b/tests/ComputeSharp.D2D1.Tests/Effects/BokehBlurEffect.cs index a24b77fb..2de73bc0 100644 --- a/tests/ComputeSharp.D2D1.Tests/Effects/BokehBlurEffect.cs +++ b/tests/ComputeSharp.D2D1.Tests/Effects/BokehBlurEffect.cs @@ -327,6 +327,11 @@ public sealed partial class BokehBlurEffect effectId: (Guid*)Unsafe.AsPointer(ref Unsafe.AsRef(in CLSID.CLSID_D2D1Composite)), effect: compositeEffect.GetAddressOf()).Assert(); + D2D1_BUFFER_PRECISION d2D1BufferPrecision = D2D1_BUFFER_PRECISION.D2D1_BUFFER_PRECISION_32BPC_FLOAT; + + // Set the channel precision to 32 bits manually to avoid banding + compositeEffect.Get()->SetValue((uint)D2D1_PROPERTY.D2D1_PROPERTY_PRECISION, (byte*)&d2D1BufferPrecision, sizeof(D2D1_BUFFER_PRECISION)).Assert(); + D2D1_COMPOSITE_MODE d2D1CompositeMode = D2D1_COMPOSITE_MODE.D2D1_COMPOSITE_MODE_PLUS; // Set the mode to plus @@ -474,6 +479,7 @@ public sealed partial class BokehBlurEffect [D2DInputCount(1)] [D2DInputComplex(0)] [D2DInputDescription(0, D2D1Filter.MinMagMipPoint)] + [D2DOutputBuffer(D2D1BufferPrecision.Float32, D2D1ChannelDepth.Four)] [D2DShaderProfile(D2D1ShaderProfile.PixelShader50)] [D2DRequiresScenePosition] [AutoConstructor] @@ -543,6 +549,7 @@ public sealed partial class BokehBlurEffect [D2DInputComplex(1)] [D2DInputDescription(0, D2D1Filter.MinMagMipPoint)] [D2DInputDescription(1, D2D1Filter.MinMagMipPoint)] + [D2DOutputBuffer(D2D1BufferPrecision.Float32, D2D1ChannelDepth.Four)] [D2DShaderProfile(D2D1ShaderProfile.PixelShader50)] [D2DRequiresScenePosition] [AutoConstructor] @@ -595,6 +602,7 @@ public sealed partial class BokehBlurEffect [D2DInputCount(1)] [D2DInputSimple(0)] [D2DInputDescription(0, D2D1Filter.MinMagMipPoint)] + [D2DOutputBuffer(D2D1BufferPrecision.Float32, D2D1ChannelDepth.Four)] [D2DShaderProfile(D2D1ShaderProfile.PixelShader50)] [AutoConstructor] internal readonly partial struct GammaHighlight : ID2D1PixelShader @@ -616,6 +624,7 @@ public sealed partial class BokehBlurEffect [D2DInputCount(1)] [D2DInputSimple(0)] [D2DInputDescription(0, D2D1Filter.MinMagMipPoint)] + [D2DOutputBuffer(D2D1BufferPrecision.Float32, D2D1ChannelDepth.Four)] [D2DShaderProfile(D2D1ShaderProfile.PixelShader50)] [AutoConstructor] internal readonly partial struct InverseGammaHighlight : ID2D1PixelShader diff --git a/tests/ComputeSharp.D2D1.Tests/EndToEndTests.cs b/tests/ComputeSharp.D2D1.Tests/EndToEndTests.cs index 514cffa9..619e57c0 100644 --- a/tests/ComputeSharp.D2D1.Tests/EndToEndTests.cs +++ b/tests/ComputeSharp.D2D1.Tests/EndToEndTests.cs @@ -55,7 +55,7 @@ public class EndToEndTests [TestMethod] public void BokehBlur() { - BokehBlurEffect bokehBlurEffect = new(32, 1); + BokehBlurEffect bokehBlurEffect = new(32, 3); string assetsPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Assets"); string temporaryPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "temp");