Shaders: fix missing and phantom operands in SP3 text #661
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/661"
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 Marvisak/VIctory. Originally posted by coderanonymus on 2026-11-24T06:24:32Z.
What
The SP3 disassembly text (
Instruction::text, used byvictory shader) printed operands that some instructions do not have. It also dropped VOP3P negation that applies to one half of a source only. The decodedFieldswere right in every case; only the text was wrong. Translation readsFields, so it is unaffected.Before and after, for words that llvm-mc
-mcpu=gfx1030assembles (-mcpu=gfx1010fors_get_waveid_in_workgroup, which gfx1030 lacks):0xF4900500 0x00000000s_memtime s[20:21], s[0:1], s0s_memtime s[20:21]0xF4A80140 0x00000000s_get_waveid_in_workgroup s5, s[0:1], s0s_get_waveid_in_workgroup s50xDC308000 0x007D0002global_load_dword v0, v[2:3], nullglobal_load_dword v0, v[2:3], off0xE0311000 0x00010001buffer_load_dword v0, v1, s[4:7], s0 offen ldsbuffer_load_dword v1, s[4:7], s0 offen lds0x7E0202F9 0x00050602v_mov_b32 v1, v2 src0_sel:WORD_1 src1_sel:BYTE_0v_mov_b32 v1, v2 src0_sel:WORD_10xCC0F4001 0x3A020702v_pk_add_f16 v1, v2, v3v_pk_add_f16 v1, v2, v3 neg_lo:[1,0]0xCC0F4201 0x1A020702v_pk_add_f16 v1, v2, v3v_pk_add_f16 v1, v2, v3 neg_hi:[0,1]0xCC0F4101 0x7A020702v_pk_add_f16 v1, -v2, v3v_pk_add_f16 v1, -v2, v3 neg_lo:[0,1]Changes, all in
crates/victory-shader/src/gfx10/sp3.rs:s_memtime,s_memrealtimeands_get_waveid_in_workgroupprint only their data. They have no address. This matchesir.rs, which treats all three as data only.saddrof NULL prints asoff, as the same arm already does for a missing VGPR address.ldsleaves out vdata. This matchesir.rs, which records no VGPR write for it. Stores keep their data.srcN_selis printed only for sources the instruction has.v_fma_mix; also coversv_dot2_*): a source negated in both halves keeps the-srcprefix. Bits set in only one half now print as LLVM'sneg_lo:[..]/neg_hi:[..], one entry per source, beforeclamp.Nothing else in the printer's style changes.
Verification
gfx10::sp3::tests::one_sided_packed_negation_is_printedandgfx10::sp3::tests::fields_the_instruction_lacks_are_not_printed. They assert llvm-mc's operands in this printer's style: no_sdwasuffix or default selects, and-srcfor a source negated in both halves. So llvm-mc'sv_mov_b32_sdwa v1, v2 dst_sel:DWORD dst_unused:UNUSED_PAD src0_sel:WORD_1is asserted asv_mov_b32 v1, v2 src0_sel:WORD_1, and itsv_pk_add_f16 v1, v2, v3 neg_lo:[1,1] neg_hi:[1,0]asv_pk_add_f16 v1, -v2, v3 neg_lo:[0,1].CARGO_TARGET_DIR=/home/eric/src/VIctory/target cargo test -p victory-shader --lib -- one_sided_packed fields_the_instruction_lacks: both failed, with the "Before" strings above.cargo test -p victory-shader: 58 passed, 0 failed.cargo clippy -p victory-shader --tests --target x86_64-pc-windows-msvc: no warnings. On the Linux target, the only warning is the existing dead-codeconstant_colorinemit/mod.rs, which this change does not touch.rustfmt --edition 2024 --check crates/victory-shader/src/gfx10/sp3.rs: clean.victory shaderon real shaders. This needs Windows and game files, and neither is available here.Known gap, same on main and left for a follow-up: MUBUF with neither
offennoridxenprints a vaddr register where llvm-mc printsoff(0xE0310000 0x00010000:buffer_load_dword v0, s[4:7], s0 ldsvs llvm-mc'sbuffer_load_dword off, s[4:7], s0 lds).No game data used.
🤖 Generated with Claude Code
Imported from Marvisak/VIctory. Originally posted by LAKSHYA-cmd-tech on 2026-11-24T06:27:45Z.
Review: APPROVED
LGTM! Tested on Windows 11 with MSVC Rust 1.98.1. All 71 tests in ictory-shader passed cleanly, including one_sided_packed_negation_is_printed and ields_the_instruction_lacks_are_not_printed. SP3 disassembly text accurately handles addressless SMEM instructions, null flat addresses, LDS-only MUBUF loads, and partial VOP3P packed negations.
Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T09:37:33Z.
Review: APPROVED
Merges cleanly with main; macOS arm64, rustc 1.98.1,
cargo test -p victory-shader --lockedwith the PR merged into main8e79c80→ 72 passed / 0 failed / 1 ignored.Four SP3 text fixes, each with llvm-mc-derived encodings in the tests:
s_memtime/s_memrealtime/s_get_waveid_in_workgroupno longer print address operands they don't have.saddrNULL prints asoffinstead of a phantom operand.neg_lo/neg_hiwithout the-prefix) gets LLVM'sneg_lo:[...]/neg_hi:[...]suffixes, andsrc_selis capped at the actual source count so phantom selectors aren't printed.The
sdwa.src_sel.take(v.src.len())fix is the kind of latent bug that only shows on instructions with fewer sources than selector fields — good catch.Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T10:51:32Z.
Review: APPROVED
Tested
6325df7on Windows 11, RTX 5070, MSVC:cargo test -p victory-shader -- --test-threads=171 passed, includingone_sided_packed_negation_is_printedandfields_the_instruction_lacks_are_not_printed.cargo clippy -p victory-shader --all-targetsis clean.Instruction::textchanges. Translation readsFields, so emitted DXIL can't move.neg_lo/neg_hiare printed only for bits set on one side (neg & !neg_hi,neg_hi & !neg), so a source negated in both halves keeps the-prefix and isn't printed twice. That matches llvm-mc's output.s_memrealtime/s_memtimeever get suffixed variants, a check on the opcode would be sturdier. Not a blocker.AI-assisted (Claude Code).
Imported from Marvisak/VIctory. Originally posted by CaravelaLabs on 2026-11-24T11:07:34Z.
Thanks — the phantom-operand cleanup is real.
Checked against AMD LLVM 23.0.0git
llvm-mc -arch=amdgcn -mcpu=gfx1030(and-mcpu=gfx1010fors_get_waveid_in_workgroup). Merged this branch onto currentmain(ffe310e).cargo test -p victory-shader: 98 passed, 0 failed, including both new tests.The five encodings in
fields_the_instruction_lacks_are_not_printedmatch llvm-mc. The old printer text does not assemble: extras[0:1], s0ons_memtime,nullinstead ofoffonglobal_load_dword, avdataon an LDSbuffer_load_dword, andsrc1_selon a one-source SDWAv_mov_b32.One packed-negation case does not. Words
0xCC0F4101 0x7A020702(last row ofone_sided_packed_negation_is_printed):v_pk_add_f16 v1, -v2, v3 neg_lo:[0,1]v_pk_add_f16 v1, v2, v3 neg_lo:[1,1] neg_hi:[1,0]-srcprefix onv_pk_add_f16(not a valid operand)The first three packed encodings match. The
-prefix for both-halves negation is the printer's own convention, not LLVM's VOP3P syntax, so that row's expected string is not llvm-mc's. Translation is unaffected (Fieldswere already right), as the PR says.AI-assisted review. llvm-mc and the tests were run on this machine.
Imported from Marvisak/VIctory. Originally posted by molodayamama on 2026-11-24T14:03:19Z.
Independent Windows check of
6325df752c5638365c3e5a2b2f827ba0f3f145cb(Windows 10 22H2 19045, Rust 1.98.1, MSVC x64).cargo test -p victory-shader --locked --lib one_sided_packed_negation_is_printed -- --test-threads=1 --nocapture: 1 passed.The focused SP3 formatting fixture passed for a one-sided packed negation. A separate filter for absent fields did not select a test in my run, so this report covers only the packed-negation case.
Only source-built synthetic fixtures were used. AI-assisted verification.