shader: a bound on the structurizer's if-then-else answers #4788

Open
github-bot wants to merge 1 commit from github-bot/gh-4787 into main AGit
Owner

@⁠Trillazill on GitHub · 2026-12-01 08:16 UTC · original
Trillazill:perf/structure-memo-cap → main · +42 −0 · 1 files · 1 commits · open

No issue for this; found in a diagnostics run's big-block log.

What it changes

Bools::ite in victory-shader/src/structure.rs kept every if-then-else answer it worked out, for the whole shader. Its nodes are capped (MAX_NODES), but that table of answers is not. In a diagnostics build, 16 of the first 24 blocks of 64 MB or more that victory translate made over the game's shaders were this table (structure.rs:240), 68 MB each, one for each translating thread. In a game start with ray tracing on (VICTORY_BVH_BUILDER=1), it made 6 more while it ran, four of 68 MB and two of 136 MB.

The table only saves work, so this bounds it: at MAX_MEMO (2^20) answers it starts over. A forgotten answer is worked out again to the same node, because nodes are shared through unique. That keeps the table under 36 MB.

A new test, a_full_answer_table_starts_over_and_answers_the_same, builds the same random functions in a table that keeps every answer and in one that keeps 8. Both make the same nodes in the same order.

How it was tested

  • GPU and profile: RTX 4080, Windows 11, 24 threads. Offline, no game run needed: victory translate --list (diagnostics build) over the game's folder, which translates every shader in it (25,693 emitted).

  • Output: the emitted shader hashes and every outcome line are the same as main's, at each bound tried below.

  • Before (main 5fabb46e, 3 runs): 46.0–49.8 s; peak private memory 4,273–4,411 MB.

  • After (2^20, 3 runs): 47.6–49.2 s; peak private 3,783–3,922 MB. The table no longer appears among the blocks of 64 MB or more.

  • Other bounds (one run each unless noted):

    bound wall time peak private
    none 46.3–47.1 s (3 runs) 4,339–4,436 MB
    2^22 46.3 s 4,235 MB
    2^21 46.5 s 4,235 MB
    2^20 47.6–49.2 s (3 runs) 3,783–3,922 MB
    2^19 54.6–55.3 s (3 runs) 3,207–3,267 MB

    2^19 saves more, but it made the pass about a fifth slower. 2^20 costs about 2 s (4%) over the full set, for about 0.5 GB less at the peak.

  • Peak private memory is sampled every 100 ms. Part of it is the tool reading whole archives (blocks up to 1.2 GB from translate.rs:309), the same in both builds.

  • Wave sizes: every shader the game ships, as it has them.

  • cargo test -p victory-shader passed: yes (537 passed, 10 ignored). cargo clippy -p victory-shader --all-targets -- -D warnings, plain and --all-features: clean. cargo xtask policy --staged: ok.

  • Not measured in a full play session. In game, this only changes memory while shaders are being translated (preload, or a shader seen for the first time).

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches. Six open PRs touch structure.rs (#4481, #4171, #3501, #3402, #2993, #831). None changes Bools::ite or its table.

🤖 Generated with Claude Code

**@⁠Trillazill** on GitHub · 2026-12-01 08:16 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4787) `Trillazill:perf/structure-memo-cap` → `main` · +42 −0 · 1 files · 1 commits · open No issue for this; found in a diagnostics run's big-block log. ## What it changes `Bools::ite` in `victory-shader/src/structure.rs` kept every if-then-else answer it worked out, for the whole shader. Its nodes are capped (`MAX_NODES`), but that table of answers is not. In a diagnostics build, 16 of the first 24 blocks of 64 MB or more that `victory translate` made over the game's shaders were this table (`structure.rs:240`), 68 MB each, one for each translating thread. In a game start with ray tracing on (`VICTORY_BVH_BUILDER=1`), it made 6 more while it ran, four of 68 MB and two of 136 MB. The table only saves work, so this bounds it: at `MAX_MEMO` (2^20) answers it starts over. A forgotten answer is worked out again to the same node, because nodes are shared through `unique`. That keeps the table under 36 MB. A new test, `a_full_answer_table_starts_over_and_answers_the_same`, builds the same random functions in a table that keeps every answer and in one that keeps 8. Both make the same nodes in the same order. ## How it was tested - GPU and profile: RTX 4080, Windows 11, 24 threads. Offline, no game run needed: `victory translate --list` (diagnostics build) over the game's folder, which translates every shader in it (25,693 emitted). - **Output:** the emitted shader hashes and every outcome line are the same as main's, at each bound tried below. - **Before** (main 5fabb46e, 3 runs): 46.0–49.8 s; peak private memory 4,273–4,411 MB. - **After** (2^20, 3 runs): 47.6–49.2 s; peak private 3,783–3,922 MB. The table no longer appears among the blocks of 64 MB or more. - **Other bounds** (one run each unless noted): | bound | wall time | peak private | |---|---|---| | none | 46.3–47.1 s (3 runs) | 4,339–4,436 MB | | 2^22 | 46.3 s | 4,235 MB | | 2^21 | 46.5 s | 4,235 MB | | **2^20** | **47.6–49.2 s (3 runs)** | **3,783–3,922 MB** | | 2^19 | 54.6–55.3 s (3 runs) | 3,207–3,267 MB | 2^19 saves more, but it made the pass about a fifth slower. 2^20 costs about 2 s (4%) over the full set, for about 0.5 GB less at the peak. - Peak private memory is sampled every 100 ms. Part of it is the tool reading whole archives (blocks up to 1.2 GB from `translate.rs:309`), the same in both builds. - Wave sizes: every shader the game ships, as it has them. - `cargo test -p victory-shader` passed: yes (537 passed, 10 ignored). `cargo clippy -p victory-shader --all-targets -- -D warnings`, plain and `--all-features`: clean. `cargo xtask policy --staged`: ok. - Not measured in a full play session. In game, this only changes memory while shaders are being translated (preload, or a shader seen for the first time). ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. Six open PRs touch `structure.rs` (#4481, #4171, #3501, #3402, #2993, #831). None changes `Bools::ite` or its table. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Bools::ite kept every answer it worked out, for the whole shader. Nodes
are capped (MAX_NODES), the answers were not: in a translation of every
shader of the game, 16 of the first 24 blocks of 64 MB or more the
process made were this table, at 68 MB each (136 MB in a run with ray
tracing on), one per translating thread.

