shader: fix source-less VOP1 length and VOP3 CMPX destination #180
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Belobug--VIctory-Belobug-AMD!180
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-180"
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?
@davutsimsekk on GitHub · 2026-11-25 19:35 UTC · original
davutsimsekk:fix/vop1-cmpx-decoding→main· +44 −2 · 2 files · 1 commits · openFixes two GFX10 decoder cases where the encoded fields do not describe the instruction's real operands.
v_nop,v_pipeflush,v_clrexcp) stay one dword. Their SRC0 field can contain a shader hash whose low bits look like an extension marker; consuming that word shifts every following instruction.v_cmpx_*writes EXEC, not the encoded VDST. The decoder now reports EXEC for those opcodes and leaves ordinary VOP3/VOPC compares on VDST.Tested
cargo test -p victory-shader --lib --locked vop1_without_operands_has_no_extension_word: 1 passed.cargo test -p victory-shader --lib --locked vop3_cmpx_writes_exec: 1 passed.Not tested
AI use
@KernelSmoker on GitHub · 2026-11-25 19:59 UTC · original
Independent verification on PR head
4d291d4(Bazzite Linux 45 x86_64, Rust 1.98.1):cargo test --offline --locked -p victory-shader: 187 passed, 0 failed, 6 ignored (lib, including both new testsvop1_without_operands_has_no_extension_wordandvop3_cmpx_writes_exec) + 3 passed, 0 failed, 1 ignored (tests/resource_tracking.rs).cargo clippy --offline --locked -p victory-shader --all-targets: 0 warnings incrates/victory-shader/src/gfx10/.gfx10/mod.rs(0x000,0x01B,0x041) matchv_nop,v_pipeflush,v_clrexcpingfx10/opcodes.rsandgfx10/fields.rs:436.v.dst = Some(scalar(EXEC, lanes))forv_cmpx*in the VOP3 arm ofgfx10/fields.rs:595brings it in line with the existing VOPC arm (fields.rs:511) and GFX10/RDNA2 semantics (VOP3v_cmpxwritesEXEConly, notVDST).v_clrexcp(0x041, e.g.0x7E00_82FF) could optionally be added alongsidev_nop/v_pipeflushinvop1_without_operands_has_no_extension_word.@lcg007xd-c on GitHub · 2026-11-25 21:13 UTC · original · approved these changes
Verified on Linux (Rust 1.98.1)
cargo test -p victory-shader --libon4d291d4: 187 passed, 0 failed, 6 ignored. Merged into current main with--no-commit: 198 passed, 0 failed (main alone: 196).gfx10/fields.rsreverted to main,vop3_cmpx_writes_execfails:left: Some(Scalar { code: 5, .. }),right: Some(Scalar { code: 126, .. }).0x3Farm ingfx10/mod.rsreverted,vop1_without_operands_has_no_extension_wordfails.cargo clippy -p victory-shader --target x86_64-pc-windows-msvc: the same 10 warnings as main, none ingfx10/.git merge --no-commit --no-ffinto main: merges cleanly.llvm-mc --disassemble -triple=amdgcn -mcpu=gfx1030:v_nop,v_pipeflushandv_clrexcpwith SRC0 =0xFF,0xFAor0xF9, followed bys_endpgm, decode as one 4-byte instruction each, thens_endpgm.0xD4110005 0x0001E501decodes asv_cmpx_lt_f32_e64 v1, 1.0, with no SGPR destination. LLVM re-encodes VDST as0x7eand warns "potentially undefined instruction encoding" for VDST = 5, so EXEC is the right destination to report.Notes (non-blocking)
gfx10/mod.rs:215uses the opcode numbers0x000 | 0x01B | 0x041, whilegfx10/fields.rs:436uses the names"v_nop" | "v_pipeflush" | "v_clrexcp". Both lists say the same thing. Matching onname(Encoding::Vop1, opcode as u16)here, or sharing one list, would keep the length decode and the operand decode from drifting apart.v_cmpxand ignorev.dst(ir.rs:987,structure.rs:1049,emit/lower.rs:10090). The VOP3 half mostly makesFieldsconsistent with the VOPC arm. It is unlikely to change generated code. The VOP1 length fix is the part that changes behaviour: every instruction after a hashedv_nopwas shifted before.Not verified
Reviewed with Claude Code.
@Yoshi-233 on GitHub · 2026-11-26 03:57 UTC · original
@KernelSmoker I checked the
v_clrexcpcase you mentioned on this fork, comparing the parent000ffddwith4d291d4. I puts_endpgmdirectly after each instruction and swept all 512 SRC0 encodings for each ofv_nop,v_pipeflush, andv_clrexcp. On the parent, all three swallowed the next word for the same five values:0xe9,0xea,0xf9,0xfa, and0xff. On the PR all 1,536 decoded with the end instruction at byte 4. An ordinaryv_mov_b32control kept its correct length for all 512 encodings on both revisions.I also checked the decoded destination for 95 named VOP3 CMPX opcodes, wave32/wave64, and four encoded destinations. All 760 disagreed with the expected EXEC destination on the parent and all 760 matched on the PR. The SSA writes and subsequent reads of EXEC already agreed on both revisions. Linux CPU-only; the PR's shader library suite passed 187 with 6 ignored.
@MamaLeVrai on GitHub · 2026-11-26 05:00 UTC · original
RDNA2 data point. This PR (
4d291d4) merged onmain4f62c2a,cargo test --release -p victory-shader --libon an RX 6950 XT (Windows 11 build 26300, Rust 1.98.1):main: 275 passed, 2 failed.The 2 failures are the same as on
main: the RDNA2 wave-size testsscalar_counted_in_a_divergent_loop_read_after_itandscalar_counted_in_nested_divergent_loops, fixed by #110 and #204. No regression here. Not run in the game.harness machine: rx6950xt-w11 | AMD Radeon RX 6950 XT (RDNA2), driver 32.0.21045.29003 | 32 GB RAM | Windows 11 build 26300
AI-assisted (Claude Code); no game data.
@adrianmjim on GitHub · 2026-11-26 19:41 UTC · original
Data from the title, on how much this changes in practice. I tested
4d291d4on native Windows 11 (26300) with an RX 7900 XT (RDNA3) and Rust 1.98.1.Unit tests.
cargo test -p victory-shader --lib -- --test-threads=1gives 268 passed, 0 failed and 6 ignored, against 266 on the base000ffdd.The title's shaders. I ran
victory translate --validate --host-lanes 32-64over the game's wholeshaders.rpf, and nothing changes against000ffdd:victory shader-infodecodes the same 26698 programs and 44386798 instructions before and after.Why nothing changes, from a full disassembly of the archive. The review above expected the VOP1 length fix to change behaviour, because instructions after a hashed
v_nopwould have been shifted. In this title they aren't:v_nophave SRC0 = 0, so they already decoded as one dword. There are nov_pipeflushorv_clrexcpat all.v_nop, at offsets 0x0 and 0xC of every program. Each has SRC2 = 0xFF and a literal, so each is 3 dwords, and all 53396 of them already decode as 3 dwords. This PR does not touch that path.v_cmpxencode VDST as 126 (EXEC_LO), so thefields.rschange gives the same operand as before.So both halves are correct guards, but this title has no instruction that needs either one.
Not tested: the current main (
4f62c2a), other titles, in-game runs.@Yoshi-233 on GitHub · 2026-11-27 01:11 UTC · original
I rechecked the current default branch,
a-publierat4eb6cfd, since #180 targetsmain. Both decoder cases still reproduce on that branch. The distinction matters for testing the build people currently get from a fresh clone.s_endpgmfor 15 (the five ignored SRC0 values on each ofv_nop,v_pipeflushandv_clrexcp). All 512 ordinary MOV length controls were correct.The patch from
4d291d4does not apply as a plain patch againsta-publier(the test hunk ingfx10/mod.rshas different context). I tried the backport of your fix in CGBJ #4 on4eb6cfd: it applies cleanly, all 1,536 instruction boundaries and 760 CMPX destinations match, and the Linuxvictory-shader --libsuite reports 212 passed, 2 ignored. This gives maintainers a tested option for the default branch. These are synthetic CPU cases; the title-corpus observation above is compatible with this result.AI-assisted testing on native x86-64 Linux, Rust 1.98.1.
@gut0to on GitHub · 2026-11-27 14:57 UTC · original · reviewed
AI-assisted static review; I inspected the decoder change and its fixtures, but did not run the test suite. One boundary case is not covered yet:
@ -212,0 +212,4 @@let opcode = (w >> 9) & 0xFF;// These VOP1s take no source, so the field is not a literal// (the console compiler stores a shader hash there).let no_source = matches!(opcode, 0x000 | 0x01B | 0x041);@gut0to on GitHub · 2026-11-27 14:57 UTC · original
AI-assisted static review; I did not run tests. The no-source table also includes opcode
0x041(v_clrexcp), but the fixture covers onlyv_nopandv_pipeflush. Could it addv_clrexcpwithSRC0 = 0xFFfollowed immediately bys_endpgm? That would verify the third opcode stays one dword and that the decoder does not consume the next instruction as a false literal.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.