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

Open
github-bot wants to merge 1 commit from github-bot/gh-489 into main AGit
Owner

@⁠bobcatchris on GitHub · 2026-11-24 06:14 UTC · original
bobcatchris:presenter-surface-recovery → main · +103 −28 · 2 files · 1 commits · open

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.
**@⁠bobcatchris** on GitHub · 2026-11-24 06:14 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/489) `bobcatchris:presenter-surface-recovery` → `main` · +103 −28 · 2 files · 1 commits · open 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.
Handle VK_ERROR_SURFACE_LOST_KHR from swapchain setup and replacement WSI queries by marking the surface lost and waiting for the retained recreate callback, instead of presenting through a stale handle.

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

AI-assisted.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:03:51 +00:00
Author
Owner

@⁠moffington on GitHub · 2026-11-24 06:28 UTC · original

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.

**@⁠moffington** on GitHub · 2026-11-24 06:28 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/489#issuecomment-7123968249) 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.
Author
Owner

@⁠bobcatchris on GitHub · 2026-11-24 23:42 UTC · original

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.

**@⁠bobcatchris** on GitHub · 2026-11-24 23:42 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/489#issuecomment-7147709965) 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.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/489/head:github-bot/gh-489'
git switch 'github-bot/gh-489'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-489'
git switch 'github-bot/gh-489'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-489'
git switch 'github-bot/gh-489'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-489'
git switch 'main'
git merge --squash 'github-bot/gh-489'
git switch 'main'
git merge --ff-only 'github-bot/gh-489'
git switch 'main'
git merge 'github-bot/gh-489'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.