VK-PRESENTER-SURFACE: recover a lost presentation surface #489

Closed
bobcatchris wants to merge 1 commit from upstream-pr/489 into main
bobcatchris commented 2026-11-24 06:14:13 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by bobcatchris on 2026-11-24T06:14:13Z.


Claimed in the coordination issue as: VK-PRESENTER-SURFACE

What and why

The Xbox Vulkan presenter could lose its WSI surface during format enumeration, swapchain creation, or swapchain replacement. The old code only handled surface loss during acquire; a lost surface found during setup left the presenter unusable, and a replacement could leave later presents aimed at the old handle.

This checks the result of every surface query and swapchain creation, marks the surface lost on VK_ERROR_SURFACE_LOST_KHR, and defers presentation until the retained recreate callback supplies a fresh surface. The presenter test injects lost startup and replacement surfaces and verifies that presentation resumes with matching pixels.

Carried from the source patch and measurements by @Sigtryggur-Mani-Gudmundsson:
github.com/Sigtryggur-Mani-Gudmundsson/graphics-runtime-patches@33ab48d3ea/README.md (recovering-a-lost-presentation-surface)

No game data, keys, or decryption are included.

Tested

  • Built vk_presenter_sync_test with CMake/Ninja, RelWithDebInfo.
  • Patched source + patched test: passes, including recovered lost startup and replacement surfaces, 128x96 pixels matched.
  • Unpatched main source + patched test: fails at presenter.ok(), proving the regression test catches the bug.
  • Unpatched main source + old test: passes, so the new failure comes from the added lost-surface cases.
  • A full runtime build in this shell hits an unrelated toolchain issue (clang++ receiving MSVC flags such as /utf-8 and /W4); the targeted presenter target builds and runs cleanly.
  • git diff --check clean.
  • Security sweep of the diff: 0 hits.

Source report measured the same fix on an RTX 4070 Ti under Wine/XWayland with 12,288 of 12,288 pixels matching after recovery.

