Shaders: fix missing and phantom operands in SP3 text #661

Merged
coderanonymus merged 1 commit from upstream-pr/661 into main 2026-11-25 00:20:43 +00:00
coderanonymus commented 2026-11-24 06:24:32 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by coderanonymus on 2026-11-24T06:24:32Z.


What

The SP3 disassembly text (Instruction::text, used by victory shader) printed operands that some instructions do not have. It also dropped VOP3P negation that applies to one half of a source only. The decoded Fields were right in every case; only the text was wrong. Translation reads Fields, so it is unaffected.

Before and after, for words that llvm-mc -mcpu=gfx1030 assembles (-mcpu=gfx1010 for s_get_waveid_in_workgroup, which gfx1030 lacks):

Words Before After (llvm-mc's operands, this printer's style)
0xF4900500 0x00000000 s_memtime s[20:21], s[0:1], s0 s_memtime s[20:21]
0xF4A80140 0x00000000 s_get_waveid_in_workgroup s5, s[0:1], s0 s_get_waveid_in_workgroup s5
0xDC308000 0x007D0002 global_load_dword v0, v[2:3], null global_load_dword v0, v[2:3], off
0xE0311000 0x00010001 buffer_load_dword v0, v1, s[4:7], s0 offen lds buffer_load_dword v1, s[4:7], s0 offen lds
0x7E0202F9 0x00050602 v_mov_b32 v1, v2 src0_sel:WORD_1 src1_sel:BYTE_0 v_mov_b32 v1, v2 src0_sel:WORD_1
0xCC0F4001 0x3A020702 v_pk_add_f16 v1, v2, v3 v_pk_add_f16 v1, v2, v3 neg_lo:[1,0]
0xCC0F4201 0x1A020702 v_pk_add_f16 v1, v2, v3 v_pk_add_f16 v1, v2, v3 neg_hi:[0,1]
0xCC0F4101 0x7A020702 v_pk_add_f16 v1, -v2, v3 v_pk_add_f16 v1, -v2, v3 neg_lo:[0,1]

Changes, all in crates/victory-shader/src/gfx10/sp3.rs:

  • SMEM: s_memtime, s_memrealtime and s_get_waveid_in_workgroup print only their data. They have no address. This matches ir.rs, which treats all three as data only.
  • FLAT: a global or scratch saddr of NULL prints as off, as the same arm already does for a missing VGPR address.
  • MUBUF: a load with lds leaves out vdata. This matches ir.rs, which records no VGPR write for it. Stores keep their data.
  • SDWA: srcN_sel is printed only for sources the instruction has.
  • VOP3P (not v_fma_mix; also covers v_dot2_*): a source negated in both halves keeps the -src prefix. Bits set in only one half now print as LLVM's neg_lo:[..] / neg_hi:[..], one entry per source, before clamp.

Nothing else in the printer's style changes.

