Shaders: a translator panic is a refusal, and the translation switches are put back after one #2917

Open
Proudnoob4 wants to merge 2 commits from upstream-pr/2917 into main
Proudnoob4 commented 2026-11-29 18:48:16 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Proudnoob4 on 2026-11-29T18:48:16Z.


What it fixes

  1. Translation switches stay on after a caught panic. with_wide_fallback, with_last_resort, with_half_meets, with_pair_meetings, with_local_waves(_any), with_pixel_mask and with_first_half_pairs set a thread-local flag, run the translation, then put the flag back, but not when the translation panics. The pipeline workers catch panics (make_with) and keep going, so the flag stays set for every later program on that thread. Seen while translating 2,680 programs in a row on one thread: after one program panicked in the wave-wide fallback, a program that translates fine on its own panicked too, in the form the leftover flag put it in.
  2. A translator panic where the thread can't unwind ends the game. A translation is made on first use, by whichever thread asks. Inside a device or list method (extern "system"), a panic is thread caused non-unwinding panic. aborting. We hit this on a 32-lane card (RTX 4080) with a wave64 compute program from DeserializeComputePipelineStateX (0x218) in the wave-wide fallback (9bba2a20): forward reference outside a phi (bitcode.rs:948). Its plain container translates.

How

  • lower::with_flag sets the flag and puts it back from a drop guard, so also on unwind. The eight switches go through it. (#2368 does the same for with_program's hash and counts; the two don't touch the same files.)
  • shader_cache runs the translation under catch_unwind: a panic becomes a refusal (the translator panicked), and the panic's message is still in the log.

The wave-wide fallback's bad IR for that program is not fixed here; the program is refused now.

Tested

  • New unit test a_flag_is_put_back_when_the_translation_under_it_panics.
  • In game (RTX 4080 16 GB, 1440p), with that program translated inside a device call: before, the game aborted; with this change the panic fired once, was refused, and the run went on into the world.
  • cargo test -p victory-shader --lib --locked: 412 passed, 51 failed. Main gives 411 and the same 51 here, all for want of an SM 6.6 device (Windows 10, test binaries without the Agility SDK); none fails only with this change.
  • CI: the clippy gate currently fails on main's own crates/victory-loader/src/crash.rs:804 (as on other open PRs, e.g. #2487), before it reaches this change. cargo clippy -p victory-gpu --no-deps flags nothing in the changed code (its one shader_cache.rs warning, the unused AtomicBool import at line 14, is on main too).

AI-assisted.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5553924275 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2917). Originally posted by [Proudnoob4](https://github.com/Proudnoob4) on 2026-11-29T18:48:16Z. --- ## What it fixes 1. **Translation switches stay on after a caught panic.** `with_wide_fallback`, `with_last_resort`, `with_half_meets`, `with_pair_meetings`, `with_local_waves(_any)`, `with_pixel_mask` and `with_first_half_pairs` set a thread-local flag, run the translation, then put the flag back, but not when the translation panics. The pipeline workers catch panics (`make_with`) and keep going, so the flag stays set for every later program on that thread. Seen while translating 2,680 programs in a row on one thread: after one program panicked in the wave-wide fallback, a program that translates fine on its own panicked too, in the form the leftover flag put it in. 2. **A translator panic where the thread can't unwind ends the game.** A translation is made on first use, by whichever thread asks. Inside a device or list method (`extern "system"`), a panic is `thread caused non-unwinding panic. aborting.` We hit this on a 32-lane card (RTX 4080) with a wave64 compute program from `DeserializeComputePipelineStateX` (0x218) in the wave-wide fallback (9bba2a20): `forward reference outside a phi` (`bitcode.rs:948`). Its plain container translates. ## How - `lower::with_flag` sets the flag and puts it back from a drop guard, so also on unwind. The eight switches go through it. (#2368 does the same for `with_program`'s hash and counts; the two don't touch the same files.) - `shader_cache` runs the translation under `catch_unwind`: a panic becomes a refusal (`the translator panicked`), and the panic's message is still in the log. The wave-wide fallback's bad IR for that program is not fixed here; the program is refused now. ## Tested - New unit test `a_flag_is_put_back_when_the_translation_under_it_panics`. - In game (RTX 4080 16 GB, 1440p), with that program translated inside a device call: before, the game aborted; with this change the panic fired once, was refused, and the run went on into the world. - `cargo test -p victory-shader --lib --locked`: 412 passed, 51 failed. Main gives 411 and the same 51 here, all for want of an SM 6.6 device (Windows 10, test binaries without the Agility SDK); none fails only with this change. - CI: the clippy gate currently fails on main's own `crates/victory-loader/src/crash.rs:804` (as on other open PRs, e.g. #2487), before it reaches this change. `cargo clippy -p victory-gpu --no-deps` flags nothing in the changed code (its one `shader_cache.rs` warning, the unused `AtomicBool` import at line 14, is on main too). AI-assisted.
AimLogin commented 2026-11-29 19:48:08 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by AimLogin on 2026-11-29T19:48:08Z.


Review note (read against main f889bb07, not run):

Two thread-local switches are still set and reset by hand, so a panic inside them leaves them on for the next program on that thread:

  • with_folded (emit/lower.rs 721-725, FOLDED.replace(true) … FOLDED.set(was)). The hunk at 726 converts with_local_waves right after it but not this one. It matters as soon as VICTORY_WAVE_FOLDED=1 is set: one panic in a folded translation would lower every later program on that worker as folded.
  • COUNTING in emit/bitcode/census.rs 73-75. This only affects the census, but it has the same pattern.

Routing both through with_flag would cover them. A test like the one in lower/tests.rs, panicking inside with_folded and then checking folded() is false, would pin it.

One more small point: a panic refusal becomes dropped work for that program, so a distinct, greppable reason in the log and in the census output (e.g. refused (panic)) would make such programs easy to count across a corpus run.

Review was AI-assisted.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7261566527 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2917#issuecomment-7261566527). Originally posted by [AimLogin](https://github.com/AimLogin) on 2026-11-29T19:48:08Z. --- Review note (read against `main` f889bb07, not run): Two thread-local switches are still set and reset by hand, so a panic inside them leaves them on for the next program on that thread: - **`with_folded`** (`emit/lower.rs` 721-725, `FOLDED.replace(true)` … `FOLDED.set(was)`). The hunk at 726 converts `with_local_waves` right after it but not this one. It matters as soon as `VICTORY_WAVE_FOLDED=1` is set: one panic in a folded translation would lower every later program on that worker as folded. - **`COUNTING`** in `emit/bitcode/census.rs` 73-75. This only affects the census, but it has the same pattern. Routing both through `with_flag` would cover them. A test like the one in `lower/tests.rs`, panicking inside `with_folded` and then checking `folded()` is false, would pin it. One more small point: a panic refusal becomes dropped work for that program, so a distinct, greppable reason in the log and in the census output (e.g. `refused (panic)`) would make such programs easy to count across a corpus run. _Review was AI-assisted._
Proudnoob4 commented 2026-11-29 20:04:16 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Proudnoob4 on 2026-11-29T20:04:16Z.


Thanks @AimLogin, both fixed in e4e503ff:

  • with_folded and the census's counting() now go through with_flag. A new test, folding_is_put_back_when_the_translation_under_it_panics, panics inside with_folded and checks that FOLDED is false afterwards.
  • The refusal now reads translation panicked: <the panic's text>, worded as the CLI's contain_panic. In a precompile this catch now runs before that one, so the failure summary keeps the text, and the play log's shader does not translate line carries it too.
  • The other hand-reset cells I found are test-only and hold an Option (emit/cost.rs with, and the test bodies in opt.rs and lds.rs), so I left them.

New since the PR was opened: on main's v2026.11.29.02 hotfix (wave64 folding off by default since 5c262d7b), regular play hit a translator panic on a pipeline worker. This was an RTX 4080, with this PR and other open PRs applied: compute 1aba2732fc75484f, forward reference outside a phi (bitcode.rs:1093), on thread victory-pipelines-11. With this PR it was refused, and the 330 s run went on with a normal picture. None of eight runs before the hotfix (folding on) met a panic.

Checked: cargo test -p victory-shader --lib gives 413 passed, both put-back tests among them. The 51 failures are the same as on main here (no SM 6.6 device). Clippy finds nothing in the changed lines; shader_cache.rs's one warning, the unused AtomicBool import at line 14, is on main too. --all-features stops in copystat.rs and host.rs, files this PR doesn't touch.

AI-assisted.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7261782206 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2917#issuecomment-7261782206). Originally posted by [Proudnoob4](https://github.com/Proudnoob4) on 2026-11-29T20:04:16Z. --- Thanks @AimLogin, both fixed in e4e503ff: - `with_folded` and the census's `counting()` now go through `with_flag`. A new test, `folding_is_put_back_when_the_translation_under_it_panics`, panics inside `with_folded` and checks that `FOLDED` is false afterwards. - The refusal now reads `translation panicked: <the panic's text>`, worded as the CLI's `contain_panic`. In a precompile this catch now runs before that one, so the failure summary keeps the text, and the play log's `shader does not translate` line carries it too. - The other hand-reset cells I found are test-only and hold an `Option` (`emit/cost.rs` `with`, and the test bodies in `opt.rs` and `lds.rs`), so I left them. New since the PR was opened: on main's v2026.11.29.02 hotfix (wave64 folding off by default since 5c262d7b), regular play hit a translator panic on a pipeline worker. This was an RTX 4080, with this PR and other open PRs applied: compute `1aba2732fc75484f`, `forward reference outside a phi` (`bitcode.rs:1093`), on thread `victory-pipelines-11`. With this PR it was refused, and the 330 s run went on with a normal picture. None of eight runs before the hotfix (folding on) met a panic. Checked: `cargo test -p victory-shader --lib` gives 413 passed, both put-back tests among them. The 51 failures are the same as on main here (no SM 6.6 device). Clippy finds nothing in the changed lines; `shader_cache.rs`'s one warning, the unused `AtomicBool` import at line 14, is on main too. `--all-features` stops in `copystat.rs` and `host.rs`, files this PR doesn't touch. AI-assisted.
AimLogin commented 2026-11-29 20:40:11 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by AimLogin on 2026-11-29T20:40:11Z.


Thanks. I checked e4e503ff:

  • with_folded and counting() now go through with_flag;
  • folding_is_put_back_when_the_translation_under_it_panics covers the case;
  • the refusal text is distinct and greppable.

Both points are resolved from my side (read, not run).

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7262264019 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2917#issuecomment-7262264019). Originally posted by [AimLogin](https://github.com/AimLogin) on 2026-11-29T20:40:11Z. --- Thanks. I checked e4e503ff: - `with_folded` and `counting()` now go through `with_flag`; - `folding_is_put_back_when_the_translation_under_it_panics` covers the case; - the refusal text is distinct and greppable. Both points are resolved from my side (read, not run).
dyshay commented 2026-11-29 20:46:55 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by dyshay on 2026-11-29T20:46:55Z.


Merged into our fork's integration branch for testing (dyshay/VIctory-NVIDIA, branch janus-prs). I read the full diff first: no network access, process spawning, binaries, build or dependency changes, or game data. It builds with --profile diag --features diagnostics, and the CPU tests of the touched crates pass. A run on an RTX 4090 is queued (Series S with ray tracing, DLSS Quality). Frame times will follow here.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7262352939 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2917#issuecomment-7262352939). Originally posted by [dyshay](https://github.com/dyshay) on 2026-11-29T20:46:55Z. --- Merged into our fork's integration branch for testing ([dyshay/VIctory-NVIDIA](https://github.com/dyshay/VIctory-NVIDIA/tree/janus-prs), branch `janus-prs`). I read the full diff first: no network access, process spawning, binaries, build or dependency changes, or game data. It builds with `--profile diag --features diagnostics`, and the CPU tests of the touched crates pass. A run on an RTX 4090 is queued (Series S with ray tracing, DLSS Quality). Frame times will follow here.
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/2917:upstream-pr/2917'
git switch 'upstream-pr/2917'

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/2917'
git switch 'upstream-pr/2917'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2917'
git switch 'upstream-pr/2917'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2917'
git switch 'main'
git merge --squash 'upstream-pr/2917'
git switch 'main'
git merge --ff-only 'upstream-pr/2917'
git switch 'main'
git merge 'upstream-pr/2917'
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
trustno1-coder/VIctory-NVIDIA!2917
No description provided.