0

What happens if the application is in the middle of drawing to the buffer(d3d surface) and the DWM need the buffer to redraw the screen or vice versa?

Is there any synchronization mechanism available?

alice
  • 2,547
  • 4
  • 24
  • 30

1 Answers1

1

Swap chains always have two or more buffers, and at any particular time, DWM owns one of them. If a new frame is not Present()ed by the app by the time a v-blank occurs, DWM redraws the last frame using the buffer it already has. Synchronization can be achieved by saturating the present queue (after 3 or so calls, the next one will block until v-blank), or by manually calling WaitForVBlank. In Windows 8.1, a more robust mechanism is available using IDXGISwapChain2::GetFrameLatencyWaitableObject. There is no way to force DWM to wait for the app since that would hang the whole OS UI.

MooseBoys
  • 6,641
  • 1
  • 19
  • 43
  • 1
    After posting the question, I did some more googling and found [this](http://blogs.msdn.com/b/greg_schechter/archive/2006/03/10/549310.aspx) and [this](http://stackoverflow.com/questions/1840516/is-double-buffering-required-with-desktop-composition-enabled) post. They say the window can be rendered by DWM in the middle of updating it, so "structural tearing" can happen. Is that only relavent to some old versions of Windows? – alice Jan 17 '14 at 13:58
  • @alice It looks like both those links acknowledge "structural tearing" as Presenting in the middle of rendering, e.g. `DrawTriangle(); Present(); DrawRect();` Obviously, if the intent was for both the triangle and rectangle to appear simultaneously, this call pattern won't produce the right effect. That's just bad app logic though. – MooseBoys Jan 17 '14 at 19:22