Verification

  • New tests gfx10::sp3::tests::one_sided_packed_negation_is_printed and gfx10::sp3::tests::fields_the_instruction_lacks_are_not_printed. They assert llvm-mc's operands in this printer's style: no _sdwa suffix or default selects, and -src for a source negated in both halves. So llvm-mc's v_mov_b32_sdwa v1, v2 dst_sel:DWORD dst_unused:UNUSED_PAD src0_sel:WORD_1 is asserted as v_mov_b32 v1, v2 src0_sel:WORD_1, and its v_pk_add_f16 v1, v2, v3 neg_lo:[1,1] neg_hi:[1,0] as v_pk_add_f16 v1, -v2, v3 neg_lo:[0,1].
  • Before the fix, 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.
  • After the fix, 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-code constant_color in emit/mod.rs, which this change does not touch.
  • rustfmt --edition 2024 --check crates/victory-shader/src/gfx10/sp3.rs: clean.
  • Not run: victory shader on 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 offen nor idxen prints a vaddr register where llvm-mc prints off (0xE0310000 0x00010000: buffer_load_dword v0, s[4:7], s0 lds vs llvm-mc's buffer_load_dword off, s[4:7], s0 lds).

No game data used.

🤖 Generated with Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:issue:6575995099 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/661). Originally posted by [coderanonymus](https://github.com/coderanonymus) on 2026-11-24T06:24:32Z. --- ## What The SP3 disassembly text (`Instruction::text`, used by `victory shader`) printed operands that some instructions do not have. It also dropped VOP3P negation that applies to one half of a source only. The decoded `Fields` were right in every case; only the text was wrong. Translation reads `Fields`, so it is unaffected. Before and after, for words that llvm-mc `-mcpu=gfx1030` assembles (`-mcpu=gfx1010` for `s_get_waveid_in_workgroup`, which gfx1030 lacks): | Words | Before | After (llvm-mc's operands, this printer's style) | |---|---|---| | `0xF4900500 0x00000000` | `s_memtime s[20:21], s[0:1], s0` | `s_memtime s[20:21]` | | `0xF4A80140 0x00000000` | `s_get_waveid_in_workgroup s5, s[0:1], s0` | `s_get_waveid_in_workgroup s5` | | `0xDC308000 0x007D0002` | `global_load_dword v0, v[2:3], null` | `global_load_dword v0, v[2:3], off` | | `0xE0311000 0x00010001` | `buffer_load_dword v0, v1, s[4:7], s0 offen lds` | `buffer_load_dword v1, s[4:7], s0 offen lds` | | `0x7E0202F9 0x00050602` | `v_mov_b32 v1, v2 src0_sel:WORD_1 src1_sel:BYTE_0` | `v_mov_b32 v1, v2 src0_sel:WORD_1` | | `0xCC0F4001 0x3A020702` | `v_pk_add_f16 v1, v2, v3` | `v_pk_add_f16 v1, v2, v3 neg_lo:[1,0]` | | `0xCC0F4201 0x1A020702` | `v_pk_add_f16 v1, v2, v3` | `v_pk_add_f16 v1, v2, v3 neg_hi:[0,1]` | | `0xCC0F4101 0x7A020702` | `v_pk_add_f16 v1, -v2, v3` | `v_pk_add_f16 v1, -v2, v3 neg_lo:[0,1]` | Changes, all in `crates/victory-shader/src/gfx10/sp3.rs`: - SMEM: `s_memtime`, `s_memrealtime` and `s_get_waveid_in_workgroup` print only their data. They have no address. This matches `ir.rs`, which treats all three as data only. - FLAT: a global or scratch `saddr` of NULL prints as `off`, as the same arm already does for a missing VGPR address. - MUBUF: a load with `lds` leaves out vdata. This matches `ir.rs`, which records no VGPR write for it. Stores keep their data. - SDWA: `srcN_sel` is printed only for sources the instruction has. - VOP3P (not `v_fma_mix`; also covers `v_dot2_*`): a source negated in both halves keeps the `-src` prefix. Bits set in only one half now print as LLVM's `neg_lo:[..]` / `neg_hi:[..]`, one entry per source, before `clamp`. Nothing else in the printer's style changes. ## Verification - New tests `gfx10::sp3::tests::one_sided_packed_negation_is_printed` and `gfx10::sp3::tests::fields_the_instruction_lacks_are_not_printed`. They assert llvm-mc's operands in this printer's style: no `_sdwa` suffix or default selects, and `-src` for a source negated in both halves. So llvm-mc's `v_mov_b32_sdwa v1, v2 dst_sel:DWORD dst_unused:UNUSED_PAD src0_sel:WORD_1` is asserted as `v_mov_b32 v1, v2 src0_sel:WORD_1`, and its `v_pk_add_f16 v1, v2, v3 neg_lo:[1,1] neg_hi:[1,0]` as `v_pk_add_f16 v1, -v2, v3 neg_lo:[0,1]`. - Before the fix, `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. - After the fix, `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-code `constant_color` in `emit/mod.rs`, which this change does not touch. - `rustfmt --edition 2024 --check crates/victory-shader/src/gfx10/sp3.rs`: clean. - Not run: `victory shader` on 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 `offen` nor `idxen` prints a vaddr register where llvm-mc prints `off` (`0xE0310000 0x00010000`: `buffer_load_dword v0, s[4:7], s0 lds` vs llvm-mc's `buffer_load_dword off, s[4:7], s0 lds`). No game data used. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
LAKSHYA-cmd-tech commented 2026-11-24 06:54:17 +00:00 (Migrated from github.com)

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.

<!-- greyfinch-sync:Marvisak/VIctory:review:6034662175 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/661#pullrequestreview-6034662175). Originally posted by [LAKSHYA-cmd-tech](https://github.com/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.
catminou4 commented 2026-11-24 10:03:30 +00:00 (Migrated from github.com)

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 --locked with the PR merged into main 8e79c80 → 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_workgroup no longer print address operands they don't have.
  • LDS loads drop the unused vdata operand.
  • saddr NULL prints as off instead of a phantom operand.
  • VOP3P one-sided negation (neg_lo/neg_hi without the - prefix) gets LLVM's neg_lo:[...]/neg_hi:[...] suffixes, and src_sel is 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.

<!-- greyfinch-sync:Marvisak/VIctory:review:6036818364 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/661#pullrequestreview-6036818364). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T09:37:33Z. **Review:** APPROVED --- Merges cleanly with main; macOS arm64, rustc 1.98.1, `cargo test -p victory-shader --locked` with the PR merged into main `8e79c80` → **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_workgroup` no longer print address operands they don't have. - LDS loads drop the unused vdata operand. - `saddr` NULL prints as `off` instead of a phantom operand. - VOP3P one-sided negation (`neg_lo`/`neg_hi` without the `-` prefix) gets LLVM's `neg_lo:[...]`/`neg_hi:[...]` suffixes, and `src_sel` is 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.
mercuryVM commented 2026-11-24 11:03:50 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T10:51:32Z.

Review: APPROVED


Tested 6325df7 on Windows 11, RTX 5070, MSVC: cargo test -p victory-shader -- --test-threads=1 71 passed, including one_sided_packed_negation_is_printed and fields_the_instruction_lacks_are_not_printed. cargo clippy -p victory-shader --all-targets is clean.

  • Only Instruction::text changes. Translation reads Fields, so emitted DXIL can't move.
  • neg_lo/neg_hi are 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.
  • Small thing: the SMEM no-address list keys on the mnemonic string. If s_memrealtime/s_memtime ever get suffixed variants, a check on the opcode would be sturdier. Not a blocker.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:review:6037883291 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/661#pullrequestreview-6037883291). Originally posted by [mercuryVM](https://github.com/mercuryVM) on 2026-11-24T10:51:32Z. **Review:** APPROVED --- Tested 6325df7 on Windows 11, RTX 5070, MSVC: `cargo test -p victory-shader -- --test-threads=1` 71 passed, including `one_sided_packed_negation_is_printed` and `fields_the_instruction_lacks_are_not_printed`. `cargo clippy -p victory-shader --all-targets` is clean. - Only `Instruction::text` changes. Translation reads `Fields`, so emitted DXIL can't move. - `neg_lo`/`neg_hi` are 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. - Small thing: the SMEM no-address list keys on the mnemonic string. If `s_memrealtime`/`s_memtime` ever get suffixed variants, a check on the opcode would be sturdier. Not a blocker. AI-assisted (Claude Code).
CaravelaLabs commented 2026-11-24 12:04:24 +00:00 (Migrated from github.com)

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=gfx1010 for s_get_waveid_in_workgroup). Merged this branch onto current main (ffe310e). cargo test -p victory-shader: 98 passed, 0 failed, including both new tests.

