shader: refuse invalid destination codes and catch translator panics instead of crashing #135

Closed
INeedThis56 wants to merge 0 commits from upstream-pr/135 into main
INeedThis56 commented 2026-11-29 02:46:53 +00:00 (Migrated from github.com)

Imported from uiliannn/VItoriaBr. Originally posted by INeedThis56 on 2026-11-29T02:46:53Z.


Summary

Two changes to victory-shader so that a shader the translator does not expect drops that program's draws instead of crashing the whole runtime.

1. Fix an out-of-bounds panic in ir.rs (unspill)
A destination field that holds a scalar code of 128 or above (for example, a VOP3 compare v_cmp_lt_f32 0x88, v1, 1.0) was accepted by add_regs, because codes from PARKED up are valid for parked moves. It then indexed unspill's 128-entry used table out of bounds. Now unspill leaves such a program as it is, and build refuses any non-parked instruction that names a code ≥ PARKED, returning the same "register range out of bounds" error that 0xFF already got. Codes 0–127 translate exactly as before. This also prevents a parked scalar from being given a code that the program itself names.

2. Catch translator panics in emit::translate
A panic now becomes ShaderError::Unsupported { what: PANICKED }, so it follows the existing "shader does not translate; its pipelines' draws are dropped" path. The panic message still reaches the panic hook. The retry switches (with_local_waves, with_local_waves_any, with_first_half_pairs) are now restored by a drop guard, so a caught panic cannot leave them enabled for later translations on that thread.

How it was found

I mutated the GFX10 programs from the crate's own tests (bit flips, word replacement, insertion and deletion) and ran each one through spill::build → structure → resource::track → io::raise → emit. Each mutation ran as wave64/wave32 compute and wave32 pixel, on 32- and 64-lane hosts.

  • Before the fix: 16 distinct panics, all at ir.rs:315.
  • After the fix: none in about 1.4 million runs, about 38% of which translated completely.
  • Container parsing: I also ran about 300k byte mutations of the FSSM/XDAT parsing (native_programs), with no panics.

Testing

  • Two new tests: ir::tests::a_destination_past_the_machine_codes_is_refused (all 256 destination codes × wave32/wave64) and emit::lower::tests::a_panic_leaves_the_retry_switches_as_they_were.
  • Ran on Linux: the victory-shader suite passes (190 tests), and clippy with the workspace lints reports nothing on the changed code.
  • Not tested: the Windows CI job, and an actual game run. Please run cargo xtask ci on Windows before merging.
<!-- greyfinch-sync:uiliannn/VItoriaBr:issue:5546932217 --> Imported from [uiliannn/VItoriaBr](https://github.com/uiliannn/VitoriaBr2.0/pull/135). Originally posted by [INeedThis56](https://github.com/INeedThis56) on 2026-11-29T02:46:53Z. --- ## Summary Two changes to `victory-shader` so that a shader the translator does not expect drops that program's draws instead of crashing the whole runtime. **1. Fix an out-of-bounds panic in `ir.rs` (`unspill`)** A destination field that holds a scalar code of 128 or above (for example, a VOP3 compare `v_cmp_lt_f32 0x88, v1, 1.0`) was accepted by `add_regs`, because codes from `PARKED` up are valid for parked moves. It then indexed `unspill`'s 128-entry `used` table out of bounds. Now `unspill` leaves such a program as it is, and `build` refuses any non-parked instruction that names a code ≥ `PARKED`, returning the same `"register range out of bounds"` error that `0xFF` already got. Codes 0–127 translate exactly as before. This also prevents a parked scalar from being given a code that the program itself names. **2. Catch translator panics in `emit::translate`** A panic now becomes `ShaderError::Unsupported { what: PANICKED }`, so it follows the existing "shader does not translate; its pipelines' draws are dropped" path. The panic message still reaches the panic hook. The retry switches (`with_local_waves`, `with_local_waves_any`, `with_first_half_pairs`) are now restored by a drop guard, so a caught panic cannot leave them enabled for later translations on that thread. ## How it was found I mutated the GFX10 programs from the crate's own tests (bit flips, word replacement, insertion and deletion) and ran each one through `spill::build` → `structure` → `resource::track` → `io::raise` → `emit`. Each mutation ran as wave64/wave32 compute and wave32 pixel, on 32- and 64-lane hosts. - **Before the fix:** 16 distinct panics, all at `ir.rs:315`. - **After the fix:** none in about 1.4 million runs, about 38% of which translated completely. - **Container parsing:** I also ran about 300k byte mutations of the FSSM/XDAT parsing (`native_programs`), with no panics. ## Testing - Two new tests: `ir::tests::a_destination_past_the_machine_codes_is_refused` (all 256 destination codes × wave32/wave64) and `emit::lower::tests::a_panic_leaves_the_retry_switches_as_they_were`. - Ran on Linux: the `victory-shader` suite passes (190 tests), and clippy with the workspace lints reports nothing on the changed code. - **Not tested:** the Windows CI job, and an actual game run. Please run `cargo xtask ci` on Windows before merging.

Pull request closed

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
uiliannn/VItoriaBr!135
No description provided.