Add option to enable v-sync in shader panels

このコミットが含まれているのは:
Sergio Pedri committed 2022-01-20 23:04:41 +01:00
1 親 b1fb409f73
コミット 9bc9c97eaa
6ファイル変更
+76 -2

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

+28
ファイルの表示
@@ -135,6 +135,34 @@ partial class AnimatedComputeShaderPanel
@this.swapChainManager.QueueDynamicResolutionModeChange(isDynamicResolutionEnabled);
}
/// <summary>
/// Gets or sets whether vertical sync is enabled.
/// <para>The default value for this property is <see langword="true"/>.</para>
/// </summary>
public bool IsVerticalSyncEnabled
{
get => (bool)GetValue(IsVerticalSyncEnabledProperty);
set => SetValue(IsVerticalSyncEnabledProperty, value);
}
/// <summary>
/// The <see cref="DependencyProperty"/> backing <see cref="IsVerticalSyncEnabled"/>.
/// </summary>
public static readonly DependencyProperty IsVerticalSyncEnabledProperty = DependencyProperty.Register(
nameof(IsVerticalSyncEnabled),
typeof(bool),
typeof(AnimatedComputeShaderPanel),
new PropertyMetadata(true, OnIsVerticalSyncEnabledPropertyChanged));
/// <inheritdoc cref="DependencyPropertyChangedCallback"/>
private static void OnIsVerticalSyncEnabledPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var @this = (AnimatedComputeShaderPanel)d;
var isVerticalSyncEnabled = (bool)e.NewValue;
@this.swapChainManager.QueueVerticalSyncModeChange(isVerticalSyncEnabled);
}
/// <summary>
/// Gets or sets whether or not the rendering is paused.
/// </summary>
+1
ファイルの表示
@@ -50,6 +50,7 @@ public sealed partial class AnimatedComputeShaderPanel : SwapChainPanel
this.swapChainManager.QueueCompositionScaleChange(CompositionScaleX, CompositionScaleY);
this.swapChainManager.QueueResolutionScaleChange(ResolutionScale);
this.swapChainManager.QueueDynamicResolutionModeChange(IsDynamicResolutionEnabled);
this.swapChainManager.QueueVerticalSyncModeChange(IsVerticalSyncEnabled);
if (!IsPaused &&
ShaderRunner is IShaderRunner shaderRunner)
+28
ファイルの表示
@@ -169,4 +169,32 @@ partial class ComputeShaderPanel
@this.swapChainManager.QueueDynamicResolutionModeChange(isDynamicResolutionEnabled);
}
/// <summary>
/// Gets or sets whether vertical sync is enabled.
/// <para>The default value for this property is <see langword="true"/>.</para>
/// </summary>
public bool IsVerticalSyncEnabled
{
get => (bool)GetValue(IsVerticalSyncEnabledProperty);
set => SetValue(IsVerticalSyncEnabledProperty, value);
}
/// <summary>
/// The <see cref="DependencyProperty"/> backing <see cref="IsVerticalSyncEnabled"/>.
/// </summary>
public static readonly DependencyProperty IsVerticalSyncEnabledProperty = DependencyProperty.Register(
nameof(IsVerticalSyncEnabled),
typeof(bool),
typeof(ComputeShaderPanel),
new PropertyMetadata(true, OnIsVerticalSyncEnabledPropertyChanged));
/// <inheritdoc cref="DependencyPropertyChangedCallback"/>
private static void OnIsVerticalSyncEnabledPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var @this = (ComputeShaderPanel)d;
var isVerticalSyncEnabled = (bool)e.NewValue;
@this.swapChainManager.QueueVerticalSyncModeChange(isVerticalSyncEnabled);
}
}
+1
ファイルの表示
@@ -50,6 +50,7 @@ public sealed partial class ComputeShaderPanel : SwapChainPanel
this.swapChainManager.QueueCompositionScaleChange(CompositionScaleX, CompositionScaleY);
this.swapChainManager.QueueResolutionScaleChange(ResolutionScale);
this.swapChainManager.QueueDynamicResolutionModeChange(IsDynamicResolutionEnabled);
this.swapChainManager.QueueVerticalSyncModeChange(IsVerticalSyncEnabled);
if (FrameRequestQueue is IFrameRequestQueue frameRequestQueue &&
ShaderRunner is IShaderRunner shaderRunner)
+11
ファイルの表示
@@ -97,6 +97,17 @@ partial class SwapChainManager<TOwner>
}
}
/// <summary>
/// Queues a change in the vertical sync mode.
/// </summary>
/// <param name="isVerticalSyncEnabled">Whether or not to use vertical sync.</param>
public void QueueVerticalSyncModeChange(bool isVerticalSyncEnabled)
{
ThrowIfDisposed();
this.syncInterval = isVerticalSyncEnabled ? 1u : 0u;
}
/// <summary>
/// Queues a resize operation.
/// </summary>
+7 -2
ファイルの表示
@@ -175,6 +175,11 @@ internal sealed unsafe partial class SwapChainManager<TOwner> : NativeObject
/// </summary>
private volatile bool isDynamicResolutionEnabled;
/// <summary>
/// The flags to enable or disable vertical sync.
/// </summary>
private volatile uint syncInterval;
/// <summary>
/// The <see cref="Stopwatch"/> instance tracking time since the first rendered frame.
/// </summary>
@@ -388,7 +393,7 @@ internal sealed unsafe partial class SwapChainManager<TOwner> : NativeObject
private unsafe partial void OnPresent()
{
// Wait for the swap chain to be ready for presenting
_ = Win32.WaitForSingleObjectEx(frameLatencyWaitableObject, 1000, true);
_ = Win32.WaitForSingleObjectEx(frameLatencyWaitableObject, Win32.INFINITE, true);
using ComPtr<ID3D12Resource> d3D12Resource = default;
@@ -455,7 +460,7 @@ internal sealed unsafe partial class SwapChainManager<TOwner> : NativeObject
this.d3D12CommandQueue.Get()->Signal(this.d3D12Fence.Get(), updatedFenceValue).Assert();
// Present the new frame
this.dxgiSwapChain3.Get()->Present(0, 0).Assert();
this.dxgiSwapChain3.Get()->Present(SyncInterval: this.syncInterval, 0).Assert();
if (updatedFenceValue > this.d3D12Fence.Get()->GetCompletedValue())
{