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

Open
github-bot wants to merge 1 commit from github-bot/gh-3083 into main AGit
Owner

@⁠RVZO6 on GitHub · 2026-11-26 06:57 UTC · original
RVZO6:rvzo/v-cmpx-dst-exec → main · +90 −2 · 2 files · 1 commits · open

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).

**@⁠RVZO6** on GitHub · 2026-11-26 06:57 UTC · [original](https://github.com/Marvisak/VIctory/pull/3083) `RVZO6:rvzo/v-cmpx-dst-exec` → `main` · +90 −2 · 2 files · 1 commits · open ### 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).
On GFX10+, v_cmpx_* instructions implicitly write EXEC and ignore the
encoded scalar destination bits in both VOP3 (w0[7:0]; LLVM
VOPCX_Real_gfx10._e64_gfx10: Inst{7-0} = ?, AMDGPUMCCodeEmitter::postEncodeVOPCX)
and VOPC SDWA (ext[15:8]; VOPCX_Real_gfx10._sdwa_gfx10 uses _nosdst_sdwa).

Previously fields.rs decoded v_cmpx_* VOP3 dst from w0[7:0] (yielding s0
instead of EXEC whenever w0[7:0] != 0x7e) and let SDWA ext[15:8] override
v.dst on v_cmpx_* when bit 15 was set. Align both encodings with
Encoding::Vopc (and with ir.rs, structure.rs, resource.rs, and lower.rs)
by always decoding v_cmpx_* destinations as EXEC.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 07:26:58 +00:00
Author
Owner

@⁠oni-swr on GitHub · 2026-11-26 07:11 UTC · original

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: #1633

**@⁠oni-swr** on GitHub · 2026-11-26 07:11 UTC · [original](https://github.com/Marvisak/VIctory/pull/3083#issuecomment-7185186776) 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://git.gtahub.st/github/Marvisak--VIctory/issues/1633
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 07:08 UTC · original · approved these changes

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).

**@⁠Dukestar69** on GitHub · 2026-11-26 07:08 UTC · [original](https://github.com/Marvisak/VIctory/pull/3083#pullrequestreview-6069855049) · **approved these changes** 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).
Author
Owner

@⁠Marvisak on GitHub · 2026-11-26 08:20 UTC · original

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

**@⁠Marvisak** on GitHub · 2026-11-26 08:20 UTC · [original](https://github.com/Marvisak/VIctory/pull/3083#issuecomment-7186485867) <!-- 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)_
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 08:29 UTC · original · approved these changes

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.

**@⁠fuzeofficlal** on GitHub · 2026-11-26 08:29 UTC · [original](https://github.com/Marvisak/VIctory/pull/3083#pullrequestreview-6070712225) · **approved these changes** 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.
Author
Owner

@⁠futurepro62 on GitHub · 2026-11-26 10:51 UTC · original

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.
**@⁠futurepro62** on GitHub · 2026-11-26 10:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/3083#issuecomment-7189923989) 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 can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/3083/head:github-bot/gh-3083'
git switch 'github-bot/gh-3083'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3083'
git switch 'github-bot/gh-3083'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3083'
git switch 'github-bot/gh-3083'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3083'
git switch 'main'
git merge --squash 'github-bot/gh-3083'
git switch 'main'
git merge --ff-only 'github-bot/gh-3083'
git switch 'main'
git merge 'github-bot/gh-3083'
git push origin 'main'
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!3083
No description provided.