victory-shader: decode once across bounded-loop IR rebuilds (DECODE-ONCE-BOUNDED-RANGE / #3357) #3709

Open
cloph-dsp wants to merge 1 commit from upstream-pr/3709 into main
cloph-dsp commented 2026-11-28 10:10:42 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-28T10:10:42Z.


Depends on: #1633

What

Decode each GFX10 program once and reuse the decoded instruction list across the bounded-loop IR rebuilds in range::build. Previously every iteration of the M0 induction re-ran gfx10::decode; now a program with relative moves is decoded once and each rebuild takes the already-decoded instructions.

A fast path covers programs with no v_movrel*/v_swaprel_b32 instructions: it builds and structures the IR once and returns, so such programs never enter the induction.

Change

  • crates/victory-shader/src/ir.rs: expose decode(), build_bounded_decoded() and build_bounded_owned() (pub(crate)); build_bounded() now decodes once and delegates.
  • crates/victory-shader/src/range.rs: decode once in build(), add build_decoded()/build_with() so the induction reuses the list; factor relative_name() for the fast path; add synthetic test an_m0_bounded_loop_decodes_once_and_keeps_its_ir_and_structure.

Validation

Windows, Rust 1.100.0/MSVC, per-worktree CARGO_TARGET_DIR, CARGO_BUILD_JOBS=2, --locked:

  • cargo test --locked -p victory-shader --lib -- range::tests::an_m0_bounded_loop_decodes_once_and_keeps_its_ir_and_structure --exact --test-threads=1 --quiet -> 1 passed, 0 failed, 305 filtered, exit 0.
  • git diff --check origin/main HEAD -> clean.

The test asserts the cached build equals both the public build() and an uncached rebuild that counts decodes (>1), and that the structured IR fields (exits, guards, reach, masks, other, highs, active, restored, discards) match.

AI-assisted: Hy4 flash. GPU/driver: N/A (pure CPU synthetic shader). No game data, assets, extracted shaders, DRM or decrypt used.

<!-- greyfinch-sync:Marvisak/VIctory:issue:5539063592 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3709). Originally posted by [cloph-dsp](https://github.com/cloph-dsp) on 2026-11-28T10:10:42Z. --- Depends on: #1633 ## What Decode each GFX10 program once and reuse the decoded instruction list across the bounded-loop IR rebuilds in `range::build`. Previously every iteration of the M0 induction re-ran `gfx10::decode`; now a program with relative moves is decoded once and each rebuild takes the already-decoded instructions. A fast path covers programs with no `v_movrel*`/`v_swaprel_b32` instructions: it builds and structures the IR once and returns, so such programs never enter the induction. ## Change - `crates/victory-shader/src/ir.rs`: expose `decode()`, `build_bounded_decoded()` and `build_bounded_owned()` (`pub(crate)`); `build_bounded()` now decodes once and delegates. - `crates/victory-shader/src/range.rs`: decode once in `build()`, add `build_decoded()`/`build_with()` so the induction reuses the list; factor `relative_name()` for the fast path; add synthetic test `an_m0_bounded_loop_decodes_once_and_keeps_its_ir_and_structure`. ## Validation Windows, Rust 1.100.0/MSVC, per-worktree `CARGO_TARGET_DIR`, `CARGO_BUILD_JOBS=2`, `--locked`: - `cargo test --locked -p victory-shader --lib -- range::tests::an_m0_bounded_loop_decodes_once_and_keeps_its_ir_and_structure --exact --test-threads=1 --quiet` -> 1 passed, 0 failed, 305 filtered, exit 0. - `git diff --check origin/main HEAD` -> clean. The test asserts the cached build equals both the public `build()` and an uncached rebuild that counts decodes (>1), and that the structured IR fields (exits, guards, reach, masks, other, highs, active, restored, discards) match. AI-assisted: Hy4 flash. GPU/driver: N/A (pure CPU synthetic shader). No game data, assets, extracted shaders, DRM or decrypt used.
andrewpozdnakov7-jpg commented 2026-11-28 10:46:19 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-28T10:46:19Z.


I compared 1af7df4 against the exact main range builder on 12 generated shaders. The programs and compared structured fields matched for Wave32 and Wave64, with and without the bounded relative-move loop.

  • With the loop and 128 or 1,024 ALU instructions before it, the proposed path was 4.0–8.9% faster across the four configurations. For 1,024 instructions, Wave32 was 4.04 → 3.83 ms and Wave64 3.93 → 3.58 ms per build. The eight-instruction loop cases were 0.6–3.0% slower, and the no-relative cases ranged from 5.7% faster to 2.4% slower. Medians are from twelve balanced Windows release pairs per case.
  • Test commit d1c523d sits directly on your head and adds a forward-branching shader with no relative moves. It compares the fast path with a direct IR build and structuring in both wave widths. All five range tests, strict shader Clippy, and the asset policy passed. The timing fixture was temporary and uses no title data or GPU.

@cloph-dsp, the test is ready to cherry-pick if you want the fast path covered alongside your loop test. Please retain the Git author on cherry-pick or rebase, or add Co-authored-by: andrewpozdnakov7-jpg <[email protected]> if folding the test into your commit.

AI-assisted with OpenAI Codex.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7238111245 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3709#issuecomment-7238111245). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-28T10:46:19Z. --- I compared `1af7df4` against the exact `main` range builder on 12 generated shaders. The programs and compared structured fields matched for Wave32 and Wave64, with and without the bounded relative-move loop. - With the loop and 128 or 1,024 ALU instructions before it, the proposed path was 4.0–8.9% faster across the four configurations. For 1,024 instructions, Wave32 was 4.04 → 3.83 ms and Wave64 3.93 → 3.58 ms per build. The eight-instruction loop cases were 0.6–3.0% slower, and the no-relative cases ranged from 5.7% faster to 2.4% slower. Medians are from twelve balanced Windows release pairs per case. - [Test commit `d1c523d`](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/d1c523d3cb08cc2cb18680f0d8464cba84ba6c00) sits directly on your head and adds a forward-branching shader with no relative moves. It compares the fast path with a direct IR build and structuring in both wave widths. All five range tests, strict shader Clippy, and the asset policy passed. The timing fixture was temporary and uses no title data or GPU. @cloph-dsp, the test is ready to cherry-pick if you want the fast path covered alongside your loop test. Please retain the Git author on cherry-pick or rebase, or add `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>` if folding the test into your commit. AI-assisted with OpenAI Codex.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3709:upstream-pr/3709'
git switch 'upstream-pr/3709'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3709'
git switch 'upstream-pr/3709'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3709'
git switch 'upstream-pr/3709'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3709'
git switch 'main'
git merge --squash 'upstream-pr/3709'
git switch 'main'
git merge --ff-only 'upstream-pr/3709'
git switch 'main'
git merge 'upstream-pr/3709'
git push origin 'main'
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!3709
No description provided.