perf: the card compare's result area is a ring, not drained when half taken #255

Manually merged
github merged 2 commits from github-bot/gh-255 into main 2026-11-26 14:23:03 +00:00 AGit
Owner

@⁠Skyfrye on GitHub · 2026-11-25 21:57 UTC · original
Skyfrye:nep/compare-result-ring → main · +281 −28 · 3 files · 2 commits · merged 2026-11-26 14:21 UTC

Draft: the in-game check on this base is pending (the test machine's GPU is in use for a few hours). Everything below the game run is done.

Change

Each submission that has host copies in the card's memory records a compare whose results take one dword per piece in a 1 MiB area (CardWork::differs). The area was reused from its start only when no plan was in the air (Host::card_done: if !relay() || work.out == 0 { work.taken = 0 }). With the relay a plan is nearly always in the air, so the area only filled up, and every time it was half taken the submitting thread drained every flight — a wait for the card and the copy-back of all of them — before it could go on (card_results_low → settle(WHY_MOST), counted as "lists in the air").

Plans land in the order they were made, and their results are read before card_done (relay_card_back, then card_done). So the area is now a ring (resultring.rs):

  • a plan takes one stretch for the ranges the card compares, after the newest plan's, wrapping to the start;
  • it gives it back in card_done; the space comes back in landing order, so the next plans keep going without the area ever being empty;
  • the drain stays for an area three quarters taken by plans still in the air, and (second commit, from an independent review) when the free dwords lie in no stretch as long as plans asked for lately: once wrapped, free space can be split between the area's end and its start, and a plan compared only in part has its whole landing fetched the slow way;
  • a plan that finds no stretch long enough compares the ranges that fit and fetches the others, as when the area ran out before.

No range of a plan in the air is ever handed to another plan, so a compare never overwrites results not yet read. The compare shader writes every dword of its range (0 or 1), so a reused stretch needs no clearing.

VICTORY_RESULT_RING=0 restores the previous rule (reused only when empty, drained at half).

Linked issue: none.

Verification

Windows 11 26300, Rust 1.98.1 (MSVC), RTX 5080, on upstream main at affaf15, from third_party/victory:

cargo build --locked --release -p victory                              -> Finished, no new warning (the 3 of main)
cargo build --locked --profile diag -p victory --features diagnostics  -> Finished, no new warning
cargo test --locked -p victory-gpu --lib resultring                    -> 5 passed (CPU only)
cargo xtask policy                                                     -> asset policy: ok

With give made to keep every stretch (as if no plan ever landed), 3 of the first 4 tests fail; the fourth checks the former rule and passes either way. With short_for_next made to answer false, free_dwords_split_between_the_end_and_the_start_call_for_a_landing fails.

Pending: a game run (GTA VI 1.0.2.1, my own copy, launcher settings) with the diagnostics frame lines ("settled for: ... lists in the air", "of the waiting for the card in settles"), against main and with VICTORY_RESULT_RING=0. I will add the numbers here before marking the PR ready.

Oracle and test data

None involved. Failure cases (resultring.rs tests): 300 plans through an area of 100 dwords with three always in the air, each compared in full and never overlapping; a full area grants only what is free; a plan that lands early frees its stretch once older ones are back; the former rule without wrapping; free dwords split between the end and the start call for a landing.

Checklist

  • The PR covers a single reviewable behaviour (the compare's result area is reused as plans land).
  • A test fails without this change and passes with it.
  • The commands and results of each check are given above (the game run is pending, said above).
  • An unimplemented function returns an error (E_NOTIMPL), never a fake success. (Not concerned.)
  • README: not touched.
  • No game, console or SDK file, no key, no dump, no download link.
  • Findings drawn from a title: none.
  • Code taken from another project: none.

AI assistance: written with Claude Code (Claude Opus 5.5): the reading of the base, the change, its tests, the checks on my machine and this description.

🤖 Generated with Claude Code

**@⁠Skyfrye** on GitHub · 2026-11-25 21:57 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/255) `Skyfrye:nep/compare-result-ring` → `main` · +281 −28 · 3 files · 2 commits · merged 2026-11-26 14:21 UTC **Draft: the in-game check on this base is pending** (the test machine's GPU is in use for a few hours). Everything below the game run is done. ## Change Each submission that has host copies in the card's memory records a compare whose results take one dword per piece in a 1 MiB area (`CardWork::differs`). The area was reused from its start only when no plan was in the air (`Host::card_done`: `if !relay() || work.out == 0 { work.taken = 0 }`). With the relay a plan is nearly always in the air, so the area only filled up, and every time it was half taken the submitting thread drained every flight — a wait for the card and the copy-back of all of them — before it could go on (`card_results_low` → `settle(WHY_MOST)`, counted as "lists in the air"). Plans land in the order they were made, and their results are read before `card_done` (`relay_card_back`, then `card_done`). So the area is now a ring (`resultring.rs`): - a plan takes one stretch for the ranges the card compares, after the newest plan's, wrapping to the start; - it gives it back in `card_done`; the space comes back in landing order, so the next plans keep going without the area ever being empty; - the drain stays for an area three quarters taken by plans still in the air, and (second commit, from an independent review) when the free dwords lie in no stretch as long as plans asked for lately: once wrapped, free space can be split between the area's end and its start, and a plan compared only in part has its whole landing fetched the slow way; - a plan that finds no stretch long enough compares the ranges that fit and fetches the others, as when the area ran out before. No range of a plan in the air is ever handed to another plan, so a compare never overwrites results not yet read. The compare shader writes every dword of its range (0 or 1), so a reused stretch needs no clearing. `VICTORY_RESULT_RING=0` restores the previous rule (reused only when empty, drained at half). Linked issue: none. ## Verification Windows 11 26300, Rust 1.98.1 (MSVC), RTX 5080, on upstream `main` at `affaf15`, from `third_party/victory`: ``` cargo build --locked --release -p victory -> Finished, no new warning (the 3 of main) cargo build --locked --profile diag -p victory --features diagnostics -> Finished, no new warning cargo test --locked -p victory-gpu --lib resultring -> 5 passed (CPU only) cargo xtask policy -> asset policy: ok ``` With `give` made to keep every stretch (as if no plan ever landed), 3 of the first 4 tests fail; the fourth checks the former rule and passes either way. With `short_for_next` made to answer `false`, `free_dwords_split_between_the_end_and_the_start_call_for_a_landing` fails. Pending: a game run (GTA VI 1.0.2.1, my own copy, launcher settings) with the diagnostics frame lines ("settled for: ... lists in the air", "of the waiting for the card in settles"), against `main` and with `VICTORY_RESULT_RING=0`. I will add the numbers here before marking the PR ready. ## Oracle and test data None involved. Failure cases (`resultring.rs` tests): 300 plans through an area of 100 dwords with three always in the air, each compared in full and never overlapping; a full area grants only what is free; a plan that lands early frees its stretch once older ones are back; the former rule without wrapping; free dwords split between the end and the start call for a landing. ## Checklist - [x] The PR covers a single reviewable behaviour (the compare's result area is reused as plans land). - [x] A test fails without this change and passes with it. - [x] The commands and results of each check are given above (the game run is pending, said above). - [x] An unimplemented function returns an error (`E_NOTIMPL`), never a fake success. (Not concerned.) - [x] README: not touched. - [x] No game, console or SDK file, no key, no dump, no download link. - [x] Findings drawn from a title: none. - [x] Code taken from another project: none. AI assistance: written with Claude Code (Claude Opus 5.5): the reading of the base, the change, its tests, the checks on my machine and this description. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Each submission that has host copies in the card's memory records a
compare whose results take one dword per piece of a 1 MiB area. The area
was reused from its start only when no plan was in the air; with the relay
one nearly always is, so the area only filled up, and each time it was
half taken the submitting thread drained every flight (a wait for the card
and the copy-back of all of them, counted as "lists in the air") before it
could go on.

Plans land in the order they were made, so the space they take comes back
in that order. The area is now a ring (resultring.rs): a plan takes one
stretch for the ranges the card compares, after the newest plan's, wrapping
to the start, and gives it back when it lands (Host::card_done, after its
results were read). The drain stays for an area three quarters taken by
plans still in the air. A plan that finds no stretch long enough compares
the ranges that fit and fetches the others, as when the area ran out before.

VICTORY_RESULT_RING=0 restores the previous rule (reused only when empty,
drained at half).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Found by an independent review of the ring. Once the ring has wrapped, its
free dwords can lie in two stretches, after the newest plan and before the
oldest, neither as long as a plan needs. The plan then got part of what it
asked for and compared only the ranges that fit; a plan with a range not
compared has its whole landing fetched the slow way. The former rule
(drain at half, then start from 0) always left one stretch.

The ring now remembers the most plans asked for lately (decaying by a
sixteenth at each plan) and Host::card_results_low also lets the flights
land when the longest free stretch is shorter than that.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:40:40 +00:00
Author
Owner

@⁠LooperSalty on GitHub · 2026-11-26 00:07 UTC · original

Reviewed: this looks good to merge (tests pass, only the 3 known victory-gpu failures from main). Please mark it ready for review when you are happy with it and we will merge it.

**@⁠LooperSalty** on GitHub · 2026-11-26 00:07 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/255#issuecomment-7178411786) Reviewed: this looks good to merge (tests pass, only the 3 known victory-gpu failures from main). Please mark it ready for review when you are happy with it and we will merge it.
Author
Owner

@⁠KainanP on GitHub · 2026-11-26 10:32 UTC · original

Test report for #255 on three adapters.

Merges cleanly onto current main. Setup: current origin/main (c4c93bd) merged with this PR, Windows 11, cargo test --locked in third_party/victory. Adapters: RTX 4060 Laptop (DXGI 0), Intel UHD 8086:a78b (16-lane waves, no FP64), WARP. The hardware adapter is picked by name through a local, uncommitted test hook and confirmed in its log; WARP for victory-gpu is --features diagnostics + VICTORY_D3D12_WARP=1. victory-gpu runs with --test-threads=1.

victory-gpu --lib main main + #255
RTX 4060 Laptop 183 passed, main's 3 failed 188 passed, main's 3 failed
Intel UHD 183 passed, main's 3 failed 188 passed, main's 3 failed
WARP 196 passed, main's 3 failed 201 passed, main's 3 failed

"main's 3" = descriptor::host::tests::spans_say_the_next_start_and_the_lowest_level_viewed, indirect::tests::warp_card_fetch_copies_flagged_pieces_to_their_slots, indirect::tests::warp_card_patch_writes_the_masked_bytes_and_no_others. They fail on all three adapters on main too. The 5 resultring tests pass everywhere. No new failure.

Notes from reading the diff:

  • take uses taken.front() as the lowest taken start. That holds only while stretches come back in order. After an out-of-order give (the a_plan_that_lands_early... case), the hole stays unused until the older stretch is back. That is safe, just wasted space, as the doc comment says.
  • The ring logic is only tested in ResultRing. Nothing drives card_results_low / card_done with the relay on, where give must receive exactly the (start, granted) that take returned. A WARP test with two or three plans in the air would pin that link.

AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this.

**@⁠KainanP** on GitHub · 2026-11-26 10:32 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/255#issuecomment-7189494554) Test report for #255 on three adapters. Merges cleanly onto current main. Setup: current `origin/main` (c4c93bd) merged with this PR, Windows 11, `cargo test --locked` in `third_party/victory`. Adapters: RTX 4060 Laptop (DXGI 0), Intel UHD 8086:a78b (16-lane waves, no FP64), WARP. The hardware adapter is picked by name through a local, uncommitted test hook and confirmed in its log; WARP for victory-gpu is `--features diagnostics` + `VICTORY_D3D12_WARP=1`. victory-gpu runs with `--test-threads=1`. | `victory-gpu --lib` | main | main + #255 | |---|---|---| | RTX 4060 Laptop | 183 passed, main's 3 failed | 188 passed, main's 3 failed | | Intel UHD | 183 passed, main's 3 failed | 188 passed, main's 3 failed | | WARP | 196 passed, main's 3 failed | 201 passed, main's 3 failed | "main's 3" = `descriptor::host::tests::spans_say_the_next_start_and_the_lowest_level_viewed`, `indirect::tests::warp_card_fetch_copies_flagged_pieces_to_their_slots`, `indirect::tests::warp_card_patch_writes_the_masked_bytes_and_no_others`. They fail on all three adapters on main too. The 5 `resultring` tests pass everywhere. No new failure. Notes from reading the diff: - `take` uses `taken.front()` as the lowest taken start. That holds only while stretches come back in order. After an out-of-order `give` (the `a_plan_that_lands_early...` case), the hole stays unused until the older stretch is back. That is safe, just wasted space, as the doc comment says. - The ring logic is only tested in `ResultRing`. Nothing drives `card_results_low` / `card_done` with the relay on, where `give` must receive exactly the `(start, granted)` that `take` returned. A WARP test with two or three plans in the air would pin that link. _AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this._
github manually merged commit e11296d0b3 into main 2026-11-26 14:23:03 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.