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

Manually merged
github merged 1 commit from gh-pr/661/head into gh-pr/661/base 2026-11-26 04:11:54 +00:00
Owner

@⁠coderanonymus on GitHub · 2026-11-24 06:24 UTC · original
coderanonymus:sp3-text-operands → main · +72 −4 · 1 files · 1 commits · merged 2026-11-25 00:20 UTC

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

**@⁠coderanonymus** on GitHub · 2026-11-24 06:24 UTC · [original](https://github.com/Marvisak/VIctory/pull/661) `coderanonymus:sp3-text-operands` → `main` · +72 −4 · 1 files · 1 commits · merged 2026-11-25 00:20 UTC ## 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)
The disassembly text showed operands that some instructions lack, and
dropped VOP3P negation that applies to one half only:

- s_memtime, s_memrealtime and s_get_waveid_in_workgroup printed the
  unused SMEM base and offset.
- A global or scratch access with no SGPR base printed `null`, not `off`.
- A MUBUF load with lds printed the unused vdata as a destination.
- VOP1 SDWA printed src1_sel, though VOP1 has no second source.
- VOP3P ops other than v_fma_mix with only neg_lo or only neg_hi set on
  a source printed as if the source were not negated. These now get
  LLVM's neg_lo:[..] and neg_hi:[..] suffixes; a source negated in both
  halves keeps `-src`.

Expected operands come from llvm-mc -mcpu=gfx1030 (gfx1010 for
s_get_waveid_in_workgroup). Only the text changes; translation reads
Fields and is unaffected.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:11:53 +00:00
github manually merged commit 6325df752c into gh-pr/661/base 2026-11-26 04:11:54 +00:00
Author
Owner

@⁠CaravelaLabs on GitHub · 2026-11-24 11:07 UTC · original

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.

**@⁠CaravelaLabs** on GitHub · 2026-11-24 11:07 UTC · [original](https://github.com/Marvisak/VIctory/pull/661#issuecomment-7129689001) 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.
Author
Owner

@⁠molodayamama on GitHub · 2026-11-24 14:03 UTC · original

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.

**@⁠molodayamama** on GitHub · 2026-11-24 14:03 UTC · [original](https://github.com/Marvisak/VIctory/pull/661#issuecomment-7133764605) 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.
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!661
No description provided.