diff --git a/samples/ComputeSharp.SwapChain.Core.Shared/ComputeSharp.SwapChain.Core.Shared.projitems b/samples/ComputeSharp.SwapChain.Core.Shared/ComputeSharp.SwapChain.Core.Shared.projitems
index 80831f63..8fd7c01f 100644
--- a/samples/ComputeSharp.SwapChain.Core.Shared/ComputeSharp.SwapChain.Core.Shared.projitems
+++ b/samples/ComputeSharp.SwapChain.Core.Shared/ComputeSharp.SwapChain.Core.Shared.projitems
@@ -17,8 +17,7 @@
-
-
+
diff --git a/samples/ComputeSharp.SwapChain.Core.Shared/Controls/D2D1AnimatedPixelShaderPanel.cs b/samples/ComputeSharp.SwapChain.Core.Shared/Controls/D2D1AnimatedPixelShaderPanel.cs
index a3889ca3..38351f58 100644
--- a/samples/ComputeSharp.SwapChain.Core.Shared/Controls/D2D1AnimatedPixelShaderPanel.cs
+++ b/samples/ComputeSharp.SwapChain.Core.Shared/Controls/D2D1AnimatedPixelShaderPanel.cs
@@ -1,4 +1,5 @@
using ComputeSharp.SwapChain.Core.Shaders;
+using Microsoft.Graphics.Canvas;
using Microsoft.Graphics.Canvas.UI.Xaml;
#if WINDOWS_UWP
using Windows.UI.Xaml;
@@ -28,9 +29,9 @@ public sealed class D2D1AnimatedPixelShaderPanel : Control
private CanvasAnimatedControl? canvasAnimatedControl;
///
- /// The instance currently in use, if any.
+ /// The instance currently in use, if any.
///
- private volatile ID2D1ShaderRunner? shaderRunner;
+ private volatile PixelShaderEffect? pixelShaderEffect;
///
/// Creates a new instance.
@@ -56,7 +57,7 @@ public sealed class D2D1AnimatedPixelShaderPanel : Control
private void D2D1AnimatedPixelShaderPanel_Loaded(object sender, RoutedEventArgs e)
{
if (this.canvasAnimatedControl is { } canvasAnimatedControl &&
- ShaderRunner is not null &&
+ PixelShaderEffect is not null &&
!IsPaused)
{
canvasAnimatedControl.Paused = false;
@@ -75,43 +76,50 @@ public sealed class D2D1AnimatedPixelShaderPanel : Control
///
/// Draws a new frame on the wrapped instance.
///
- ///
+ /// The source instance.
+ /// The object to perform drawing with.
private void CanvasAnimatedControl_Draw(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args)
{
- this.shaderRunner?.Execute(sender, args);
+ // Set the effect properties
+ this.pixelShaderEffect!.ElapsedTime = args.Timing.TotalTime;
+ this.pixelShaderEffect.ScreenWidth = sender.ConvertDipsToPixels((float)sender.Size.Width, CanvasDpiRounding.Round);
+ this.pixelShaderEffect.ScreenHeight = sender.ConvertDipsToPixels((float)sender.Size.Height, CanvasDpiRounding.Round);
+
+ // Draw the effect
+ args.DrawingSession.DrawImage(this.pixelShaderEffect);
}
///
- /// Gets or sets the instance to use to render content.
+ /// Gets or sets the instance to use to render content.
///
- public ID2D1ShaderRunner? ShaderRunner
+ public PixelShaderEffect? PixelShaderEffect
{
- get => (ID2D1ShaderRunner?)GetValue(ShaderRunnerProperty);
- set => SetValue(ShaderRunnerProperty, value);
+ get => (PixelShaderEffect?)GetValue(PixelShaderEffectProperty);
+ set => SetValue(PixelShaderEffectProperty, value);
}
///
- /// The backing .
+ /// The backing .
///
- public static readonly DependencyProperty ShaderRunnerProperty = DependencyProperty.Register(
- nameof(ShaderRunner),
- typeof(ID2D1ShaderRunner),
+ public static readonly DependencyProperty PixelShaderEffectProperty = DependencyProperty.Register(
+ nameof(PixelShaderEffect),
+ typeof(PixelShaderEffect),
typeof(D2D1AnimatedPixelShaderPanel),
- new PropertyMetadata(null, OnShaderRunnerPropertyChanged));
+ new PropertyMetadata(null, OnPixelShaderEffectPropertyChanged));
///
- private static void OnShaderRunnerPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
+ private static void OnPixelShaderEffectPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
D2D1AnimatedPixelShaderPanel @this = (D2D1AnimatedPixelShaderPanel)d;
- ID2D1ShaderRunner? shaderRunner = (ID2D1ShaderRunner?)e.NewValue;
+ PixelShaderEffect? pixelShaderEffect = (PixelShaderEffect?)e.NewValue;
- // Save the new shader runner for later (as the dependency property cannot be accessed by the render thread)
- @this.shaderRunner = shaderRunner;
+ // Save the new pixel shader effect for later (as the dependency property cannot be accessed by the render thread)
+ @this.pixelShaderEffect = pixelShaderEffect;
- // Pause or start the render thread if a runner is available
+ // Pause or start the render thread if an effect is available
if (@this.canvasAnimatedControl is { } canvasAnimatedControl)
{
- bool shouldRender = @this.IsLoaded && !@this.IsPaused && shaderRunner is not null;
+ bool shouldRender = @this.IsLoaded && !@this.IsPaused && pixelShaderEffect is not null;
canvasAnimatedControl.Paused = !shouldRender;
}
@@ -143,7 +151,7 @@ public sealed class D2D1AnimatedPixelShaderPanel : Control
if (@this.canvasAnimatedControl is { } canvasAnimatedControl)
{
- bool shouldRender = @this.IsLoaded && !isPaused && @this.ShaderRunner is not null;
+ bool shouldRender = @this.IsLoaded && !isPaused && @this.PixelShaderEffect is not null;
canvasAnimatedControl.Paused = !shouldRender;
}
diff --git a/samples/ComputeSharp.SwapChain.Core.Shared/Shaders/D2D1ShaderRunner{T}.cs b/samples/ComputeSharp.SwapChain.Core.Shared/Shaders/D2D1ShaderRunner{T}.cs
deleted file mode 100644
index 259c3993..00000000
--- a/samples/ComputeSharp.SwapChain.Core.Shared/Shaders/D2D1ShaderRunner{T}.cs
+++ /dev/null
@@ -1,61 +0,0 @@
-using System;
-using CommunityToolkit.Diagnostics;
-using ComputeSharp.D2D1;
-#if WINDOWS_UWP
-using ComputeSharp.D2D1.Uwp;
-#else
-using ComputeSharp.D2D1.WinUI;
-#endif
-using Microsoft.Graphics.Canvas;
-using Microsoft.Graphics.Canvas.UI.Xaml;
-
-namespace ComputeSharp.SwapChain.Core.Shaders;
-
-///
-/// A simple implementation powered by a supplied shader type.
-///
-/// The type of shader to use to render frames.
-public sealed class D2D1ShaderRunner : ID2D1ShaderRunner, IDisposable
- where T : unmanaged, ID2D1PixelShader
-{
- ///
- /// The instance used to create shaders to run.
- ///
- private readonly Func shaderFactory;
-
- ///
- /// The reusable instance to use to render frames.
- ///
- private readonly PixelShaderEffect pixelShaderEffect;
-
- ///
- /// Creates a new instance.
- ///
- /// The instance used to create shaders to run.
- public D2D1ShaderRunner(Func shaderFactory)
- {
- Guard.IsNotNull(shaderFactory);
-
- this.shaderFactory = shaderFactory;
- this.pixelShaderEffect = new PixelShaderEffect();
- }
-
- ///
- public void Execute(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args)
- {
- int widthInPixels = sender.ConvertDipsToPixels((float)sender.Size.Width, CanvasDpiRounding.Round);
- int heightInPixels = sender.ConvertDipsToPixels((float)sender.Size.Height, CanvasDpiRounding.Round);
-
- // Set the constant buffer
- this.pixelShaderEffect.ConstantBuffer = this.shaderFactory(args.Timing.TotalTime, widthInPixels, heightInPixels);
-
- // Draw the shader
- args.DrawingSession.DrawImage(this.pixelShaderEffect);
- }
-
- ///
- public void Dispose()
- {
- this.pixelShaderEffect.Dispose();
- }
-}
\ No newline at end of file
diff --git a/samples/ComputeSharp.SwapChain.Core.Shared/Shaders/ID2D1ShaderRunner.cs b/samples/ComputeSharp.SwapChain.Core.Shared/Shaders/ID2D1ShaderRunner.cs
deleted file mode 100644
index f62bdd65..00000000
--- a/samples/ComputeSharp.SwapChain.Core.Shared/Shaders/ID2D1ShaderRunner.cs
+++ /dev/null
@@ -1,16 +0,0 @@
-using Microsoft.Graphics.Canvas.UI.Xaml;
-
-namespace ComputeSharp.SwapChain.Core.Shaders;
-
-///
-/// An interface for a shader runner to be used with a Win2D renderer.
-///
-public interface ID2D1ShaderRunner
-{
- ///
- /// Draws a new frame on a target instance.
- ///
- /// The target instance.
- /// The instance to use to draw the new frame.
- void Execute(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args);
-}
\ No newline at end of file
diff --git a/samples/ComputeSharp.SwapChain.Core.Shared/Shaders/PixelShaderEffect.cs b/samples/ComputeSharp.SwapChain.Core.Shared/Shaders/PixelShaderEffect.cs
new file mode 100644
index 00000000..e0257d28
--- /dev/null
+++ b/samples/ComputeSharp.SwapChain.Core.Shared/Shaders/PixelShaderEffect.cs
@@ -0,0 +1,121 @@
+using System;
+using ComputeSharp.D2D1;
+#if WINDOWS_UWP
+using ComputeSharp.D2D1.Uwp;
+#else
+using ComputeSharp.D2D1.WinUI;
+#endif
+using Microsoft.Graphics.Canvas;
+
+#nullable enable
+
+namespace ComputeSharp.SwapChain.Core.Shaders;
+
+///
+/// An base effect for an animated pixel shader.
+///
+public abstract class PixelShaderEffect : CanvasEffect
+{
+ ///
+ /// The current elapsed time.
+ ///
+ private TimeSpan elapsedTime;
+
+ ///
+ /// The current screen width in raw pixels.
+ ///
+ private int screenWidth;
+
+ ///
+ /// The current screen height in raw pixels.
+ ///
+ private int screenHeight;
+
+ ///
+ /// Gets or sets the total elapsed time.
+ ///
+ public TimeSpan ElapsedTime
+ {
+ get => this.elapsedTime;
+ set => SetAndInvalidateEffectGraph(ref this.elapsedTime, value);
+ }
+
+ ///
+ /// Gets or sets the screen width in raw pixels.
+ ///
+ public int ScreenWidth
+ {
+ get => this.screenWidth;
+ set => SetAndInvalidateEffectGraph(ref this.screenWidth, value);
+ }
+
+ ///
+ /// Gets or sets the screen height in raw pixels.
+ ///
+ public int ScreenHeight
+ {
+ get => this.screenHeight;
+ set => SetAndInvalidateEffectGraph(ref this.screenHeight, value);
+ }
+
+ ///
+ /// An effect for an animated pixel shader.
+ ///
+ /// The type of pixel shader to render.
+ public sealed class For : PixelShaderEffect
+ where T : unmanaged, ID2D1PixelShader
+ {
+ ///
+ /// The factory to use.
+ ///
+ private readonly Factory factory;
+
+ ///
+ /// The instance in use.
+ ///
+ private PixelShaderEffect? effect;
+
+ ///
+ /// Creates a new instance with the specified parameters.
+ ///
+ /// The input factory.
+ public For(Factory factory)
+ {
+ this.factory = factory;
+ }
+
+ ///
+ protected override ICanvasImage BuildEffectGraph()
+ {
+ this.effect = new PixelShaderEffect();
+
+ return this.effect;
+ }
+
+ ///
+ protected override void ConfigureEffectGraph()
+ {
+ this.effect!.ConstantBuffer = this.factory(ElapsedTime, ScreenWidth, ScreenHeight);
+ }
+
+ ///
+ protected override void Dispose(bool disposing)
+ {
+ base.Dispose(disposing);
+
+ if (disposing)
+ {
+ this.effect?.Dispose();
+ }
+ }
+
+ ///
+ /// A factory of a given shader instance.
+ ///
+ /// The total elapsed time.
+ /// The screen width in raw pixels.
+ /// The screen height in raw pixels.
+ /// A shader instance to render.
+ public delegate T Factory(TimeSpan elapsedTime, int screenWidth, int screenHeight);
+ }
+}
diff --git a/samples/ComputeSharp.SwapChain.Core.Shared/Shaders/Runners/D2D1ContouredLayersRunner.cs b/samples/ComputeSharp.SwapChain.Core.Shared/Shaders/Runners/D2D1ContouredLayersRunner.cs
index 9b0d89fc..9707c246 100644
--- a/samples/ComputeSharp.SwapChain.Core.Shared/Shaders/Runners/D2D1ContouredLayersRunner.cs
+++ b/samples/ComputeSharp.SwapChain.Core.Shared/Shaders/Runners/D2D1ContouredLayersRunner.cs
@@ -9,7 +9,6 @@ using ComputeSharp.D2D1.WinUI;
#endif
using ComputeSharp.SwapChain.Shaders.D2D1;
using Microsoft.Graphics.Canvas;
-using Microsoft.Graphics.Canvas.UI.Xaml;
using Windows.ApplicationModel;
#nullable enable
@@ -17,9 +16,9 @@ using Windows.ApplicationModel;
namespace ComputeSharp.SwapChain.Core.Shaders.Runners;
///
-/// A specialized for .
+/// A specialized for .
///
-public sealed class D2D1ContouredLayersRunner : ID2D1ShaderRunner, IDisposable
+public sealed class D2D1ContouredLayersEffect : PixelShaderEffect
{
///
/// The reusable instance to use to render frames.
@@ -27,54 +26,55 @@ public sealed class D2D1ContouredLayersRunner : ID2D1ShaderRunner, IDisposable
private PixelShaderEffect? pixelShaderEffect;
///
- public unsafe void Execute(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args)
+ protected override unsafe ICanvasImage BuildEffectGraph()
{
- if (this.pixelShaderEffect is null)
- {
- string filename = Path.Combine(Package.Current.InstalledLocation.Path, "Assets", "Textures", "RustyMetal.png");
+ string filename = Path.Combine(Package.Current.InstalledLocation.Path, "Assets", "Textures", "RustyMetal.png");
- // As a temporary workaround for the lack of image decoding helpers for D2D1ResourceTextureManager, and in order to
- // keep the code here synchronous and simple, we can just leverage the DirectX 12 APIs to load textures. That is, we
- // first load a texture (which will use WIC behind the scenes) to get the decoded image data in GPU memory, and then
- // copy the data in a readback texture we can read from on the CPU. We can't just load an upload texture and read
- // from it, as that type of texture can only be written to from the CPU. From there, we create a D2D resource texture.
- using ReadOnlyTexture2D readOnlyTexture = GraphicsDevice.GetDefault().LoadReadOnlyTexture2D(filename);
- using ReadBackTexture2D readBackTexture = GraphicsDevice.GetDefault().AllocateReadBackTexture2D(readOnlyTexture.Width, readOnlyTexture.Height);
+ // As a temporary workaround for the lack of image decoding helpers for D2D1ResourceTextureManager, and in order to
+ // keep the code here synchronous and simple, we can just leverage the DirectX 12 APIs to load textures. That is, we
+ // first load a texture (which will use WIC behind the scenes) to get the decoded image data in GPU memory, and then
+ // copy the data in a readback texture we can read from on the CPU. We can't just load an upload texture and read
+ // from it, as that type of texture can only be written to from the CPU. From there, we create a D2D resource texture.
+ using ReadOnlyTexture2D readOnlyTexture = GraphicsDevice.GetDefault().LoadReadOnlyTexture2D(filename);
+ using ReadBackTexture2D readBackTexture = GraphicsDevice.GetDefault().AllocateReadBackTexture2D(readOnlyTexture.Width, readOnlyTexture.Height);
- readOnlyTexture.CopyTo(readBackTexture);
+ readOnlyTexture.CopyTo(readBackTexture);
- // Get the buffer pointer, the stride, and calculate the buffer size without the trailing padding.
- // That is, the area between the end of the data in the last row and the stride is not included.
- Rgba32* dataBuffer = readBackTexture.View.DangerousGetAddressAndByteStride(out int strideInBytes);
- int bufferSize = ((readBackTexture.Height - 1) * strideInBytes) + (readBackTexture.View.Width * sizeof(Rgba32));
+ // Get the buffer pointer, the stride, and calculate the buffer size without the trailing padding.
+ // That is, the area between the end of the data in the last row and the stride is not included.
+ Rgba32* dataBuffer = readBackTexture.View.DangerousGetAddressAndByteStride(out int strideInBytes);
+ int bufferSize = ((readBackTexture.Height - 1) * strideInBytes) + (readBackTexture.View.Width * sizeof(Rgba32));
- // Create the resource texture manager to use in the shader
- D2D1ResourceTextureManager resourceTextureManager = new(
- extents: stackalloc uint[] { (uint)readBackTexture.Height, (uint)readBackTexture.Width },
- bufferPrecision: D2D1BufferPrecision.UInt8Normalized,
- channelDepth: D2D1ChannelDepth.Four,
- filter: D2D1Filter.MinMagMipLinear,
- extendModes: stackalloc D2D1ExtendMode[] { D2D1ExtendMode.Mirror, D2D1ExtendMode.Mirror },
- data: new ReadOnlySpan(dataBuffer, bufferSize),
- strides: stackalloc uint[] { (uint)strideInBytes });
+ // Create the resource texture manager to use in the shader
+ D2D1ResourceTextureManager resourceTextureManager = new(
+ extents: stackalloc uint[] { (uint)readBackTexture.Height, (uint)readBackTexture.Width },
+ bufferPrecision: D2D1BufferPrecision.UInt8Normalized,
+ channelDepth: D2D1ChannelDepth.Four,
+ filter: D2D1Filter.MinMagMipLinear,
+ extendModes: stackalloc D2D1ExtendMode[] { D2D1ExtendMode.Mirror, D2D1ExtendMode.Mirror },
+ data: new ReadOnlySpan(dataBuffer, bufferSize),
+ strides: stackalloc uint[] { (uint)strideInBytes });
- // Create the new pixel shader effect
- this.pixelShaderEffect = new PixelShaderEffect() { ResourceTextureManagers = { [0] = resourceTextureManager } };
- }
+ // Create the new pixel shader effect
+ this.pixelShaderEffect = new PixelShaderEffect() { ResourceTextureManagers = { [0] = resourceTextureManager } };
- int widthInPixels = sender.ConvertDipsToPixels((float)sender.Size.Width, CanvasDpiRounding.Round);
- int heightInPixels = sender.ConvertDipsToPixels((float)sender.Size.Height, CanvasDpiRounding.Round);
-
- // Set the constant buffer
- this.pixelShaderEffect.ConstantBuffer = new ContouredLayers((float)args.Timing.TotalTime.TotalSeconds, new int2(widthInPixels, heightInPixels));
-
- // Draw the shader
- args.DrawingSession.DrawImage(this.pixelShaderEffect);
+ return this.pixelShaderEffect;
}
///
- public void Dispose()
+ protected override void ConfigureEffectGraph()
{
- this.pixelShaderEffect?.Dispose();
+ this.pixelShaderEffect!.ConstantBuffer = new ContouredLayers((float)ElapsedTime.TotalSeconds, new int2(ScreenWidth, ScreenHeight));
+ }
+
+ ///
+ protected override void Dispose(bool disposing)
+ {
+ base.Dispose(disposing);
+
+ if (disposing)
+ {
+ this.pixelShaderEffect?.Dispose();
+ }
}
}
\ No newline at end of file
diff --git a/samples/ComputeSharp.SwapChain.Core.Shared/ViewModels/MainViewModel.cs b/samples/ComputeSharp.SwapChain.Core.Shared/ViewModels/MainViewModel.cs
index 076a6dc0..3944abaa 100644
--- a/samples/ComputeSharp.SwapChain.Core.Shared/ViewModels/MainViewModel.cs
+++ b/samples/ComputeSharp.SwapChain.Core.Shared/ViewModels/MainViewModel.cs
@@ -95,40 +95,40 @@ public sealed partial class MainViewModel : ObservableObject
new(
nameof(ColorfulInfinity),
new ShaderRunner(static time => new((float)time.TotalSeconds)),
- new D2D1ShaderRunner(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
+ new PixelShaderEffect.For(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
new(
nameof(FractalTiling),
new ShaderRunner(static time => new((float)time.TotalSeconds)),
- new D2D1ShaderRunner(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
+ new PixelShaderEffect.For(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
new(
nameof(MengerJourney),
new ShaderRunner(static time => new((float)time.TotalSeconds)),
- new D2D1ShaderRunner(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
+ new PixelShaderEffect.For(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
new(
nameof(Octagrams),
new ShaderRunner(static time => new((float)time.TotalSeconds)),
- new D2D1ShaderRunner(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
+ new PixelShaderEffect.For(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
new(
nameof(ProteanClouds),
new ShaderRunner(static time => new((float)time.TotalSeconds)),
- new D2D1ShaderRunner(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
+ new PixelShaderEffect.For(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
new(
nameof(TwoTiledTruchet),
new ShaderRunner(static time => new((float)time.TotalSeconds)),
- new D2D1ShaderRunner(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
+ new PixelShaderEffect.For(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
new(
nameof(PyramidPattern),
new ShaderRunner(static time => new((float)time.TotalSeconds)),
- new D2D1ShaderRunner(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
+ new PixelShaderEffect.For(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
new(
nameof(TriangleGridContouring),
new ShaderRunner(static time => new((float)time.TotalSeconds)),
- new D2D1ShaderRunner(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
- new(nameof(ContouredLayers), new ContouredLayersRunner(), new D2D1ContouredLayersRunner()),
+ new PixelShaderEffect.For(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
+ new(nameof(ContouredLayers), new ContouredLayersRunner(), new D2D1ContouredLayersEffect()),
new(
nameof(TerracedHills),
new ShaderRunner(static time => new((float)time.TotalSeconds)),
- new D2D1ShaderRunner(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
+ new PixelShaderEffect.For(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
};
///
diff --git a/samples/ComputeSharp.SwapChain.Core.Shared/ViewModels/ShaderRunnerViewModel.cs b/samples/ComputeSharp.SwapChain.Core.Shared/ViewModels/ShaderRunnerViewModel.cs
index eb8d1ef6..7ff1af01 100644
--- a/samples/ComputeSharp.SwapChain.Core.Shared/ViewModels/ShaderRunnerViewModel.cs
+++ b/samples/ComputeSharp.SwapChain.Core.Shared/ViewModels/ShaderRunnerViewModel.cs
@@ -18,12 +18,12 @@ public sealed partial class ShaderRunnerViewModel : ObservableObject
///
/// The name of the shader type to execute.
/// The instance to execute.
- /// The instance to execute.
- public ShaderRunnerViewModel(string shaderType, IShaderRunner shaderRunner, ID2D1ShaderRunner d2D1ShaderRunner)
+ /// The instance to execute.
+ public ShaderRunnerViewModel(string shaderType, IShaderRunner shaderRunner, PixelShaderEffect pixelShaderEffect)
{
ShaderType = shaderType;
ShaderRunner = shaderRunner;
- D2D1ShaderRunner = d2D1ShaderRunner;
+ PixelShaderEffect = pixelShaderEffect;
}
///
@@ -37,9 +37,9 @@ public sealed partial class ShaderRunnerViewModel : ObservableObject
public IShaderRunner ShaderRunner { get; }
///
- /// Gets the instance to execute.
+ /// Gets the instance to execute.
///
- public ID2D1ShaderRunner D2D1ShaderRunner { get; }
+ public PixelShaderEffect PixelShaderEffect { get; }
///
/// Gets or sets whether the current shader is selected.
diff --git a/samples/ComputeSharp.SwapChain.Uwp/Views/MainView.xaml b/samples/ComputeSharp.SwapChain.Uwp/Views/MainView.xaml
index 2cfb1d41..ea7f8a1d 100644
--- a/samples/ComputeSharp.SwapChain.Uwp/Views/MainView.xaml
+++ b/samples/ComputeSharp.SwapChain.Uwp/Views/MainView.xaml
@@ -162,7 +162,7 @@
-
+
diff --git a/samples/ComputeSharp.SwapChain.WinUI/Views/MainWindow.xaml b/samples/ComputeSharp.SwapChain.WinUI/Views/MainWindow.xaml
index 9368dd8e..410e1310 100644
--- a/samples/ComputeSharp.SwapChain.WinUI/Views/MainWindow.xaml
+++ b/samples/ComputeSharp.SwapChain.WinUI/Views/MainWindow.xaml
@@ -165,7 +165,7 @@
-
+
diff --git a/src/ComputeSharp.D2D1.UI/CanvasEffect.Interop.cs b/src/ComputeSharp.D2D1.UI/CanvasEffect.Interop.cs
index 0da3a77e..58399b07 100644
--- a/src/ComputeSharp.D2D1.UI/CanvasEffect.Interop.cs
+++ b/src/ComputeSharp.D2D1.UI/CanvasEffect.Interop.cs
@@ -1,4 +1,5 @@
using System;
+using System.Diagnostics.CodeAnalysis;
using System.Numerics;
using ABI.Microsoft.Graphics.Canvas;
using ComputeSharp.D2D1.Extensions;
@@ -65,6 +66,7 @@ unsafe partial class CanvasEffect
///
/// The current instance.
/// Thrown if the current instance is disposed.
+ [MemberNotNull(nameof(canvasImage))]
private ICanvasImage GetCanvasImage()
{
lock (this.lockObject)
diff --git a/src/ComputeSharp.D2D1.UI/CanvasEffect.cs b/src/ComputeSharp.D2D1.UI/CanvasEffect.cs
index 050a4421..efef99d5 100644
--- a/src/ComputeSharp.D2D1.UI/CanvasEffect.cs
+++ b/src/ComputeSharp.D2D1.UI/CanvasEffect.cs
@@ -155,14 +155,6 @@ public abstract partial class CanvasEffect : ICanvasImage, ICanvasImageInterop.I
InvalidateEffectGraph(invalidationType);
}
- ///
- public void Dispose()
- {
- Dispose(disposing: true);
-
- GC.SuppressFinalize(this);
- }
-
///
/// Disposes any disposable resources in the current instance.
///
@@ -211,6 +203,14 @@ public abstract partial class CanvasEffect : ICanvasImage, ICanvasImageInterop.I
this.isDisposed = true;
}
+ ///
+ public void Dispose()
+ {
+ Dispose(disposing: true);
+
+ GC.SuppressFinalize(this);
+ }
+
///
/// Indicates the invalidation type to request when invoking and related methods.
///