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

Closed
github-bot wants to merge 1 commit from github-bot/gh-109 into main AGit
Owner

@⁠Bushyon on GitHub · 2026-12-01 20:38 UTC · original
Bushyon:by-address-card-budget → main · +49 −9 · 1 files · 1 commits · closed without merging

The bug

two_sided (used by shadow::by_address) counts the bytes it puts on the card's own memory in a function-local static USED that only grows: a copy that goes is never taken off. After 4 GiB has passed through it over a session (not 4 GiB alive at once), every later copy goes to the PC's memory, however much room the card has. A long-session slowdown, ray tracing only.

The fix

  • The count is now a module-level CARD_RESERVED.
  • reserve_card reserves a copy's bytes and undoes the reservation when the limit would be passed or the buffer isn't made.
  • Shadow::drop gives the bytes back for copies that were on the card.
  • The limit (4 GiB) and the room check are unchanged.

Tests

  • New unit test the_count_is_of_copies_alive (limit, refused, not made, room back after a drop). It compiles but I could not run it: the test exe under wine printed nothing here.
  • ./build.sh build ok. In the game (run.sh play, VICTORY_BVH_BUILDER=1, 5 min, 64 MB limit via a temporary switch not in this PR) old and new counting placed copies the same way and nothing crashed. No copies were freed in that time, which is the only case where they differ, so this is not shown in the game.

AI-assisted.

**@⁠Bushyon** on GitHub · 2026-12-01 20:38 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/109) `Bushyon:by-address-card-budget` → `main` · +49 −9 · 1 files · 1 commits · closed without merging ## The bug `two_sided` (used by `shadow::by_address`) counts the bytes it puts on the card's own memory in a function-local `static USED` that only grows: a copy that goes is never taken off. After 4 GiB has passed through it over a session (not 4 GiB alive at once), every later copy goes to the PC's memory, however much room the card has. A long-session slowdown, ray tracing only. ## The fix - The count is now a module-level `CARD_RESERVED`. - `reserve_card` reserves a copy's bytes and undoes the reservation when the limit would be passed or the buffer isn't made. - `Shadow::drop` gives the bytes back for copies that were on the card. - The limit (4 GiB) and the room check are unchanged. ## Tests - New unit test `the_count_is_of_copies_alive` (limit, refused, not made, room back after a drop). It compiles but I could not run it: the test exe under wine printed nothing here. - `./build.sh build` ok. In the game (`run.sh play`, `VICTORY_BVH_BUILDER=1`, 5 min, 64 MB limit via a temporary switch not in this PR) old and new counting placed copies the same way and nothing crashed. No copies were freed in that time, which is the only case where they differ, so this is not shown in the game. AI-assisted.
The card-side byte count in two_sided was a function-local static that
only grew: a copy that went was never taken off. After 4 GiB had passed
through it over a session, every later copy went to the PC's memory
however much room the card had.

The count is now a module-level CARD_RESERVED. reserve_card reserves a
copy's bytes and undoes the reservation when the limit is passed or the
buffer isn't made; Shadow::drop gives the bytes back.

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

@⁠Frtuchinno on GitHub · 2026-12-01 20:52 UTC · original

Ran the tests you couldn't run, on an RX 7800 XT (RDNA3), CachyOS, proton-cachyos-slr, this PR merged on 37bb30f:

test shadow::card_reserve_tests::the_count_is_of_copies_alive ... ok
test result: ok. 11 passed; 0 failed; 1 ignored (shadow::)

The ignored one is merge_tests::runs_of_equal_pages, marked #[ignore] in the tree already.

Why the test exe printed nothing: it imports d3d12.dll, and without the DLL overrides run.sh sets, Wine/Proton loads its builtin d3d12 → wined3d, which isn't there, so the process exits during import (status c0000135, exit code 53) before the harness prints anything. With the same overrides as run.sh it runs:

export WINEDLLOVERRIDES='d3d12,d3d12core,dxgi=n;d3dcompiler_47=n,b'
PKG=victory-gpu ./build.sh test --lib --no-run       # build only
source env.sh
"$WINE_BIN" target/x86_64-pc-windows-msvc/release/deps/victory_gpu-*.exe <filter>

(Running the whole victory-gpu suite in one go still dies part-way with exit status 5 on unmodified main here, so a filter is the way to check one module. build.sh appends its own flags after its arguments, so a test filter can't go through it; hence running the exe directly.)

**@⁠Frtuchinno** on GitHub · 2026-12-01 20:52 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/109#issuecomment-7325398085) Ran the tests you couldn't run, on an RX 7800 XT (RDNA3), CachyOS, `proton-cachyos-slr`, this PR merged on `37bb30f`: ``` test shadow::card_reserve_tests::the_count_is_of_copies_alive ... ok test result: ok. 11 passed; 0 failed; 1 ignored (shadow::) ``` The ignored one is `merge_tests::runs_of_equal_pages`, marked `#[ignore]` in the tree already. **Why the test exe printed nothing:** it imports `d3d12.dll`, and without the DLL overrides `run.sh` sets, Wine/Proton loads its builtin `d3d12` → `wined3d`, which isn't there, so the process exits during import (status `c0000135`, exit code 53) before the harness prints anything. With the same overrides as `run.sh` it runs: ```sh export WINEDLLOVERRIDES='d3d12,d3d12core,dxgi=n;d3dcompiler_47=n,b' PKG=victory-gpu ./build.sh test --lib --no-run # build only source env.sh "$WINE_BIN" target/x86_64-pc-windows-msvc/release/deps/victory_gpu-*.exe <filter> ``` (Running the whole `victory-gpu` suite in one go still dies part-way with exit status 5 on unmodified `main` here, so a filter is the way to check one module. `build.sh` appends its own flags after its arguments, so a test filter can't go through it; hence running the exe directly.)
github-bot closed this pull request 2026-12-02 01:56:37 +00:00
Author
Owner

@⁠goldfishdev on GitHub · 2026-12-02 01:54 UTC · original

Merged to main as cherry-picked commit 7df1fdd. Thanks!

**@⁠goldfishdev** on GitHub · 2026-12-02 01:54 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/109#issuecomment-7332234009) Merged to main as cherry-picked commit `7df1fdd`. Thanks!

Pull request closed

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