Shaders/Decode: always decode GFX10 v_cmpx_* VOP3 and SDWA destination as EXEC #3081

Open
RVZO6 wants to merge 1 commit from upstream-pr/3083 into main
RVZO6 commented 2026-11-26 06:57:15 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by RVZO6 on 2026-11-26T06:57:15Z.


Problem

On GFX10+ (RDNA1/RDNA2), v_cmpx_* instructions implicitly write EXEC and ignore the encoded scalar destination bits in both VOP3 and VOPC SDWA encodings:

  • VOP3 (VOPCX_Real_gfx10._e64_gfx10 in LLVM llvm/lib/Target/AMDGPU/VOPCInstructions.td: let Inst{7-0} = ?; // sdst, and AMDGPUMCCodeEmitter::postEncodeVOPCX): hardware ignores w0[7:0] and writes only EXEC. Previously gfx10/fields.rs decoded v.dst = Some(scalar(vdst as u8, lanes)) for all VOP3 compares, so any v_cmpx_* VOP3 encoding with w0[7:0] != 0x7e (e.g. 0x00) decoded dst = s0 / s[0:1] and printed v_cmpx_* s0, ... in Instruction::text().
  • VOPC SDWA (VOPCX_Real_gfx10._sdwa_gfx10 uses _nosdst_sdwa): hardware has no sdst field and writes only EXEC. Previously gfx10/fields.rs let ext[15:8] overwrite v.dst when bit 15 was set on v_cmpx_*_sdwa.

Fix

In crates/victory-shader/src/gfx10/fields.rs:

  • Ignore ext[15:8] for v_cmpx* in the VOPC SDWA arm.
  • Always set v.dst = Some(scalar(EXEC, lanes)) for v_cmpx* in the VOP3 compare arm, aligning both encodings with Encoding::Vopc (and with ir.rs, structure.rs, resource.rs, and lower.rs).

Tests & Verification

  • Added gfx10::sp3::tests::v_cmpx_vop3_and_sdwa_always_write_exec in crates/victory-shader/src/gfx10/sp3.rs covering wave32 and wave64 fields() and text() for VOP3 v_cmpx_lt_f32 (vdst = 0x00 and 0x7e), VOPC SDWA v_cmpx_eq_f16 (sd = 1, sdst = s6), plus a non-EXEC v_cmp_eq_f16 SDWA control.
    • Negative control (before fix): fails with left: Some(Scalar { code: 0, dwords: 1 }), right: Some(Scalar { code: 126, dwords: 1 }).
    • After fix: verified green on Windows MSVC + WARP SM 6.6 CI (run 45768895488): victory-shader 304 passed, 0 failed; clippy default & --all-features clean; xtask policy clean.
  • Not run: the title; any hardware GPU.

Claimed in #1633.
AI-assisted: T3 Code (Antigravity, gemini-4-neon).

<!-- greyfinch-sync:Marvisak/VIctory:issue:6621292803 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3083). Originally posted by [RVZO6](https://github.com/RVZO6) on 2026-11-26T06:57:15Z. --- ### Problem On GFX10+ (RDNA1/RDNA2), `v_cmpx_*` instructions implicitly write `EXEC` and ignore the encoded scalar destination bits in both VOP3 and VOPC SDWA encodings: - **VOP3** (`VOPCX_Real_gfx10._e64_gfx10` in LLVM `llvm/lib/Target/AMDGPU/VOPCInstructions.td`: `let Inst{7-0} = ?; // sdst`, and `AMDGPUMCCodeEmitter::postEncodeVOPCX`): hardware ignores `w0[7:0]` and writes only `EXEC`. Previously `gfx10/fields.rs` decoded `v.dst = Some(scalar(vdst as u8, lanes))` for all VOP3 compares, so any `v_cmpx_*` VOP3 encoding with `w0[7:0] != 0x7e` (e.g. `0x00`) decoded `dst = s0` / `s[0:1]` and printed `v_cmpx_* s0, ...` in `Instruction::text()`. - **VOPC SDWA** (`VOPCX_Real_gfx10._sdwa_gfx10` uses `_nosdst_sdwa`): hardware has no `sdst` field and writes only `EXEC`. Previously `gfx10/fields.rs` let `ext[15:8]` overwrite `v.dst` when bit 15 was set on `v_cmpx_*_sdwa`. ### Fix In `crates/victory-shader/src/gfx10/fields.rs`: - Ignore `ext[15:8]` for `v_cmpx*` in the VOPC SDWA arm. - Always set `v.dst = Some(scalar(EXEC, lanes))` for `v_cmpx*` in the VOP3 compare arm, aligning both encodings with `Encoding::Vopc` (and with `ir.rs`, `structure.rs`, `resource.rs`, and `lower.rs`). ### Tests & Verification - Added `gfx10::sp3::tests::v_cmpx_vop3_and_sdwa_always_write_exec` in `crates/victory-shader/src/gfx10/sp3.rs` covering wave32 and wave64 `fields()` and `text()` for VOP3 `v_cmpx_lt_f32` (`vdst = 0x00` and `0x7e`), VOPC SDWA `v_cmpx_eq_f16` (`sd = 1, sdst = s6`), plus a non-EXEC `v_cmp_eq_f16` SDWA control. - **Negative control (before fix)**: fails with `left: Some(Scalar { code: 0, dwords: 1 }), right: Some(Scalar { code: 126, dwords: 1 })`. - **After fix**: verified green on Windows MSVC + WARP SM 6.6 CI ([run 45768895488](https://github.com/RVZO6/VIctory/actions/runs/45768895488)): `victory-shader` 304 passed, 0 failed; clippy default & `--all-features` clean; `xtask policy` clean. - **Not run:** the title; any hardware GPU. Claimed in #1633. AI-assisted: T3 Code (Antigravity, gemini-4-neon).
Dukestar69 commented 2026-11-26 08:03:04 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T07:08:38Z.

Review: APPROVED


Tested locally merged onto origin/main (63bcca4) on Windows 11 x64:

  • cargo test -p victory-shader gfx10::: 17 passed, 0 failed (including v_cmpx_vop3_and_sdwa_always_write_exec).
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6069855049 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3083#pullrequestreview-6069855049). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T07:08:38Z. **Review:** APPROVED --- Tested locally merged onto `origin/main` (`63bcca4`) on Windows 11 x64: - `cargo test -p victory-shader gfx10::`: 17 passed, 0 failed (including `v_cmpx_vop3_and_sdwa_always_write_exec`). - `cargo clippy -p victory-shader --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
oni-swr commented 2026-11-26 08:03:13 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-26T07:11:14Z.


Independent CPU-only verification of #3083 at 61ce014a against exact parent 63bcca43. Synthetic instruction words, no game files, no GPU, no adapter involved.

Test. A decoder sweep over decode / fields(wave64) / text(wave64) for wave32 and wave64:

  • VOP3: every opcode below 0x100 that names a v_cmp* (95 v_cmpx_*, 95 non-X), each with encoded w0[7:0] in {0x00, 0x01, 0x06, 0x6a, 0x6b, 0x7c, 0x7d, 0x7e, 0x7f}.
  • VOPC SDWA: the same 95 + 95 opcodes with (sd, sdst) in {(1, s6), (1, vcc_lo), (1, exec_lo), (1, m0), (0, s6), (0, 0)}.
  • Expected: every v_cmpx_* decodes dst = exec (code 126, one dword on wave32, two on wave64) and prints exec_lo / exec; every non-X compare keeps its encoded SGPR (VOP3) or the SDWA sdst when sd = 1, VCC when sd = 0.

Results.

Tree v_cmpx_* cases not decoded as EXEC Non-X compare control mismatches
Exact parent 63bcca43 2,090 of 2,850 (VOP3 1,520 of 1,710; SDWA 570 of 1,140), same count printing a non-exec register 0 of 2,850
#3083 61ce014a 0 of 2,850 0 of 2,850

The parent's only correct v_cmpx cases are VOP3 with w0[7:0] = 0x7e, and SDWA with sd = 0 or sdst = exec_lo. I also hashed every decoded field: all non-v_cmpx results (these compares, VOPC e32 for all opcodes, and VOP3 opcodes 0x100..0x3ff) are byte-identical between the parent and #3083, and the v_cmpx fields are identical apart from dst. So the change touches only the v_cmpx destination.

Limits. The expectation that GFX10 ignores sdst for VOP3 v_cmpx comes from LLVM's AMDGPU VOPCInstructions.td (VOPCX_Real_gfx10, let Inst{7-0} = ?; // sdst on _nosdst_e64), which I read; I did not test it on hardware, so these results show the decoder matches that description, not what silicon does with non-zero bits. I did not run the lowering or any shader; downstream use of dst was not exercised.

AI use: Claude Code (Claude Sonnet 5.5) for the work; coordinated by Codex (gpt-6.2-sol). Coordination: https://github.com/Marvisak/VIctory/issues/1633#issuecomment-7185048463

<!-- greyfinch-sync:Marvisak/VIctory:comment:7185186776 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3083#issuecomment-7185186776). Originally posted by [oni-swr](https://github.com/oni-swr) on 2026-11-26T07:11:14Z. --- Independent CPU-only verification of #3083 at 61ce014a against exact parent 63bcca43. Synthetic instruction words, no game files, no GPU, no adapter involved. **Test.** A decoder sweep over `decode` / `fields(wave64)` / `text(wave64)` for wave32 and wave64: - VOP3: every opcode below 0x100 that names a `v_cmp*` (95 `v_cmpx_*`, 95 non-X), each with encoded `w0[7:0]` in {0x00, 0x01, 0x06, 0x6a, 0x6b, 0x7c, 0x7d, 0x7e, 0x7f}. - VOPC SDWA: the same 95 + 95 opcodes with (sd, sdst) in {(1, s6), (1, vcc_lo), (1, exec_lo), (1, m0), (0, s6), (0, 0)}. - Expected: every `v_cmpx_*` decodes `dst = exec` (code 126, one dword on wave32, two on wave64) and prints `exec_lo` / `exec`; every non-X compare keeps its encoded SGPR (VOP3) or the SDWA `sdst` when `sd = 1`, VCC when `sd = 0`. **Results.** | Tree | `v_cmpx_*` cases not decoded as EXEC | Non-X compare control mismatches | |---|---|---| | Exact parent 63bcca43 | 2,090 of 2,850 (VOP3 1,520 of 1,710; SDWA 570 of 1,140), same count printing a non-exec register | 0 of 2,850 | | #3083 61ce014a | 0 of 2,850 | 0 of 2,850 | The parent's only correct `v_cmpx` cases are VOP3 with `w0[7:0] = 0x7e`, and SDWA with `sd = 0` or `sdst = exec_lo`. I also hashed every decoded field: all non-`v_cmpx` results (these compares, VOPC e32 for all opcodes, and VOP3 opcodes 0x100..0x3ff) are byte-identical between the parent and #3083, and the `v_cmpx` fields are identical apart from `dst`. So the change touches only the `v_cmpx` destination. **Limits.** The expectation that GFX10 ignores `sdst` for VOP3 `v_cmpx` comes from LLVM's AMDGPU `VOPCInstructions.td` (`VOPCX_Real_gfx10`, `let Inst{7-0} = ?; // sdst` on `_nosdst_e64`), which I read; I did not test it on hardware, so these results show the decoder matches that description, not what silicon does with non-zero bits. I did not run the lowering or any shader; downstream use of `dst` was not exercised. AI use: Claude Code (Claude Sonnet 5.5) for the work; coordinated by Codex (gpt-6.2-sol). Coordination: https://github.com/Marvisak/VIctory/issues/1633#issuecomment-7185048463
fuzeofficlal commented 2026-11-26 09:05:43 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T08:29:43Z.

Review: APPROVED


Clean decoding fix across both VOP3 and VOPC SDWA encodings:

  • crates/victory-shader/src/gfx10/fields.rs aligns VOP3 (v_cmpx* always writes implicit EXEC) and SDWA (ignoring ext[15:8] for v_cmpx* while keeping explicit scalar destination for ordinary v_cmp_*) with Encoding::Vopc and all 95 v_cmpx_* opcodes in gfx10/opcodes.rs.
  • Wave32/wave64 operand widths agree with sp3.rs formatting and the existing EXEC tracking in ir.rs, structure.rs, and emit/lower.rs.

Verified locally on Windows 11:

  • cargo clippy -p victory-shader --all-targets --locked -- -D warnings: clean
  • cargo test -p victory-shader --lib --locked -- gfx10::: 17/17 passed (including v_cmpx_vop3_and_sdwa_always_write_exec)

(Optional follow-up idea: a lowering test verifying that a v_cmpx_* encoding with a non-canonical destination such as 0x00 narrows EXEC without clobbering s0.)

LGTM.

<!-- greyfinch-sync:Marvisak/VIctory:review:6070712225 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3083#pullrequestreview-6070712225). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T08:29:43Z. **Review:** APPROVED --- Clean decoding fix across both VOP3 and VOPC SDWA encodings: - `crates/victory-shader/src/gfx10/fields.rs` aligns VOP3 (`v_cmpx*` always writes implicit `EXEC`) and SDWA (ignoring `ext[15:8]` for `v_cmpx*` while keeping explicit scalar destination for ordinary `v_cmp_*`) with `Encoding::Vopc` and all 95 `v_cmpx_*` opcodes in `gfx10/opcodes.rs`. - Wave32/wave64 operand widths agree with `sp3.rs` formatting and the existing EXEC tracking in `ir.rs`, `structure.rs`, and `emit/lower.rs`. Verified locally on Windows 11: - `cargo clippy -p victory-shader --all-targets --locked -- -D warnings`: clean - `cargo test -p victory-shader --lib --locked -- gfx10::`: 17/17 passed (including `v_cmpx_vop3_and_sdwa_always_write_exec`) (Optional follow-up idea: a lowering test verifying that a `v_cmpx_*` encoding with a non-canonical destination such as `0x00` narrows `EXEC` without clobbering `s0`.) LGTM.
Marvisak commented 2026-11-26 09:06:05 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T08:20:58Z.


Automated triage for the maintainers.

Merge candidate. In gfx10/fields.rs (Instruction::fields), v_cmpx_* now always decodes its destination as EXEC: the VOP3 arm no longer takes w0[7:0] as an SGPR, and the VOPC SDWA arm no longer lets ext[15:8] override it. This matches the VOPC e32 arm and what the consumers in origin/main already assume by name (ir.rs register writes, resource.rs, emit/lower.rs lane_bits_for), so lowering is unchanged and the fix is to the decoded fields and text(). The evidence cited is LLVM's AMDGPU VOPCInstructions.td (GFX10 v_cmpx e64/SDWA carry no sdst). The new test gfx10::sp3::tests::v_cmpx_vop3_and_sdwa_always_write_exec includes a non-X v_cmp SDWA control.

CI: passing (check).


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7186485867 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3083#issuecomment-7186485867). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-26T08:20:58Z. --- <!-- victory-triage v1 head=61ce014a9269b7494b04dfb180223b59c723e65b verdict=merge-candidate at=2026-11-26T08:17:59Z --> Automated triage for the maintainers. **Merge candidate.** In `gfx10/fields.rs` (`Instruction::fields`), `v_cmpx_*` now always decodes its destination as EXEC: the VOP3 arm no longer takes `w0[7:0]` as an SGPR, and the VOPC SDWA arm no longer lets `ext[15:8]` override it. This matches the VOPC e32 arm and what the consumers in `origin/main` already assume by name (`ir.rs` register writes, `resource.rs`, `emit/lower.rs` `lane_bits_for`), so lowering is unchanged and the fix is to the decoded fields and `text()`. The evidence cited is LLVM's AMDGPU `VOPCInstructions.td` (GFX10 `v_cmpx` e64/SDWA carry no sdst). The new test `gfx10::sp3::tests::v_cmpx_vop3_and_sdwa_always_write_exec` includes a non-X `v_cmp` SDWA control. CI: passing (check). --- _Generated by [Claude Code](https://claude.ai/code)_
futurepro62 commented 2026-11-26 11:04:04 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by futurepro62 on 2026-11-26T10:51:11Z.


NVIDIA full-suite run, to go with the reports above by Dukestar69, fuzeofficlal, since none of them names a GPU run. Tested exact head 61ce014 (on its base 63bcca4).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), dxil.dll from Windows SDK 10.0.26100 (the loader's default), debug.
  • cargo build --workspace --locked, then cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware: 867 passed, 0 failed, 10 ignored.
  • The new tests ran and passed: v_cmpx_vop3_and_sdwa_always_write_exec.
  • --skip leaves out tests that fail on main 63bcca4 on this card too, not because of this PR: heap_direct_texture_reads_mark_their_heap_index ends the victory-shader test process with 0xc0000005 (#2571), so without the skip the rest of that crate never reports; dynamic_slots_are_held_until_released, lists_share_a_table_and_copies_keep_their_views and the two stride_tests hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); gathers_at_a_level_match_the_hardware fails on lane 0 (#1744).

Not tested

  • AMD (the tests take the default adapter), a release build, the title (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7189923989 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3083#issuecomment-7189923989). Originally posted by [futurepro62](https://github.com/futurepro62) on 2026-11-26T10:51:11Z. --- NVIDIA full-suite run, to go with the reports above by Dukestar69, fuzeofficlal, since none of them names a GPU run. Tested exact head `61ce014` (on its base `63bcca4`). **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), `dxil.dll` from Windows SDK 10.0.26100 (the loader's default), debug. - `cargo build --workspace --locked`, then `cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware`: **867 passed, 0 failed, 10 ignored**. - The new tests ran and passed: `v_cmpx_vop3_and_sdwa_always_write_exec`. - `--skip` leaves out tests that fail on main `63bcca4` on this card too, not because of this PR: `heap_direct_texture_reads_mark_their_heap_index` ends the `victory-shader` test process with `0xc0000005` (#2571), so without the skip the rest of that crate never reports; `dynamic_slots_are_held_until_released`, `lists_share_a_table_and_copies_keep_their_views` and the two `stride_tests` hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); `gathers_at_a_level_match_the_hardware` fails on lane 0 (#1744). **Not tested** - AMD (the tests take the default adapter), a release build, the title (test run only). **AI use** - Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3083:upstream-pr/3083'
git switch 'upstream-pr/3083'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3083'
git switch 'upstream-pr/3083'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3083'
git switch 'upstream-pr/3083'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3083'
git switch 'main'
git merge --squash 'upstream-pr/3083'
git switch 'main'
git merge --ff-only 'upstream-pr/3083'
git switch 'main'
git merge 'upstream-pr/3083'
git push origin 'main'
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!3081
No description provided.