From 941488a647f827c10efecb795472822ca0b67acb Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Thu, 8 Dec 2022 20:38:50 +0100 Subject: [PATCH] Forward effect sources upon realization --- ...ixelShaderEffect{T}.ICanvasImageInterop.cs | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.ICanvasImageInterop.cs b/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.ICanvasImageInterop.cs index 27a4b599..1d9a64b5 100644 --- a/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.ICanvasImageInterop.cs +++ b/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.ICanvasImageInterop.cs @@ -127,7 +127,12 @@ unsafe partial class PixelShaderEffect // Create the effect, if it doesn't exist already if (this.d2D1Effect.Get() is null) { - Realize(flags, targetDpi, deviceContext); + if (!Realize(flags, targetDpi, deviceContext)) + { + *ppImage = null; + + return E.E_FAIL; + } } else if (!flags.HasFlag(WIN2D_GET_D2D_IMAGE_FLAGS_MINIMAL_REALIZATION)) { @@ -221,7 +226,8 @@ unsafe partial class PixelShaderEffect /// The current flags in use. /// The target DPI in use. /// The instance in use. - private void Realize(WIN2D_GET_D2D_IMAGE_FLAGS flags, float targetDpi, ID2D1DeviceContext* deviceContext) + /// Whether the effect was realized correctly. + private bool Realize(WIN2D_GET_D2D_IMAGE_FLAGS flags, float targetDpi, ID2D1DeviceContext* deviceContext) { using ComPtr d2D1Factory = default; @@ -279,6 +285,20 @@ unsafe partial class PixelShaderEffect this.d2D1Effect.Get()->SetPrecisionProperty(this.d2D1BufferPrecision); } + // Forward all available sources (the effect is being created now, so no need to validate the underlying resources) + for (int i = 0; i < SourceCollection.Count; i++) + { + if (!SetD2DInput( + index: i, + value: Sources.Storage[0].GetWrapper(), + flags: flags, + targetDpi: targetDpi, + d2D1DeviceContext: deviceContext)) + { + return false; + } + } + // Set all available resource texture managers (only set those that are not null, as they're all null by default anyway). // The loop only goes over the indices of valid slots for resource textures for the current effect, and ignores the others. foreach (int index in ResourceTextureManagerCollection.Indices) @@ -288,6 +308,8 @@ unsafe partial class PixelShaderEffect D2D1PixelShaderEffect.SetResourceTextureManagerForD2D1Effect(this.d2D1Effect.Get(), resourceTextureManager, index); } } + + return true; } ///