diff --git a/src/dxgi.cpp b/src/dxgi.cpp index 05d77519a..beadcfeca 100644 --- a/src/dxgi.cpp +++ b/src/dxgi.cpp @@ -122,6 +122,7 @@ namespace bgfx , m_factory(NULL) , m_adapter(NULL) , m_output(NULL) + , m_tearingSupported(false) { } @@ -389,6 +390,8 @@ namespace bgfx : 0 ; + m_tearingSupported = allowTearing; + DX_RELEASE_I(factory5); } @@ -785,6 +788,11 @@ namespace bgfx #endif // BX_PLATFORM_WINDOWS || BX_PLATFORM_WINRT } + bool Dxgi::tearingSupported() + { + return m_tearingSupported; + } + } // namespace bgfx #endif // BGFX_CONFIG_RENDERER_DIRECT3D11 || BGFX_CONFIG_RENDERER_DIRECT3D12 diff --git a/src/dxgi.h b/src/dxgi.h index b49439ad7..c4dccfa64 100644 --- a/src/dxgi.h +++ b/src/dxgi.h @@ -99,6 +99,9 @@ namespace bgfx /// void trim(); + /// + bool tearingSupported(); + /// void* m_dxgiDll; void* m_dxgiDebugDll; @@ -108,6 +111,7 @@ namespace bgfx FactoryI* m_factory; AdapterI* m_adapter; OutputI* m_output; + bool m_tearingSupported; }; } // namespace bgfx diff --git a/src/renderer_d3d11.cpp b/src/renderer_d3d11.cpp index 25474514c..8f6ab6117 100644 --- a/src/renderer_d3d11.cpp +++ b/src/renderer_d3d11.cpp @@ -2287,7 +2287,12 @@ namespace bgfx { namespace d3d11 if (NULL != m_swapChain && m_needPresent) { - hr = m_swapChain->Present(syncInterval, 0); + uint32_t presentFlags = 0; + if (!syncInterval && (m_dxgi.tearingSupported())) + { + presentFlags |= DXGI_PRESENT_ALLOW_TEARING; + } + hr = m_swapChain->Present(syncInterval, presentFlags); m_needPresent = false; } diff --git a/src/renderer_d3d12.cpp b/src/renderer_d3d12.cpp index 26330ec54..8e782e915 100644 --- a/src/renderer_d3d12.cpp +++ b/src/renderer_d3d12.cpp @@ -1508,7 +1508,19 @@ namespace bgfx { namespace d3d12 HRESULT hr = S_OK; uint32_t syncInterval = !!(m_resolution.reset & BGFX_RESET_VSYNC); - uint32_t flags = 0 == syncInterval ? DXGI_PRESENT_RESTART : 0; + uint32_t flags = 0; + if (syncInterval) + { + flags |= DXGI_PRESENT_RESTART; + } + else + { + if (m_dxgi.tearingSupported()) + { + flags |= DXGI_PRESENT_ALLOW_TEARING; + } + } + for (uint32_t ii = 1, num = m_numWindows; ii < num && SUCCEEDED(hr); ++ii) { FrameBufferD3D12& frameBuffer = m_frameBuffers[m_windows[ii].idx];