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

Open
github-bot wants to merge 2 commits from github-bot/gh-2917 into main AGit
Owner

@⁠Proudnoob4 on GitHub · 2026-11-29 18:48 UTC · original
Proudnoob4:pr/translator-panics → main · +74 −55 · 6 files · 2 commits · open

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.

**@⁠Proudnoob4** on GitHub · 2026-11-29 18:48 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2917) `Proudnoob4:pr/translator-panics` → `main` · +74 −55 · 6 files · 2 commits · open ## 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.
- The translator's switches (`with_wide_fallback`, `with_last_resort`, `with_half_meets`,
  `with_pair_meetings`, `with_local_waves(_any)`, `with_pixel_mask`, `with_first_half_pairs`) set their
  thread-local flag through `lower::with_flag`, which puts it back also when the translation panics.
  Before, a caught panic (the pipeline workers catch them, `make_with`) left the flag set for every later
  program on that thread: translating 2,680 programs in a row on one thread, a program that translates on
  its own (code hash ffc541031e0f607e) panicked after another had panicked in the wave-wide fallback, in
  the form the leftover flag put it in. (#2368 does the same for `with_program`'s hash and counts.)
- shader_cache: the translation runs under catch_unwind; a panic is an Err ("the translator panicked"),
  its message still in the log. A translation is made on first use, by whichever thread asks; inside a
  device or list method, which cannot unwind, a panic ended the game ("thread caused non-unwinding
  panic. aborting."). That happened on a 32-lane card (RTX 4080) with a wave64 compute program from
  DeserializeComputePipelineStateX (0x218) in the wave-wide fallback (9bba2a20): code hash
  e4d73679b3cd31b9, "forward reference outside a phi" (bitcode.rs:948). Its plain container translates.

Test: a_flag_is_put_back_when_the_translation_under_it_panics. In game with that program translated inside
a device call: before, the game aborted; now the panic fired once, was refused, and the run reached the
world. The wave-wide form's bad IR for that program itself is not fixed here (it is refused now).

Code hashes are the first 16 hex digits of the BLAKE3 of the program's code.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-29 18:51:27 +00:00
Author
Owner

@⁠AimLogin on GitHub · 2026-11-29 19:48 UTC · original

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.

**@⁠AimLogin** on GitHub · 2026-11-29 19:48 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2917#issuecomment-7261566527) 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._
Review of #2917 (AimLogin):
- `with_folded` (VICTORY_WAVE_FOLDED=1) sets FOLDED through `lower::with_flag`, so a panic in a folded
  program no longer leaves folding on for that thread's next programs; the census's test-only
  `counting()` likewise.
- shader_cache words the refusal as the CLI's `contain_panic` does, with the panic's own text:
  "translation panicked: <message>". A precompile now meets this catch before its own, so its failure
  summary keeps the text, and the play log's "shader does not translate" line carries it too.

Test: folding_is_put_back_when_the_translation_under_it_panics.
Author
Owner

@⁠Proudnoob4 on GitHub · 2026-11-29 20:04 UTC · original

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.

**@⁠Proudnoob4** on GitHub · 2026-11-29 20:04 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2917#issuecomment-7261782206) 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.
Author
Owner

@⁠AimLogin on GitHub · 2026-11-29 20:40 UTC · original

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).

**@⁠AimLogin** on GitHub · 2026-11-29 20:40 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2917#issuecomment-7262264019) 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).
Author
Owner

@⁠dyshay on GitHub · 2026-11-29 20:46 UTC · original

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.

**@⁠dyshay** on GitHub · 2026-11-29 20:46 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2917#issuecomment-7262352939) 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 has changes conflicting with the target branch.
  • crates/victory-shader/src/emit/lower/tests.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2917/head:github-bot/gh-2917'
git switch 'github-bot/gh-2917'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2917'
git switch 'github-bot/gh-2917'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2917'
git switch 'github-bot/gh-2917'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2917'
git switch 'main'
git merge --squash 'github-bot/gh-2917'
git switch 'main'
git merge --ff-only 'github-bot/gh-2917'
git switch 'main'
git merge 'github-bot/gh-2917'
git push origin 'main'
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!2917
No description provided.