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

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

+15 -5
ファイルの表示
@@ -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));
}
}
}