Shaders: reuse SSA sums when tracing memory addresses #139

Merged
TG0000 merged 4 commits from upstream-pr/139 into main 2026-11-25 21:36:04 +00:00
TG0000 commented 2026-11-24 00:52:45 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by TG0000 on 2026-11-24T00:52:45Z.


Change

Shader resource tracking now caches decomposed address sums by SSA value after copy propagation. Memory accesses and built descriptors can reuse shared additions. Across an unrolled sequence of address increments and loads, this reduces address decomposition from quadratic to linear work.

Synthetic regressions check every address in a shared chain, 32-bit wraparound, preservation of a computed offset, the fallback for sums with two computed terms, and the error for an untraceable base.

Synthetic release benchmark

Windows MSVC on a Ryzen 9 5900X. The benchmark measures the full resource::track call on prebuilt SSA, using the same harness before and after. Times are medians of seven batches.

Address increments × loads per increment Before After Speedup
16 × 4 30.41 µs 11.36 µs 2.7×
128 × 4 1,513.25 µs 209.12 µs 7.2×
384 × 4 13,215.01 µs 606.71 µs 21.8×
cargo +stable-x86_64-pc-windows-msvc test -p victory-shader --release --test resource_tracking bench_unrolled_loads -- --ignored --nocapture

Verification

  • MSVC workspace tests passed serially on WARP with 267 passed and 5 ignored. Workspace Clippy completed with existing warnings. Both runs used a temporary local module rename for the duplicate test module on main. PR #129
  • All three synthetic regression tests passed on both revisions. The asset-policy check passed on the clean branch.

AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6572082019 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/139). Originally posted by [TG0000](https://github.com/TG0000) on 2026-11-24T00:52:45Z. --- ## Change Shader resource tracking now caches decomposed address sums by SSA value after copy propagation. Memory accesses and built descriptors can reuse shared additions. Across an unrolled sequence of address increments and loads, this reduces address decomposition from quadratic to linear work. Synthetic regressions check every address in a shared chain, 32-bit wraparound, preservation of a computed offset, the fallback for sums with two computed terms, and the error for an untraceable base. ## Synthetic release benchmark Windows MSVC on a Ryzen 9 5900X. The benchmark measures the full `resource::track` call on prebuilt SSA, using the same harness before and after. Times are medians of seven batches. | Address increments × loads per increment | Before | After | Speedup | | --- | ---: | ---: | ---: | | 16 × 4 | 30.41 µs | 11.36 µs | 2.7× | | 128 × 4 | 1,513.25 µs | 209.12 µs | 7.2× | | 384 × 4 | 13,215.01 µs | 606.71 µs | 21.8× | ```powershell cargo +stable-x86_64-pc-windows-msvc test -p victory-shader --release --test resource_tracking bench_unrolled_loads -- --ignored --nocapture ``` ## Verification - MSVC workspace tests passed serially on WARP with 267 passed and 5 ignored. Workspace Clippy completed with existing warnings. Both runs used a temporary local module rename for the duplicate test module on `main`. [PR #129](https://github.com/Marvisak/VIctory/pull/129) - All three synthetic regression tests passed on both revisions. The asset-policy check passed on the clean branch. AI-assisted.
raffclar commented 2026-11-24 06:54:46 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by raffclar on 2026-11-24T00:55:40Z.


Couldn't find any issues with this. A guess a very long chain of additions could cause a stack overflow

<!-- greyfinch-sync:Marvisak/VIctory:comment:7118578851 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/139#issuecomment-7118578851). Originally posted by [raffclar](https://github.com/raffclar) on 2026-11-24T00:55:40Z. --- Couldn't find any issues with this. A guess a very long chain of additions could cause a stack overflow
DaviTostes commented 2026-11-24 06:54:46 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DaviTostes on 2026-11-24T00:56:42Z.


Tested 1c5493f on Arch Linux x86_64, rustc 1.98.1: pass.\n\n- cargo test -p victory-shader: 59 passed, 0 failed, 1 ignored (3 test binaries), including the 4 tests this PR adds.\n- The full workspace still needs #112 for the victory-gpu E0425, but the shader crate and these tests run green on Linux.\n\nNo game data used. AI-assisted (DeepSeek V4.1 Flash coding agent).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7118595832 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/139#issuecomment-7118595832). Originally posted by [DaviTostes](https://github.com/DaviTostes) on 2026-11-24T00:56:42Z. --- Tested `1c5493f` on **Arch Linux x86_64, rustc 1.98.1**: **pass**.\n\n- `cargo test -p victory-shader`: **59 passed, 0 failed, 1 ignored** (3 test binaries), including the 4 tests this PR adds.\n- The full workspace still needs #112 for the `victory-gpu` E0425, but the shader crate and these tests run green on Linux.\n\nNo game data used. AI-assisted (DeepSeek V4.1 Flash coding agent).
catminou4 commented 2026-11-24 09:13:23 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T09:13:23Z.

Review: APPROVED


Merges cleanly with current main (8e79c80); cargo test -p victory-shader --locked → lib tests green, and the new integration suite tests/resource_tracking.rs → 3 passed / 0 failed (1 ignored benchmark) on macOS arm64 / rustc 1.98.1.

The sums cache is sound: it's keyed by SSA value and only filled after the value's operands are settled, and inputs/origin don't change during tracing, so every use of a value sees the same sum — including the opaque fallback, which the comment calls out. The &self → &mut self ripple is mechanical, and phi_site is a clean extraction. The integration tests cover the shared-chain, two-dynamic-terms and offset cases the cache could plausibly break.

<!-- greyfinch-sync:Marvisak/VIctory:review:6036480940 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/139#pullrequestreview-6036480940). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T09:13:23Z. **Review:** APPROVED --- Merges cleanly with current main (`8e79c80`); `cargo test -p victory-shader --locked` → lib tests green, and the new integration suite `tests/resource_tracking.rs` → **3 passed / 0 failed** (1 ignored benchmark) on macOS arm64 / rustc 1.98.1. The `sums` cache is sound: it's keyed by SSA value and only filled after the value's operands are settled, and `inputs`/`origin` don't change during tracing, so every use of a value sees the same sum — including the opaque fallback, which the comment calls out. The `&self` → `&mut self` ripple is mechanical, and `phi_site` is a clean extraction. The integration tests cover the shared-chain, two-dynamic-terms and offset cases the cache could plausibly break.
TG0000 commented 2026-11-24 23:06:06 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by TG0000 on 2026-11-24T23:00:23Z.


Merged main in (fast-forward). Main's tracer is unchanged; the sums are cached behind a RefCell and dropped when the spilled parameters change the origins.
One test follows main's rule that an address from no root parameter is title memory; the same file passes on main without the cache.
victory-shader 209 + 3 tests pass on Windows (RX 6800). The benchmark was not run again. AI-assisted (Claude Code).

999 perf/shader-lane-condition-search : MERGED, CENSUS BEFORE THE PUSH

local ref: prready/999 (255377d), GitHub head 3ca9456
git push fork prready/999:perf/shader-lane-condition-search
Resolved: main now remembers refuted states in Bools::meet too; kept this PR's search, tables and implies, added main's decides on the new node table. The pass that finds all missing phis was REWRITTEN: it looks at main's live edges only and skips edges main calls never taken or dead.
Checks: Mac lint 0, Mac tests formats 23, shader 120. Windows tests gpu 78, shader 211, 0 failed.
Not done: the census against main. "None goes from translating to refused", the byte-for-byte check and all timings in the body are from ffe310e and the old phi pass. Do not repeat them for this head.
Draft comment (if pushed without the census):
Merged main in (fast-forward). Main's search now remembers failed states as well, so item 1 gains less than the table says.
The pass that finds every missing phi was rewritten: it follows main's live edges and skips the edges main calls never taken or dead.
victory-shader 211 tests pass on Windows (RX 6800), clippy clean. The corpus comparison and the timings in the description are from ffe310e and were not run again on this head.
AI-assisted (Claude Code).

No push needed (mergeable, no failing check, no open question)

prready/1000, 993, 188, 172, 153, 126 = head + main, only to prove that they merge and build: do not push.
All six: clean merge, Mac lint 0, Mac tests pass (formats 23 to 25, shader 118 to 121). Their Windows-only tests (1000 and 153 gpu, 188 loader) were not run on the merge.
#1000: the two nits promised for its next change (a message when the test is skipped, one line on the order) are still open.
#124 is closed on GitHub: nothing done.

Worktree: C:\Users\theo_\victory-prs (detached at origin/main).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7146900716 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/139#issuecomment-7146900716). Originally posted by [TG0000](https://github.com/TG0000) on 2026-11-24T23:00:23Z. --- Merged main in (fast-forward). Main's tracer is unchanged; the sums are cached behind a RefCell and dropped when the spilled parameters change the origins. One test follows main's rule that an address from no root parameter is title memory; the same file passes on main without the cache. victory-shader 209 + 3 tests pass on Windows (RX 6800). The benchmark was not run again. AI-assisted (Claude Code). ## 999 perf/shader-lane-condition-search : MERGED, CENSUS BEFORE THE PUSH local ref: prready/999 (255377d), GitHub head 3ca9456 git push fork prready/999:perf/shader-lane-condition-search Resolved: main now remembers refuted states in Bools::meet too; kept this PR's search, tables and implies, added main's `decides` on the new node table. The pass that finds all missing phis was REWRITTEN: it looks at main's live edges only and skips edges main calls never taken or dead. Checks: Mac lint 0, Mac tests formats 23, shader 120. Windows tests gpu 78, shader 211, 0 failed. Not done: the census against main. "None goes from translating to refused", the byte-for-byte check and all timings in the body are from ffe310e and the old phi pass. Do not repeat them for this head. Draft comment (if pushed without the census): Merged main in (fast-forward). Main's search now remembers failed states as well, so item 1 gains less than the table says. The pass that finds every missing phi was rewritten: it follows main's live edges and skips the edges main calls never taken or dead. victory-shader 211 tests pass on Windows (RX 6800), clippy clean. The corpus comparison and the timings in the description are from ffe310e and were not run again on this head. AI-assisted (Claude Code). ## No push needed (mergeable, no failing check, no open question) prready/1000, 993, 188, 172, 153, 126 = head + main, only to prove that they merge and build: do not push. All six: clean merge, Mac lint 0, Mac tests pass (formats 23 to 25, shader 118 to 121). Their Windows-only tests (1000 and 153 gpu, 188 loader) were not run on the merge. #1000: the two nits promised for its next change (a message when the test is skipped, one line on the order) are still open. #124 is closed on GitHub: nothing done. Worktree: C:\Users\theo_\victory-prs (detached at origin/main).
Marvisak commented 2026-11-25 01:07:46 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:25:45Z.


Automated triage for the maintainers.

Merge candidate. Re-checked at a4ae870. The new head only merges main (940d32f); the PR's own changes to crates/victory-shader/src/resource.rs and crates/victory-shader/tests/resource_tracking.rs are byte-for-byte the ones reviewed at 90cf2f6. Tracer::sum caches each add result by SSA value (inputs, spilled values and s_getpc results are still looked up fresh). On current main the only places that change origin or spilled are still the two propagate_copies calls in Tracer::new, and the cache is cleared after the second one, so cached sums cannot go stale. The tests cover every offset in a shared chain, 32-bit wraparound, a kept dynamic term, the two-dynamic-term fallback and the title-memory rule.

CI: check passing on a4ae870.

Reply to @TG0000: thanks for the merge. The earlier CI failures are gone on this head, as you say. The one-line Inst::write(&program, …) change noted for #1757 only applies if that PR lands first, so it is not a blocker here.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148499843 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/139#issuecomment-7148499843). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:25:45Z. --- <!-- victory-triage v1 head=a4ae8703b633f9c5796ab519252910dffc9e9988 verdict=merge-candidate at=2026-11-25T14:51:05Z --> Automated triage for the maintainers. **Merge candidate.** Re-checked at `a4ae870`. The new head only merges `main` (`940d32f`); the PR's own changes to `crates/victory-shader/src/resource.rs` and `crates/victory-shader/tests/resource_tracking.rs` are byte-for-byte the ones reviewed at `90cf2f6`. `Tracer::sum` caches each add result by SSA value (inputs, spilled values and `s_getpc` results are still looked up fresh). On current `main` the only places that change `origin` or `spilled` are still the two `propagate_copies` calls in `Tracer::new`, and the cache is cleared after the second one, so cached sums cannot go stale. The tests cover every offset in a shared chain, 32-bit wraparound, a kept dynamic term, the two-dynamic-term fallback and the title-memory rule. CI: `check` passing on `a4ae870`. Reply to @TG0000: thanks for the merge. The earlier CI failures are gone on this head, as you say. The one-line `Inst::write(&program, …)` change noted for #1757 only applies if that PR lands first, so it is not a blocker here. --- _Generated by [Claude Code](https://claude.ai/code)_
Dathinel commented 2026-11-25 07:03:05 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dathinel on 2026-11-25T06:06:57Z.


Integration note if this lands alongside #1757. On main 940d32f with this PR alone (90cf2f6), cargo test --frozen -p victory-shader --test resource_tracking passes all three regression tests (benchmark ignored).

Adding #1757 (e18d930) merges cleanly in Git, but the same command on the combined tree 914c95f9 fails with E0061 at the Inst::write call in shared_address_keeps_its_dynamic_term_and_wraps_offsets. The arena change makes the owning program an explicit argument. Updating just that test call to program.blocks[0].insts[1].write(&program, Reg::S(4)) restores all three passes.

The current standalone call is correct. This is a one-line adjustment for whichever PR integrates second. AI-assisted; tested locally on Windows MSVC.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7154456664 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/139#issuecomment-7154456664). Originally posted by [Dathinel](https://github.com/Dathinel) on 2026-11-25T06:06:57Z. --- Integration note if this lands alongside #1757. On main `940d32f` with this PR alone (`90cf2f6`), `cargo test --frozen -p victory-shader --test resource_tracking` passes all three regression tests (benchmark ignored). Adding #1757 (`e18d930`) merges cleanly in Git, but the same command on the combined tree `914c95f9` fails with E0061 at the `Inst::write` call in `shared_address_keeps_its_dynamic_term_and_wraps_offsets`. The arena change makes the owning program an explicit argument. Updating just that test call to `program.blocks[0].insts[1].write(&program, Reg::S(4))` restores all three passes. The current standalone call is correct. This is a one-line adjustment for whichever PR integrates second. AI-assisted; tested locally on Windows MSVC.
DenRakEiw commented 2026-11-25 11:54:17 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T11:54:17Z.

Review: APPROVED


Verified against origin/main (940d32f) on Windows 11 + NVIDIA GeForce RTX 5090 and WARP:

  • Reusing SSA sums when tracing memory addresses merges cleanly and passes all unit and integration tests.
  • cargo test -p victory-shader resource::tests: 33/33 passed on RTX 5090 and WARP.
  • cargo test -p victory-shader --test resource_tracking: 3/3 passed (1 benchmark ignored).
  • cargo clippy -p victory-shader --all-targets -- -D warnings: 0 warnings.
  • cargo xtask policy: 184 files ok.

AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6057120031 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/139#pullrequestreview-6057120031). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-25T11:54:17Z. **Review:** APPROVED --- Verified against `origin/main` (`940d32f`) on Windows 11 + NVIDIA GeForce RTX 5090 and WARP: - Reusing SSA sums when tracing memory addresses merges cleanly and passes all unit and integration tests. - `cargo test -p victory-shader resource::tests`: 33/33 passed on RTX 5090 and WARP. - `cargo test -p victory-shader --test resource_tracking`: 3/3 passed (1 benchmark ignored). - `cargo clippy -p victory-shader --all-targets -- -D warnings`: 0 warnings. - `cargo xtask policy`: 184 files ok. AI-assisted (Gemini 4 Neon).
TG0000 commented 2026-11-25 13:02:49 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by TG0000 on 2026-11-25T12:28:39Z.


Merged main 940d32f in (fast-forward, no conflict). The CI run before was on a machine without a hardware GPU; main skips such shader checks there since 42363ab and ccfb029, and the new run passes.

Windows (RX 6800 and WARP, one thread): victory-gpu 143 and victory-shader 247 passed; the portable tests passed on a Mac; clippy -D warnings clean for the Windows target, with and without all features.

Thanks @Dathinel: if #1757 lands first I will make that one-line change here. AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7162425582 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/139#issuecomment-7162425582). Originally posted by [TG0000](https://github.com/TG0000) on 2026-11-25T12:28:39Z. --- Merged main 940d32f in (fast-forward, no conflict). The CI run before was on a machine without a hardware GPU; main skips such shader checks there since 42363ab and ccfb029, and the new run passes. Windows (RX 6800 and WARP, one thread): victory-gpu 143 and victory-shader 247 passed; the portable tests passed on a Mac; clippy `-D warnings` clean for the Windows target, with and without all features. Thanks @Dathinel: if #1757 lands first I will make that one-line change here. AI-assisted (Claude Code).
upstream-sync closed this pull request 2026-11-25 22:02:35 +00:00
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!139
No description provided.