fix(vk): the mesh draw log counters stop counting once they stop logging #2522

Merged
HumanBean merged 2 commits from neotoxic/Longshot:fix-mesh-log-counters into main 2026-11-28 05:21:49 +00:00
Contributor

Summary

Two "log the first N" counters run on every mesh draw, and both were incremented on every draw, not only while under
their limit (if (logged++ < 6)):

  • mesh_program_locked (gpu/vk/vk_shader.cpp): 6 lines of the draw's stages, through log_program_stages, which
    reads every stage back from guest memory, hashes it and parses it, under shader_mu;
  • the replay's NOP_DRAW_MESH (gpu/vk/vk_replay.cpp): 8 lines of the draw's arguments.

After 2^31 mesh draws the signed int overflows: undefined behaviour, and in practice it wraps negative, so both log
on every mesh draw for the next 2^31, mesh_program_locked's with its stage read-back and parse. At the game's few
hundred mesh draws a frame that is a long session (tens of hours at 60 fps), a game left running. Each counter now
counts only while it logs (if (logged < 6 && ++logged)): the same 6 and 8 lines, then nothing.

How to see it on main: not in a play session (it takes 2^31 draws); the test below shows both counters still
counting after their limit.

I found it in a static read of the renderer's per-draw paths; a sweep of the other 157 x++ < N counters in gpu/
and host/ found no other one evaluated on every draw (the rest sit in error branches, behind debug switches, or run
once per object or frame).

Testing

Tested: Windows 11 Pro 26300, RTX 5080 (NVIDIA), Ryzen 9 7950X: built as a pack over main's base (dev.py pack,
dev.py rt) and played from the kokiri-start repo save into Kokiri Forest (5774 draws on arrival, 590-690 after),
walking: the log has the 8 vk: mesh draw kind lines and the 6 mesh draw stage lines, as on main, then none; the game
closed cleanly (stop: close work done). tests/test_mesh_log_counters.py (new, two commits: the test, then the fix)
fails on main @ be663a08 ("counter after 1000 mesh draws: 1000, not 6" and "1000, not 8") and passes here, with
llvm-mingw's clang++ and with MinGW g++. run_all.py --strict (all of it): 688 passed, 111 failed, 45 skipped; 110 fail the same on main on this Windows PC
(Linux-only and POSIX checks), and test_recording_admission.py's parallel case crashed once under the 32-way run
(0xC0000374) and passes run again alone, as it passed in the same run on main: it reads none of the changed files.

Still to test: None.

Measurements

Verdict: the bug is gone (both counters stop at their limits); nothing to measure in fps: the lines logged are the same.

Setup: Windows 11 Pro 26300, RTX 5080, NVIDIA driver of this PC; the check run on main and here; Kokiri Forest from the kokiri-start repo save, the log lines counted.

Before: main @ be663a08 After: this PR @ 95af4413
test_mesh_log_counters.py fails (counters at 1000 after 1000 mesh draws) passes (6 and 8)
Kokiri Forest run: mesh draw log lines 8 + 6 8 + 6

Risks

None expected: the same lines are logged, and the counters stay at their limits instead of growing. A revert is enough.

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.
  • mise run test passes (any failure that also fails on main is named).
  • 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.

