Updated WinUI 3 sample to leverage IPixelShader<TPixel>
このコミットが含まれているのは:
1 親
c32f09ecb3
コミット
1494e41a53
2ファイル変更
+25
-15
検索条件に一致するファイルはありません
+10
-10
@@ -1,8 +1,8 @@
|
||||
using System.Collections.Generic;
|
||||
using ComputeSharp.SwapChain.Shaders;
|
||||
using ComputeSharp.SwapChain.WinUI.Models;
|
||||
using ComputeSharp.WinUI;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using ComputeSharp.SwapChain.WinUI.Models;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
|
||||
namespace ComputeSharp.SwapChain.WinUI.ViewModels
|
||||
@@ -59,15 +59,15 @@ namespace ComputeSharp.SwapChain.WinUI.ViewModels
|
||||
/// </summary>
|
||||
public IReadOnlyList<ComputeShader> ComputeShaderOptions { get; } = new ComputeShader[]
|
||||
{
|
||||
new("Colorful infinity", new ShaderRunner<ColorfulInfinity>(static (texture, time) => new(texture, (float)time.TotalSeconds))),
|
||||
new("Extruded truchet", new ShaderRunner<ExtrudedTruchetPattern>(static (texture, time) => new(texture, (float)time.TotalSeconds))),
|
||||
new("Fractal tiling", new ShaderRunner<FractalTiling>(static (texture, time) => new(texture, (float)time.TotalSeconds))),
|
||||
new("Menger Journey", new ShaderRunner<MengerJourney>(static (texture, time) => new(texture, (float)time.TotalSeconds))),
|
||||
new("Octagrams", new ShaderRunner<Octagrams>(static (texture, time) => new(texture, (float)time.TotalSeconds))),
|
||||
new("Protean clouds", new ShaderRunner<ProteanClouds>(static (texture, time) => new(texture, (float)time.TotalSeconds))),
|
||||
new("Two tiled truchet", new ShaderRunner<TwoTiledTruchet>(static (texture, time) => new(texture, (float)time.TotalSeconds))),
|
||||
new("Pyramid pattern", new ShaderRunner<PyramidPattern>(static (texture, time) => new(texture, (float)time.TotalSeconds))),
|
||||
new("Triangle grid contouring", new ShaderRunner<TriangleGridContouring>(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 time => new((float)time.TotalSeconds))),
|
||||
new("Fractal tiling", new ShaderRunner<FractalTiling>(static time => new((float)time.TotalSeconds))),
|
||||
new("Menger Journey", new ShaderRunner<MengerJourney>(static time => new((float)time.TotalSeconds))),
|
||||
new("Octagrams", new ShaderRunner<Octagrams>(static time => new((float)time.TotalSeconds))),
|
||||
new("Protean clouds", new ShaderRunner<ProteanClouds>(static time => new((float)time.TotalSeconds))),
|
||||
new("Two tiled truchet", new ShaderRunner<TwoTiledTruchet>(static time => new((float)time.TotalSeconds))),
|
||||
new("Pyramid pattern", new ShaderRunner<PyramidPattern>(static time => new((float)time.TotalSeconds))),
|
||||
new("Triangle grid contouring", new ShaderRunner<TriangleGridContouring>(static time => new((float)time.TotalSeconds)))
|
||||
};
|
||||
|
||||
private ComputeShader selectedComputeShader;
|
||||
|
||||
@@ -7,18 +7,28 @@ namespace ComputeSharp.WinUI
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of shader to use to render frames.</typeparam>
|
||||
public sealed class ShaderRunner<T> : IShaderRunner
|
||||
where T : struct, IComputeShader
|
||||
where T : struct, IPixelShader<Float4>
|
||||
{
|
||||
/// <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>
|
||||
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>
|
||||
/// Creates a new <see cref="ShaderRunner{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <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;
|
||||
}
|
||||
@@ -26,7 +36,7 @@ namespace ComputeSharp.WinUI
|
||||
/// <inheritdoc/>
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする