feat(host): one frame is recorded and played with no game, on any build, with the rounds judged from round 2 #2322
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/renderer
area/saves
area/tooling
area/upscaling
beanstalk: approved
beanstalk: failed
beanstalk: needs approval
beanstalk: running
beanstalk: tested
ci: approved
good first issue
gpu/amd
gpu/igpu
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
needs measurements
platform/linux
platform/macos
platform/steam-deck
platform/windows
preview
priority
critical
priority
high
priority
low
regression
risk
high
risk
low
risk
medium
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
ci: approved
No milestone
No project
No assignees
3 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!2322
Loading…
Reference in a new issue
No description provided.
Delete branch "TrashPanda/Longshot:feat/trace-replay-continued"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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>withHOS_RX_TRACE_AT=<present>, and play it withlongshot --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 currentmain(one conflict, the interface version, which is now 46). Their third commit, the shader-preparation supervisor, is a separate topic and is offered separately, asfeat/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 onmainalready (#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):
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.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_VERSIONand 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.feat(host)scripts/trace_compare.pyplays 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:mainhas none. Test:tests/test_trace_compare.py.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 setsRX_VK_UPLOAD_BUDGET_MS=0unless the run sets it and printsplay: round N: D draws, L left out, P pipelines made.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.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-forestand--scene market,RX_VK_ASYNC=0); every file underLongshot/work/trace/, none of it committed.scripts/trace_compare.pyPASS, worst judged round 0.000004, twice.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.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) andUndefined-Value-ShaderOutputNotConsumed-DynamicRendering(a fragment output with no colour attachment).python -I -B tests/run_all.pythroughsuite.py compareagainstmainat753fb5af: 931 passed, 3 failed, 26 skipped on the branch (a0bd1883, then two commits that change a message and the doc), 928 / 3 / 26 onmain; 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 forrx_trace_*in the harnesses that cutrx_backend.candvk_texture.cpp).Still to test:
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).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 addsHOS_RX_TRACEandHOS_RX_TRACE_AT(HumanBean's rows, both off by default); the player setsRX_VK_ASYNC=0,RX_VK_RECORDER=offandRX_VK_UPLOAD_BUDGET_MS=0for its own run unless set, which changes no default of the game.753fb5af62cef5a42bRisks
A tool for developers: with
HOS_RX_TRACEand--play-traceunset nothing runs but one test ofrx_trace_onbefore each renderer call (HumanBean's). A trace is made from the game: it never leaves the PC.MKWVK_API_VERSIONgoes 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 bumpRX_TRACE_VERSION). Revert is enough; nothing in a player's saves or options changes.Checklist
Ready for review
main; the title is a Conventional Commit.mise run testpasses (any failure that also fails onmainis named): the 3 that fail onmainfail here too.main, or Measurements says why there is nothing to measure.third_party/untouched; nothing GPL-incompatible. No trace, picture or log made from the game is in the branch.When it applies
gpu/vk/switches.def.tests/that reads changed source is updated, not weakened.MKWVK_API_VERSIONbumped (MkwVkHostorMkwVkRendereringpu/vk/vk_api.hchanged).Assisted-by:/Co-Authored-By:trailers.Ready to merge
main, measured again or a comment says why the numbers still hold.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.
Possibly related, for context:
2cef5a42be6ffa4553daWIP: feat(host): one frame is recorded and played with no game, on any build, with the rounds judged from round 2to feat(host): one frame is recorded and played with no game, on any build, with the rounds judged from round 2@review
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.
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.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.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.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.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.
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.
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)
@fixcan 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:
6ffa4553daagainst0e32bc100d: 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:
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.
@ -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.")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);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;}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)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")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: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")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.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.