Shaders: refuse an SGPR destination past exec_hi when decoding (ir::build panicked, release too) #279
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/279"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from avatarmanz/VIctory-7900XTX. Originally posted by sharan104 on 2026-11-26T14:14:36Z.
VOP3 compares,
v_readlane_b32andv_readfirstlane_b32take their SGPR destination from an 8-bit field. Codes from 128 up don't name a register. Butfields.rshanded them on asOperand::Scalar, which promises a code below 128. The IR treats such codes as parked scalars, andir::buildthen indexes its 128-entry table of machine scalars past the end (ir.rs:336). Bounds checks stay on in release builds, so a corrupt shader's words alone crashed the process, in release too.A throwaway sweep of a million random short programs through
decode,textandir::build(debug build, not committed) found 1,073 panics, all at that spot. After this change it found none.Fix:
decoderefuses such an instruction withShaderError::Isa("an SGPR destination past exec_hi"), so the shader is reported as not translating instead of crashing.v_cmpxis exempt: it writes EXEC, and the IR never reads its destination field. Any shader this now refuses used to panic, so no shader that translated before is lost.Test:
gfx10::tests::rejects_sgpr_destinations_past_exec_hi.v_cmp_lt_f32 s6,v_readfirstlane_b32 s2andv_readlane_b32 s2still decode.decodeandir::build.v_cmpxwith code 0x9F is still accepted.The test fails before the fix and passed 10 runs out of 10 after it.
Results:
cargo test -p victory-shader --locked: 303 passed, 0 failed, 4 ignored.-D warningsis clean, with and without--all-features.🤖 Generated with Claude Code
Imported from avatarmanz/VIctory-7900XTX. Originally posted by compaccount1-coder on 2026-11-26T15:20:37Z.
Independent confirmation from a random-input run, in case it helps this get merged:
I fed mutated GFX10 instruction words (taken from the test programs here, with random bits flipped and some fully random words) into
gfx10::decode→ir::build→structure::structureonmain(c9c932c). Within 20,000 cases it panicked twice, both atir.rs:336inir::unspill(used[usize::from(c)],usedis[bool; 128]):On this PR's branch (
2799904), both are refused bygfx10::decode, and 100,000 more random cases through the same three stages gave no panic. Of 500,000 random compute programs through the whole pipeline on top of it (spill::build→structure→resource::track→io::raise→emit::emit, on a CS skeleton likewave64_tests::native), one other panic came up. It is unrelated to this one (adebug_assertincross_lane, a lowering gap rather than a decoding one) and fixed in #308.So the decoding crash the random run found is the one this PR fixes. Windows 11, Rust 1.98.1, the scratch harness not committed anywhere.
AI-assisted: yes (Claude Code)
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.