feat(host): one frame is recorded and played with no game, on any build, with the rounds judged from round 2 #2322

Open
TrashPanda wants to merge 9 commits from TrashPanda/Longshot:feat/trace-replay-continued into main
Contributor

Summary

This continues pull request #1334 by HumanBean (M1 of the renderer rework plan: record one frame of the renderer's work, HOS_RX_TRACE=<file> with HOS_RX_TRACE_AT=<present>, and play it with longshot --play-trace <file>). HumanBean's two trace commits are kept as they were, under their name; the first two commits of this branch are theirs, taken to current main (one conflict, the interface version, which is now 46). Their third commit, the shader-preparation supervisor, is a separate topic and is offered separately, as feat/prepare-supervisor-continued. It was done with AI agents under TrashPanda's direction, and it is offered to HumanBean to take, fold into #1334, or supersede with their own, as they prefer. The 12 earlier commits of #1334 are on main already (#1339 and #1484) and are not here.

What was added on top, each its own commit, and why (a trace is only worth having if it can judge a change to the renderer, which needs the same frame on two builds):

  1. fix(host) a round starts from the snapshot's guest memory. The renderer writes into guest memory while it plays (write-backs, words the GPU fills in imported pools), and only the frame's own records were taken back, so rounds converged over several and never became equal (consecutive rounds 1.2e-4 apart for ever). The player keeps a copy of the pages it holds at the snapshot and puts back and marks the ones that differ before each round. HumanBean's own note on #1334 named this as not yet right. Game-free test: tests/test_rx_trace_rewind.py.
  2. feat(host) a trace plays on any build with the same layouts. The header compared the build string, so every other commit refused it. It now compares the trace format, MKWVK_API_VERSION and the layout digest (rx_trace_struct_check: the structs and op records the file stores) and the guest window, and each refusal names both values; the recording build is only logged. Test: tests/test_rx_trace_format.py.
  3. feat(host) scripts/trace_compare.py plays a trace on two runtimes through the queue, takes a picture of every round and prints each round's difference (mean absolute RGB difference, 0 to 1, the measure #1334 used) with a difference image, exiting 0 or 1 against --max. Its PNG code is its own: main has none. Test: tests/test_trace_compare.py.
  4. fix(host) the first round uploads every texture, and every round says what it drew. Round 1 differed from the rest by 0.03 to 0.04 although all rounds drew the same 773 draws: the renderer's per-frame upload budget deferred new ASTC textures to later frames (99 new ASTC textures left for a later frame). The player sets RX_VK_UPLOAD_BUDGET_MS=0 unless the run sets it and prints play: round N: D draws, L left out, P pipelines made.
  5. feat(host) round 1 is named the warm-up (printed at the start, in the doc, and the compare script judges from round 2): what is left in round 1 (0.005 to 0.015) is not explained.
  6. docs(host) the doc says what has been checked, what not, and the next steps.

Read first: host/rx_trace_play.c (rewind_take, rewind_all, the round loop), host/rx_trace_format.h (rx_trace_refusal), scripts/trace_compare.py, docs/dev/reference/trace-replay.md.

M1's bar is "a recorded Kokiri Forest and a recorded Castle Town replay to the same pictures as the live run, and replay clean under validation on one card of each vendor". Met for the pictures on the RTX 4070 Ti and the AMD integrated GPU, one frame each; not met clean under validation: the play runs to its end with two message kinds from the renderer itself (below). Not in this pull request, and the next steps, with sizes: recording with the render thread on (a job sequence number from the renderer to the recorder; medium); more than one frame (4 to 5 GB a frame uncompressed, so pages stored once by content and compressed; large); recording the bytes the game reads back and comparing them in play (medium).

Testing

Tested: by the agents on Linux, RTX 4070 Ti (NVIDIA, Vulkan) and for one scene the AMD Ryzen 7 9800X3D's integrated GPU (RADV), through the job queue, headless (gamerun --scene kokiri-forest and --scene market, RX_VK_ASYNC=0); every file under Longshot/work/trace/, none of it committed.

  • Kokiri Forest, present 3200, recorded 4.1 to 4.4 GB (181 to 183 images, 931 MB; 0.81 M pages). 12 rounds played: rounds 2 to 11 equal to within 0.00001 on the final build (one earlier first play on a fresh, cold runtime had rounds 2 and 3 0.027 off the rest); round 1 0.0047 to 0.044 by run (0.00003 once). The same trace played on the base build and on a build with PR 2307's three commits (CPU texture decoding; a different build string, same layouts): scripts/trace_compare.py PASS, worst judged round 0.000004, twice.
  • Castle Town's market (teleport 3), present 4500, 5.06 GB (186 images, 1.04 M pages), 2,412 draws a round, 0 left out: rounds 2 to 11 within 0.000002, round 1 0.0021, played round 6 against live present 4501 0.000134 (the live frames 4498 to 4502: 0.0025, 0.0019, 0.0013, 0.00013, 0.0013).
  • AMD integrated GPU (RX_VK_DEVICE=1, 17 fps, present 1600): 3.9 GB (190 images); rounds 2 to 11 identical, round 1 0.00044, played round 6 against live present 1601 0.00044.
  • Played against live in Kokiri Forest: 0.0005 on the first recording (round 7 against live 3201; HumanBean quoted 0.009 against 0.007 to 0.018 between two live sessions on a busier view); on a second recording every play was 0.0266 from the live shot of the present right after the snapshot (which follows a 3 to 4 s stall) and 0.0018 and 0.0030 from the two before it: not understood, said in the doc.
  • RX_VK_VALIDATION=1, 4 rounds on the RTX: exit 0 and two kinds, ten each, VUID-RuntimeSpirv-MeshEXT-10883 (a mesh shader with a task payload and no task shader) and Undefined-Value-ShaderOutputNotConsumed-DynamicRendering (a fragment output with no colour attachment).
  • python -I -B tests/run_all.py through suite.py compare against main at 753fb5af: 931 passed, 3 failed, 26 skipped on the branch (a0bd1883, then two commits that change a message and the doc), 928 / 3 / 26 on main; no check fails only on the branch; the three new checks pass. The rebase needed edits to seven checks' stubs (HumanBean's commits, not weakened: stubs for rx_trace_* in the harnesses that cut rx_backend.c and vk_texture.cpp).
  • With the render thread on (the default) recording is refused and the game goes on.