When it applies

  • A fix: a game-free test that fails on main and passes here.
  • Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths. (Windows: the renderer built here by dev.py pack; Linux: CI's build)
  • 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.

🤖 Generated with Claude Code

## Summary Two "log the first N" counters run on every mesh draw, and both were incremented on every draw, not only while under their limit (`if (logged++ < 6)`): - `mesh_program_locked` (`gpu/vk/vk_shader.cpp`): 6 lines of the draw's stages, through `log_program_stages`, which reads every stage back from guest memory, hashes it and parses it, under `shader_mu`; - the replay's `NOP_DRAW_MESH` (`gpu/vk/vk_replay.cpp`): 8 lines of the draw's arguments. After 2^31 mesh draws the signed `int` overflows: undefined behaviour, and in practice it wraps negative, so both log on every mesh draw for the next 2^31, `mesh_program_locked`'s with its stage read-back and parse. At the game's few hundred mesh draws a frame that is a long session (tens of hours at 60 fps), a game left running. Each counter now counts only while it logs (`if (logged < 6 && ++logged)`): the same 6 and 8 lines, then nothing. How to see it on `main`: not in a play session (it takes 2^31 draws); the test below shows both counters still counting after their limit. I found it in a static read of the renderer's per-draw paths; a sweep of the other 157 `x++ < N` counters in `gpu/` and `host/` found no other one evaluated on every draw (the rest sit in error branches, behind debug switches, or run once per object or frame). ## Testing **Tested:** Windows 11 Pro 26300, RTX 5080 (NVIDIA), Ryzen 9 7950X: built as a pack over main's base (`dev.py pack`, `dev.py rt`) and played from the `kokiri-start` repo save into Kokiri Forest (5774 draws on arrival, 590-690 after), walking: the log has the 8 `vk: mesh draw kind` lines and the 6 mesh draw stage lines, as on `main`, then none; the game closed cleanly (`stop: close work done`). `tests/test_mesh_log_counters.py` (new, two commits: the test, then the fix) fails on `main` @ be663a08 ("counter after 1000 mesh draws: 1000, not 6" and "1000, not 8") and passes here, with llvm-mingw's clang++ and with MinGW g++. `run_all.py --strict` (all of it): 688 passed, 111 failed, 45 skipped; 110 fail the same on `main` on this Windows PC (Linux-only and POSIX checks), and `test_recording_admission.py`'s `parallel` case crashed once under the 32-way run (0xC0000374) and passes run again alone, as it passed in the same run on `main`: it reads none of the changed files. **Still to test:** None. ## Measurements **Verdict:** the bug is gone (both counters stop at their limits); nothing to measure in fps: the lines logged are the same. Setup: Windows 11 Pro 26300, RTX 5080, NVIDIA driver of this PC; the check run on main and here; Kokiri Forest from the kokiri-start repo save, the log lines counted. | | Before: main @ be663a08 | After: this PR @ 95af4413 | |---|---|---| | `test_mesh_log_counters.py` | fails (counters at 1000 after 1000 mesh draws) | passes (6 and 8) | | Kokiri Forest run: mesh draw log lines | 8 + 6 | 8 + 6 | ## Risks None expected: the same lines are logged, and the counters stay at their limits instead of growing. A revert is enough. ## Checklist ### Ready for review - [x] One topic, on current `main`; the title is a Conventional Commit. - [x] Tested on my own PC, in the game for a change the game runs, as Testing says. - [x] `mise run test` passes (any failure that also fails on `main` is named). - [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. ### When it applies - [x] A fix: a game-free test that fails on `main` and passes here. - [x] Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths. (Windows: the renderer built here by `dev.py pack`; Linux: CI's build) - [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. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Cuts mesh_program_locked's and the replay's NOP_DRAW_MESH log counters out
of their sources and runs 1000 mesh draws: each must log its limit (6, 8)
and its counter stop there. Fails on main, where both counters reach 1000
and would overflow after 2^31 mesh draws.

Assisted-by: Claude Code
Co-Authored-By: Claude Opus 5.5 <[email protected]>
fix(vk): the mesh draw log counters stop counting once they stop logging
Some checks are pending
CI / Conventional Commit title (pull_request) Blocked by required conditions
CI / Rust (rustfmt, clippy, cargo test) (pull_request) Blocked by required conditions
CI / longshot-builder end to end (synthetic game) (pull_request) Blocked by required conditions
CI / Host C for Windows (llvm-mingw, compile only) (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
PR description / Description follows the template (pull_request_target) Successful in 13s
95af44131e
Both counters were incremented on every mesh draw, not only while under
their limit, so a long session overflowed them (signed int, undefined
behaviour) and they logged every mesh draw again, mesh_program_locked's
reading back and parsing the draw's stages each time.

Assisted-by: Claude Code
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Author
Contributor

Tested in game: Windows 11 Pro 26300, RTX 5080, Ryzen 9 7950X: a pack over main's base, played from the kokiri-start repo save into Kokiri Forest (5774 draws on arrival, 590-690 walking): the 8 'vk: mesh draw kind' lines and 6 mesh draw stage lines as on main, then none; closed cleanly.

Tested in game: Windows 11 Pro 26300, RTX 5080, Ryzen 9 7950X: a pack over main's base, played from the kokiri-start repo save into Kokiri Forest (5774 draws on arrival, 590-690 walking): the 8 'vk: mesh draw kind' lines and 6 mesh draw stage lines as on main, then none; closed cleanly.
Author
Contributor

The description: the bug, the test failing on main and passing here, the in-game run.

The description: the bug, the test failing on main and passing here, the in-game run.
Author
Contributor

Measurements: the verdict and setup lines.

Measurements: the verdict and setup lines.
Author
Contributor

Testing: the whole suite, not only the changed checks.

Testing: the whole suite, not only the changed checks.
neotoxic changed title from WIP: fix(vk): the mesh draw log counters stop counting once they stop logging to fix(vk): the mesh draw log counters stop counting once they stop logging 2026-11-25 11:25:41 +00:00
Owner
@review
BeanBot left a comment

Recommendation: Approve. The code is ready: only testing is left. The counters now stop at their limits, removing the signed overflow without changing the intended log output. The reported Windows run supports the fix, but the remaining Tier 1 platforms and pending CI checks need results before merge. Recommend approval; not approved on the forge.

The change prevents mesh draw logging from resuming after a very long session. It adds a focused game-free regression test and makes no other intended player-facing change.

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

  • L1: The changed renderer path has not been exercised on the remaining Tier 1 systems. When: The reported run covers NVIDIA on Windows; there is no reported run on NVIDIA Linux, AMD Windows or Linux, or Steam Deck to check the shared mesh replay path. Do: Run a mesh-drawing scene on those Tier 1 systems and confirm the initial log limits and normal rendering.

Checks: Still running: 9 checks.

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

Does it help: Yes. The reported test leaves the counters at 1000 on the base and at 6 and 8 on this head; the reported Windows game run logged the same initial 6 and 8 lines as main. This is a correctness fix, not a claimed performance gain.

Other systems: Both counters execute in renderer paths shared across platforms. The shader counter is protected by shader_mu; replay is serialized by replay_mu. The reported game run covers NVIDIA on Windows; Linux, AMD and Steam Deck runs were not reported.

Switches: None.

Reviewed: 95af44131e against be663a08a3: Read AGENTS.md, CONTRIBUTING.md, the pull request template, the standards and fix-with-test rules, the diff, both commit messages, the new test, and the changed code with its immediate callers and locking context. Skimmed the replay and shader files outside that context and the test runner and source-cutting helper; the two large changed renderer files were not read in full. docs/review-checklist.md and the adjacent Tooling AGENTS.md were absent.; nothing run (a code review).

Checked and fine:

  • Both commits record AI assistance; the diff contains no generated files, game-derived files, API changes or switch changes.
  • The regression test checks the counter values and log calls after 1000 iterations and is reported to fail on the base for the intended reason.
  • The shader counter is reached under shader_mu; the replay path is serialized.

Testing: No commands from the pull request were run during review. The author reports a Windows game run and regression-test runs with llvm-mingw clang++ and MinGW g++; the supplied CI status still has checks running.

Overlaps and merge order: Not established from the offline checkout.


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

**Recommendation: Approve.** The code is ready: only testing is left. The counters now stop at their limits, removing the signed overflow without changing the intended log output. The reported Windows run supports the fix, but the remaining Tier 1 platforms and pending CI checks need results before merge. Recommend approval; not approved on the forge. The change prevents mesh draw logging from resuming after a very long session. It adds a focused game-free regression test and makes no other intended player-facing change. **Testing before merging (1)** (runs on the systems it can change; it doesn't hold the recommendation) - **L1**: The changed renderer path has not been exercised on the remaining Tier 1 systems. *When:* The reported run covers NVIDIA on Windows; there is no reported run on NVIDIA Linux, AMD Windows or Linux, or Steam Deck to check the shared mesh replay path. **Do:** Run a mesh-drawing scene on those Tier 1 systems and confirm the initial log limits and normal rendering. **Checks:** Still running: 9 checks. <details> <summary>More: does it help, other systems, switches, what was read</summary> **Does it help:** Yes. The reported test leaves the counters at 1000 on the base and at 6 and 8 on this head; the reported Windows game run logged the same initial 6 and 8 lines as main. This is a correctness fix, not a claimed performance gain. **Other systems:** Both counters execute in renderer paths shared across platforms. The shader counter is protected by shader_mu; replay is serialized by replay_mu. The reported game run covers NVIDIA on Windows; Linux, AMD and Steam Deck runs were not reported. **Switches:** None. **Reviewed:** 95af44131e51 against be663a08a30f: Read AGENTS.md, CONTRIBUTING.md, the pull request template, the standards and fix-with-test rules, the diff, both commit messages, the new test, and the changed code with its immediate callers and locking context. Skimmed the replay and shader files outside that context and the test runner and source-cutting helper; the two large changed renderer files were not read in full. docs/review-checklist.md and the adjacent Tooling AGENTS.md were absent.; nothing run (a code review). **Checked and fine:** - Both commits record AI assistance; the diff contains no generated files, game-derived files, API changes or switch changes. - The regression test checks the counter values and log calls after 1000 iterations and is reported to fail on the base for the intended reason. - The shader counter is reached under shader_mu; the replay path is serialized. **Testing:** No commands from the pull request were run during review. The author reports a Windows game run and regression-test runs with llvm-mingw clang++ and MinGW g++; the supplied CI status still has checks running. **Overlaps and merge order:** Not established from the offline checkout. </details> --- <sub>Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.</sub>
HumanBean deleted branch fix-mesh-log-counters 2026-11-28 05:21:50 +00:00
Some checks are pending
CI / Conventional Commit title (pull_request) Blocked by required conditions
CI / Rust (rustfmt, clippy, cargo test) (pull_request) Blocked by required conditions
CI / longshot-builder end to end (synthetic game) (pull_request) Blocked by required conditions
CI / Host C for Windows (llvm-mingw, compile only) (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
PR description / Description follows the template (pull_request_target) Successful in 13s
Some workflows are waiting to be reviewed.
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!2522
No description provided.