shader: a lane mask that needs its own value fails instead of overflo… #43

Manually merged
github merged 1 commit from gh-pr/43/head into gh-pr/43/base 2026-11-26 03:47:52 +00:00
Owner

@⁠9hvn9yt2vk-netizen on GitHub · 2026-11-23 23:42 UTC · original
9hvn9yt2vk-netizen:shader-mask-cycle → main · +48 −1 · 2 files · 1 commits · merged 2026-11-24 00:34 UTC

…wing the stack

In a wave64 compute program, writing only EXEC's high dword (for example s_mov_b32 exec_hi, 0) and then running any vector instruction crashed the whole process with a stack overflow. The new mask is opaque and keyed by the unchanged low dword, so lowering the instruction's guard asked for that dword's value, the value is a lane mask read as data, its ballot needs the mask's lane bit, and that bit needs the value again: mask_dword -> boolean -> atom -> get -> mask_dword, without end.

mask_dword now notes the masks whose ballot it is building, and a mask reached again on the way fails with a reason. The instruction then fails like any other that cannot be expressed: its result is missing, and only a side effect that uses it stops the translation. A shader the translator cannot handle must not take the title down at pipeline creation.

Found with a random-input harness over the whole translation (ir, resource, io, structure, emit) of random decodable compute programs. The new test overflows the stack without the fix. One million further programs (about 160,000 fully translated) gave no panic, hang or overflow.

**@⁠9hvn9yt2vk-netizen** on GitHub · 2026-11-23 23:42 UTC · [original](https://github.com/Marvisak/VIctory/pull/43) `9hvn9yt2vk-netizen:shader-mask-cycle` → `main` · +48 −1 · 2 files · 1 commits · merged 2026-11-24 00:34 UTC …wing the stack In a wave64 compute program, writing only EXEC's high dword (for example s_mov_b32 exec_hi, 0) and then running any vector instruction crashed the whole process with a stack overflow. The new mask is opaque and keyed by the unchanged low dword, so lowering the instruction's guard asked for that dword's value, the value is a lane mask read as data, its ballot needs the mask's lane bit, and that bit needs the value again: mask_dword -> boolean -> atom -> get -> mask_dword, without end. mask_dword now notes the masks whose ballot it is building, and a mask reached again on the way fails with a reason. The instruction then fails like any other that cannot be expressed: its result is missing, and only a side effect that uses it stops the translation. A shader the translator cannot handle must not take the title down at pipeline creation. Found with a random-input harness over the whole translation (ir, resource, io, structure, emit) of random decodable compute programs. The new test overflows the stack without the fix. One million further programs (about 160,000 fully translated) gave no panic, hang or overflow.
In a wave64 compute program, writing only EXEC's high dword (for
example s_mov_b32 exec_hi, 0) and then running any vector instruction
crashed the whole process with a stack overflow. The new mask is opaque
and keyed by the unchanged low dword, so lowering the instruction's guard
asked for that dword's value, the value is a lane mask read as data, its
ballot needs the mask's lane bit, and that bit needs the value again:
mask_dword -> boolean -> atom -> get -> mask_dword, without end.

mask_dword now notes the masks whose ballot it is building, and a mask
reached again on the way fails with a reason. The instruction then fails
like any other that cannot be expressed: its result is missing, and only
a side effect that uses it stops the translation. A shader the translator
cannot handle must not take the title down at pipeline creation.

Found with a random-input harness over the whole translation (ir,
resource, io, structure, emit) of random decodable compute programs. The
new test overflows the stack without the fix. One million further
programs (about 160,000 fully translated) gave no panic, hang or
overflow.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:47:50 +00:00
github manually merged commit ea24ea109c into gh-pr/43/base 2026-11-26 03:47:52 +00:00
Author
Owner

@⁠DaviTostes on GitHub · 2026-11-23 23:51 UTC · original

Tested ea24ea1 stacked on #39 on Arch Linux x86_64, rustc 1.98.1: pass.

  • main alone does not build on Linux (E0425 in victory-gpu), so the check uses #39 as the base; the merge is clean.
  • cargo test --workspace: 156 passed, 0 failed, 3 ignored.
  • The new an_exec_high_write_does_not_overflow_the_stack test runs and passes; no other test changed. No game data used.

AI-assisted (DeepSeek V4.1 Flash coding agent).