The five encodings in fields_the_instruction_lacks_are_not_printed match llvm-mc. The old printer text does not assemble: extra s[0:1], s0 on s_memtime, null instead of off on global_load_dword, a vdata on an LDS buffer_load_dword, and src1_sel on a one-source SDWA v_mov_b32.

One packed-negation case does not. Words 0xCC0F4101 0x7A020702 (last row of one_sided_packed_negation_is_printed):

  • this PR prints v_pk_add_f16 v1, -v2, v3 neg_lo:[0,1]
  • llvm-mc disassembles v_pk_add_f16 v1, v2, v3 neg_lo:[1,1] neg_hi:[1,0]
  • llvm-mc rejects a -src prefix on v_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 (Fields were already right), as the PR says.

AI-assisted review. llvm-mc and the tests were run on this machine.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7129689001 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/661#issuecomment-7129689001). Originally posted by [CaravelaLabs](https://github.com/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=gfx1010` for `s_get_waveid_in_workgroup`). Merged this branch onto current `main` (`ffe310e`). `cargo test -p victory-shader`: 98 passed, 0 failed, including both new tests. The five encodings in `fields_the_instruction_lacks_are_not_printed` match llvm-mc. The old printer text does not assemble: extra `s[0:1], s0` on `s_memtime`, `null` instead of `off` on `global_load_dword`, a `vdata` on an LDS `buffer_load_dword`, and `src1_sel` on a one-source SDWA `v_mov_b32`. One packed-negation case does not. Words `0xCC0F4101 0x7A020702` (last row of `one_sided_packed_negation_is_printed`): - this PR prints `v_pk_add_f16 v1, -v2, v3 neg_lo:[0,1]` - llvm-mc disassembles `v_pk_add_f16 v1, v2, v3 neg_lo:[1,1] neg_hi:[1,0]` - llvm-mc rejects a `-src` prefix on `v_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 (`Fields` were already right), as the PR says. AI-assisted review. llvm-mc and the tests were run on this machine.
molodayamama commented 2026-11-24 14:05:00 +00:00 (Migrated from github.com)

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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7133764605 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/661#issuecomment-7133764605). Originally posted by [molodayamama](https://github.com/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.
upstream-sync closed this pull request 2026-11-25 01:04:40 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
Marvisak/VIctory!661
No description provided.