perf(shader): isolate IR allocations and preserve diagnostics #547

Manually merged
github merged 109 commits from github-bot/gh-547 into main 2026-12-05 20:12:34 +00:00 AGit
Owner

@⁠tommiehansen on GitHub · 2026-12-05 02:41 UTC · original
tommiehansen:review-split/404-perf-only → main · +176 −83 · 1 files · 2 commits · merged 2026-12-05 20:08 UTC

Benchmark highlights — pinned mixed-corpus replay

Linux and Windows audit, corrected head 5439540 versus b581f7e. Six balanced process orders per platform.

Workload Linux CPU time Windows CPU time
Small shaders in mixed corpus −31.4% −33.8%
Reverse 4096-layer CFG −9.5% −12.4%
Forward 4096-layer CFG −9.1% −13.6%
Distinct shader inputs 691 1,007
IR output parity 100% 100%

The original reported 10x regression did not reproduce on either hosted runner, including the original implementation. The corrected head retains CPU build gains; this is not proof against all heap-state regressions or a gameplay FPS measurement. Detailed historical tables below.


Review split from #404, based on current upstream main. The diff contains this one slice.

Linux shader suite: 295 passed and 2 ignored. The audit job failed the inherited launcher-switch documentation check tracked in #528.

Exact pinned CI evidence

No hardware timing or gameplay results. The original PR remains available until maintainers choose the integration order.

Post-review follow-up — 2026-12-05

Head: 54395407391a6f49ff8d666bfbd9e8e8c6f44c72.

Restored main's original build iteration and per-instruction allocation lifetime while retaining effects_into and the independent unspill/IR optimizations. This follows the regression-isolation variant in Kal0s-design's review. The previously reported small-program gain and mixed-corpus regression are historical, not measurements of this head. Please repeat the full mixed-corpus replay before merging.

Fresh pinned debug/release CI started; new test and performance results must be reported at this head. Previous validation is retained at its original revision.

Independent mixed-corpus replay

Windows/Linux audit compares the pinned base b581f7e, original split 22ffc99, and corrected split 5439540. It collects the existing synthetic library-test inputs on the base, then replays the same corpus with the exact two 4096-layer diamond programs in mixed and isolated processes. Six balanced process orders, full IR-result digests, and per-case build timings are recorded. The audit is independent of the old manual measurements; no real-title assets are supplied and no FPS claim is made. Results are pending.

Linux mixed-corpus result (pinned audit)

Ubuntu job completed with identical IR result digests for all 691 distinct synthetic library-test inputs across all three revisions. Six balanced process orders, paired median ratios versus b581f7e:

Workload Original split 22ffc99 Corrected 5439540
Mixed: 689 small programs -32.7% -31.4%
Mixed: reverse 4096-layer CFG -13.6% -9.5%
Mixed: forward 4096-layer CFG -17.2% -9.1%
Isolated: reverse CFG -20.0% -10.6%
Isolated: forward CFG -13.6% -12.9%

Negative values mean lower CPU build time. The reported 10x regression did not reproduce on this Linux runner, even at the original split. The corrected split retains substantial small-program gains. Windows replay is pending; these results neither reproduce the original Windows heap state nor establish gameplay FPS.

Windows mixed-corpus result (pinned audit)

Windows job completed with identical IR result digests for all 1,007 distinct synthetic inputs across all three revisions. Six balanced process orders, paired median CPU build time changes versus b581f7e:

Workload Original split Corrected split
Mixed: 1,005 small programs -39.3% -33.8%
Mixed: reverse large CFG -12.9% -12.4%
Mixed: forward large CFG -11.7% -13.6%
Isolated: reverse large CFG -13.1% -11.2%
Isolated: forward large CFG -15.4% -11.5%

Both Windows and Linux hosted runs pass. The original reported 10x regression did not reproduce on either hosted runner, including the original implementation, so this is not proof that the original heap-state issue cannot occur. The corrected split retains meaningful CPU gains on both systems. No gameplay FPS claim.

Standard CI raw-artifact follow-up (2026-12-05)

Synthetic CPU workload Base (ms) Candidate (ms) Paired time change
Guard-run structurisation 20.8294 13.9630 −33.59%
Corpus translation 5.4917 5.2408 −4.65%

