Skip to content

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

Merged
Marvisak merged 1 commit into
Marvisak:mainfrom
9hvn9yt2vk-netizen:shader-mask-cycle
Nov 24, 2026
Merged

Marvisak merged 1 commit into
Marvisak:mainfrom
9hvn9yt2vk-netizen:shader-mask-cycle

Conversation

@9hvn9yt2vk-netizen

Copy link
Copy Markdown
Contributor

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

…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.
@DaviTostes

Copy link
Copy Markdown

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 Build: make workspace tests run on Linux #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).

@Marvisak
Marvisak merged commit a6888a6 into Marvisak:main Nov 24, 2026
@tedin7

tedin7 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants