I did a bit more testing and it looks like detach_clear_flags is needed, more so, when front / back flags are added at attach (without a complication of added flags on detach) whether it will be cleared or not depends on initial surface caps. So it seems to me, while the whole logic adding or removing those flags is convoluted and doesn't always make much sense to me, the invariant is that whatever flags were added through attach / detach mechanics they are going to be removed when the surface goes off the chain (which is currently not the case in my patch; it should or to detach_clear_flags in ddraw_surface_attach_surface and also exclude pre-existing flags from that). I am yet to finalize the change and merge the tests. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/10992#note_141482