Search code examples
delaydirect3dtimingdirectx-9

DirectX9: delay between present() and actual screen update


My question is about the delay between calling the present method in DirectX9 and the update appearing on the screen.

On a Windows system, I have a window opened using DirectX9 and update it in a simple way (change the color of the entire window, then call the IDirect3DSwapChain9's present method). I call the swapchain's present method with the flag D3DPRESENT_DONOTWAIT during a vertical blank interval. There is only one buffer associated with the swapchain. I also obtain an external measurement of when the CRT screen I use actually changes color through a photodiode connected to the center of the screen. I obtain this measurement with sub-millisecond accuracy and delay.

What I found was that the changes appear exactly in the third refresh after the call to present(). Thus, when I call present() at the end of the vertical blank, just before the screen refreshing, the change will appear on the screen exactly 2*screen_duration + 0.5*refresh_duration after the call to present().

My question is a general one:

  • in how far can I rely on this delay (changes appearing in the third refresh) being the same on different systems ...
  • ... or does it vary with monitors (leaving aside the response times of LCD and LED monitors)
  • ... or with graphics-cards
  • are there other factors influencing this delay

An additional question:

  • does anybody know a way of determining, within DirectX9, when a change appeared on the screen (without external measurements)

Solution

  • There's a lot of variables at play here, especially since DirectX 9 itself is legacy and is effectively emulated on modern versions of Windows.

    You might want to read Accurately Profiling Direct3D API Calls (Direct3D 9), although that article doesn't directly address presentation.

    On Windows Vista or later, once you call Present to flip the front and back buffers, it's passed off to the Desktop Windows Manager for composition and eventual display. There are a lot of factors at play here including GPU vendor, driver version, OS version, Windows settings, 3rd party driver 'value add' features, full-screen vs. windowed mode, etc.

    In short: Your Mileage May Vary (YMMV) so don't expect your timings to generalize beyond your immediate setup.

    If your application requires knowing exactly when present happens instead of just "best effort" as is more common, I recommend moving to DirectX9Ex, DirectX 11, or DirectX 12 and taking advantage of the DXGI frame statistics.