Both output digests identical; structurisation 95% CI −35.62% to −31.50%. Small node-probe +2.18% descriptive change is inconclusive, not established regression. Four complete ABBA blocks, eight runs per arm. Independently checked all 16 raw checkpoint revisions, per-run sample concatenation, medians and digests against results.json. The Python review gate incorrectly interprets rounds=8 (runs per arm) as eight ABBA blocks; its automatic verdict remains inconclusive pending a harness fix. The CIs above, where stated, are the Rust report's per-workload estimates. Generic software Vulkan control passed with identical SPIR-V, not activation of this PR. No physical GPU or gameplay FPS claim. Pinned CI/artifacts.

**@⁠tommiehansen** on GitHub · 2026-12-05 02:41 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/547) `tommiehansen:review-split/404-perf-only` → `main` · +176 −83 · 1 files · 2 commits · merged 2026-12-05 20:08 UTC ## Benchmark highlights — pinned mixed-corpus replay [Linux and Windows audit](https://github.com/tommiehansen/VIctory-xmem/actions/runs/47501599157), corrected head `5439540` versus `b581f7e`. Six balanced process orders per platform. | Workload | Linux CPU time | Windows CPU time | |---|---:|---:| | Small shaders in mixed corpus | **−31.4%** | **−33.8%** | | Reverse 4096-layer CFG | −9.5% | −12.4% | | Forward 4096-layer CFG | −9.1% | −13.6% | | Distinct shader inputs | 691 | 1,007 | | IR output parity | 100% | 100% | The original reported 10x regression did not reproduce on either hosted runner, including the original implementation. The corrected head retains CPU build gains; this is not proof against all heap-state regressions or a gameplay FPS measurement. Detailed historical tables below. --- Review split from #404, based on current upstream main. The diff contains this one slice. Linux shader suite: 295 passed and 2 ignored. The audit job failed the inherited launcher-switch documentation check tracked in #528. [Exact pinned CI evidence](https://github.com/tommiehansen/VIctory-xmem/actions/runs/47466412636/job/145504220133) No hardware timing or gameplay results. The original PR remains available until maintainers choose the integration order. ### Post-review follow-up — 2026-12-05 Head: `54395407391a6f49ff8d666bfbd9e8e8c6f44c72`. Restored main's original build iteration and per-instruction allocation lifetime while retaining effects_into and the independent unspill/IR optimizations. This follows the regression-isolation variant in [Kal0s-design's review](https://git.gtahub.st/github/lobomfz--VIctory-xmem/pulls/547). The previously reported small-program gain and mixed-corpus regression are historical, not measurements of this head. Please repeat the full mixed-corpus replay before merging. [Fresh pinned debug/release CI](https://github.com/tommiehansen/VIctory-xmem/actions/runs/47499397549) started; new test and performance results must be reported at this head. Previous validation is retained at its original revision. ### Independent mixed-corpus replay [Windows/Linux audit](https://github.com/tommiehansen/VIctory-xmem/actions/runs/47501599157) compares the pinned base `b581f7e`, original split `22ffc99`, and corrected split `5439540`. It collects the existing synthetic library-test inputs on the base, then replays the same corpus with the exact two 4096-layer diamond programs in mixed and isolated processes. Six balanced process orders, full IR-result digests, and per-case build timings are recorded. The audit is independent of the old manual measurements; no real-title assets are supplied and no FPS claim is made. Results are pending. ### Linux mixed-corpus result (pinned audit) [Ubuntu job](https://github.com/tommiehansen/VIctory-xmem/actions/runs/47501599157/job/145616648516) completed with identical IR result digests for all 691 distinct synthetic library-test inputs across all three revisions. Six balanced process orders, paired median ratios versus `b581f7e`: | Workload | Original split `22ffc99` | Corrected `5439540` | | --- | ---: | ---: | | Mixed: 689 small programs | -32.7% | -31.4% | | Mixed: reverse 4096-layer CFG | -13.6% | -9.5% | | Mixed: forward 4096-layer CFG | -17.2% | -9.1% | | Isolated: reverse CFG | -20.0% | -10.6% | | Isolated: forward CFG | -13.6% | -12.9% | Negative values mean lower CPU build time. The reported 10x regression did not reproduce on this Linux runner, even at the original split. The corrected split retains substantial small-program gains. Windows replay is pending; these results neither reproduce the original Windows heap state nor establish gameplay FPS. ### Windows mixed-corpus result (pinned audit) [Windows job](https://github.com/tommiehansen/VIctory-xmem/actions/runs/47501599157/job/145616648335) completed with identical IR result digests for all 1,007 distinct synthetic inputs across all three revisions. Six balanced process orders, paired median CPU build time changes versus `b581f7e`: | Workload | Original split | Corrected split | | --- | ---: | ---: | | Mixed: 1,005 small programs | -39.3% | -33.8% | | Mixed: reverse large CFG | -12.9% | -12.4% | | Mixed: forward large CFG | -11.7% | -13.6% | | Isolated: reverse large CFG | -13.1% | -11.2% | | Isolated: forward large CFG | -15.4% | -11.5% | Both Windows and Linux hosted runs pass. The original reported 10x regression did not reproduce on either hosted runner, including the original implementation, so this is not proof that the original heap-state issue cannot occur. The corrected split retains meaningful CPU gains on both systems. No gameplay FPS claim. ### Standard CI raw-artifact follow-up (2026-12-05) | Synthetic CPU workload | Base (ms) | Candidate (ms) | Paired time change | |---|---:|---:|---:| | Guard-run structurisation | 20.8294 | 13.9630 | −33.59% | | Corpus translation | 5.4917 | 5.2408 | −4.65% | Both output digests identical; structurisation 95% CI −35.62% to −31.50%. Small node-probe +2.18% descriptive change is inconclusive, not established regression. Four complete ABBA blocks, eight runs per arm. Independently checked all 16 raw checkpoint revisions, per-run sample concatenation, medians and digests against results.json. The Python review gate incorrectly interprets `rounds=8` (runs per arm) as eight ABBA blocks; its automatic verdict remains inconclusive pending a harness fix. The CIs above, where stated, are the Rust report's per-workload estimates. Generic software Vulkan control passed with identical SPIR-V, not activation of this PR. No physical GPU or gameplay FPS claim. [Pinned CI/artifacts](https://github.com/tommiehansen/VIctory-xmem/actions/runs/47512649200/job/145651188802).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-05 02:41:35 +00:00
Author
Owner

