Shaders: refuse an SGPR destination past exec_hi when decoding (ir::build panicked, release too) #279
No reviewers
Labels
No labels
accessibility
already-solved
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
merged
needs-decision
needs-game-run
needs-rebase
not-merged
nvidia
obsolete
question
security
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/avatarmanz--VIctory-7900XTX!279
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@sharan104 on GitHub · 2026-11-26 14:14 UTC · original
sharan104:fix/gfx10-sgpr-dst→main· +41 −0 · 1 files · 1 commits · openVOP3 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
VOP3 compares, v_readlane_b32 and v_readfirstlane_b32 name their SGPR destination in an 8-bit field, and the decoder passed codes 128-255 through as Operand::Scalar, whose contract is that the decoder gives none above 127. The IR takes such codes for parked scalars (add_regs lets them through), and ir::build then indexed its table of the 128 machine codes with one: a panic ("index out of bounds: the len is 128 but the index is 159", ir.rs:336), in release builds too, from nothing but the words of a corrupt shader. decode now refuses such an instruction with ShaderError::Isa, as it refuses other code that names nothing. v_cmpx is left alone: it writes EXEC whatever its destination field holds, and the IR never reads that field. A sweep of a million random short programs through decode, text and ir::build (debug build) found no other panic. Test: gfx10::tests::rejects_sgpr_destinations_past_exec_hi (panicked at ir.rs:336 before the fix). Co-Authored-By: Claude Opus 5.5 <[email protected]>@compaccount1-coder on GitHub · 2026-11-26 15:20 UTC · original
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.