From f52fe417e19a9ee213475fa9b4e857f5abe129de Mon Sep 17 00:00:00 2001 From: assiduous Date: Mon, 1 Jun 2020 17:32:54 -0700 Subject: D3D swap chain: checking if DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT flag is supported --- .../include/SwapChainD3DBase.hpp | 28 +++++++++++++++++----- 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'Graphics/GraphicsEngineD3DBase') diff --git a/Graphics/GraphicsEngineD3DBase/include/SwapChainD3DBase.hpp b/Graphics/GraphicsEngineD3DBase/include/SwapChainD3DBase.hpp index 120de712..0389f583 100644 --- a/Graphics/GraphicsEngineD3DBase/include/SwapChainD3DBase.hpp +++ b/Graphics/GraphicsEngineD3DBase/include/SwapChainD3DBase.hpp @@ -187,16 +187,32 @@ protected: // mode (or monitor resolution) will be changed to match the dimensions of the application window. swapChainDesc.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH; + + CComPtr pDXGIFactory; + + HRESULT hr = CreateDXGIFactory1(__uuidof(pDXGIFactory), reinterpret_cast(static_cast(&pDXGIFactory))); + CHECK_D3D_RESULT_THROW(hr, "Failed to create DXGI factory"); + // DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT enables querying a waitable object that can be // used to synchronize presentation with CPU timeline. // The flag is not supported in D3D11 fullscreen mode. if (!(m_FSDesc.Fullscreen && m_pRenderDevice->GetDeviceCaps().DevType == RENDER_DEVICE_TYPE_D3D11)) - swapChainDesc.Flags |= DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT; + { + // We do not need pDXGIFactory3 itself, however DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT flag + // is only supported starting with Windows 8.1, and so is IDXGIFactory3 interface. We query this + // interface to check Windows 8.1. + // Note that we can't use IsWindows8Point1OrGreater because unlike IsWindows8OrGreater, it returns + // false if an application is not manifested for Windows 8.1 or Windows 10, even if the current + // operating system version is Windows 8.1 or Windows 10. + CComPtr pDXGIFactory3; + if (SUCCEEDED(pDXGIFactory->QueryInterface(__uuidof(pDXGIFactory3), reinterpret_cast(static_cast(&pDXGIFactory3))))) + { + swapChainDesc.Flags |= DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT; + } + } + CComPtr pSwapChain1; - CComPtr factory; - HRESULT hr = CreateDXGIFactory1(__uuidof(factory), reinterpret_cast(static_cast(&factory))); - CHECK_D3D_RESULT_THROW(hr, "Failed to create DXGI factory"); #if PLATFORM_WIN32 @@ -208,7 +224,7 @@ protected: FullScreenDesc.Scaling = static_cast(m_FSDesc.Scaling); FullScreenDesc.ScanlineOrdering = static_cast(m_FSDesc.ScanlineOrder); - hr = factory->CreateSwapChainForHwnd(pD3D11DeviceOrD3D12CmdQueue, hWnd, &swapChainDesc, &FullScreenDesc, nullptr, &pSwapChain1); + hr = pDXGIFactory->CreateSwapChainForHwnd(pD3D11DeviceOrD3D12CmdQueue, hWnd, &swapChainDesc, &FullScreenDesc, nullptr, &pSwapChain1); CHECK_D3D_RESULT_THROW(hr, "Failed to create Swap Chain"); { @@ -228,7 +244,7 @@ protected: if (m_FSDesc.Fullscreen) LOG_WARNING_MESSAGE("UWP applications do not support fullscreen mode"); - hr = factory->CreateSwapChainForCoreWindow( + hr = pDXGIFactory->CreateSwapChainForCoreWindow( pD3D11DeviceOrD3D12CmdQueue, reinterpret_cast(m_Window.pCoreWindow), &swapChainDesc, -- cgit v1.2.3