**@⁠DaviTostes** on GitHub · 2026-11-23 23:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/43#issuecomment-7117442114) Tested `ea24ea1` stacked on **#39** on **Arch Linux x86_64, rustc 1.98.1**: **pass**. - `main` alone does not build on Linux (E0425 in `victory-gpu`), so the check uses #39 as the base; the merge is clean. - `cargo test --workspace`: **156 passed, 0 failed, 3 ignored**. - The new `an_exec_high_write_does_not_overflow_the_stack` test runs and passes; no other test changed. No game data used. AI-assisted (DeepSeek V4.1 Flash coding agent).
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 00:48 UTC · original

checked: PR head ea24ea1 on its merge-base 97c78d1, Linux x86_64 (Debian, kernel 6.12), rustc/cargo 1.98.1, throwaway worktree, no game files used. This was run while the PR was being merged (it shows merged at 00:34 UTC), so it is a record, not a gate.

Ran (shader crate only, so I did not hit the victory-gpu build error mentioned above):

  • cargo test -j4 -p victory-shader: 52 passed, 0 failed, including an_exec_high_write_does_not_overflow_the_stack.
  • cargo clippy -j4 -p victory-shader --tests: no new warnings (the constant_color is never used test-module warning also appears on trees that do not touch emit/mod.rs).
  • Fail-before check: with only lower.rs reverted to 97c78d1 and the new test kept, cargo test -p victory-shader an_exec_high ends with thread ... has overflowed its stack, fatal runtime error: stack overflow, SIGABRT. With the fix it passes. So the test does guard the fix.

Review notes:

  • The guard is correct as I read it: the key is inserted before boolean, removed on both the Ok and Err path (let bit = ...; remove; bit?), so an error does not leave a stale entry that would block a later legitimate lookup.
  • On this test input emit returns Ok(()) with the fix (I printed it temporarily). So the if let Err(e) branch, with its "its own value" message assertion, never runs; the test effectively proves "no crash" only. That is the important part. If you want the message pinned, a program whose side effect uses the failing instruction's result would hit the Err branch.
  • A stack overflow aborts the whole test binary rather than failing one test, so a regression here would show up as a crash of the entire victory-shader test run.

Not verified: Windows runtime, GPU, or the random-input harness the description mentions (it is not in the tree, so I could not rerun the "one million programs" claim).

**@⁠tedin7** on GitHub · 2026-11-24 00:48 UTC · [original](https://github.com/Marvisak/VIctory/pull/43#issuecomment-7118445741) checked: PR head `ea24ea1` on its merge-base `97c78d1`, Linux x86_64 (Debian, kernel 6.12), rustc/cargo 1.98.1, throwaway worktree, no game files used. This was run while the PR was being merged (it shows merged at 00:34 UTC), so it is a record, not a gate. Ran (shader crate only, so I did not hit the `victory-gpu` build error mentioned above): - `cargo test -j4 -p victory-shader`: 52 passed, 0 failed, including `an_exec_high_write_does_not_overflow_the_stack`. - `cargo clippy -j4 -p victory-shader --tests`: no new warnings (the `constant_color is never used` test-module warning also appears on trees that do not touch `emit/mod.rs`). - Fail-before check: with only `lower.rs` reverted to `97c78d1` and the new test kept, `cargo test -p victory-shader an_exec_high` ends with `thread ... has overflowed its stack, fatal runtime error: stack overflow`, SIGABRT. With the fix it passes. So the test does guard the fix. Review notes: - The guard is correct as I read it: the key is inserted before `boolean`, removed on both the Ok and Err path (`let bit = ...; remove; bit?`), so an error does not leave a stale entry that would block a later legitimate lookup. - On this test input `emit` returns `Ok(())` with the fix (I printed it temporarily). So the `if let Err(e)` branch, with its "its own value" message assertion, never runs; the test effectively proves "no crash" only. That is the important part. If you want the message pinned, a program whose side effect uses the failing instruction's result would hit the `Err` branch. - A stack overflow aborts the whole test binary rather than failing one test, so a regression here would show up as a crash of the entire `victory-shader` test run. Not verified: Windows runtime, GPU, or the random-input harness the description mentions (it is not in the tree, so I could not rerun the "one million programs" claim).
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/Marvisak--VIctory!43
No description provided.