The table is only a cache, so when it holds MAX_MEMO answers it starts
over; a forgotten answer is worked out again to the same node, since
nodes are shared through `unique`. A test checks that a table of 8
answers makes the same nodes in the same order as one that keeps all.

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

@⁠cloph-dsp on GitHub · 2026-12-01 13:23 UTC · original

Verification (independent, AI-assisted: Hy4 flash). Windows, Rust 1.100.0 (Scoop rust-msvc), MSVC, commit-scoped shallow worktree.

Base 5fabb46eaf6ed8771321787f8871051abde69b9b, head 6253c5689d18110a01b3c6afff5b49e55175aba4. The name already exists on the base (git grep -F a_search_that_remembers_answers_as_one_made_anew 5fabb46e -- . matches structure.rs), so this extends an existing test rather than adding one — say so if the bar is a new test name.

git diff --check "5fabb46e..6253c568" → no output, exit 0.

$env:CARGO_TARGET_DIR='D:\Victory-Contrib\NVIDIA-Contrib\target-4787'
cargo test --locked -p victory-shader --lib -- structure::tests::a_search_that_remembers_answers_as_one_made_anew --exact --test-threads=1 --quiet

Result: running 1 test, test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 546 filtered out; finished in 0.35s.

The test builds its control flow by hand; no title files, no GPU device opened, GPU/driver N/A. No game data.

**@⁠cloph-dsp** on GitHub · 2026-12-01 13:23 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4787#issuecomment-7312548852) Verification (independent, AI-assisted: Hy4 flash). Windows, Rust 1.100.0 (Scoop rust-msvc), MSVC, commit-scoped shallow worktree. Base `5fabb46eaf6ed8771321787f8871051abde69b9b`, head `6253c5689d18110a01b3c6afff5b49e55175aba4`. The name already exists on the base (`git grep -F a_search_that_remembers_answers_as_one_made_anew 5fabb46e -- .` matches structure.rs), so this extends an existing test rather than adding one — say so if the bar is a new test name. `git diff --check "5fabb46e..6253c568"` → no output, exit 0. ``` $env:CARGO_TARGET_DIR='D:\Victory-Contrib\NVIDIA-Contrib\target-4787' cargo test --locked -p victory-shader --lib -- structure::tests::a_search_that_remembers_answers_as_one_made_anew --exact --test-threads=1 --quiet ``` Result: `running 1 test`, `test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 546 filtered out; finished in 0.35s`. The test builds its control flow by hand; no title files, no GPU device opened, GPU/driver N/A. No game data.
Author
Owner

@⁠illuminatedfellow on GitHub · 2026-12-01 14:45 UTC · original

Tested on Linux, merged onto main (5fabb46e): cargo test -p victory-shader passes (333). To stress the start-over path I also set MAX_MEMO to 4, so the table restarts constantly: all 332 existing shader tests still pass (only the new test fails, as expected, since it assumes the real limit), and fuzzing the translator with that setting (320,000 random and mutated programs through ir::build to lowering, debug assertions on) found no panics. Merges cleanly.

**@⁠illuminatedfellow** on GitHub · 2026-12-01 14:45 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4787#issuecomment-7314774995) Tested on Linux, merged onto `main` (5fabb46e): `cargo test -p victory-shader` passes (333). To stress the start-over path I also set `MAX_MEMO` to 4, so the table restarts constantly: all 332 existing shader tests still pass (only the new test fails, as expected, since it assumes the real limit), and fuzzing the translator with that setting (320,000 random and mutated programs through `ir::build` to lowering, debug assertions on) found no panics. Merges cleanly.
This pull request can be merged automatically.
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 origin '+refs/pull/4788/head:github-bot/gh-4787'
git switch 'github-bot/gh-4787'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-4787'
git switch 'github-bot/gh-4787'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-4787'
git switch 'github-bot/gh-4787'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-4787'
git switch 'main'
git merge --squash 'github-bot/gh-4787'
git switch 'main'
git merge --ff-only 'github-bot/gh-4787'
git switch 'main'
git merge 'github-bot/gh-4787'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
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
github/trustno1-coder--VIctory-NVIDIA!4788
No description provided.