Shaders: computed_with and read_as_number indexed once per lowering (39f0 translate 25 s to 2.6 s) #1569

Manually merged
github merged 4 commits from github-bot/gh-1569 into main 2026-11-29 08:21:22 +00:00 AGit
Owner

@⁠101Leafy on GitHub · 2026-11-28 21:50 UTC · original
101Leafy:nv/lower-indexed → main · +52 −27 · 10 files · 4 commits · merged 2026-11-29 08:16 UTC

What it changes

computed_with and read_as_number scanned every instruction of the program on each call, and computed_with calls itself again for each move it follows. On a large title shader that was most of the translate time: pixel shader 39f0e9aeb156a61c (13,890 blocks, 2,453 descriptor loads) took 25 to 45 s to translate.

Both now build an index on first use and keep it for the rest of the lowering, in two OnceCells on Lower:

  • numbers: every value a scalar or vector instruction or a phi reads.
  • readers: for each value, the instructions that read it, in program order.

The answers are the same as before. The output DXIL does not change, so emit::VERSION stays.

How it was tested

  • Tested on: RTX 5080 16 GB, Windows 10, cargo test only (no game run). Translation runs on the CPU, so the profile does not matter; the times are for this one shader.
  • Before: 39f0e9aeb156a61c translates in 25 s.
  • After: 2.6 s.
  • For shader changes, the wave sizes tested: no change to the output at either size; the lib tests cover both.
  • cargo test passed for the crates it touches: cargo test -p victory-shader --lib gives the same results with and without this change (the same 38 tests that need a card fail on both).

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches. Related: none for these two functions.
**@⁠101Leafy** on GitHub · 2026-11-28 21:50 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1569) `101Leafy:nv/lower-indexed` → `main` · +52 −27 · 10 files · 4 commits · merged 2026-11-29 08:16 UTC ## What it changes `computed_with` and `read_as_number` scanned every instruction of the program on each call, and `computed_with` calls itself again for each move it follows. On a large title shader that was most of the translate time: pixel shader `39f0e9aeb156a61c` (13,890 blocks, 2,453 descriptor loads) took 25 to 45 s to translate. Both now build an index on first use and keep it for the rest of the lowering, in two `OnceCell`s on `Lower`: - `numbers`: every value a scalar or vector instruction or a phi reads. - `readers`: for each value, the instructions that read it, in program order. The answers are the same as before. The output DXIL does not change, so `emit::VERSION` stays. ## How it was tested - Tested on: RTX 5080 16 GB, Windows 10, cargo test only (no game run). Translation runs on the CPU, so the profile does not matter; the times are for this one shader. - Before: `39f0e9aeb156a61c` translates in 25 s. - After: 2.6 s. - For shader changes, the wave sizes tested: no change to the output at either size; the lib tests cover both. - `cargo test` passed for the crates it touches: `cargo test -p victory-shader --lib` gives the same results with and without this change (the same 38 tests that need a card fail on both). ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. Related: none for these two functions.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-28 21:54:10 +00:00
Author
Owner

@⁠notquiteog on GitHub · 2026-11-28 21:51 UTC · original

Great job here!

**@⁠notquiteog** on GitHub · 2026-11-28 21:51 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1569#issuecomment-7246326118) Great job here!
github-bot force-pushed github-bot/gh-1569 from 12b4080e88 to 7cc0d15333 2026-11-29 01:46:35 +00:00 Compare
github manually merged commit 236f9395b1 into main 2026-11-29 08:21:22 +00:00
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!1569
No description provided.