Add ability for IShaderRunner to skip presenting frames
このコミットが含まれているのは:
1 親
d406eb4cbc
コミット
044ddb8648
4ファイル変更
+45
-27
検索条件に一致するファイルはありません
@@ -23,7 +23,7 @@ public sealed class ContouredLayersRunner : IShaderRunner
|
||||
private ReadOnlyTexture2D<Rgba32, Float4>? texture;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Execute(IReadWriteTexture2D<Float4> texture, TimeSpan timespan, object? parameter)
|
||||
public bool TryExecute(IReadWriteTexture2D<Float4> texture, TimeSpan timespan, object? parameter)
|
||||
{
|
||||
if (this.texture is null)
|
||||
{
|
||||
@@ -33,5 +33,7 @@ public sealed class ContouredLayersRunner : IShaderRunner
|
||||
}
|
||||
|
||||
GraphicsDevice.Default.ForEach(texture, new ContouredLayers((float)timespan.TotalSeconds, this.texture));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -185,11 +185,14 @@ partial class SwapChainManager<TOwner>
|
||||
return;
|
||||
}
|
||||
|
||||
// Start the initial frame separately, before the timer starts. This ensures that
|
||||
// resuming after a pause correctly renders the first frame at the right time.
|
||||
OnResize();
|
||||
OnUpdate(renderStopwatch.Elapsed, parameter);
|
||||
OnPresent();
|
||||
|
||||
// Start the initial frame separately, before the timer starts. This ensures that
|
||||
// resuming after a pause correctly renders the first frame at the right time.
|
||||
if (OnUpdate(renderStopwatch.Elapsed, parameter))
|
||||
{
|
||||
OnPresent();
|
||||
}
|
||||
|
||||
renderStopwatch.Start();
|
||||
|
||||
@@ -202,8 +205,11 @@ partial class SwapChainManager<TOwner>
|
||||
}
|
||||
|
||||
OnResize();
|
||||
OnUpdate(renderStopwatch.Elapsed, parameter);
|
||||
OnPresent();
|
||||
|
||||
if (OnUpdate(renderStopwatch.Elapsed, parameter))
|
||||
{
|
||||
OnPresent();
|
||||
}
|
||||
}
|
||||
|
||||
renderStopwatch.Stop();
|
||||
@@ -215,41 +221,46 @@ partial class SwapChainManager<TOwner>
|
||||
private void RenderLoopWithDynamicResolution()
|
||||
{
|
||||
Stopwatch renderStopwatch = this.renderStopwatch ??= new();
|
||||
Stopwatch frameStopwatch = new();
|
||||
CancellationToken cancellationToken = this.renderCancellationTokenSource!.Token;
|
||||
|
||||
DynamicResolutionManager.Create(out DynamicResolutionManager frameTimeWatcher);
|
||||
|
||||
|
||||
if (!OnFrameRequest(out object? parameter, cancellationToken))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Stopwatch frameStopwatch = Stopwatch.StartNew();
|
||||
|
||||
OnResize();
|
||||
OnUpdate(renderStopwatch.Elapsed, parameter);
|
||||
OnPresent();
|
||||
|
||||
if (OnUpdate(renderStopwatch.Elapsed, parameter))
|
||||
{
|
||||
OnPresent();
|
||||
}
|
||||
|
||||
renderStopwatch.Start();
|
||||
|
||||
while (!cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
// Evaluate the dynamic resolution frame time step, if the mode is enabled
|
||||
if (frameTimeWatcher.Advance(frameStopwatch.ElapsedTicks, ref this.targetResolutionScale))
|
||||
{
|
||||
this.isResizePending = true;
|
||||
}
|
||||
|
||||
if (!OnFrameRequest(out parameter, cancellationToken))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
OnResize();
|
||||
|
||||
frameStopwatch.Restart();
|
||||
|
||||
OnResize();
|
||||
OnUpdate(renderStopwatch.Elapsed, parameter);
|
||||
OnPresent();
|
||||
if (OnUpdate(renderStopwatch.Elapsed, parameter))
|
||||
{
|
||||
OnPresent();
|
||||
|
||||
// Evaluate the dynamic resolution frame time step
|
||||
if (frameTimeWatcher.Advance(frameStopwatch.ElapsedTicks, ref this.targetResolutionScale))
|
||||
{
|
||||
this.isResizePending = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
renderStopwatch.Stop();
|
||||
@@ -309,9 +320,10 @@ partial class SwapChainManager<TOwner>
|
||||
/// </summary>
|
||||
/// <param name="time">The current time since the start of the application.</param>
|
||||
/// <param name="parameter">The input parameter for the frame being rendered.</param>
|
||||
private void OnUpdate(TimeSpan time, object? parameter)
|
||||
/// <returns>Whether or not to present the resulting frame.</returns>
|
||||
private bool OnUpdate(TimeSpan time, object? parameter)
|
||||
{
|
||||
this.shaderRunner!.Execute(this.texture!, time, parameter);
|
||||
return this.shaderRunner!.TryExecute(this.texture!, time, parameter);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -12,10 +12,11 @@ namespace ComputeSharp.WinUI;
|
||||
public interface IShaderRunner
|
||||
{
|
||||
/// <summary>
|
||||
/// Renders a single frame to a texture.
|
||||
/// Tries to render a single frame to a texture, optionally skipping the frame if needed.
|
||||
/// </summary>
|
||||
/// <param name="texture">The target texture to render the frame to.</param>
|
||||
/// <param name="timespan">The timespan for the current frame.</param>
|
||||
/// <param name="parameter">The input parameter for the frame being rendered.</param>
|
||||
void Execute(IReadWriteTexture2D<Float4> texture, TimeSpan timespan, object? parameter);
|
||||
/// <returns>Whether or not to present the current frame. If <see langword="false"/>, the frame will be skipped.</returns>
|
||||
bool TryExecute(IReadWriteTexture2D<Float4> texture, TimeSpan timespan, object? parameter);
|
||||
}
|
||||
@@ -8,7 +8,8 @@ namespace ComputeSharp.WinUI;
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// An <see cref="IShaderRunner"/> implementation powered by a supplied shader type.
|
||||
/// A simple <see cref="IShaderRunner"/> implementation powered by a supplied shader type.
|
||||
/// All rendered frames produced by this type will always be presented.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of shader to use to render frames.</typeparam>
|
||||
public sealed class ShaderRunner<T> : IShaderRunner
|
||||
@@ -56,7 +57,7 @@ public sealed class ShaderRunner<T> : IShaderRunner
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Execute(IReadWriteTexture2D<Float4> texture, TimeSpan time, object? parameter)
|
||||
public bool TryExecute(IReadWriteTexture2D<Float4> texture, TimeSpan time, object? parameter)
|
||||
{
|
||||
if (this.shaderFactory is Func<TimeSpan, T> shaderFactory)
|
||||
{
|
||||
@@ -66,5 +67,7 @@ public sealed class ShaderRunner<T> : IShaderRunner
|
||||
{
|
||||
GraphicsDevice.Default.ForEach(texture, this.statefulShaderFactory!(time, parameter));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする