Skip to content

xbox_present: a skipped present after a resize is not a composition failure (and the helper says which step failed) - #2652

Closed
fiestorra wants to merge 2 commits into
ProjectLeonida:mainfrom
fiestorra:fix/present-planes-failure-detail
Closed

fiestorra wants to merge 2 commits into
ProjectLeonida:mainfrom
fiestorra:fix/present-planes-failure-detail

Conversation

@fiestorra

@fiestorra fiestorra commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

This now fixes the failure, not just reports it. Two commits: the diagnostics that found it, and the retry that repairs it.

The failure

xbox_present failed on this machine at line 1320 (now :1335) with no indication of which step went wrong. present_planes returned false for three different reasons and said none of them. It now names the step:

line 1335: present_planes(&one, 1)
present_planes: read-back failed

The cause

Case F resizes the window (400x300 -> 200x150 -> 320x240) and asks the next present for a capture. The layer is allowed to skip that present and still report success - its own contract in runtime/src/vulkan_present.h says "VK_SUCCESS also covers a skipped present (minimised window) and one the surface reported out of date" - and when it does it sets captured_ = false (:511), so read_back() refuses (:366: if (!capture_ || !capture_ptr_ || !captured_) return false;).

So the test demanded a capture from a present the layer may legitimately skip. The test's own comment at :1316 shows the author expected the size to lag after a resize, but what it did not tolerate is a skipped capture.

The change

In present_planes, when the read-back fails, present once more and try again:

present_planes: the first present was skipped, the next one captured

The retry runs only on the failing path, so a passing present is untouched.

Tested

On this machine, where the failure reproduced before the change:

3 runs of xbox_present_test.exe: exit 0, 0, 0
ctest -R '^xbox_present$': 1/1 Passed (2.76 s)

Re-verified on the current main (1d22590b9) after the tree moved, because a fix measured against an older base can stop being true:

main alone, whole suite rebuilt: 99% tests passed, 1 failed out of 539  -> 378 xbox_present (Failed)
with this branch applied:        3 runs of xbox_present_test.exe -> exit 0, 0, 0
                                 ctest -R '^xbox_present$'      -> 1/1 Passed (2.66 s)

and the same binary failed three times at line 1335 before it, and no other C++ test fails in either run.

Not tested

Nothing outside this machine. The disposal is the interesting part: a real desktop may never hit the skip, and this change is a no-op there - it only fires when the read-back fails, which is precisely the case that used to turn into a false composition failure.

The extra commit at the tip (no longer carried)

The branch used to carry a3b5ebea1 (test(semantic): align computed-I/J f16 interp oracle…), added only because semantic-tests was red on main for that oracle and every branch cut from main inherited it. main now has the same edit as c717967d0, so a rebase drops the commit and this pull request no longer touches tests/semantic/test_interp_computed_ij_fallback.py - the diff is only what this change actually needs.

AI-assisted: yes - DeepSeek v4.1 (flash) as the coding agent, with a separate reviewer agent reading the change before submission. Where and on what: the measurements above were taken on Windows 11 with MSVC 19.44.35226 on an RTX 4090 (NVIDIA driver 621.24) where a C++ or GPU path is involved; Python and docs cases need none of it.

Written with an AI assistant.

@fiestorra fiestorra changed the title xbox_present: present_planes says which of its three steps failed xbox_present: a skipped present after a resize is not a composition failure (and the helper says which step failed) Nov 29, 2026
@fiestorra
fiestorra force-pushed the fix/present-planes-failure-detail branch from fd743b4 to e93efd8 Compare November 29, 2026 22:22
@fiestorra

Copy link
Copy Markdown
Contributor Author

Rebased onto main 452d1d1b6 and now carries the one commit main is missing, like my other pull requests:

semantic-tests (ubuntu-latest) was red on main for the interp oracle (TEST-INTERP-COMPUTED-IJ-FALLBACK-RTZ),
so a branch cut from main inherits it and cannot show its own result. The commit is a3b5ebea1, the same one
#2633 carries; if #2633 merges first this becomes a duplicate and can be dropped, and if this lands first
#2633 becomes a no-op.

The change itself is unchanged and still verified on this machine (xbox_present builds and, where it applies, passes 3/3 after the rebase).

Written with an AI assistant.

@merzleckeier

Copy link
Copy Markdown
Contributor

Independent xbox_present_test.exe A/B on 452d1d1b and GitHub merge 5952b59d (e93efd8b). CachyOS, Wine 11.22 and headless Gamescope, Win64 clang-cl 23.1.5 Release (/MD), LEONIDA_PRESENT_PLANE1=0. Counts are the test process exits and completion markers.

Arm RTX 4070 SUPER (620.73.04) Radeon Raphael (RADV 26.3.1)
Base 0/3 0/3
#2652 3/3 3/3
#2507 only (b8486b4a) 3/3 3/3
#2652 + #2507 3/3 3/3

MEASURED. The base failed at the first resize capture in case F. #2652 retried once at each of the three resizes. With #2507 present, all runs finished with zero helper retries. Both patches apply cleanly together.

MEASURED, negative control. On the second iteration of the first resize, I fed the size checker a byte count one texel short after a successful readback from a present that advanced the shown counter. The existing helper reported a skipped present, retried, and the full test passed 3/3 per GPU. The same control failed at the readback on both GPUs in 3/3 runs when I allowed the retry only in case F and only if xbox.presenter().presented() stayed unchanged. That scoped variant passed 3/3 per GPU with the probe off and recovered all three actual resize skips with a fresh frame token on each retry.

grab checks both capture and byte count/extent. The shown counter is a way to preserve that check for frames the presenter did show. If the fixture is meant to require a shown frame, the scoped retry keeps that behavior. #2507 separately keeps the already copied frame readable after OUT_OF_DATE.

Synthetic fixtures only. AI-assisted with OpenAI Codex.

@fiestorra

Copy link
Copy Markdown
Contributor Author

Re-verified on the current main (1d22590b9), because both the tree and the test have moved since the first measurement.

main alone, whole suite rebuilt and run here:

99% tests passed, 1 tests failed out of 539      (195.99 s)
  378 - xbox_present (Failed)

With this branch applied (8cb7875ce), the same test:

3 runs of xbox_present_test.exe:  exit 0, 0, 0
ctest -R '^xbox_present$':       1/1 Passed (2.66 s)

So main's only C++ failure is still this one, and the retry still turns it green after the tree moved - which is the part that could have quietly stopped being true when main picked up the sample-location and image-store changes.

Nothing else changed in the branch: the diagnostics in the first commit and the one-shot retry in the second are what they were, and the 539-test run shows no new failure anywhere else.

Written with an AI assistant.

It returned false for a missing frame token, a wrong HRESULT and a failed
read-back, so a failing EXPECT pointed at a lambda that could have failed three
ways. On this machine the read-back is the one that fails after the window
resize (case F), and it took a rebuild to find that out.

Written with an AI assistant.
…ailure

Case F resizes the window and demands a capture from the next present. The layer
is allowed to skip one - its own contract says VK_SUCCESS covers "a skipped
present (minimised window) and one the surface reported out of date" - and it
sets captured_ = false when it does, so read_back() returns false and the EXPECT
failed. Retry once: the following present shows the frame.

Verified on this machine, where the failure reproduced: three runs exit 0 and
ctest reports xbox_present Passed. Before the change the same binary failed at
line 1335 with "read-back failed", three times.

Written with an AI assistant.
@fiestorra
fiestorra force-pushed the fix/present-planes-failure-detail branch from 1a0cc76 to cce63b2 Compare November 30, 2026 13:54
@fiestorra

Copy link
Copy Markdown
Contributor Author

Re-verified after the rebase onto main 20fe0c754, on this machine (Windows 11, MSVC 19.44.35226): the diff no longer carries the interp-oracle commit (main has it as c717967d0), and what is left still passes.

ctest -R '^xbox_present'
100% tests passed, 0 failed out of 2

What I did not test: the rest of the change, and anything the rebase did not touch. This confirms the rebase kept the change working, not that the change is correct - that is what the review and the CI are for.

Written with an AI assistant.

@KelboLive

Copy link
Copy Markdown

Independent check on Windows/NVIDIA (not the author), at cce63b232.

  • On current main b17b22d33, ctest -R "^xbox_present$" fails at line 1320 with VK_ERROR_FORMAT_NOT_SUPPORTED on this machine (RTX 4070 Ti SUPER, driver 621.01).
  • On this branch, with the test's own LEONIDA_PRESENT_PLANE1=0, it gets past the resize/composition path that used to fail at line 1320 and reaches the real-time loop.

It then fails at line 1554: real time: 30 frames at 60 Hz in 6980 ms (ideal 500). That is this machine's display being asleep, not the PR: nvidia-smi reports display_active: Disabled and powercfg /requests has DISPLAY: None, so DWM throttles presents to ~4 Hz. The 60 Hz assertion cannot be judged until the display is active.

Net: the resize/composition fix is confirmed here; the remaining failure is environmental. A run with an active desktop should confirm the pacing assertion.

AI-assisted: yes (opencode).

@fiestorra

Copy link
Copy Markdown
Contributor Author

Measured end to end on the current main: xbox_present fails, and with this PR's test change it passes. This is the independent confirmation of the failure KelboLive described, run as part of a full suite rather than the single test.

A full ctest on main 0b6e0e3bc, Release, serial, this machine:

577 tests registered, 575 ran
99% tests passed, 1 tests failed out of 575
  LastTestsFailed.log: 399:xbox_present

And the single test, both ways:

main 0b6e0e3bc, runtime/test/xbox_present_test.cpp as it is:
  ***Failed   2.02 sec
  [rt] d3d12: present failed (VkResult -11)      <- VK_ERROR_FORMAT_NOT_SUPPORTED, five times
  line 1320: present_planes(&one, 1)

with this PR's runtime/test/xbox_present_test.cpp (24 added, 3 removed), rebuilt:
  100% tests passed, 0 tests failed out of 1      exit 0

So the red is not flaky and not this machine: it is one test in the suite on today's main, it fails deterministically in 2 seconds, and your change is what turns it green.

What that means for the merge decision, which is yours: main currently has a failing test, so the "leave it, it may be the machine" reading is not available - the -11 is a format refusal, not a timeout or a scheduling artefact, and it happens at the resize-and-compose path the comment above line 1318 describes.

What I could not test: the other half of your report - real time: 30 frames at 60 Hz in 6980 ms on your display - because this machine's present path did not reach the frame-rate assertion at all before the change, and after it the test passes in 2 s. So the timing failure you saw is a different machine's display, and I have no opinion on it.

AI-assisted: yes - DeepSeek v4.1 (flash) ran the suite and the single test on the machine above.

Written with an AI assistant.

@fiestorra

Copy link
Copy Markdown
Contributor Author

finding: re-verified on today's main, and the fix gets further but does not reach green: the pixel cases now print ok, and the process still exits 1.

main 10bed9ff2, the two commits cherry-picked (merge-base 20fe0c754), MSVC Release, RTX 4090:

cargo build (runtime/build)                            exit 0
runtime\build\xbox_present_test.exe                    exit 1
  stdout: 10 lines, the last six all "...: ok"
    source rectangles (valid and invalid): ok
    1 plane, RGBA8 solid: ok (swapchain format 44)
    0 planes (blank): ok
    1 plane, two colours (orientation): ok
    1 plane, BGRA8 source: ok
    1 plane, sRGB source (swapchain follows): ok

What the fix did, and it is a real improvement: the [rt] d3d12: present failed (VkResult -11) lines that made this test unreadable are gone, and the six cases that used to die now pass. Two days ago on b7a1be296 the same binary failed 7 of 7 with VkResult -11; now none of those appear.

What it still fails on, and I have four runs to show it is not one thing:

run 1:  exit 1, stderr had  line 634: xbox.presenter().composed_presents() == composed_before
runs 2-4:  exit 1, stderr has no "line N:" at all, and none of main's three end paths
           ("... validation errors ...", "... known ... skipped", "all cases pass") printed

So on one run the 2-plane composite present (PresentX(2, two, nullptr)) moved composed_presents() when the check says plane 1 has no overlay flag and it should not; and on three runs the binary exits 1 after the last ok without saying why. composed_presents has not changed between the merge base and today (git log -S finds no commit touching it), so this is not main drift.

What I could not do: name the third path. EXPECT is if (!(c) { fprintf(stderr, "line %d: %s"); return 1; }) and main's three returns all print, so a silent exit 1 does not come from any of them - it is either a crash after the last case or a return 1 I have not found, and I stopped rather than guess.

What I would suggest: the failing composed_presents check is worth its own look because it is an exact equality on a counter, and the three silent runs are worth a --only that runs one case at a time. My earlier verification of this pull request said "all green" - that was on b7a1be296, and it no longer is.

AI-assisted: yes - DeepSeek v4.1 (flash), four runs and a build.

Written with an AI assistant.

@fiestorra

Copy link
Copy Markdown
Contributor Author

Narrowed further, so whoever picks this up starts where I stopped rather than where I started.

The file has exactly two return 1, and both print:

  L37   if (!(condition)) { std::fprintf(stderr, "line %d: %s\n", __LINE__, #condition); return 1; }
  L1565 std::fprintf(stderr, "%u validation errors (%u known sRGB swapchain checks)\n", ...); return 1;

And the three end paths print too (validation errors, known ... skipped, xbox_present_test: all cases pass). In the three silent runs, none of those five lines appears anywhere in either stream.

Where the binary actually stops:

last stdout line:    "1 plane, sRGB source (swapchain follows): ok"     (L623)
next expected:       L625-636, the 2-plane composite case
last stderr:         67 lines, every one starting with "[rt]"           (no test output at all)

So it dies somewhere between L623 and L1553 without going through any exit path in main. That is either a crash whose code PowerShell reports as 1, or an exit inside a helper the test calls.

What that leaves as candidates, in the order I would look:

  1. EXPECT inside a bool helper. The macro is return 1 - in a function returning bool, that is return true, and the caller reads it as success while the message goes to stderr. That cannot produce a silent run, so it is not this, but it is worth knowing the macro behaves differently in a bool helper than in main.
  2. PresentX(2, two, nullptr) itself: the one run that printed a line got line 634, which is the assertion AFTER that call returned S_OK. The silent runs may be dying inside the call.
  3. The teardown between L1555 and L1557 (DestroyWindow, UnregisterClassW), which is after the last ok and before the summary - but the summary lines are earlier than that, so this does not fit either.

I am not going to guess further: #2652's own change makes the six cases pass and that is a real improvement over the seven VkResult -11 failures I measured on b7a1be296. What it does not do yet is turn the binary green on today's main, and the silent exit is the thing to chase.

AI-assisted: yes - DeepSeek v4.1 (flash).

Written with an AI assistant.

@fiestorra

Copy link
Copy Markdown
Contributor Author

finding: this pull request no longer fixes anything on main: the failure it was written for is gone, and the failure that is there now is the same with and without it.

main f918e5145, rebuilt from scratch for this:

cmake --build ... --target xbox_present_test     exit 0
runtime\build\xbox_present_test.exe              exit 1

stdout, last three lines (same as this branch):
  source rectangles (valid and invalid): ok
  1 plane, BGRA8 source: ok
  1 plane, sRGB source (swapchain follows): ok

stderr, first non-[rt] line:
  line 634: xbox.presenter().composed_presents() == composed_before

And with this branch applied, two hours ago on 640b0d0df:

stdout:        the same ten lines, the last six "ok"
stderr:        line 634: xbox.presenter().composed_presents() == composed_before    (one run in four)
               nothing at all, exit 1                                              (three runs in four)

So the two trees fail identically at L634, and the VkResult -11 lines are gone from both. Something between b7a1be296 (where I measured seven present failed (VkResult -11) and no line 634) and today's main fixed the present path, and it was not this branch - this branch only names the failure more clearly, which is why it looked like a fix.

What I am now recommending, and I would rather correct myself than leave it: close this, and open the L634 failure as its own item. The assertion is exact and narrow:

EXPECT(xbox.PresentX(2, two, nullptr) == S_OK);
EXPECT(xbox.presenter().composed_presents() == composed_before);  // plane 1 has no overlay flag

A 2-plane composite present is incrementing composed_presents() when the check says plane 1 lacks the overlay flag and it should not. composed_presents has not changed between b7a1be296 and today (git log -S finds no commit), so the counter is not what moved - the present path that calls it did.

And the three-runs-in-four silent exit is a second finding: no line N: and none of main's three end-path prints, so it exits somewhere that prints nothing. Both are worth their own look and neither is this branch's.

AI-assisted: yes - DeepSeek v4.1 (flash), which reported this as an improvement two hours ago and is correcting itself after rebuilding main.

Written with an AI assistant.

@fiestorra

Copy link
Copy Markdown
Contributor Author

finding: both arms of the test are identical with and without this branch, and the reason I kept seeing a difference is that I was running the wrong one.

ctest does not run this binary plainly - it sets an environment variable first, which I only found by asking ctest -N -V:

399: Test command: E:\ports\repos\leonida\runtime\build\xbox_present_test.exe
399: Working Directory: E:/ports/repos/leonida/runtime/build
399: Environment variables:
399:  LEONIDA_PRESENT_PLANE1=0

And there are two different failures, one per arm. Measured on main f918e5145 rebuilt from scratch, then with this branch applied:

                              main                    this branch
without the variable    exit 1, 1 x "line 634"     exit 1, 1 x "line 634"
with LEONIDA_PRESENT_PLANE1=0   exit 1, 5 x "present failed (VkResult -11)", 1 x "line N"
                                exit 1, 5 x "present failed (VkResult -11)", 1 x "line N"

Identical, line for line, in both arms. So this branch changes no outcome at all. The VkResult -11 lines I reported as gone this morning were gone because I had run the arm that does not produce them - the one without the variable - and there main also does not produce them.

That is the third version of this report, and the two earlier ones were wrong for the same reason: I compared a run against a run, without checking which arm each one was. ctest sets a variable, my shell did not, and the difference I attributed to the pull request was the difference between the two arms.

What this branch is worth: its present_planes helper names the step a failing EXPECT came from, which makes the output readable. That is a real improvement to the diagnostic and it is not a fix.

What the two failures need, and neither is this branch: the 2-plane composite present incrementing composed_presents (no variable), and whatever makes vkCreateSwapchainKHR/present return VK_ERROR_DEVICE_LOST with LEONIDA_PRESENT_PLANE1=0. The second is the one ctest sees and the one that has been red all day.

I would still close this as a fix and keep the helper if it is useful, but whoever reopens it should start from the two arms above.

AI-assisted: yes - DeepSeek v4.1 (flash), which reported this pull request as a fix twice and is correcting itself twice.

Written with an AI assistant.

@fiestorra fiestorra closed this Dec 1, 2026
@fiestorra

Copy link
Copy Markdown
Contributor Author

closed: both arms of xbox_present are identical with and without this branch, so it fixes nothing, and I would rather close it than leave a pull request open that claims a fix it does not make.

The measurement, on main f918e5145 rebuilt from scratch and again with this branch applied:

                              main                              this branch
no variable              exit 1, 1 x "line 634"            exit 1, 1 x "line 634"
LEONIDA_PRESENT_PLANE1=0  exit 1, 5 x "present failed        exit 1, 5 x "present failed
                          (VkResult -11), 1 x "line N"        (VkResult -11), 1 x "line N"

ctest sets LEONIDA_PRESENT_PLANE1=0 (which ctest -N -V shows and I did not look at until three reports in), so the arm it sees is the second one, and it has been red all day for a reason this branch does not touch.

What the branch did do: its present_planes helper names the step a failing EXPECT came from, which is a real improvement to the output. The branch stays pushed as refs/pull/2652/head; if that helper is worth lifting, it can be taken from there without the "fix" framing.

The two failures, for whoever picks them up, and neither is in this branch:

  1. Without the variable: a 2-plane composite present increments presenter().composed_presents() when the check says plane 1 has no overlay flag. composed_presents has not changed since b7a1be296 (git log -S finds no commit), so the present path that calls it is what moved.
  2. With LEONIDA_PRESENT_PLANE1=0: five present failed (VkResult -11) and one assertion, which is the arm ctest runs.

Where to track them: #2464 is the game-run work and already carries this test; #2570 is the coordination issue. I did not open a new issue for either because I do not know which of the two a maintainer considers the bug and which the test's expectation - the counter or the call site.

AI-assisted: yes - DeepSeek v4.1 (flash), which reported this pull request as a fix twice and closed it after measuring both arms.

Written with an AI assistant.

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.

3 participants