Surface attachment handling is always a bit of a pain, but I don't see anything obviously wrong with this, at least. I do kind of hate having both "is_root" and "is_chain_start", and I suspect that's going to end up being confusing. I haven't looked much into how hard it would be to avoid though. Perhaps different naming or some comments could help? Do we need "detach_clear_flags"? I.e., shouldn't the caps we remove depend purely on the state of the flip chain at detachment time, instead of on prior attachments and detachments? In terms of follow-up, this may be a good opportunity to fold BackBuffer3DAttachmentTest(), BackBufferAttachmentFlipTest(), and DX1_BackBufferFlipTest() into test_flip() and test_surface_attachment(), to the extent those don't already overlap. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/10992#note_141416