shadow: by_address limits the card bytes alive, not all ever placed #333

Closed
github-bot wants to merge 0 commits from github-bot/gh-333 into main AGit
Owner

@⁠Bushyon on GitHub · 2026-12-01 14:17 UTC · original
Bushyon:by-address-card-budget → main · +65 −6 · 1 files · 72 commits · closed without merging

shadow: by_address limits the card bytes alive, not all ever placed

The bug

shadow::by_address makes the copies programs find memory by address through: the structures rays are traced through, read with every step of every ray. It puts a copy's shader side in the card's own memory up to VICTORY_MEMORY_CARD_MB (4096 by default). The bytes were counted in a function-local static USED, which:

  • only grew: a copy that went was never taken off;
  • counted copies that never reached the card: the fetch_add happened before the limit check, so a copy refused for being over the limit was added anyway, and so was one whose uav_buffer failed.

So after 4 GiB had passed through it over a session (not 4 GiB alive at once), every later copy by address went to the PC's memory, however much room the card had. It is a long-session slowdown, and only for ray tracing.

The fix

  • The count is now a module-level BY_ADDRESS_CARD.
  • reserve_card reserves a copy's bytes, and undoes the reservation when the limit is passed or the buffer isn't made.
  • A copy records the bytes it counts (Shadow::by_address_card) and gives them back in Drop.
  • The limit and the room check are unchanged.

Tests

  • New the_count_is_of_copies_alive, against a counter of its own so parallel tests can't disturb it. It covers a copy within the limit, one refused over it, one whose buffer wasn't made, and room coming back once a copy goes.
  • cargo clippy -p victory-gpu --all-targets with and without --all-features, -D warnings: clean.
  • cargo test -p victory-gpu: 476 passed. One run hit watch::tests::what_the_kernel_writes_through_is_not_guarded_for_another_view, which passes alone; the watch tests are timing-sensitive under the parallel run on main too.
  • cargo xtask policy --staged: ok.

Measured in the game

Two hands-off runs, VICTORY_BVH_BUILDER=1 (ray tracing on) and VICTORY_MEMORY_CARD_MB=64, so that the limit is reached within minutes. The same build ran both ways: one with a temporary switch that brought back the old counting, one with the fix. A temporary log recorded where each copy went (neither switch nor log is in this PR).

Copies by address Old counting This PR
on the card 1 (16 MB) 17 (17 MB)
in the PC's memory 31 (1,088 MB) 14 (896 MB)
what the count said was on the card 1,104 MB 17 MB

With the old count, every refused copy was added, so the 64 KiB copies were turned away too while the card held 16 MB. With the fix, the count matches what is on the card, and only the copies that are alone over the 64 MB limit go to the PC's memory. Copies being freed (bytes given back) didn't happen in these short runs; the unit test covers it.

Independent of #331 (small buffers placed together); this one touches only shadow.rs.

🤖 Generated with Claude Code

