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

Merged
101Leafy merged 4 commits from upstream-pr/1569 into main 2026-11-29 08:16:55 +00:00
101Leafy commented 2026-11-28 21:50:00 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by 101Leafy on 2026-11-28T21:50:00Z.


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.
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5544906977 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1569). Originally posted by [101Leafy](https://github.com/101Leafy) on 2026-11-28T21:50:00Z. --- ## 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.
notquiteog commented 2026-11-28 21:51:38 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by notquiteog on 2026-11-28T21:51:38Z.


Great job here!

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7246326118 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1569#issuecomment-7246326118). Originally posted by [notquiteog](https://github.com/notquiteog) on 2026-11-28T21:51:38Z. --- Great job here!
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
trustno1-coder/VIctory-NVIDIA!1569
No description provided.