From 4aeb97113ae20f0ee11cceee77f4a4ee3c204e20 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Thu, 21 Apr 2022 01:49:40 +0200 Subject: [PATCH] Use infinite RECT for default mapping with 0 inputs --- src/ComputeSharp.D2D1/Extensions/RECTExtensions.cs | 13 +++++++++++++ .../PixelShaderEffect.ID2D1DrawTransformMethods.cs | 6 ++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/ComputeSharp.D2D1/Extensions/RECTExtensions.cs b/src/ComputeSharp.D2D1/Extensions/RECTExtensions.cs index df8d053a..792b7374 100644 --- a/src/ComputeSharp.D2D1/Extensions/RECTExtensions.cs +++ b/src/ComputeSharp.D2D1/Extensions/RECTExtensions.cs @@ -14,6 +14,19 @@ namespace ComputeSharp.D2D1.Extensions; /// internal static class RECTExtensions { + /// + /// Modifies a target instance to be a D2D1 infinite rectangle. + /// + /// The target instance to modify. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void MakeD2D1Infinite(this ref RECT rect) + { + rect.left = int.MinValue; + rect.top = int.MinValue; + rect.right = int.MaxValue; + rect.bottom = int.MaxValue; + } + /// /// Creates a from a value. /// diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.ID2D1DrawTransformMethods.cs b/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.ID2D1DrawTransformMethods.cs index a40b0bc6..d9833da2 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.ID2D1DrawTransformMethods.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.ID2D1DrawTransformMethods.cs @@ -208,8 +208,10 @@ partial struct PixelShaderEffect } else if (inputRectCount == 0) { - // If there are no inputs, just ignore (users will need a custom mapping) - *outputRect = default; + // If there are no inputs, make the output rectangle infinite. This is useful + // to make output-only effects work fine by default, without needing a custom + // transform. In this case, the target area will be the output node anyway. + outputRect->MakeD2D1Infinite(); @this->inputRect = default;