Updated WinUI 3 sample to leverage IPixelShader<TPixel>

このコミットが含まれているのは:
Sergio Pedri committed 2021-11-20 00:28:01 +01:00
1 親 c32f09ecb3
コミット 1494e41a53
2ファイル変更
+25 -15

検索条件に一致するファイルはありません

@@ -1,8 +1,8 @@
using System.Collections.Generic; using System.Collections.Generic;
using ComputeSharp.SwapChain.Shaders; using ComputeSharp.SwapChain.Shaders;
using ComputeSharp.SwapChain.WinUI.Models;
using ComputeSharp.WinUI; using ComputeSharp.WinUI;
using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.ComponentModel;
using ComputeSharp.SwapChain.WinUI.Models;
using CommunityToolkit.Mvvm.Input; using CommunityToolkit.Mvvm.Input;
namespace ComputeSharp.SwapChain.WinUI.ViewModels namespace ComputeSharp.SwapChain.WinUI.ViewModels
@@ -59,15 +59,15 @@ namespace ComputeSharp.SwapChain.WinUI.ViewModels
/// </summary> /// </summary>
public IReadOnlyList<ComputeShader> ComputeShaderOptions { get; } = new ComputeShader[] public IReadOnlyList<ComputeShader> ComputeShaderOptions { get; } = new ComputeShader[]
{ {
new("Colorful infinity", new ShaderRunner<ColorfulInfinity>(static (texture, time) => new(texture, (float)time.TotalSeconds))), new("Colorful infinity", new ShaderRunner<ColorfulInfinity>(static time => new((float)time.TotalSeconds))),
new("Extruded truchet", new ShaderRunner<ExtrudedTruchetPattern>(static (texture, time) => new(texture, (float)time.TotalSeconds))), new("Extruded truchet", new ShaderRunner<ExtrudedTruchetPattern>(static time => new((float)time.TotalSeconds))),
new("Fractal tiling", new ShaderRunner<FractalTiling>(static (texture, time) => new(texture, (float)time.TotalSeconds))), new("Fractal tiling", new ShaderRunner<FractalTiling>(static time => new((float)time.TotalSeconds))),
new("Menger Journey", new ShaderRunner<MengerJourney>(static (texture, time) => new(texture, (float)time.TotalSeconds))), new("Menger Journey", new ShaderRunner<MengerJourney>(static time => new((float)time.TotalSeconds))),
new("Octagrams", new ShaderRunner<Octagrams>(static (texture, time) => new(texture, (float)time.TotalSeconds))), new("Octagrams", new ShaderRunner<Octagrams>(static time => new((float)time.TotalSeconds))),
new("Protean clouds", new ShaderRunner<ProteanClouds>(static (texture, time) => new(texture, (float)time.TotalSeconds))), new("Protean clouds", new ShaderRunner<ProteanClouds>(static time => new((float)time.TotalSeconds))),
new("Two tiled truchet", new ShaderRunner<TwoTiledTruchet>(static (texture, time) => new(texture, (float)time.TotalSeconds))), new("Two tiled truchet", new ShaderRunner<TwoTiledTruchet>(static time => new((float)time.TotalSeconds))),
new("Pyramid pattern", new ShaderRunner<PyramidPattern>(static (texture, time) => new(texture, (float)time.TotalSeconds))), new("Pyramid pattern", new ShaderRunner<PyramidPattern>(static time => new((float)time.TotalSeconds))),
new("Triangle grid contouring", new ShaderRunner<TriangleGridContouring>(static (texture, time) => new(texture, (float)time.TotalSeconds))) new("Triangle grid contouring", new ShaderRunner<TriangleGridContouring>(static time => new((float)time.TotalSeconds)))
}; };
private ComputeShader selectedComputeShader; private ComputeShader selectedComputeShader;
+15 -5
ファイルの表示
@@ -7,18 +7,28 @@ namespace ComputeSharp.WinUI
/// </summary> /// </summary>
/// <typeparam name="T">The type of shader to use to render frames.</typeparam> /// <typeparam name="T">The type of shader to use to render frames.</typeparam>
public sealed class ShaderRunner<T> : IShaderRunner public sealed class ShaderRunner<T> : IShaderRunner
where T : struct, IComputeShader where T : struct, IPixelShader<Float4>
{ {
/// <summary> /// <summary>
/// The <see cref="Func{T1, T2, TResult}"/> instance used to create shaders to run. /// The <see cref="Func{T1, TResult}"/> instance used to create shaders to run.
/// </summary> /// </summary>
private readonly Func<IReadWriteTexture2D<Float4>, TimeSpan, T> shaderFactory; private readonly Func<TimeSpan, T> shaderFactory;
/// <summary>
/// Creates a new <see cref="ShaderRunner{T}"/> instance that will create shader instances with
/// the default constructor. Only use this constructor if the shader doesn't require any additional
/// resources or other parameters being initialized before being dispatched on the GPU.
/// </summary>
public ShaderRunner()
{
this.shaderFactory = static _ => default;
}
/// <summary> /// <summary>
/// Creates a new <see cref="ShaderRunner{T}"/> instance. /// Creates a new <see cref="ShaderRunner{T}"/> instance.
/// </summary> /// </summary>
/// <param name="shaderFactory">The <see cref="Func{T1, T2, TResult}"/> instance used to create shaders to run.</param> /// <param name="shaderFactory">The <see cref="Func{T1, T2, TResult}"/> instance used to create shaders to run.</param>
public ShaderRunner(Func<IReadWriteTexture2D<Float4>, TimeSpan, T> shaderFactory) public ShaderRunner(Func<TimeSpan, T> shaderFactory)
{ {
this.shaderFactory = shaderFactory; this.shaderFactory = shaderFactory;
} }
@@ -26,7 +36,7 @@ namespace ComputeSharp.WinUI
/// <inheritdoc/> /// <inheritdoc/>
public void Execute(IReadWriteTexture2D<Float4> texture, TimeSpan time) public void Execute(IReadWriteTexture2D<Float4> texture, TimeSpan time)
{ {
Gpu.Default.For(texture.Width, texture.Height, this.shaderFactory(texture, time)); Gpu.Default.ForEach(texture, this.shaderFactory(time));
} }
} }
} }