Skip to content

icd_shim: the binding belongs to the first commit, and the id is re-resolved when the first answer was a guess - #65

Merged
utkarshdalal merged 1 commit into
masterfrom
suggest/bind-position
Nov 10, 2026
Merged

utkarshdalal merged 1 commit into
masterfrom
suggest/bind-position

Conversation

@joshuatam

@joshuatam joshuatam commented Nov 10, 2026 •

Copy link
Copy Markdown
Collaborator

One commit on top of master. It carries the bind-at-first-commit change and the surface-destroy handling that #64 proposes, plus the part that is new here — the id in the binding. Self-contained, so it can be read or landed without waiting on #64.

The binding belongs to the first commit

gamescope keeps one override surface per X window and a new binding retires the previous holder, so a binding sent at vkCreateXlibSurfaceKHR gives the window to any surface that merely exists. The Epic overlay creates a D3D11 device and swapchain on a child of the game's window only to find Present, never presents, and destroys it 7 ms later — the child resolves to the same top-level, so that throwaway surface took the game's window, the game's later commits sat in the pending list with their buffers locked, and the next acquire waited forever on a black screen.

The binding now goes out right before a swapchain's first commit, in that flush and before the attach, once per swapchain (worker, inline and generated-frame paths). A surface that never paints never takes the window. gamescope ignores a repeat from the resource that already holds the window, so a swapchain recreated on the same surface costs nothing.

vkDestroySurfaceKHR sends gamescope_swapchain.destroy and then wl_surface.destroy; both used to be skipped by freeing only the client proxies. The order is load-bearing: the first nulls wl_surface_info->x11_surface, so the second skips wlserver_x11_surface_info_finish() and the window keeps its Xwayland main surface. Reversed, the destroy finishes the window's surface info — main_surface null, wl_id zero — for the rest of the session.

The id is a separate question, and it was still decided too early

resolve_override_target runs at surface creation because a surface has to answer caps, and surface_extent reads the window's live size. On its legitimate path that is not a guess: the named window's root-child ancestor is a full-size window — under wine explorer /desktop=shell, the one desktop window every guest window nests inside — and nothing about it can change.

On its fallback path it is a guess: the ancestor is degenerate (Dishonored nesting under a 1×1 override-redirect helper) and the target comes from pid, class, input focus and _NET_ACTIVE_WINDOW, read from a tree the guest has not drawn into yet. #64 moved the bind past that moment; the id decision should move with it.

So the resolution reports its provenance — OverrideTarget { window, provisional } — GnSurface keeps the XID winex11 named beside the one resolved from it, and bind_window_at_first_commit re-asks once when the answer was provisional, at the first instant there is evidence. The re-resolved id replaces window, so later caps calls and later swapchains agree with it, and the log names both ids when they differ. A guest on the legitimate path pays one bool and no X round trip.

Change

  • icd_shim/src/x11.rs — OverrideTarget { window, provisional }; the rule reports whether it guessed; the host test asserts both, and that a legitimate ancestor is not marked provisional.
  • icd_shim/src/proxy.rs — bind at first commit; GnSwapchain.window_bound; GnSurface.named_window / window_provisional; the re-ask; swapchain.destroy + wl_surface.destroy on surface destroy.
  • icd_shim/src/wlproto.rs — swapchain_destroy, surface_destroy.
  • docs/13 step 4 — which decision is made when and why, and the destroy order.

Testing

Odin 3 (8 Gen 2 / Adreno 830), Android 13, payload 20261110.1 (shim dd0cf2bb, the build of this commit), wine explorer /desktop=shell,1280x720, gamescope display, Epic overlay enabled on both titles, GNDRM_LOG_VKSHIM=1.

Yooka-Laylee (Epic) — two surfaces for one top-level, one owner

override target: named=0x1400043 ancestor=0x600004 1280x720 -> 0x600004 (legitimate; unchanged)
override: XID 0x1400043 -> gamescope override surface on 0x600004 (default route; guest GDI/2D not composited)
override target: named=0x1400055 ancestor=0x600004 1280x720 -> 0x600004 (legitimate; unchanged)
override: XID 0x1400055 -> gamescope override surface on 0x600004 (default route; guest GDI/2D not composited)
override: swapchain 0xb400007889064450 binds surface 0xb4000078e902e510 to XID 0x600004 at its first commit