@⁠Kal0s-design on GitHub · 2026-12-05 06:34 UTC · original

Checked 22ffc99 on native Windows (one NVIDIA desktop card plus WARP, didn't run the game). Merge base is b581f7e, current main.

The output side looks right to me. In build, the block index now moves forward with the instruction (ir.rs:172), and ends checks only leaders[b + 1] instead of a binary search (ir.rs:208). That is only the same if no leader sits strictly between two decoded instructions. decode gives that guarantee, because every leader is a decoded offset and gfx10/mod.rs:110 rejects a branch into the middle of an instruction. effects_into keeps the first occurrence when it dedups with the bitset (ir.rs:1967), as main's retain did, and index stays below REGS for every register. The read list for written VGPRs now checks r_buf instead of the growing list (ir.rs:232), so a VGPR written twice and never read would be pushed twice. Nothing in effects_into seems to produce that, and a check over every instruction the suite builds found no difference from main's order. The early return in unspill (ir.rs:327) is safe because without v_writelane_b32/v_readlane_b32 parked() never matches, and main then returns empty at its parks.iter().all(Option::is_none) check. With VICTORY_WHY_UNSPILL set it still takes the full path, so the diagnostics stay. On the parked-lane tests in wave64_tests the WHY-UNSPILL lines were the same on both trees. The flat tables in without_skips use NONE as "no entry" (ir.rs:1060, 1211). That would only matter if a write or an s_mov read held NONE, and those are only ever phi args from a dead predecessor, which these tables never key on. So the result is the same.

The remove_trivial_phis_steps early return (ir.rs:1596) is a no-op for valid programs. The one change is on programs with dead blocks, whose reads keep stale ids from before the rename. Main runs find on those and indexes replaced out of bounds when a stale id is >= values. With no phis at all, the PR now skips that panic. With phis it still happens, which #546 fixes by pruning first.

cargo test -p victory-shader --lib -- --test-threads=4 (debug) gave 420 passed, 1 failed, 4 ignored, against 419/1/4 on main. The failure is size_tests::a_reused_descriptor_register_read_only_behind_its_flag on both, and it already fails on main. The only new pass is the new test, and that test also passes on main. Clippy with --lib --tests --examples gives the same 12 warnings as main, and ir.rs is rustfmt-clean.

For the output I hashed every DXIL container the test suite produces, and all 840 of 840 are byte-identical to main. I also collected the 1046 distinct ir::build inputs the suite uses and compared main and PR on the Debug dump of the built Program, operand_reads for every instruction, and without_skips with deep false and true. All of it was identical, including the two inputs that fail to build (same error).

Timing is where I'd like a second look. I replayed those 1046 inputs through build in release, interleaving main and PR over 7 rounds. On the 1044 small programs the PR is clearly faster, about 35% lower median for the whole set. The other two are the 4096-layer diamond chains from reverse_order_diamond_chain_eliminates_trivial_phis, about 12k blocks each. With only those two loaded in the process, each built about 10% faster than main. Replayed with the rest of the corpus loaded, though, each took about 10x as long as on main, over every round and whatever order I ran them in. Since they dominate the total, the full replay came out several times slower on the PR. These timings clearly depend on heap state on both trees, because main itself took about half again as long on those two in the two-file run as in the full one. Still, the PR's 10x was steady. I bisected it to the new loop in build. Putting main's loop back, still calling effects_into but with fresh vectors per instruction, brings the big ones back to main's time. Dropping the peekable iterator before link doesn't help, and neither does allocating and freeing a list-sized vector around the loop the way next_offsets did. The extra time isn't in the loop itself. It goes into link, split_irreducible and rename, which get byte-identical blocks on both trees (I also ruled out the remove_trivial_phis_steps early return inside rename with a separate variant). My guess is something about the short-lived per-instruction allocations the old loop made and freed, and how later stages then behave on this heap. I haven't confirmed that, so treat it as a lead and not a diagnosis. It would be worth checking whether it shows up on Linux, or on a real shader cache inside the game process. The test programs are tiny compared to real shaders.

The body says this is split from #404, and that holds. The ir.rs here is #404's with only lines taken out (the pruning that went to #546). It merges cleanly with #545. With #546 it conflicts only at the end of the ir.rs tests module, where both append a test. I didn't run the Linux suite. The body's 295 passed fits the same baseline as #545 and #546 (298 each, four new tests) plus this PR's one new test. I didn't test real game shaders, a shader cache run, gameplay, or AMD and other vendors' drivers.

AI-assisted: yes

**@⁠Kal0s-design** on GitHub · 2026-12-05 06:34 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/547#issuecomment-7433449627) Checked 22ffc99 on native Windows (one NVIDIA desktop card plus WARP, didn't run the game). Merge base is b581f7e, current main. The output side looks right to me. In `build`, the block index now moves forward with the instruction (ir.rs:172), and `ends` checks only `leaders[b + 1]` instead of a binary search (ir.rs:208). That is only the same if no leader sits strictly between two decoded instructions. `decode` gives that guarantee, because every leader is a decoded offset and gfx10/mod.rs:110 rejects a branch into the middle of an instruction. `effects_into` keeps the first occurrence when it dedups with the bitset (ir.rs:1967), as main's `retain` did, and `index` stays below `REGS` for every register. The read list for written VGPRs now checks `r_buf` instead of the growing list (ir.rs:232), so a VGPR written twice and never read would be pushed twice. Nothing in `effects_into` seems to produce that, and a check over every instruction the suite builds found no difference from main's order. The early return in `unspill` (ir.rs:327) is safe because without `v_writelane_b32`/`v_readlane_b32` `parked()` never matches, and main then returns empty at its `parks.iter().all(Option::is_none)` check. With `VICTORY_WHY_UNSPILL` set it still takes the full path, so the diagnostics stay. On the parked-lane tests in wave64_tests the WHY-UNSPILL lines were the same on both trees. The flat tables in `without_skips` use `NONE` as "no entry" (ir.rs:1060, 1211). That would only matter if a write or an `s_mov` read held `NONE`, and those are only ever phi args from a dead predecessor, which these tables never key on. So the result is the same. The `remove_trivial_phis_steps` early return (ir.rs:1596) is a no-op for valid programs. The one change is on programs with dead blocks, whose reads keep stale ids from before the rename. Main runs `find` on those and indexes `replaced` out of bounds when a stale id is `>= values`. With no phis at all, the PR now skips that panic. With phis it still happens, which #546 fixes by pruning first. `cargo test -p victory-shader --lib -- --test-threads=4` (debug) gave 420 passed, 1 failed, 4 ignored, against 419/1/4 on main. The failure is `size_tests::a_reused_descriptor_register_read_only_behind_its_flag` on both, and it already fails on main. The only new pass is the new test, and that test also passes on main. Clippy with `--lib --tests --examples` gives the same 12 warnings as main, and ir.rs is rustfmt-clean. For the output I hashed every DXIL container the test suite produces, and all 840 of 840 are byte-identical to main. I also collected the 1046 distinct `ir::build` inputs the suite uses and compared main and PR on the Debug dump of the built `Program`, `operand_reads` for every instruction, and `without_skips` with `deep` false and true. All of it was identical, including the two inputs that fail to build (same error). Timing is where I'd like a second look. I replayed those 1046 inputs through `build` in release, interleaving main and PR over 7 rounds. On the 1044 small programs the PR is clearly faster, about 35% lower median for the whole set. The other two are the 4096-layer diamond chains from `reverse_order_diamond_chain_eliminates_trivial_phis`, about 12k blocks each. With only those two loaded in the process, each built about 10% faster than main. Replayed with the rest of the corpus loaded, though, each took about 10x as long as on main, over every round and whatever order I ran them in. Since they dominate the total, the full replay came out several times slower on the PR. These timings clearly depend on heap state on both trees, because main itself took about half again as long on those two in the two-file run as in the full one. Still, the PR's 10x was steady. I bisected it to the new loop in `build`. Putting main's loop back, still calling `effects_into` but with fresh vectors per instruction, brings the big ones back to main's time. Dropping the peekable iterator before `link` doesn't help, and neither does allocating and freeing a list-sized vector around the loop the way `next_offsets` did. The extra time isn't in the loop itself. It goes into `link`, `split_irreducible` and `rename`, which get byte-identical blocks on both trees (I also ruled out the `remove_trivial_phis_steps` early return inside `rename` with a separate variant). My guess is something about the short-lived per-instruction allocations the old loop made and freed, and how later stages then behave on this heap. I haven't confirmed that, so treat it as a lead and not a diagnosis. It would be worth checking whether it shows up on Linux, or on a real shader cache inside the game process. The test programs are tiny compared to real shaders. The body says this is split from #404, and that holds. The ir.rs here is #404's with only lines taken out (the pruning that went to #546). It merges cleanly with #545. With #546 it conflicts only at the end of the ir.rs tests module, where both append a test. I didn't run the Linux suite. The body's 295 passed fits the same baseline as #545 and #546 (298 each, four new tests) plus this PR's one new test. I didn't test real game shaders, a shader cache run, gameplay, or AMD and other vendors' drivers. AI-assisted: yes
Author
Owner

@⁠tommiehansen on GitHub · 2026-12-05 10:18 UTC · original

Thanks @⁠Kal0s-design for isolating the mixed-corpus regression. 5439540 restores the original build loop and per-instruction allocation lifetime, retaining the other optimizations. Six-round Linux/Windows replay shows identical IR and 31.4%/33.8% lower small-program build time, with both large CFGs also faster. Neither hosted runner reproduced the original 10x regression, so your heap-state finding remains relevant.

**@⁠tommiehansen** on GitHub · 2026-12-05 10:18 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/547#issuecomment-7436353513) Thanks @⁠Kal0s-design for isolating the mixed-corpus regression. [5439540](https://github.com/tommiehansen/VIctory-xmem/commit/54395407391a6f49ff8d666bfbd9e8e8c6f44c72) restores the original build loop and per-instruction allocation lifetime, retaining the other optimizations. [Six-round Linux/Windows replay](https://github.com/tommiehansen/VIctory-xmem/actions/runs/47501599157) shows identical IR and 31.4%/33.8% lower small-program build time, with both large CFGs also faster. Neither hosted runner reproduced the original 10x regression, so your heap-state finding remains relevant.
github-bot force-pushed github-bot/gh-547 from 5439540739 to 13599691e0 2026-12-05 20:12:01 +00:00 Compare
github manually merged commit 6f4a4ece8d into main 2026-12-05 20:12:01 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.