Added ComputeShaderPanel.ResolutionScale property
このコミットが含まれているのは:
1 親
9ead13f404
コミット
f0dbf5ce59
2ファイル変更
+79
-9
検索条件に一致するファイルはありません
@@ -1,4 +1,5 @@
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.Toolkit.Diagnostics;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
|
||||
namespace ComputeSharp.WinUI
|
||||
@@ -23,5 +24,37 @@ namespace ComputeSharp.WinUI
|
||||
typeof(IShaderRunner),
|
||||
typeof(ComputeShaderPanel),
|
||||
new PropertyMetadata(null, static (d, e) => ((ComputeShaderPanel)d).shaderRunner = (IShaderRunner?)e.NewValue));
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the resolution scale to be used to render frames.
|
||||
/// This can help achieve higher framerates with more complex shaders.
|
||||
/// </summary>
|
||||
/// <remarks>The accepted range is [0.1 and 1] (default is 1).</remarks>
|
||||
public double ResolutionScale
|
||||
{
|
||||
get => (double)GetValue(ShaderFactoryProperty);
|
||||
set => SetValue(ShaderFactoryProperty, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="DependencyProperty"/> backing <see cref="ResolutionScale"/>.
|
||||
/// </summary>
|
||||
public static readonly DependencyProperty ResolutionScaleProperty = DependencyProperty.Register(
|
||||
nameof(ResolutionScale),
|
||||
typeof(double),
|
||||
typeof(ComputeShaderPanel),
|
||||
new PropertyMetadata(1.0, static (d, e) => ((ComputeShaderPanel)d).shaderRunner = (IShaderRunner?)e.NewValue));
|
||||
|
||||
/// <inheritdoc cref="DependencyPropertyChangedCallback"/>
|
||||
private static void OnResolutionScalePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var @this = (ComputeShaderPanel)d;
|
||||
var resolutionScale = (double)e.NewValue;
|
||||
|
||||
Guard.IsBetweenOrEqualTo(resolutionScale, 0.1, 1.0, nameof(resolutionScale));
|
||||
|
||||
@this.resolutionScale = resolutionScale;
|
||||
@this.OnResize();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,11 @@ namespace ComputeSharp.WinUI
|
||||
/// </summary>
|
||||
private IShaderRunner? shaderRunner;
|
||||
|
||||
/// <summary>
|
||||
/// The resolution scale used to render frames.
|
||||
/// </summary>
|
||||
private double resolutionScale;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="ID3D12Device"/> pointer for the device currently in use.
|
||||
/// </summary>
|
||||
@@ -191,6 +196,46 @@ namespace ComputeSharp.WinUI
|
||||
// Resize the swap chain buffers
|
||||
this.dxgiSwapChain1.Get()->ResizeBuffers(0, 0, 0, DXGI_FORMAT.DXGI_FORMAT_UNKNOWN, 0);
|
||||
|
||||
if (this.resolutionScale == 1.0)
|
||||
{
|
||||
// Retrieve the back buffers for the swap chain
|
||||
fixed (ID3D12Resource** d3D12Resource0 = this.d3D12Resource0)
|
||||
fixed (ID3D12Resource** d3D12Resource1 = this.d3D12Resource1)
|
||||
{
|
||||
_ = dxgiSwapChain1.Get()->GetBuffer(0, FX.__uuidof<ID3D12Resource>(), (void**)d3D12Resource0);
|
||||
_ = dxgiSwapChain1.Get()->GetBuffer(1, FX.__uuidof<ID3D12Resource>(), (void**)d3D12Resource1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
D3D12_RESOURCE_DESC d3D12ResourceDescription;
|
||||
|
||||
// This is a workaround to detect the right scaled resolution for the back buffers.
|
||||
// First, IDXGISwapChain.Resize is called with (0, 0) as parameters for the size: this will cause
|
||||
// it to automatically resize to a 1:1 scaling factor with the available space. Then we get the
|
||||
// first backbuffer and use it to find the current resolution, scale it, and resize again to that.
|
||||
using (ComPtr<ID3D12Resource> d3D12Resource = default)
|
||||
{
|
||||
_ = dxgiSwapChain1.Get()->GetBuffer(0, FX.__uuidof<ID3D12Resource>(), (void**)&d3D12Resource);
|
||||
|
||||
d3D12ResourceDescription = d3D12Resource.Get()->GetDesc();
|
||||
}
|
||||
|
||||
uint
|
||||
scaledWidth = (uint)(d3D12ResourceDescription.Width * this.resolutionScale),
|
||||
scaledHeight = (uint)(d3D12ResourceDescription.Height * this.resolutionScale);
|
||||
|
||||
this.dxgiSwapChain1.Get()->ResizeBuffers(0, scaledWidth, scaledHeight, DXGI_FORMAT.DXGI_FORMAT_UNKNOWN, 0);
|
||||
|
||||
// Finally retrieve the scaled back buffers
|
||||
fixed (ID3D12Resource** d3D12Resource0 = this.d3D12Resource0)
|
||||
fixed (ID3D12Resource** d3D12Resource1 = this.d3D12Resource1)
|
||||
{
|
||||
_ = dxgiSwapChain1.Get()->GetBuffer(0, FX.__uuidof<ID3D12Resource>(), (void**)d3D12Resource0);
|
||||
_ = dxgiSwapChain1.Get()->GetBuffer(1, FX.__uuidof<ID3D12Resource>(), (void**)d3D12Resource1);
|
||||
}
|
||||
}
|
||||
|
||||
// Get the index of the initial back buffer
|
||||
using (ComPtr<IDXGISwapChain3> dxgiSwapChain3 = default)
|
||||
{
|
||||
@@ -199,14 +244,6 @@ namespace ComputeSharp.WinUI
|
||||
this.currentBufferIndex = dxgiSwapChain3.Get()->GetCurrentBackBufferIndex();
|
||||
}
|
||||
|
||||
// Retrieve the back buffers for the swap chain
|
||||
fixed (ID3D12Resource** d3D12Resource0 = this.d3D12Resource0)
|
||||
fixed (ID3D12Resource** d3D12Resource1 = this.d3D12Resource1)
|
||||
{
|
||||
_ = dxgiSwapChain1.Get()->GetBuffer(0, FX.__uuidof<ID3D12Resource>(), (void**)d3D12Resource0);
|
||||
_ = dxgiSwapChain1.Get()->GetBuffer(1, FX.__uuidof<ID3D12Resource>(), (void**)d3D12Resource1);
|
||||
}
|
||||
|
||||
this.texture?.Dispose();
|
||||
|
||||
D3D12_RESOURCE_DESC d3D12Resource0Description = this.d3D12Resource0.Get()->GetDesc();
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする