Skip to content

android: drop A26, A33 and A48 — the game window path returns to upstream - #38

Merged
joshuatam merged 6 commits into
gamenativefrom
refactor/audit-patches
Nov 16, 2026
Merged

joshuatam merged 6 commits into
gamenativefrom
refactor/audit-patches

Conversation

@joshuatam

Copy link
Copy Markdown
Collaborator

What this drops

Three patches that each changed how the compositor decides which window is the game, at a cost that turned out to be larger than what they bought:

patch what it did why it goes
A26 uniform app id forced w->appID = 1 for every window its only real consumer is the app_perf_requests channel, and nothing calls it: no requestAppPerformanceStats and no GAMESCOPE_APP_ID in the app, and the daemon's allowlisted concommands never ask for per-app stats. Meanwhile it made windows_share_app, is_same_app_override_decoration and is_good_override_candidate vacuous
A33 blank while the game window is absent painted a blind at the transitions its premise is A26's damage: "the app-id cannot tell the game's window from the desktop's". With A26 gone the app id distinguishes them again, so 199 lines of commit-surface and binding-time inference are inferring something that is now directly knowable
A48 bring nested app window to front asked winhandler.exe over UDP/7946 to raise any nested child whose class was not explorer.exe/tabtip.exe and whose size was over 1×1 with A26 gone its deny list is the only filter, so any win32 window that maps qualifies — an error dialog, an installer, Steam's login. The app-id test it lost is available again

Removing them leaves the window path at upstream semantics, plus A49 (reaper nudge) and A27/A28 (session lifetime here) — patches about when the session ends, not about which window is real.

Confirmed on device

OMORI (app id 1150690) flashed — game image / black / game image — and stops flashing with these three removed. Verified on the same build, same title, same scene.

That is the strongest argument for the set: the flashing tracked a patch that answers MapNotify, in a session where nothing about the guest's rendering changed.

Risk, stated plainly

A48 is the only one with a functional risk. If something in the wine virtual desktop does not raise a nested game window on its own, removing A48 leaves that window behind the desktop — desktop background on screen, or input not reaching the game. A48's own comment says the app's X11 server already answers every map with WinHandler.bringToFront; if that is live in this route too, A48 was a duplicate and this is pure deletion. Worth one launch per Proton version (9 and 10) on a title that maps a nested child, checking: game appears without the desktop background, input reaches it, rate unchanged.

If it does regress, the fix is the predicate A48 should have had rather than the deny list: raise only when the mapping window shares the app id of the focus, or is guest-owned by the reaper's own test.

Not in this PR

The shim-side spare-ring switch (GN_VKSHIM_NO_SPARES) is a gamenative-drm change and belongs there; it addresses a different flashing signature (an unwritten copy published on alternate presents), not this one.

@utkarshdalal

Copy link
Copy Markdown

Tested this build on a Retroid Pocket 6 (CI artifact from run 43618700810, gamescope version 72b5f2b+, only bin/gamescope swapped, both games on the gamescope display server).

Need for Speed Most Wanted (2012, Steam 1262560): regresses. The game reaches the title screen and stays on "PRESS START". Start, A and Start again on the device's own pad do nothing for over a minute. The app does see the pad (WinHandler: setCurrentController), the game does not.

Control on the shipped binary (f19a452+), same container, same input: the log has nested application window 0x2400001 (nfs13.exe, 1280x720) mapped: bringing it to the front, and the first Start press leaves the title screen and loads into the game.

So A48 is still doing real work under gamescope. The app's WinHandler.bringToFront path does not cover this route. I agree the deny-list filter is too loose, but that needs a tighter predicate (as you suggest in the description), not removal.

Tomb Raider I-III Remastered: fine. Picture, menu and pad input all work without A33, and I did not see the Wine desktop at startup or exit (1 s screenshot spacing at startup, screen recording at exit). One launch only.

OMORI flashing: I don't think these three patches are the cause. A build without A48 still flashed for us in windowed mode (196 of 357 recorded frames), A33 was idle during the flash, and the path that accepts the commits does not read the app id. The flash is the window's own X commits racing the override surface while OMORI is windowed, which is why fullscreen hides it. #37 addresses that. Could you re-check this PR with OMORI in windowed mode?

Suggestion: keep A48 in this PR (or replace it with the narrower predicate) and drop the OMORI claim from the description. A26 and A33 look OK to remove from what I tested, though A33 has only the one Tomb Raider launch behind it.

@utkarshdalal

Copy link
Copy Markdown

On keeping A48 but trimming it: I'd keep the trigger (the map of a nested child, since the patch notes say a later request does nothing) and replace the deny list with three conditions.

  1. Application window only. Same test the app's X11 server uses before it calls WinHandler.bringToFront (Window.isApplicationWindow in DesktopHelper.setFocusedWindow): the window is renderable and its WM_HINTS window group is its own id. That is the main window of a Win32 process. Owned popups, menus, tooltips and dialogs have another window as their group, so they stop qualifying.
  2. Guest owner only. Take the X client's pid from XRes and apply Process::IsGuestProcess, the way A49 does for tracked windows. This replaces the hard-coded explorer.exe / tabtip.exe list, since Wine's own processes fail the guest rule.
  3. Send the window handle. A48 sends only the class name, so winhandler.exe raises some window of that exe. The app's path also sends _NET_WM_HWND after the name (WinHandler.bringToFront(processName, handle)). Reading that property and adding it to the packet raises the exact window that mapped.

On the app-id predicate from the description ("raise only when the mapping window shares the app id of the focus"): I don't think it is available here. The hook runs for maps whose parent is not the root, and those nested children are not compositor windows, so they have no app id to compare. The reaper's guest test (your second suggestion) is condition 2 above.

Open point: I have not checked whether the Steam client's own windows pass the guest rule on real-Steam launches. If they do, condition 1 is the only filter for them.

Test for the result: Most Wanted still takes the pad on the title screen without a touch, and OMORI and Tomb Raider are unchanged.

gn-activate.exe is the helper that makes the guest's window foreground from
inside the wine prefix. WM_ACTIVATE/WM_SETFOCUS can only be raised there, and
under `explorer /desktop=shell` every window is an override-redirect child of
the desktop that wine never activates, so a title comes up inactive and ignores
input until it is clicked.

It ships here rather than in the app's assets because it only exists for
gamescope sessions, and because the payload VERSION then invalidates the app's
staged copy for free: the helper travels with the payload, so a new payload is
exactly when a new helper should be copied into the container prefix.

Built in the same always-rebuild block as the other artifacts -- the payload has
to carry what this run produced, not what happens to be on disk. It is deliberately
not passed to resolve_libs: it is a mingw PE, so it has no bionic NEEDEDs to
resolve, unlike the guest clients next to it.

One new prerequisite follows from this: packaging now needs mingw-w64 on the
host, as it already needs the NDK. tools/build-gn-activate.sh reports which
bitnesses it could build and the packaging step fails loudly if the 32-bit one
is missing, since that is the one a WoW64 prefix runs.
@joshuatam

Copy link
Copy Markdown
Collaborator Author

Two commits on this branch matter for the activation helper, both wired to GameNative/gamenative-drm#69.

14b0405 disable A55 patch — part of the patch audit. A26/A33/A48 already went together; A55's wlserver.cpp edit (dropping hasRepaint in wlserver_oncurserevent) is the last of the same family, and none of the three is needed once the nested window is activated from inside the prefix instead of raised from the compositor.

abe216f android: ship the Win32 activation helper in the gamescope payload — the packaging half:

  • builds target/win32/gn-activate.exe in the always-rebuild block, so the payload carries what this run produced;
  • copies it to bin/gn-activate.exe next to the gn-* clients, deliberately not passed to resolve_libs (a mingw PE has no bionic NEEDEDs);
  • one new host prerequisite: mingw-w64, alongside the NDK.

The helper itself, its --query-fg/--idle-ms modes, and the measurements that show X-level activation does not work are in GameNative/gamenative-drm#69. The app runs the exe from this payload by its Z: path, so nothing is staged into the container prefix.

joshuatam added a commit to joshuatam/GameNative that referenced this pull request Nov 15, 2026
Under `explorer /desktop=shell` the guest's window is an override-redirect child
of the desktop, and wine never activates it: the title comes up with no
foreground window, so injected input has nowhere to land and buttons do nothing
until something clicks the window.

`bin/gn-activate.exe` (GameNative/gamenative-drm#69) fixes that with one Win32
call, which is the only lever that works -- X focus and the EWMH/ICCCM activation
messages are accepted and leave wine's foreground at <none>, measured on RP6 with
NFS Most Wanted. It does not raise or reorder anything; it only sets the
foreground window, then watches for later windows and exits when it has nothing
left to act on.

Spawned once per gamescope session, eight seconds in, so the session's wineserver
exists first. The exe runs from the payload by its `Z:` path, so nothing is copied
into the container prefix.

One requirement follows: the gamescope payload must contain `bin/gn-activate.exe`,
which is what GameNative/gamescope#38 does.
gn-activate.exe is guest-shaped by every test the guest rule applies: a wine
process whose command line names a .exe outside drive_c/windows. It is session
infrastructure, not a guest of the session, and it outlives the title on
purpose -- it sets the foreground window, then watches for later windows before
idling out.

Counting it would hold the session open after the game exits, which is the same
mistake the rule already avoids for the shell: A49 nudges the reaper on guest
window map/unmap so a session ends promptly, and A28 ends it once no guest image
is left. A helper that is still running in that window keeps "no guest image
left" from ever becoming true.

Excluded by basename in IsGuestImage, next to the drive_c/windows test, so both
the per-process rule and the session-wide one share it.
The guest rule counts any wine process naming a .exe outside drive_c/windows, and
that includes the session's own shell: the launch line is
`winhandler.exe "steam.exe"`, so Steam and its helpers are guests by the rule and
outlive the title. "No guest image left" then only becomes true when Steam quits,
which is not when the game does.

So the images that are the session rather than content in it are excluded by
basename: gn-activate.exe (ours, and it outlives the title by design while it
watches for later windows), winhandler.exe, steam.exe, steamwebhelper.exe,
steamhost32.exe, eastub.exe.

The list is a judgement, not a derivation: a launcher that is also the game's UI,
and a title whose image is named like a shell, are the cases it gets wrong. It
also means the session now ends when the game exits with Steam still running --
which is the behaviour the launcher flow was asking for, and the reason the
exclusion exists.
@joshuatam
joshuatam force-pushed the refactor/audit-patches branch from 454d3b5 to 1cf0958 Compare November 15, 2026 16:19
joshuatam added a commit to joshuatam/GameNative that referenced this pull request Nov 15, 2026
Under `explorer /desktop=shell` the guest's window is an override-redirect child
of the desktop, and wine never activates it: the title comes up with no
foreground window, so injected input has nowhere to land and buttons do nothing
until something clicks the window.

`bin/gn-activate.exe` (GameNative/gamenative-drm#69) fixes that with one Win32
call, which is the only lever that works -- X focus and the EWMH/ICCCM activation
messages are accepted and leave wine's foreground at <none>, measured on RP6 with
NFS Most Wanted. It does not raise or reorder anything; it only sets the
foreground window, then watches for later windows and exits when it has nothing
left to act on.

Spawned once per gamescope session, eight seconds in, so the session's wineserver
exists first. The exe runs from the payload by its `Z:` path, so nothing is copied
into the container prefix.

One requirement follows: the gamescope payload must contain `bin/gn-activate.exe`,
which is what GameNative/gamescope#38 does.
@joshuatam
joshuatam merged commit f14eb13 into gamenative Nov 16, 2026
1 check passed
@joshuatam
joshuatam deleted the refactor/audit-patches branch November 16, 2026 14:09
utkarshdalal pushed a commit to utkarshdalal/GameNative that referenced this pull request Nov 16, 2026
…he rendering engine is now open source (#2393)

* gamescope: the present mode comes from the guest, not the container (payload 20261110.2)

On the gamescope route the guest's own request is the present mode that counts:
the shim records what DXVK asks for and forwards it, and the image count is the
shim's to advertise (three, floored) because that is what the surface capabilities
say. A present mode in the container therefore makes the shim declare one the
guest never asked for, and a `WRAPPER_MAX_IMAGE_COUNT` ceiling competes with the
capabilities the guest already read.

`setupXEnvironment` now removes both variables when the display server is not
X11, after the container, best-config, Environments-tab and game-fix merges have
all landed - so the removal covers every source of the value rather than one of
them. The X11 route keeps both, where Mesa's WSI is what consumes them.

Measured on Hades II, same save and scene: the container's `mailbox` declaration
became the guest's own `immediate`, and the swapchain went from four slots to the
three the shim advertises. At the 120 Hz cap that arm costs nothing (the acquire
is limiter-parked, not starved); see docs/performance/06 in gamenative-drm for
the census that decides it.

Also bumps the payload to 20261110.2 and rebuilds `libgamenative_drm.so` from
gamenative-drm's performance work: reference-counted live-inode set, the atomic
request decoded straight out of the payload, caller-owned pollfd buffers, and a
cached JNI method id - 6.04 -> 1.04 allocations per commit, with no CPU claim.

* update payload

* gamescope: the payload carries the LSFG present mode, and the payload is re-stamped

`nativeSetLsfgConfig` gains a `presentMode` argument — 1 for fifo, 0 for
mailbox — so the layer knows which mode generation is served with, instead of
assuming mailbox. The QuickMenu offers those two for generation and nothing
else, and the value comes from the container's `presentMode` extra, which is the
same setting the rest of the launch path reads.

The wire struct grew with it (`LsfgConfig.present_mode`), so the payload
version moves to `20261113.1`: an older payload would reject the longer frame
and the session would get no generation settings at all, silently.

The bundled `libgamenative_drm.so` is rebuilt from gamenative-drm at the head
that carries the release-note pairing and the hidden-slot fixes.

* notices: libgamenative_drm.so is GPL-3.0-or-later, and GNDRM_LOG_VKSHIM is an option

The notice said `libgamenative_drm.so` was proprietary, all rights reserved and
its source undistributed. It is GPL-3.0-or-later — the repository states it in
`Cargo.toml` and names the holder in its README — and the same binary contains
the ICD shim, so it is also the library shipped inside the gamescope payload.
A proprietary notice over a GPL binary is the one error in this file that a
distributor would have to answer for, so it now names the licence, the holder,
the source repository, the build command, and the section 6 source offer.

`GNDRM_LOG_VKSHIM` joins the environment options as a toggle. It turns on the
shim's per-frame lines and the per-session census — `present mode:`,
`proxy commit:`, `lsfg:`, `scanout frame cap:`, `proxy park timeout:` — which is
what a frame-rate report has to quote; a toggle rather than free text because
the shim reads it as a boolean and a typo would silently leave logging off.

* gamescope: 20261114.1 — the daemon names the frame in its release note

Payload re-stamp to `20261114.1`, carrying `libgamenative_drm.so` built from
gamenative-drm `a5b28dc` (the two commits since `292d0dc`).

What the daemon side of that change does, in the app's terms:

- **A released buffer is now reported by the frame it carried**, not by its
  dma-buf inode. `BufferReleased` gained `ticket`, `latch_ns` and `source`; the
  shim mints the ticket, the daemon echoes it, and the shim frees that slot and no
  other. The inode only paired while gralloc handed the same object through to
  SurfaceFlinger — true for Portal 2 on Nova (6 % fallback) and false for Dave on
  the same device (84 %).
- **A session with no release notes still runs.** Four unanswered parks free the
  slot on its fence, which is what took RP6 from 35.9 to 59.8 fps.
- **A 32-byte mark no longer vanishes.** The daemon read the scan-out channel into
  a 24-byte buffer and SOCK_SEQPACKET truncates rather than failing, so every mark
  was dropped before it could be used. Readers use `wire::INBOUND_MAX` now, with a
  test that fails the build if a frame outgrows it.
- **`sf mark:`** prints every ten seconds: hit/order/miss/skew/pending, so a
  session whose marks do not resolve is visible instead of silent.

Measured on Dave the Diver at 1280x720, cap 60, 60 Hz: Nova 60.0 fps
(`by_order` frozen, tickets answering every park), Odin 3 59.7 (`p95=17.2 ms`,
`slow=0/118`, `repeated=0`), RP6 59.8 (on the fail-open, `channel=dead:true`).

The census behind those numbers is `logf!`, so it needs `GNDRM_LOG_VKSHIM=1`; the
`GNDRM_LOG_VKSHIM` toggle in `EnvVarInfo.kt` exists for that and a session without
it is indistinguishable from a pre-census build.

* gamescope: daemon at drm 31737b1 — the release note names the exact frame

Pins `libgamenative_drm.so` to gamenative-drm `31737b1`, the head of
`refactor/vsync`, and nothing else in the payload changes: `20261114.1` still
carries the shim built from that same tree.

Three fixes in the daemon since the last pin (`37e140015` carried `292d0dc`-plus):

- **The release note names the frame the fence describes.** The daemon read the
  replaced buffer's ticket on SurfaceFlinger's binder thread, after the apply, and
  that field is overwritten by the buffer's next publish. A delayed callback could
  therefore name a newer frame, and the shim would free the slot still being
  scanned. The ticket is now snapshotted at the apply, where the buffer cannot be
  published again. Inert on the common path, and invisible in counters by design.
- **The mark fallback is exact, not merely forward.** The next publish must take
  the next ticket; a permissive rule bound a mark to the wrong registration, which
  frees the wrong slot — a tear, not a reordering. `stale`/`resync`/`skew` in
  `sf mark:` now say which of the four outcomes happened, and `resync` is the first
  measurement of `sendmsg` dropping marks under load.
- **The slot's ticket is `AtomicU64`**, stored `Release` against the `Acquire` load
  the acquire path performs under `shared`. As a plain integer the only ordering was
  temporal, and a stale read matching an unconsumed older note freed a slot early.

Measured on RP6 with this build: `sf mark: hit=9617 order=1 miss=7 stale=1 resync=0
skew=0 pending=0`, `tick=12 of ~17 notes`, rate 59.7 unchanged. The exact-next rule
is exercised there; the snapshot is verified by review, not by a counter. Nova and
Odin, where `tick=` runs in the thousands, are still unmeasured on this build.

* gamescope: daemon at drm e6ccad5 — the synced generation ceiling is the leftover

Pins the daemon to gamenative-drm `e6ccad5` (head of `refactor/vsync`).

What moved there: the synced generated ceiling is `min(cap × (m−1), refresh −
acquire)` instead of `min(cap × (m−1), refresh)`. Counting the source frames
outside the panel's budget let a cap 40 ×2 session on 60 Hz plan 80 commits a
second, of which the compositor dropped 20.

**This pin does not ship that rule by itself.** `limits.rs` is in the shim, which
travels in the gamescope payload as `libadrenotools_gamescope.so`; the daemon
carries the release-note and publish path. So the payload needs a rebuild to carry
the new ceiling, and the daemon here is unchanged in content from the previous pin
— only the build stamp and this pin move.

The consequence is deliberate: at 60 Hz, cap 40, ×2 the panel leaves 20 generated
against 40 source frames, half a frame each, which floors to none. Generation does
nothing at any cap above half the refresh; cap 30 ×2 keeps one per source. Tests
and `docs/10` state it rather than leaving it to be discovered.

* gamescope: run the activation helper from the payload

Under `explorer /desktop=shell` the guest's window is an override-redirect child
of the desktop, and wine never activates it: the title comes up with no
foreground window, so injected input has nowhere to land and buttons do nothing
until something clicks the window.

`bin/gn-activate.exe` (GameNative/gamenative-drm#69) fixes that with one Win32
call, which is the only lever that works -- X focus and the EWMH/ICCCM activation
messages are accepted and leave wine's foreground at <none>, measured on RP6 with
NFS Most Wanted. It does not raise or reorder anything; it only sets the
foreground window, then watches for later windows and exits when it has nothing
left to act on.

Spawned once per gamescope session, eight seconds in, so the session's wineserver
exists first. The exe runs from the payload by its `Z:` path, so nothing is copied
into the container prefix.

One requirement follows: the gamescope payload must contain `bin/gn-activate.exe`,
which is what GameNative/gamescope#38 does.

* update payload 20261116.1
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