變數重新整理速率顯示
可變重新整理速率顯示需要啟用 撕裂,這也稱為「vsync-off」支援。
可變重新整理速率顯示/Vsync 關閉
藉由在建立和呈現交換鏈結時設定特定旗標,可達成對變數重新整理速率顯示的支援。
若要使用此功能,應用程式用戶必須在已安裝 KB3156421 或年度更新的 Windows 10 系統上。 此功能適用於所有版本的 Direct3D 11 和 12,使用 DXGI_SWAP_EFFECT_FLIP_* 交換效果。
若要將 vsync-off 支援新增至您的應用程式,您可以參考 Direct3D 12、D3D12Fullscreen 的完整執行範例(請參閱 工作範例)。 範例程式代碼中也有一些未明確指出的點,但您需要注意。
- ResizeBuffers (或 ResizeBuffers1) 必須有相同的交換鏈結建立旗標 (DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING) 傳遞給它,Present (或 Present1)。
- DXGI_PRESENT_ALLOW_TEARING只能與同步間隔 0 搭配使用。 如果使用同步間隔 0 時,如果 CheckFeatureSupport 報告支援撕裂 且 應用程式處於視窗模式,包括無框線全螢幕模式,建議一律傳遞此撕裂旗標。 如需詳細資訊,請參閱 DXGI_PRESENT 常數。
- 停用 vsync 不一定無法擷取您的幀速率:開發人員也需要確定 Present 呼叫不會受到其他計時事件節流處理(例如 XAML 型應用程式中的
CompositionTarget::Rendering
事件)。
下列程式代碼會回顧一些您需要新增至應用程式的重要部分。
//--------------------------------------------------------------------------------------------------------
// Check Tearing Support
//--------------------------------------------------------------------------------------------------------
// Determines whether tearing support is available for fullscreen borderless windows.
void DXSample::CheckTearingSupport()
{
// Rather than create the 1.5 factory interface directly, we create the 1.4
// interface and query for the 1.5 interface. This will enable the graphics
// debugging tools which might not support the 1.5 factory interface.
ComPtr<IDXGIFactory4> factory4;
HRESULT hr = CreateDXGIFactory1(IID_PPV_ARGS(&factory4));
BOOL allowTearing = FALSE;
if (SUCCEEDED(hr))
{
ComPtr<IDXGIFactory5> factory5;
hr = factory4.As(&factory5);
if (SUCCEEDED(hr))
{
hr = factory5->CheckFeatureSupport(DXGI_FEATURE_PRESENT_ALLOW_TEARING, &allowTearing, sizeof(allowTearing));
}
}
m_tearingSupport = SUCCEEDED(hr) && allowTearing;
}
//--------------------------------------------------------------------------------------------------------
// Set up swapchain properly
//--------------------------------------------------------------------------------------------------------
// It is recommended to always use the tearing flag when it is supported.
swapChainDesc.Flags = m_tearingSupport ? DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING : 0;
//--------------------------------------------------------------------------------------------------------
// Present
//--------------------------------------------------------------------------------------------------------
UINT presentFlags = (m_tearingSupport && m_windowedMode) ? DXGI_PRESENT_ALLOW_TEARING : 0;
// Present the frame.
ThrowIfFailed(m_swapChain->Present(0, presentFlags));
相關主題