**@⁠Bushyon** on GitHub · 2026-12-01 14:17 UTC · [original](https://github.com/readmet3xt-lab/foxhound/pull/333) `Bushyon:by-address-card-budget` → `main` · +65 −6 · 1 files · 72 commits · closed without merging ## shadow: by_address limits the card bytes alive, not all ever placed ### The bug `shadow::by_address` makes the copies programs find memory by address through: the structures rays are traced through, read with every step of every ray. It puts a copy's shader side in the card's own memory up to `VICTORY_MEMORY_CARD_MB` (4096 by default). The bytes were counted in a function-local `static USED`, which: - **only grew:** a copy that went was never taken off; - **counted copies that never reached the card:** the `fetch_add` happened before the limit check, so a copy refused for being over the limit was added anyway, and so was one whose `uav_buffer` failed. So after 4 GiB had passed through it over a session (not 4 GiB alive at once), every later copy by address went to the PC's memory, however much room the card had. It is a long-session slowdown, and only for ray tracing. ### The fix - The count is now a module-level `BY_ADDRESS_CARD`. - `reserve_card` reserves a copy's bytes, and undoes the reservation when the limit is passed or the buffer isn't made. - A copy records the bytes it counts (`Shadow::by_address_card`) and gives them back in `Drop`. - The limit and the room check are unchanged. ### Tests - New `the_count_is_of_copies_alive`, against a counter of its own so parallel tests can't disturb it. It covers a copy within the limit, one refused over it, one whose buffer wasn't made, and room coming back once a copy goes. - `cargo clippy -p victory-gpu --all-targets` with and without `--all-features`, `-D warnings`: clean. - `cargo test -p victory-gpu`: 476 passed. One run hit `watch::tests::what_the_kernel_writes_through_is_not_guarded_for_another_view`, which passes alone; the `watch` tests are timing-sensitive under the parallel run on `main` too. - `cargo xtask policy --staged`: ok. ### Measured in the game Two hands-off runs, `VICTORY_BVH_BUILDER=1` (ray tracing on) and `VICTORY_MEMORY_CARD_MB=64`, so that the limit is reached within minutes. The same build ran both ways: one with a temporary switch that brought back the old counting, one with the fix. A temporary log recorded where each copy went (neither switch nor log is in this PR). | Copies by address | Old counting | This PR | |---|---|---| | on the card | 1 (16 MB) | 17 (17 MB) | | in the PC's memory | 31 (1,088 MB) | 14 (896 MB) | | what the count said was on the card | **1,104 MB** | **17 MB** | With the old count, every refused copy was added, so the 64 KiB copies were turned away too while the card held 16 MB. With the fix, the count matches what is on the card, and only the copies that are alone over the 64 MB limit go to the PC's memory. Copies being freed (bytes given back) didn't happen in these short runs; the unit test covers it. Independent of #331 (small buffers placed together); this one touches only `shadow.rs`. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
by_address kept the card's bytes of its copies in a function-local counter
that only grew: a copy that went was never taken off, and a copy refused over
VICTORY_MEMORY_CARD_MB or not made (no memory) was counted all the same. Once
4 GiB (the default) had passed through it over a run, every later copy by
address, the structures rays are traced through, read with every step of
every ray, went to the PC's memory whatever room the card had.

The count is now BY_ADDRESS_CARD: a reservation is undone when the limit is
passed or the buffer is not made, and a copy gives its bytes back when it
goes (Shadow::by_address_card). Test: the_count_is_of_copies_alive.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 14:20:45 +00:00
Author
Owner

@⁠Aniseto on GitHub · 2026-12-01 14:21 UTC · original

Ran the new the_count_is_of_copies_alive test at 5a4eaf0 on an NVIDIA Blackwell desktop part with 16 GB of VRAM.

Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only, 16 GB, mesh shaders) driver 32.0.16.2140 (621.40), Intel Core i5-12400F, 64 GB RAM, rustc 1.98.1 (48a229cea 2026-09-01), MSVC 14.44.35207, debug build, detached worktree at the exact PR head, own CARGO_TARGET_DIR, no local patches.

cargo test -q --locked -p victory-gpu --lib the_count_is_of_copies_alive -- --test-threads=1
1 passed; 0 failed; 0 ignored; 512 filtered out      (exit 0)

The new unit test passes here. It covers the counter of card bytes alive: copies within the limit, one refused over it, one whose buffer was not made, and room coming back after a copy goes. The description's 476-test package run and the long-session ray-tracing symptom were not repeated; no title was run.

Not tested: the full workspace suite, a retail title, a long ray-traced session, Wine, AMD adapters, release profile, game data.

AI-assisted (OpenCode), model: MiMo-V2.6-Flash Free - checked out the PR's head commit in a detached worktree, built it, ran the test, wrote this report; the worktree was not modified; no game data was used.

**@⁠Aniseto** on GitHub · 2026-12-01 14:21 UTC · [original](https://github.com/readmet3xt-lab/foxhound/pull/333#issuecomment-7314112751) Ran the new `the_count_is_of_copies_alive` test at `5a4eaf0` on an NVIDIA Blackwell desktop part with 16 GB of VRAM. Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only, 16 GB, mesh shaders) driver 32.0.16.2140 (621.40), Intel Core i5-12400F, 64 GB RAM, rustc 1.98.1 (48a229cea 2026-09-01), MSVC 14.44.35207, debug build, detached worktree at the exact PR head, own `CARGO_TARGET_DIR`, no local patches. ``` cargo test -q --locked -p victory-gpu --lib the_count_is_of_copies_alive -- --test-threads=1 1 passed; 0 failed; 0 ignored; 512 filtered out (exit 0) ``` The new unit test passes here. It covers the counter of card bytes alive: copies within the limit, one refused over it, one whose buffer was not made, and room coming back after a copy goes. The description's 476-test package run and the long-session ray-tracing symptom were not repeated; no title was run. Not tested: the full workspace suite, a retail title, a long ray-traced session, Wine, AMD adapters, release profile, game data. AI-assisted (OpenCode), model: **MiMo-V2.6-Flash Free** - checked out the PR's head commit in a detached worktree, built it, ran the test, wrote this report; the worktree was not modified; no game data was used.
github-bot closed this pull request 2026-12-02 07:54:39 +00:00

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.