Still to test:

  • Windows, an RTX or any card: record one frame with RX_VK_ASYNC=0, play it 12 rounds, expecting rounds 2 to 11 equal; futondestroyer's validation of the first version (Windows 11, RTX 4070, NVIDIA 621.01, c1fc152d: rounds 6 to 9 0.0000843 to 0.0000987 from the live frame, three processes within 2.3e-8, 760 draws in round 1 against 796 later) is credited and was not repeated on this head (by hand).
  • An Intel GPU: record and play one frame (by hand).
  • Castle Town at other places than the market, and a second card of each vendor (by hand).

Measurements

Verdict: nothing to chase in fps: a tool for developers that is off unless asked for (HOS_RX_TRACE, --play-trace). Costs measured: a round takes 255 to 450 ms in Kokiri Forest on the RTX 4070 Ti (it compares and puts back 3 GB of pages and 0.9 GB of images; before the rewind 255 ms), and a trace is 4 to 5 GB. Setup: Linux, RTX 4070 Ti, NVIDIA driver, 1920x1080 offscreen, 12 rounds. Switches: this adds HOS_RX_TRACE and HOS_RX_TRACE_AT (HumanBean's rows, both off by default); the player sets RX_VK_ASYNC=0, RX_VK_RECORDER=off and RX_VK_UPLOAD_BUDGET_MS=0 for its own run unless set, which changes no default of the game.

Before: main @ 753fb5af6 After: this PR @ 2cef5a42b
Kokiri Forest frame, played vs live (round 7 vs present 3201) no trace 0.0005 (first recording)
Rounds 2 to 11 against each other no trace 0.000004 at most (RTX), 0 (AMD)
Market frame, played vs live no trace 0.000134

Risks

A tool for developers: with HOS_RX_TRACE and --play-trace unset nothing runs but one test of rx_trace_on before each renderer call (HumanBean's). A trace is made from the game: it never leaves the PC. MKWVK_API_VERSION goes to 46 (three renderer entries appended). A trace plays on a build whose layout digest matches; a change to a struct the file stores makes older traces refuse with a message, and a field that keeps its place and changes meaning is not seen by the digest (the doc says to bump RX_TRACE_VERSION). Revert is enough; nothing in a player's saves or options changes.

Checklist

Ready for review

  • One topic, on current main; the title is a Conventional Commit.
  • Tested on my own PC, in the game for a change the game runs, as Testing says. Not ticked: run by agents, headless, on one NVIDIA and one AMD GPU on Linux, not by a person; not on Windows.
  • mise run test passes (any failure that also fails on main is named): the 3 that fail on main fail here too.
  • Measured against main, or Measurements says why there is nothing to measure.
  • No game files, build output or hand-edited generated files; third_party/ untouched; nothing GPL-incompatible. No trace, picture or log made from the game is in the branch.

When it applies

  • A switch added or changed: it ships at the default the measurements chose, with its row in gpu/vk/switches.def.
  • A check under tests/ that reads changed source is updated, not weakened.
  • MKWVK_API_VERSION bumped (MkwVkHost or MkwVkRenderer in gpu/vk/vk_api.h changed).
  • Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths. Not ticked: built on Linux only.
  • Docs updated.
  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers.

Ready to merge

  • Everything in Still to test has run, its results in Tested.
  • Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers").
  • Approved in review, every comment answered.
  • CI passes on the head; on current main, measured again or a comment says why the numbers still hold.
## Summary This continues pull request #1334 by HumanBean (M1 of the renderer rework plan: record one frame of the renderer's work, `HOS_RX_TRACE=<file>` with `HOS_RX_TRACE_AT=<present>`, and play it with `longshot --play-trace <file>`). **HumanBean's two trace commits are kept as they were, under their name**; the first two commits of this branch are theirs, taken to current `main` (one conflict, the interface version, which is now 46). Their third commit, the shader-preparation supervisor, is a separate topic and is offered separately, as `feat/prepare-supervisor-continued`. It was done with AI agents under TrashPanda's direction, and it is offered to HumanBean to take, fold into #1334, or supersede with their own, as they prefer. The 12 earlier commits of #1334 are on `main` already (#1339 and #1484) and are not here. What was added on top, each its own commit, and why (a trace is only worth having if it can judge a change to the renderer, which needs the same frame on two builds): 1. `fix(host)` **a round starts from the snapshot's guest memory.** The renderer writes into guest memory while it plays (write-backs, words the GPU fills in imported pools), and only the frame's own records were taken back, so rounds converged over several and never became equal (consecutive rounds 1.2e-4 apart for ever). The player keeps a copy of the pages it holds at the snapshot and puts back and marks the ones that differ before each round. HumanBean's own note on #1334 named this as not yet right. Game-free test: `tests/test_rx_trace_rewind.py`. 2. `feat(host)` **a trace plays on any build with the same layouts.** The header compared the build string, so every other commit refused it. It now compares the trace format, `MKWVK_API_VERSION` and the layout digest (`rx_trace_struct_check`: the structs and op records the file stores) and the guest window, and each refusal names both values; the recording build is only logged. Test: `tests/test_rx_trace_format.py`. 3. `feat(host)` **`scripts/trace_compare.py`** plays a trace on two runtimes through the queue, takes a picture of every round and prints each round's difference (mean absolute RGB difference, 0 to 1, the measure #1334 used) with a difference image, exiting 0 or 1 against `--max`. Its PNG code is its own: `main` has none. Test: `tests/test_trace_compare.py`. 4. `fix(host)` **the first round uploads every texture, and every round says what it drew.** Round 1 differed from the rest by 0.03 to 0.04 although all rounds drew the same 773 draws: the renderer's per-frame upload budget deferred new ASTC textures to later frames (`99 new ASTC textures left for a later frame`). The player sets `RX_VK_UPLOAD_BUDGET_MS=0` unless the run sets it and prints `play: round N: D draws, L left out, P pipelines made`. 5. `feat(host)` **round 1 is named the warm-up** (printed at the start, in the doc, and the compare script judges from round 2): what is left in round 1 (0.005 to 0.015) is not explained. 6. `docs(host)` the doc says what has been checked, what not, and the next steps. Read first: `host/rx_trace_play.c` (`rewind_take`, `rewind_all`, the round loop), `host/rx_trace_format.h` (`rx_trace_refusal`), `scripts/trace_compare.py`, `docs/dev/reference/trace-replay.md`. M1's bar is "a recorded Kokiri Forest and a recorded Castle Town replay to the same pictures as the live run, and replay clean under validation on one card of each vendor". Met for the pictures on the RTX 4070 Ti and the AMD integrated GPU, one frame each; **not met clean under validation**: the play runs to its end with two message kinds from the renderer itself (below). Not in this pull request, and the next steps, with sizes: recording with the render thread on (a job sequence number from the renderer to the recorder; medium); more than one frame (4 to 5 GB a frame uncompressed, so pages stored once by content and compressed; large); recording the bytes the game reads back and comparing them in play (medium). ## Testing **Tested:** by the agents on Linux, RTX 4070 Ti (NVIDIA, Vulkan) and for one scene the AMD Ryzen 7 9800X3D's integrated GPU (RADV), through the job queue, headless (`gamerun --scene kokiri-forest` and `--scene market`, `RX_VK_ASYNC=0`); every file under `Longshot/work/trace/`, none of it committed. - Kokiri Forest, present 3200, recorded 4.1 to 4.4 GB (181 to 183 images, 931 MB; 0.81 M pages). 12 rounds played: rounds 2 to 11 equal to within 0.00001 on the final build (one earlier first play on a fresh, cold runtime had rounds 2 and 3 0.027 off the rest); round 1 0.0047 to 0.044 by run (0.00003 once). The same trace played on the base build and on a build with PR 2307's three commits (CPU texture decoding; a different build string, same layouts): `scripts/trace_compare.py` PASS, worst judged round 0.000004, twice. - Castle Town's market (teleport 3), present 4500, 5.06 GB (186 images, 1.04 M pages), 2,412 draws a round, 0 left out: rounds 2 to 11 within 0.000002, round 1 0.0021, played round 6 against live present 4501 0.000134 (the live frames 4498 to 4502: 0.0025, 0.0019, 0.0013, 0.00013, 0.0013). - AMD integrated GPU (`RX_VK_DEVICE=1`, 17 fps, present 1600): 3.9 GB (190 images); rounds 2 to 11 identical, round 1 0.00044, played round 6 against live present 1601 0.00044. - Played against live in Kokiri Forest: 0.0005 on the first recording (round 7 against live 3201; HumanBean quoted 0.009 against 0.007 to 0.018 between two live sessions on a busier view); on a second recording every play was 0.0266 from the live shot of the present right after the snapshot (which follows a 3 to 4 s stall) and 0.0018 and 0.0030 from the two before it: not understood, said in the doc. - `RX_VK_VALIDATION=1`, 4 rounds on the RTX: exit 0 and two kinds, ten each, `VUID-RuntimeSpirv-MeshEXT-10883` (a mesh shader with a task payload and no task shader) and `Undefined-Value-ShaderOutputNotConsumed-DynamicRendering` (a fragment output with no colour attachment). - `python -I -B tests/run_all.py` through `suite.py compare` against `main` at 753fb5af: 931 passed, 3 failed, 26 skipped on the branch (a0bd1883, then two commits that change a message and the doc), 928 / 3 / 26 on `main`; no check fails only on the branch; the three new checks pass. The rebase needed edits to seven checks' stubs (HumanBean's commits, not weakened: stubs for `rx_trace_*` in the harnesses that cut `rx_backend.c` and `vk_texture.cpp`). - With the render thread on (the default) recording is refused and the game goes on. **Still to test:** - Windows, an RTX or any card: record one frame with `RX_VK_ASYNC=0`, play it 12 rounds, expecting rounds 2 to 11 equal; futondestroyer's validation of the first version (Windows 11, RTX 4070, NVIDIA 621.01, c1fc152d: rounds 6 to 9 0.0000843 to 0.0000987 from the live frame, three processes within 2.3e-8, 760 draws in round 1 against 796 later) is credited and was **not repeated on this head** (by hand). - An Intel GPU: record and play one frame (by hand). - Castle Town at other places than the market, and a second card of each vendor (by hand). ## Measurements **Verdict:** nothing to chase in fps: a tool for developers that is off unless asked for (`HOS_RX_TRACE`, `--play-trace`). Costs measured: a round takes 255 to 450 ms in Kokiri Forest on the RTX 4070 Ti (it compares and puts back 3 GB of pages and 0.9 GB of images; before the rewind 255 ms), and a trace is 4 to 5 GB. Setup: Linux, RTX 4070 Ti, NVIDIA driver, 1920x1080 offscreen, 12 rounds. Switches: this adds `HOS_RX_TRACE` and `HOS_RX_TRACE_AT` (HumanBean's rows, both off by default); the player sets `RX_VK_ASYNC=0`, `RX_VK_RECORDER=off` and `RX_VK_UPLOAD_BUDGET_MS=0` for its own run unless set, which changes no default of the game. | | Before: main @ 753fb5af6 | After: this PR @ 2cef5a42b | |---|---|---| | Kokiri Forest frame, played vs live (round 7 vs present 3201) | no trace | 0.0005 (first recording) | | Rounds 2 to 11 against each other | no trace | 0.000004 at most (RTX), 0 (AMD) | | Market frame, played vs live | no trace | 0.000134 | ## Risks A tool for developers: with `HOS_RX_TRACE` and `--play-trace` unset nothing runs but one test of `rx_trace_on` before each renderer call (HumanBean's). **A trace is made from the game: it never leaves the PC.** `MKWVK_API_VERSION` goes to 46 (three renderer entries appended). A trace plays on a build whose layout digest matches; a change to a struct the file stores makes older traces refuse with a message, and a field that keeps its place and changes meaning is not seen by the digest (the doc says to bump `RX_TRACE_VERSION`). Revert is enough; nothing in a player's saves or options changes. ## Checklist ### Ready for review - [x] One topic, on current `main`; the title is a Conventional Commit. - [ ] Tested on my own PC, in the game for a change the game runs, as Testing says. Not ticked: run by agents, headless, on one NVIDIA and one AMD GPU on Linux, not by a person; not on Windows. - [x] `mise run test` passes (any failure that also fails on `main` is named): the 3 that fail on `main` fail here too. - [x] Measured against `main`, or Measurements says why there is nothing to measure. - [x] No game files, build output or hand-edited generated files; `third_party/` untouched; nothing GPL-incompatible. No trace, picture or log made from the game is in the branch. ### When it applies - [x] A switch added or changed: it ships at the default the measurements chose, with its row in `gpu/vk/switches.def`. - [x] A check under `tests/` that reads changed source is updated, not weakened. - [x] `MKWVK_API_VERSION` bumped (`MkwVkHost` or `MkwVkRenderer` in `gpu/vk/vk_api.h` changed). - [ ] Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths. Not ticked: built on Linux only. - [x] Docs updated. - [x] AI assistance recorded with `Assisted-by:` / `Co-Authored-By:` trailers. ### Ready to merge - [ ] Everything in Still to test has run, its results in Tested. - [ ] Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers"). - [ ] Approved in review, every comment answered. - [ ] CI passes on the head; on current `main`, measured again or a comment says why the numbers still hold.
The renderer rework plan's M1 (track T). HOS_RX_TRACE=<file> with HOS_RX_TRACE_AT=<present> writes a snapshot of what
a renderer needs to start from (pools, pages, samplers, textures, programs, events) and every call up to the next
present; longshot --play-trace <file> [--frames N] plays it to the renderer with no game running. A trace is game
data and stays on the PC. docs/development/trace-replay.md says when it fits and what it cannot test.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_017vw8dzCsAL3UdW7ft8ptL9
The renderer rework plan's M1. A played frame was darker than the game's and lacked what earlier frames had drawn:
nothing that lived only on the GPU was in a trace. The renderer now reads every GPU-written image back at the
snapshot (trace_images_capture, MKWVK_API_VERSION 30; 223 images, 828 MB in Kokiri Forest) and the player puts them
back before each round, with guest memory rewound, so each round starts from the snapshot; --carry starts only the
first there. The snapshot is taken after its present, which lets the frame's waiting submits through. Format 4.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_017vw8dzCsAL3UdW7ft8ptL9
The playing renderer writes into guest memory outside the frame's memory records (mirror write-backs, the words the GPU
fills in imported pools, texel write-backs), and undo_all took only the records' pages back, so a round began from what
the round before left and rounds converged over about six. The player now keeps a copy of every page it holds when the
snapshot is in place and, before each later round, compares them and puts back and marks the ones that differ.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
The header compared the build string, so a trace of one commit was refused by every other, and a trace can only judge a
change to the renderer if the changed build plays it. What has to match is what the file stores and the renderer
reads: the trace format, MKWVK_API_VERSION and the layout digest (rx_trace_struct_check: the structs and op records).
Each refusal now names both values; a different build string is told in the log, not refused. tests/test_rx_trace_format.py
checks each refusal and that another build plays.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Plays the trace on two runtimes through the job queue, a picture of every round, and reports round by round the mean
absolute RGB difference (the measure the trace's pull request used), writes a difference image per round, judges from a
round on (--from-round) against --max, and exits 0 or 1. Its PNG reading and writing is its own (the renderer's shots are
8-bit RGB). tests/test_trace_compare.py runs it over synthetic pictures.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
The first round of a play differed from the later ones by 0.03 to 0.04 although every round drew the same 773 draws
with none left out: the renderer's per-frame upload budget (RX_VK_UPLOAD_BUDGET_MS, 12 ms) deferred new ASTC textures to
later frames (97, then 88, 72 and 60 more in the next rounds, which the log says: "new ASTC textures left for a later
frame"), so the first rounds drew without them. A play holds no frame time, so the player sets the budget to 0 unless
the run sets it. It also prints, for each round, the draws made, the draws left out and the pipelines made since the
round before, so a round that differs can be explained from the log.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Rounds 2 and later were equal to within 0.00001 in six plays; round 1 differs by 0.005 to 0.04 for a reason that is not
found (not skipped draws, not the upload budget alone, not pipelines or programs still being made). The player says so
at the start and the doc gives the rule: compare from round 2. Also documents the layout check and scripts/trace_compare.py.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
fix(host): the warm-up message and the doc say what was seen: one cold first play had rounds that differed
Some checks failed
PR description / Description follows the template (pull_request_target) Successful in 6s
Website / Website on Cloudflare (pull_request_target) Has been skipped
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
Website / Website on Cloudflare (pull_request) Has been cancelled
2cef5a42be
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Author
Contributor

Tested in game: Linux, RTX 4070 Ti (NVIDIA 595.99.02) and the Ryzen integrated GPU on RADV. Recorded one frame in Kokiri Forest and one in Castle Town's market on the RTX, and one on the integrated GPU, each with RX_VK_ASYNC=0, and played each for 12 rounds with no game: rounds 2 to 11 equal to within 0.00001; market round 6 against the live frame 0.000134 (neighbouring live frames 0.0013 to 0.0025). A trace recorded on this branch played on this branch plus #2307's change: scripts/trace_compare.py PASS, worst round 0.000004. Not clean under the validation layer: MeshEXT-10883 and ShaderOutputNotConsumed, both from the renderer. Windows not run on this head.

Tested in game: Linux, RTX 4070 Ti (NVIDIA 595.99.02) and the Ryzen integrated GPU on RADV. Recorded one frame in Kokiri Forest and one in Castle Town's market on the RTX, and one on the integrated GPU, each with RX_VK_ASYNC=0, and played each for 12 rounds with no game: rounds 2 to 11 equal to within 0.00001; market round 6 against the live frame 0.000134 (neighbouring live frames 0.0013 to 0.0025). A trace recorded on this branch played on this branch plus #2307's change: scripts/trace_compare.py PASS, worst round 0.000004. Not clean under the validation layer: MeshEXT-10883 and ShaderOutputNotConsumed, both from the renderer. Windows not run on this head.
Member

Possibly related, for context:

  • PR #2323 WIP: feat(build): one shader that crashes or hangs the GPU driver costs the preparation that shader, not the whole run — Separate PR for shader-preparation supervisor split from the original trace work
  • issue #1493 Renderer rewrite — Renderer rework plan calls for record/replay as a safety net
Possibly related, for context: - PR #2323 WIP: feat(build): one shader that crashes or hangs the GPU driver costs the preparation that shader, not the whole run — Separate PR for shader-preparation supervisor split from the original trace work - issue #1493 Renderer rewrite — Renderer rework plan calls for record/replay as a safety net
TrashPanda force-pushed feat/trace-replay-continued from 2cef5a42be
Some checks failed
PR description / Description follows the template (pull_request_target) Successful in 6s
Website / Website on Cloudflare (pull_request_target) Has been skipped
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
Website / Website on Cloudflare (pull_request) Has been cancelled
to 6ffa4553da
Some checks failed
CI / Conventional Commit title (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Blocked by required conditions
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Blocked by required conditions
CI / Workflow lint (actionlint) (pull_request) Blocked by required conditions
CI / Website build and checks (pull_request) Blocked by required conditions
Guide screenshots / Guide images and local UI source review (pull_request) Blocked by required conditions
Third-party parts / As their notes say (pull_request) Blocked by required conditions
Third-party parts / The same as upstream (pull_request) Blocked by required conditions
Website / Website on Cloudflare (pull_request) Blocked by required conditions
PR description / Description follows the template (pull_request_target) Failing after 27s
2026-11-23 15:10:08 +00:00
Compare
HumanBean changed title from WIP: feat(host): one frame is recorded and played with no game, on any build, with the rounds judged from round 2 to feat(host): one frame is recorded and played with no game, on any build, with the rounds judged from round 2 2026-11-23 16:18:17 +00:00
Owner
@review
BeanBot left a comment

Recommendation: Request changes. The recorder can race the renderer’s dirty-page collection, and the comparison tool can report a pass using stale pictures or no judged rounds. The trace workflow also needs Windows and Intel validation before its cross-platform behavior is established.

Adds an opt-in recorder and game-free player for one renderer frame, plus a picture comparison tool. It enables repeatable renderer investigation, at the cost of multi-gigabyte traces and substantial replay memory and time; correctness of the recording and comparison needs fixes.

Blocking (5): must change before merging.

  1. L1 host/rx_trace.c:251: The recorder clears the same dirty marks the renderer collects and restores them only afterwards, so the two collectors can miss a write. (more on the line) Do: Give the recorder independent write marks or synchronize its collection with every renderer collector so neither consumes the other's marks.
  2. L2 host/rx_backend.c:711: rx_trace_on is read plainly on renderer-calling threads while the recorder writes it atomically on another thread. (more on the line) Do: Use atomic loads for every access to the flag, with publication ordering appropriate for recorder initialization and shutdown.
  3. L3 scripts/trace_compare.py:118: Replay reuses existing screenshot directories without removing or isolating old rounds. (more on the line) Do: Use fresh per-run screenshot directories and require the expected newly produced rounds from each replay before comparing.
  4. L4 scripts/trace_compare.py:160: The comparison can pass without judging any pictures, and silently ignores rounds missing on one side. (more on the line) Do: Reject an empty judged range and require matching, complete expected round sets, allowing only the explicitly documented unfinished final picture.
  5. L5 scripts/trace_compare.py:119: Relative runtime paths are used both as the subprocess working directory and as the executable path. (more on the line) Do: Resolve each runtime to an absolute path before constructing the executable and passing cwd.

Should fix (1): not blocking, but worth doing before merging.

  • L6 tests/test_rx_trace_format.py:456: This new compiler-based check defaults to gcc and does not declare the suite's compiler argument. (more on the line) Do: Declare RUN_ALL_ARGS = ["--cc", "{cc}"] and honor the selected compiler for standalone runs as well.

Nits (1): optional.

  • L7 gpu/vk/switches.def:208: The HOS_RX_TRACE_AT row describes a default that the recorder does not implement. (more on the line) Do: Describe the value as required, or implement and document the first-present default consistently.

Testing before merging (2) (runs on the systems it can change; it doesn't hold the recommendation)

  • L8: The Windows recording and replay path has not been exercised on this head. When: Windows uses different guest-memory commitment and file handling, so the reported Linux runs do not show that a recorded frame can be replayed there. Do: On Windows, record and replay a frame for at least 12 rounds, including a UTF-8 path, and compare judged rounds and a live picture.
  • L9: The new Vulkan image capture and restoration path has not been exercised on an Intel GPU. When: The reported NVIDIA and AMD runs do not cover Intel's Vulkan implementation for the image formats and copies used by capture and replay. Do: Record and replay a representative frame on Intel, compare judged rounds and the live picture, and inspect validation output.

@fix can do L1, L2, L3, L4, L5, L6 and L7.

Checks: Failing on this head, which is behind its base, where it passes: PR description / Description follows the template (pull_request_target). @rebase (or @fix) brings it up to date and runs it again; not held against it. Still running: 10 checks.

More: does it help, other systems, switches, what was read

Does it help: Unproven as a general renderer comparison tool. The PR reports Linux replays within 0.00001 between judged rounds on an RTX 4070 Ti and an AMD integrated GPU, and a market replay 0.000134 from a live picture. One cold play differed by 0.027 in rounds 2 and 3, and one recording differed by 0.0266 from the next live picture. Windows and Intel were not tested on this head.

Other systems: Recording touches shared guest-memory dirty marks and renderer calls even though the feature is opt-in; the dirty-mark race can affect the live recording run. Replay changes Vulkan image restoration and memory handling on all vendors. Linux NVIDIA and AMD runs are reported; Windows and Intel remain untested. Temporal upscaler history, frame generation, multisampled and sparse images are explicitly outside the recorded state.

Switches: HOS_RX_TRACE is off by default and names a game-derived output file. HOS_RX_TRACE_AT is required and must be at least 1, although its switch-table row incorrectly says the first present is the default. Replay defaults RX_VK_ASYNC=0, RX_VK_RECORDER=off and RX_VK_UPLOAD_BUDGET_MS=0 only when each is unset; explicit environment values override them. --play-trace, --frames and --carry add command-line controls.

Reviewed: 6ffa4553da against 0e32bc100d: Read the repository instructions, contribution rules, PR template, commit log, changed host trace and comparison paths, and the renderer and backend diffs; inspected the new tests and trace documentation. Skimmed the remaining changed harnesses and surrounding renderer code. The complete changed code and all callers were not read in full; docs/review-checklist.md and the sibling Tooling checkout were absent.; nothing run (a code review).

Checked and fine:

  • The renderer interface version is bumped from 45 to 46 for the appended entries.
  • The added switches have entries in switches.def.
  • The listed commits record AI assistance in trailers.
  • The PR reports that traces and pictures made from the game were not committed.

Testing: No commands that build or execute project code were run, as requested. The PR reports Linux game-free checks and NVIDIA and AMD recording and replay runs; CI is still running.

Overlaps and merge order: The PR identifies #1334 as prior work and separates the shader-preparation supervisor; no independent overlap search was possible with the network closed.


Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.

**Recommendation: Request changes.** The recorder can race the renderer’s dirty-page collection, and the comparison tool can report a pass using stale pictures or no judged rounds. The trace workflow also needs Windows and Intel validation before its cross-platform behavior is established. Adds an opt-in recorder and game-free player for one renderer frame, plus a picture comparison tool. It enables repeatable renderer investigation, at the cost of multi-gigabyte traces and substantial replay memory and time; correctness of the recording and comparison needs fixes. **Blocking (5)**: must change before merging. 1. **L1** `host/rx_trace.c:251`: The recorder clears the same dirty marks the renderer collects and restores them only afterwards, so the two collectors can miss a write. (more on the line) **Do:** Give the recorder independent write marks or synchronize its collection with every renderer collector so neither consumes the other's marks. 2. **L2** `host/rx_backend.c:711`: rx_trace_on is read plainly on renderer-calling threads while the recorder writes it atomically on another thread. (more on the line) **Do:** Use atomic loads for every access to the flag, with publication ordering appropriate for recorder initialization and shutdown. 3. **L3** `scripts/trace_compare.py:118`: Replay reuses existing screenshot directories without removing or isolating old rounds. (more on the line) **Do:** Use fresh per-run screenshot directories and require the expected newly produced rounds from each replay before comparing. 4. **L4** `scripts/trace_compare.py:160`: The comparison can pass without judging any pictures, and silently ignores rounds missing on one side. (more on the line) **Do:** Reject an empty judged range and require matching, complete expected round sets, allowing only the explicitly documented unfinished final picture. 5. **L5** `scripts/trace_compare.py:119`: Relative runtime paths are used both as the subprocess working directory and as the executable path. (more on the line) **Do:** Resolve each runtime to an absolute path before constructing the executable and passing cwd. **Should fix (1)**: not blocking, but worth doing before merging. - **L6** `tests/test_rx_trace_format.py:456`: This new compiler-based check defaults to gcc and does not declare the suite's compiler argument. (more on the line) **Do:** Declare RUN_ALL_ARGS = ["--cc", "{cc}"] and honor the selected compiler for standalone runs as well. **Nits (1)**: optional. - **L7** `gpu/vk/switches.def:208`: The HOS_RX_TRACE_AT row describes a default that the recorder does not implement. (more on the line) **Do:** Describe the value as required, or implement and document the first-present default consistently. **Testing before merging (2)** (runs on the systems it can change; it doesn't hold the recommendation) - **L8**: The Windows recording and replay path has not been exercised on this head. *When:* Windows uses different guest-memory commitment and file handling, so the reported Linux runs do not show that a recorded frame can be replayed there. **Do:** On Windows, record and replay a frame for at least 12 rounds, including a UTF-8 path, and compare judged rounds and a live picture. - **L9**: The new Vulkan image capture and restoration path has not been exercised on an Intel GPU. *When:* The reported NVIDIA and AMD runs do not cover Intel's Vulkan implementation for the image formats and copies used by capture and replay. **Do:** Record and replay a representative frame on Intel, compare judged rounds and the live picture, and inspect validation output. `@fix` can do L1, L2, L3, L4, L5, L6 and L7. **Checks:** Failing on this head, which is behind its base, where it passes: `PR description / Description follows the template (pull_request_target)`. `@rebase` (or `@fix`) brings it up to date and runs it again; not held against it. Still running: 10 checks. <details> <summary>More: does it help, other systems, switches, what was read</summary> **Does it help:** Unproven as a general renderer comparison tool. The PR reports Linux replays within 0.00001 between judged rounds on an RTX 4070 Ti and an AMD integrated GPU, and a market replay 0.000134 from a live picture. One cold play differed by 0.027 in rounds 2 and 3, and one recording differed by 0.0266 from the next live picture. Windows and Intel were not tested on this head. **Other systems:** Recording touches shared guest-memory dirty marks and renderer calls even though the feature is opt-in; the dirty-mark race can affect the live recording run. Replay changes Vulkan image restoration and memory handling on all vendors. Linux NVIDIA and AMD runs are reported; Windows and Intel remain untested. Temporal upscaler history, frame generation, multisampled and sparse images are explicitly outside the recorded state. **Switches:** HOS_RX_TRACE is off by default and names a game-derived output file. HOS_RX_TRACE_AT is required and must be at least 1, although its switch-table row incorrectly says the first present is the default. Replay defaults RX_VK_ASYNC=0, RX_VK_RECORDER=off and RX_VK_UPLOAD_BUDGET_MS=0 only when each is unset; explicit environment values override them. --play-trace, --frames and --carry add command-line controls. **Reviewed:** 6ffa4553da8c against 0e32bc100dbe: Read the repository instructions, contribution rules, PR template, commit log, changed host trace and comparison paths, and the renderer and backend diffs; inspected the new tests and trace documentation. Skimmed the remaining changed harnesses and surrounding renderer code. The complete changed code and all callers were not read in full; docs/review-checklist.md and the sibling Tooling checkout were absent.; nothing run (a code review). **Checked and fine:** - The renderer interface version is bumped from 45 to 46 for the appended entries. - The added switches have entries in switches.def. - The listed commits record AI assistance in trailers. - The PR reports that traces and pictures made from the game were not committed. **Testing:** No commands that build or execute project code were run, as requested. The PR reports Linux game-free checks and NVIDIA and AMD recording and replay runs; CI is still running. **Overlaps and merge order:** The PR identifies #1334 as prior work and separates the shader-preparation supervisor; no independent overlap search was possible with the network closed. </details> --- <sub>Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.</sub>
@ -205,2 +205,4 @@
SW(HOS_RT_POOL_MB, tune, int, "the game's pool scaled with the output's pixels: at least 512 MB, 900 MB past 4K", "Sets the size of the game's render-target pool in MB, over the scaled default.")
SW(HOS_RUMBLE_BACKEND, attempt, enum, "auto: the Vibration row's Auto (RenHDrum for a DualSense on a cable, a Switch controller's own HD rumble, the motors otherwise)", "renhdrum: RenHDrum for every controller it can play (a DualSense over Bluetooth, an Xbox One or Series controller's four motors, a Switch controller's packets), for testers; motors: every controller's motors; hd: no RenHDrum at all (host/vibration.h).")
SW(HOS_RX_TRACE, diag, string, "off: nothing recorded", "Records one frame of the renderer's calls and the guest memory they read into this file, for longshot --play-trace. Game data.")
SW(HOS_RX_TRACE_AT, diag, int, "the first present", "Which present (counted from 1) the recorded frame follows.")
Member

L7 (nit): The HOS_RX_TRACE_AT row describes a default that the recorder does not implement.

When: Setting HOS_RX_TRACE alone leaves trace_at at zero and refuses to record, although the table says the first present is selected.

Do: Describe the value as required, or implement and document the first-present default consistently.

**L7** (nit): The HOS_RX_TRACE_AT row describes a default that the recorder does not implement. *When:* Setting HOS_RX_TRACE alone leaves trace_at at zero and refuses to record, although the table says the first present is selected. **Do:** Describe the value as required, or implement and document the first-present default consistently.
@ -691,2 +709,3 @@
}
void rx_nvn_submit(const uint64_t *handles, int n) { vk ? vk->nvn_submit(handles, n) : wgr_nvn_submit(handles, n); }
void rx_nvn_submit(const uint64_t *handles, int n) {
if (rx_trace_on) rx_trace_submit(handles, n, 0, 0);
Member

L2 (blocking): rx_trace_on is read plainly on renderer-calling threads while the recorder writes it atomically on another thread.

When: When a present finishes recording and clears the flag while another game thread enters a renderer wrapper, the unsynchronized plain read races the atomic store; the C memory model does not guarantee that the wrapper sees a valid, current state.

Do: Use atomic loads for every access to the flag, with publication ordering appropriate for recorder initialization and shutdown.

**L2** (blocking): rx_trace_on is read plainly on renderer-calling threads while the recorder writes it atomically on another thread. *When:* When a present finishes recording and clears the flag while another game thread enters a renderer wrapper, the unsynchronized plain read races the atomic store; the C memory model does not guarantee that the wrapper sees a valid, current state. **Do:** Use atomic loads for every access to the flag, with publication ordering appropriate for recorder initialization and shutdown.
@ -0,0 +248,4 @@
put(RX_TRACE_IMAGE, image, sizeof *image, texels, texels ? (size_t)image->bytes : 0);
trace_images++, trace_image_bytes += texels ? image->bytes : 0, trace_images_unread += !texels;
return !trace_failed;
}
Member

L1 (blocking): The recorder clears the same dirty marks the renderer collects and restores them only afterwards, so the two collectors can miss a write.

When: During a recording, the recorder clears a marked pool page in rx_trace_collect while a renderer capture on another thread scans it. The renderer sees the page as clean before HOS_WRITTEN restores the mark and can use stale mirrored contents for the live frame.

Do: Give the recorder independent write marks or synchronize its collection with every renderer collector so neither consumes the other's marks.

**L1** (blocking): The recorder clears the same dirty marks the renderer collects and restores them only afterwards, so the two collectors can miss a write. *When:* During a recording, the recorder clears a marked pool page in rx_trace_collect while a renderer capture on another thread scans it. The renderer sees the page as clean before HOS_WRITTEN restores the mark and can use stale mirrored contents for the live frame. **Do:** Give the recorder independent write marks or synchronize its collection with every renderer collector so neither consumes the other's marks.
@ -0,0 +115,4 @@
def play(runtime, trace, frames, shots, label):
"""Plays the trace on a runtime through the job queue; the pictures go to shots"""
shots.mkdir(parents=True, exist_ok=True)
Member

L3 (blocking): Replay reuses existing screenshot directories without removing or isolating old rounds.

When: Run a comparison twice with the same output directory; if a later replay fails to write a screenshot, rounds_in still finds the previous run's vk_*.png and can report PASS using that stale picture.

Do: Use fresh per-run screenshot directories and require the expected newly produced rounds from each replay before comparing.

**L3** (blocking): Replay reuses existing screenshot directories without removing or isolating old rounds. *When:* Run a comparison twice with the same output directory; if a later replay fails to write a screenshot, rounds_in still finds the previous run's vk_*.png and can report PASS using that stale picture. **Do:** Use fresh per-run screenshot directories and require the expected newly produced rounds from each replay before comparing.
@ -0,0 +116,4 @@
def play(runtime, trace, frames, shots, label):
"""Plays the trace on a runtime through the job queue; the pictures go to shots"""
shots.mkdir(parents=True, exist_ok=True)
exe = Path(runtime) / ("longshot.exe" if os.name == "nt" else "longshot")
Member

L5 (blocking): Relative runtime paths are used both as the subprocess working directory and as the executable path.

When: The documented --a work/rt-base invocation constructs work/rt-base/longshot and then runs it with cwd set to work/rt-base, so the child looks for work/rt-base/work/rt-base/longshot and fails.

Do: Resolve each runtime to an absolute path before constructing the executable and passing cwd.

**L5** (blocking): Relative runtime paths are used both as the subprocess working directory and as the executable path. *When:* The documented --a work/rt-base invocation constructs work/rt-base/longshot and then runs it with cwd set to work/rt-base, so the child looks for work/rt-base/work/rt-base/longshot and fails. **Do:** Resolve each runtime to an absolute path before constructing the executable and passing cwd.
@ -0,0 +157,4 @@
out.mkdir(parents=True, exist_ok=True)
ra, rb = rounds_in(sa), rounds_in(sb)
common = sorted(set(ra) & set(rb))
if len(common) < 2:
Member

L4 (blocking): The comparison can pass without judging any pictures, and silently ignores rounds missing on one side.

When: With two common pictures and --from-round greater than both round numbers, worst remains zero and the script prints PASS. Similarly, a missing picture for a bad round is excluded by the intersection.

Do: Reject an empty judged range and require matching, complete expected round sets, allowing only the explicitly documented unfinished final picture.

**L4** (blocking): The comparison can pass without judging any pictures, and silently ignores rounds missing on one side. *When:* With two common pictures and --from-round greater than both round numbers, worst remains zero and the script prints PASS. Similarly, a missing picture for a bad round is excluded by the intersection. **Do:** Reject an empty judged range and require matching, complete expected round sets, allowing only the explicitly documented unfinished final picture.
@ -0,0 +453,4 @@
def main():
p = argparse.ArgumentParser(description=__doc__)
p.add_argument("--cc", default="gcc")
Member

L6 (should fix): This new compiler-based check defaults to gcc and does not declare the suite's compiler argument.

When: On a supported test machine with CC set to Clang and no gcc, run_all invokes this test without --cc and the fixture cannot compile, even though the suite has selected an available compiler.

Do: Declare RUN_ALL_ARGS = ["--cc", "{cc}"] and honor the selected compiler for standalone runs as well.

**L6** (should fix): This new compiler-based check defaults to gcc and does not declare the suite's compiler argument. *When:* On a supported test machine with CC set to Clang and no gcc, run_all invokes this test without --cc and the fixture cannot compile, even though the suite has selected an available compiler. **Do:** Declare RUN_ALL_ARGS = ["--cc", "{cc}"] and honor the selected compiler for standalone runs as well.
Some checks failed
CI / Conventional Commit title (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Blocked by required conditions
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Blocked by required conditions
CI / Workflow lint (actionlint) (pull_request) Blocked by required conditions
CI / Website build and checks (pull_request) Blocked by required conditions
Guide screenshots / Guide images and local UI source review (pull_request) Blocked by required conditions
Third-party parts / As their notes say (pull_request) Blocked by required conditions
Third-party parts / The same as upstream (pull_request) Blocked by required conditions
Website / Website on Cloudflare (pull_request) Blocked by required conditions
PR description / Description follows the template (pull_request_target) Failing after 27s
This pull request doesn't have enough approvals yet. 0 of 1 approvals granted.
Some workflows are waiting to be reviewed.
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 'feat/trace-replay-continued:TrashPanda-feat/trace-replay-continued'
git switch 'TrashPanda-feat/trace-replay-continued'
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
3 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
MagicBeanDev/Longshot!2322
No description provided.