Two surfaces created for the same window, one bind. The second never took the window because it never painted — the case that produced a black screen before. re-resolved: 0, because the ancestor is the full-size desktop window and the legitimate branch was taken.

fps 59.9–61.0 over 2 min 30 s, GPU 79–82 %, cpu 33–42 %
stall signatures (in_flight≥2, acquire timeout, RELEASE_TIMEOUT): 0
session-blank: 3 transitions, all at startup (see gamescope #36)

FINAL FANTASY VII REMAKE INTERGRADE (Epic, vkd3d/D3D12) — a surface that never binds, and a swapchain recreate

override: proxy surface 0x…8b459010 (own wl_surface … for XID 0x1400019, bound at its first present)
override: proxy surface 0x…8b45c250 (own wl_surface … for XID 0x1400066, bound at its first present)
override: swapchain 0x…fa70 binds surface 0x…c250 to XID 0x600004 at its first commit
proxy swapchain destroyed: sc=0x…fa70 1280x720 presents=1 commits=1
override: swapchain 0x…ad50 binds surface 0x…c250 to XID 0x600004 at its first commit

Surface …9010 never binds at all — created for the game's window, it never painted, so it never took it. The swapchain was then destroyed and recreated on the same surface: the window was not unbound (the proxy lives on the surface), the recreate re-bound, and gamescope ignored it for the resource already holding the window.

fps 30.0 with LIMIT -- (the title's own cap), GPU 78–83 %, cpu 8 %  ← CPU idle, no slot starvation
stall signatures: 0 · gamescope Error/Warn: 0 in either log · re-resolved: 0

Both sessions ended through Back → QuickMenu → Exit.

Build: ./tools/build-android.sh clean, check-exports.sh PASS, clippy -D warnings clean on --all-targets, cargo test -p adrenotools_gamescope 124 passed.

Not tested

A guest that destroys its Vulkan surface mid-session while its window lives — a DXVK/vkd3d device loss. That is the only path that reaches the A33 gap branch, and neither title did it here.

…d is re-resolved when the first answer was a guess

Where the binding goes, and where the id that goes in it comes from, are two
different questions and they have two different answers.

The binding belongs to the first commit. gamescope keeps one override surface
per X window and a new binding retires the previous holder, so a binding sent at
`vkCreateXlibSurfaceKHR` gives the window to any surface that exists, whether
or not it ever paints: the Epic overlay creates a D3D11 device and swapchain on
a child of the game's window only to find `Present`, destroys it 7 ms later, and
never presents. The child resolves to the same top-level, so that throwaway
surface took the game's window; the game's later commits then sat in
gamescope's pending list with their buffers locked, all five images stayed in
flight and the next acquire waited forever on a black screen. The binding now
goes out right before a swapchain's first commit, in that flush and before the
attach, once per swapchain. gamescope ignores a repeat from the resource that
already holds the window, so a swapchain recreated on the same surface (resize,
present-mode change) costs nothing.

`vkDestroySurfaceKHR` now sends `gamescope_swapchain.destroy` and then
`wl_surface.destroy`, both of which the client used to skip by freeing only its
proxies. The order is load-bearing: the first nulls
`wl_surface_info->x11_surface`, so the second skips
`wlserver_x11_surface_info_finish()` and the window keeps its Xwayland main
surface. Reversed, the destroy finishes the window's surface info — main_surface
null, wl_id zero — for the rest of the session.

The id is a second question. `resolve_override_target` runs at surface creation
because a surface has to answer caps and `surface_extent` reads the window's live
size. On its legitimate path that is not a guess: the named window's root-child
ancestor is a full-size window — under `wine explorer /desktop=shell`, the one
desktop window every guest window nests inside — and nothing about it changes.
On its fallback path it is a guess: the ancestor is degenerate (Dishonored
nesting under a 1x1 override-redirect helper) and the target comes from pid,
class, input focus and `_NET_ACTIVE_WINDOW`, read from a tree the guest has not
drawn into yet.

So the resolution now reports its provenance, `OverrideTarget { window,
provisional }`, `GnSurface` keeps the XID winex11 named beside the one resolved
from it, and `bind_window_at_first_commit` re-asks when the answer was
provisional — once per swapchain, at the first instant there is evidence, with
the re-resolved id replacing `window` so later caps calls and later swapchains
agree. The log names both ids when they differ. A guest on the legitimate path
pays one bool and no X round trip.

docs/13 step 4 states which decision is made when and why, and records the
destroy order.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants