Fix blocking presents in borderless windowed flip modes

This commit is contained in:
Cameron Gutman
2022-04-15 23:21:52 -05:00
parent 62136a1a96
commit fd563726f0
+15 -20
View File
@@ -602,20 +602,10 @@ bool DXVA2Renderer::initializeDevice(SDL_Window* window, bool enableVsync)
// to reduce latency by avoiding double v-syncing. // to reduce latency by avoiding double v-syncing.
d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
// If V-sync is enabled (not rendering faster than display), // D3DSWAPEFFECT_FLIPEX requires at least 2 back buffers to allow us to
// we can use FlipEx for more efficient swapping. // continue while DWM is waiting to render the surface to the display.
if (enableVsync) { d3dpp.SwapEffect = D3DSWAPEFFECT_FLIPEX;
// D3DSWAPEFFECT_FLIPEX requires at least 2 back buffers to allow us to d3dpp.BackBufferCount = 2;
// continue while DWM is waiting to render the surface to the display.
d3dpp.SwapEffect = D3DSWAPEFFECT_FLIPEX;
d3dpp.BackBufferCount = 2;
}
else {
// With V-sync off, we won't use FlipEx because that will block while
// DWM is waiting to render our surface (effectively behaving like V-Sync).
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferCount = 1;
}
m_BlockingPresent = false; m_BlockingPresent = false;
@@ -679,12 +669,17 @@ bool DXVA2Renderer::initializeDevice(SDL_Window* window, bool enableVsync)
return false; return false;
} }
hr = m_Device->SetMaximumFrameLatency(1); // We must not call this for flip swapchains. It will counterintuitively
if (FAILED(hr)) { // increase latency by forcing our Present() to block on DWM even when
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, // using D3DPRESENT_INTERVAL_IMMEDIATE.
"SetMaximumFrameLatency() failed: %x", if (d3dpp.SwapEffect != D3DSWAPEFFECT_FLIPEX) {
hr); hr = m_Device->SetMaximumFrameLatency(1);
return false; if (FAILED(hr)) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"SetMaximumFrameLatency() failed: %x",
hr);
return false;
}
} }
return true; return true;