GPUs tested: AMD Radeon RX 7900 XTX, driver 32.0.32029.2010, Windows 11; source report used NVIDIA GeForce RTX 4070 Ti under Wine/XWayland

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly.
  • One topic.
  • No game data, keys or decryption.
  • Regression test added for the lost-surface cases.
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5467128888 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/489). Originally posted by [bobcatchris](https://github.com/bobcatchris) on 2026-11-24T06:14:13Z. --- Claimed in the coordination issue as: VK-PRESENTER-SURFACE ### What and why The Xbox Vulkan presenter could lose its WSI surface during format enumeration, swapchain creation, or swapchain replacement. The old code only handled surface loss during acquire; a lost surface found during setup left the presenter unusable, and a replacement could leave later presents aimed at the old handle. This checks the result of every surface query and swapchain creation, marks the surface lost on `VK_ERROR_SURFACE_LOST_KHR`, and defers presentation until the retained recreate callback supplies a fresh surface. The presenter test injects lost startup and replacement surfaces and verifies that presentation resumes with matching pixels. Carried from the source patch and measurements by @Sigtryggur-Mani-Gudmundsson: https://github.com/Sigtryggur-Mani-Gudmundsson/graphics-runtime-patches/blob/33ab48d3ea90f9925351aeee8708181a71fb9634/README.md#recovering-a-lost-presentation-surface No game data, keys, or decryption are included. ### Tested - Built `vk_presenter_sync_test` with CMake/Ninja, RelWithDebInfo. - Patched source + patched test: passes, including `recovered lost startup and replacement surfaces, 128x96 pixels matched`. - Unpatched `main` source + patched test: fails at `presenter.ok()`, proving the regression test catches the bug. - Unpatched `main` source + old test: passes, so the new failure comes from the added lost-surface cases. - A full runtime build in this shell hits an unrelated toolchain issue (`clang++` receiving MSVC flags such as `/utf-8` and `/W4`); the targeted presenter target builds and runs cleanly. - `git diff --check` clean. - Security sweep of the diff: 0 hits. Source report measured the same fix on an RTX 4070 Ti under Wine/XWayland with 12,288 of 12,288 pixels matching after recovery. GPUs tested: AMD Radeon RX 7900 XTX, driver 32.0.32029.2010, Windows 11; source report used NVIDIA GeForce RTX 4070 Ti under Wine/XWayland AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly. - [x] One topic. - [x] No game data, keys or decryption. - [x] Regression test added for the lost-surface cases.
moffington commented 2026-11-24 06:28:22 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by moffington on 2026-11-24T06:28:22Z.


Tested de191a94 on an RTX 3060 using Win32 Vulkan under Wine 11.20. vk_presenter_sync_test passed, with all 128×96 capture pixels matching after recovery. The same test against the merge-base presenter (8f481cf1) failed at presenter.ok() during startup.

I also injected a second VK_ERROR_SURFACE_LOST_KHR during setup of the replacement surface. The presenter destroyed that surface, kept read_back() unavailable until recovery, and resumed presenting with an exact pixel match on the first successful frame.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7123968249 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/489#issuecomment-7123968249). Originally posted by [moffington](https://github.com/moffington) on 2026-11-24T06:28:22Z. --- Tested de191a94 on an RTX 3060 using Win32 Vulkan under Wine 11.20. vk_presenter_sync_test passed, with all 128×96 capture pixels matching after recovery. The same test against the merge-base presenter (8f481cf1) failed at presenter.ok() during startup. I also injected a second VK_ERROR_SURFACE_LOST_KHR during setup of the replacement surface. The presenter destroyed that surface, kept read_back() unavailable until recovery, and resumed presenting with an exact pixel match on the first successful frame.
bobcatchris commented 2026-11-24 23:42:44 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by bobcatchris on 2026-11-24T23:42:44Z.


Rebased on current main. Verified on RX 7900 XTX with Vulkan validation: vk_presenter_sync and d3d12_present both pass; no-game-data and security checks clean.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7147709965 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/489#issuecomment-7147709965). Originally posted by [bobcatchris](https://github.com/bobcatchris) on 2026-11-24T23:42:44Z. --- Rebased on current main. Verified on RX 7900 XTX with Vulkan validation: vk_presenter_sync and d3d12_present both pass; no-game-data and security checks clean.
zmasi commented 2026-11-29 00:31:00 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-29T00:31:00Z.


#489 | head c0d7bd3966 (merged cleanly with main 829530dbd0 — no conflicts on current main) | ctest --test-dir runtime/build -C RelWithDebInfo -R "^(vk_presenter_sync|d3d12_present)$" --output-on-failure (LEONIDA_VK_VALIDATION=1) | red on main: building vk_presenter_sync_test against main's runtime/src/vulkan_present.h fails vk_presenter_sync at line 300: presenter.ok() under injected startup VK_ERROR_SURFACE_LOST_KHR | green on PR+main: 2/2 CTests (vk_presenter_sync — presenter sync: recovered lost startup and replacement surfaces, 128x96 pixels matched, d3d12_present — 70 frames cleared and presented through the Xbox-ABI proxy on Vulkan) pass in 3.31 s on RTX 3090 with 0 Khronos validation errors; check_no_game_data.py 0 violations | Windows 11, MSVC 19.44, RTX 3090, Vulkan SDK 1.4.363.1 | AI-assisted: yes

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7248166305 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/489#issuecomment-7248166305). Originally posted by [zmasi](https://github.com/zmasi) on 2026-11-29T00:31:00Z. --- #489 | head c0d7bd396686c61d308ae1583a6e65c15d876fc2 (merged cleanly with main 829530dbd0196aa817dbec74aaafc79407b94b57 — no conflicts on current `main`) | `ctest --test-dir runtime/build -C RelWithDebInfo -R "^(vk_presenter_sync|d3d12_present)$" --output-on-failure` (`LEONIDA_VK_VALIDATION=1`) | red on main: building `vk_presenter_sync_test` against `main`'s `runtime/src/vulkan_present.h` fails `vk_presenter_sync` at `line 300: presenter.ok()` under injected startup `VK_ERROR_SURFACE_LOST_KHR` | green on PR+main: `2/2` CTests (`vk_presenter_sync` — `presenter sync: recovered lost startup and replacement surfaces, 128x96 pixels matched`, `d3d12_present` — `70 frames cleared and presented through the Xbox-ABI proxy on Vulkan`) pass in `3.31 s` on RTX 3090 with `0` Khronos validation errors; `check_no_game_data.py` `0` violations | Windows 11, MSVC 19.44, RTX 3090, Vulkan SDK 1.4.363.1 | AI-assisted: yes
enlight3d commented 2026-11-29 08:57:54 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by enlight3d on 2026-11-29T08:57:54Z.


Validation run of this PR on a Windows PC with a real GPU.

  • PR head: c0d7bd3966
  • main: 54b2a81e95
  • Tested merged: yes, git merge --no-ff of the PR head into main was clean.

Commands (RelWithDebInfo, Ninja, LEONIDA_REQUIRE_VULKAN=ON):

git fetch origin pull/489/head:pr-489
git checkout --detach origin/main && git merge --no-edit --no-ff pr-489
cmake -S runtime -B runtime/build -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLEONIDA_REQUIRE_VULKAN=ON
cmake --build runtime/build -j 8 --target vk_presenter_sync_test gta6rt
ctest -R "^vk_presenter_(sync|sparse_capture)$" --output-on-failure -j1
  • Green: 2/2 passed (neither skipped). vk_presenter_sync prints recovered lost startup and replacement surfaces, 128x96 pixels matched and ends ok.
  • Red (behavioural): the PR's test kept, runtime/src/vulkan_present.h reverted to main (the test still builds). vk_presenter_sync exits 1 at line 300: presenter.ok(), the startup case with VK_ERROR_SURFACE_LOST_KHR on the first surface formats query. vk_presenter_sparse_capture (same executable, --sparse-capture) passes with and without the change, as expected.
  • Link: no new imports vs main (dumpbin /imports of gta6rt.exe, 703 DLL!symbol entries, identical to a main build).

Machine: RTX 3090 24 GB, NVIDIA 621.40, Windows 11 Pro 10.0.26300, MSVC 19.44.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7253445975 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/489#issuecomment-7253445975). Originally posted by [enlight3d](https://github.com/enlight3d) on 2026-11-29T08:57:54Z. --- Validation run of this PR on a Windows PC with a real GPU. - PR head: c0d7bd396686c61d308ae1583a6e65c15d876fc2 - main: 54b2a81e95c470c953ddee6177fd6255cbaf041d - Tested merged: yes, `git merge --no-ff` of the PR head into main was clean. Commands (RelWithDebInfo, Ninja, `LEONIDA_REQUIRE_VULKAN=ON`): ``` git fetch origin pull/489/head:pr-489 git checkout --detach origin/main && git merge --no-edit --no-ff pr-489 cmake -S runtime -B runtime/build -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLEONIDA_REQUIRE_VULKAN=ON cmake --build runtime/build -j 8 --target vk_presenter_sync_test gta6rt ctest -R "^vk_presenter_(sync|sparse_capture)$" --output-on-failure -j1 ``` - Green: 2/2 passed (neither skipped). `vk_presenter_sync` prints `recovered lost startup and replacement surfaces, 128x96 pixels matched` and ends `ok`. - Red (behavioural): the PR's test kept, `runtime/src/vulkan_present.h` reverted to main (the test still builds). `vk_presenter_sync` exits 1 at `line 300: presenter.ok()`, the startup case with `VK_ERROR_SURFACE_LOST_KHR` on the first surface formats query. `vk_presenter_sparse_capture` (same executable, `--sparse-capture`) passes with and without the change, as expected. - Link: no new imports vs main (`dumpbin /imports` of `gta6rt.exe`, 703 DLL!symbol entries, identical to a main build). Machine: RTX 3090 24 GB, NVIDIA 621.40, Windows 11 Pro 10.0.26300, MSVC 19.44.
bobcatchris commented 2026-11-29 18:37:07 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by bobcatchris on 2026-11-29T18:37:07Z.


Rebased cleanly onto main (4755667f5 -> 2256ec1b6) with zero conflicts.

  • Local verification (Windows 11 10.0.26200, MSVC 19.39.33519, AMD Radeon RX 7900 XTX gfx1100, driver 32.0.32029.2010):
    • ctest --test-dir runtime/build -R "^vk_presenter_sync$" -> PASS (0.66 s).
    • python -I scripts/check_no_game_data.py runtime/src/vulkan_present.h runtime/test/vk_presenter_sync_test.cpp -> clean.
  • AI-assisted: Antigravity (Gemini 4 Neon).
<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7260624247 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/489#issuecomment-7260624247). Originally posted by [bobcatchris](https://github.com/bobcatchris) on 2026-11-29T18:37:07Z. --- Rebased cleanly onto `main` (`4755667f5` -> `2256ec1b6`) with zero conflicts. - Local verification (Windows 11 `10.0.26200`, MSVC `19.39.33519`, AMD Radeon RX 7900 XTX `gfx1100`, driver `32.0.32029.2010`): - `ctest --test-dir runtime/build -R "^vk_presenter_sync$"` -> PASS (0.66 s). - `python -I scripts/check_no_game_data.py runtime/src/vulkan_present.h runtime/test/vk_presenter_sync_test.cpp` -> clean. - AI-assisted: Antigravity (Gemini 4 Neon).
bobcatchris commented 2026-11-29 18:50:12 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by bobcatchris on 2026-11-29T18:50:12Z.


Temporarily closing to free an open-PR slot for fresh d3d12 fixes; rebased branch presenter-surface-recovery (2256ec1b6) remains intact and can be reopened anytime.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7260797454 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/489#issuecomment-7260797454). Originally posted by [bobcatchris](https://github.com/bobcatchris) on 2026-11-29T18:50:12Z. --- Temporarily closing to free an open-PR slot for fresh d3d12 fixes; rebased branch presenter-surface-recovery (2256ec1b6) remains intact and can be reopened anytime.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
ProjectLeonida/mandy!489
No description provided.