shader: fix source-less VOP1 length and VOP3 CMPX destination #180

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

@⁠davutsimsekk on GitHub · 2026-11-25 19:35 UTC · original
davutsimsekk:fix/vop1-cmpx-decoding → main · +44 −2 · 2 files · 1 commits · open

Fixes two GFX10 decoder cases where the encoded fields do not describe the instruction's real operands.

  • The source-less VOP1 opcodes (v_nop, v_pipeflush, v_clrexcp) stay one dword. Their SRC0 field can contain a shader hash whose low bits look like an extension marker; consuming that word shifts every following instruction.
  • VOP3 v_cmpx_* writes EXEC, not the encoded VDST. The decoder now reports EXEC for those opcodes and leaves ordinary VOP3/VOPC compares on VDST.

Tested

  • cargo test -p victory-shader --lib --locked vop1_without_operands_has_no_extension_word: 1 passed.
  • cargo test -p victory-shader --lib --locked vop3_cmpx_writes_exec: 1 passed.
  • Windows 11, Rust 1.98.1, locked offline build.

Not tested

  • No in-game run; synthetic instruction words only.

AI use

  • Automated coding agent for analysis, patch preparation and test runs.
**@⁠davutsimsekk** on GitHub · 2026-11-25 19:35 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/180) `davutsimsekk:fix/vop1-cmpx-decoding` → `main` · +44 −2 · 2 files · 1 commits · open Fixes two GFX10 decoder cases where the encoded fields do not describe the instruction's real operands. - The source-less VOP1 opcodes (`v_nop`, `v_pipeflush`, `v_clrexcp`) stay one dword. Their SRC0 field can contain a shader hash whose low bits look like an extension marker; consuming that word shifts every following instruction. - VOP3 `v_cmpx_*` writes EXEC, not the encoded VDST. The decoder now reports EXEC for those opcodes and leaves ordinary VOP3/VOPC compares on VDST. **Tested** - `cargo test -p victory-shader --lib --locked vop1_without_operands_has_no_extension_word`: 1 passed. - `cargo test -p victory-shader --lib --locked vop3_cmpx_writes_exec`: 1 passed. - Windows 11, Rust 1.98.1, locked offline build. **Not tested** - No in-game run; synthetic instruction words only. **AI use** - Automated coding agent for analysis, patch preparation and test runs.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:37:23 +00:00
Author
Owner

@⁠KernelSmoker on GitHub · 2026-11-25 19:59 UTC · original

Independent verification on PR head 4d291d4 (Bazzite Linux 45 x86_64, Rust 1.98.1):

  • Linux cargo test --offline --locked -p victory-shader: 187 passed, 0 failed, 6 ignored (lib, including both new tests vop1_without_operands_has_no_extension_word and vop3_cmpx_writes_exec) + 3 passed, 0 failed, 1 ignored (tests/resource_tracking.rs).
  • cargo clippy --offline --locked -p victory-shader --all-targets: 0 warnings in crates/victory-shader/src/gfx10/.
  • Code check:
    • The three source-less VOP1 opcodes in gfx10/mod.rs (0x000, 0x01B, 0x041) match v_nop, v_pipeflush, v_clrexcp in gfx10/opcodes.rs and gfx10/fields.rs:436.
    • Setting v.dst = Some(scalar(EXEC, lanes)) for v_cmpx* in the VOP3 arm of gfx10/fields.rs:595 brings it in line with the existing VOPC arm (fields.rs:511) and GFX10/RDNA2 semantics (VOP3 v_cmpx writes EXEC only, not VDST).
    • Minor note: v_clrexcp (0x041, e.g. 0x7E00_82FF) could optionally be added alongside v_nop/v_pipeflush in vop1_without_operands_has_no_extension_word.
**@⁠KernelSmoker** on GitHub · 2026-11-25 19:59 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/180#issuecomment-7173039431) Independent verification on PR head `4d291d4` (Bazzite Linux 45 x86_64, Rust 1.98.1): - Linux `cargo test --offline --locked -p victory-shader`: **187 passed, 0 failed, 6 ignored** (lib, including both new tests `vop1_without_operands_has_no_extension_word` and `vop3_cmpx_writes_exec`) + **3 passed, 0 failed, 1 ignored** (`tests/resource_tracking.rs`). - `cargo clippy --offline --locked -p victory-shader --all-targets`: **0 warnings** in `crates/victory-shader/src/gfx10/`. - Code check: - The three source-less VOP1 opcodes in `gfx10/mod.rs` (`0x000`, `0x01B`, `0x041`) match `v_nop`, `v_pipeflush`, `v_clrexcp` in `gfx10/opcodes.rs` and `gfx10/fields.rs:436`. - Setting `v.dst = Some(scalar(EXEC, lanes))` for `v_cmpx*` in the VOP3 arm of `gfx10/fields.rs:595` brings it in line with the existing VOPC arm (`fields.rs:511`) and GFX10/RDNA2 semantics (VOP3 `v_cmpx` writes `EXEC` only, not `VDST`). - Minor note: `v_clrexcp` (`0x041`, e.g. `0x7E00_82FF`) could optionally be added alongside `v_nop`/`v_pipeflush` in `vop1_without_operands_has_no_extension_word`.
Author
Owner

@⁠lcg007xd-c on GitHub · 2026-11-25 21:13 UTC · original · approved these changes

Verified on Linux (Rust 1.98.1)

  • cargo test -p victory-shader --lib on 4d291d4: 187 passed, 0 failed, 6 ignored. Merged into current main with --no-commit: 198 passed, 0 failed (main alone: 196).
  • Fail-without-fix, one half at a time, keeping both new tests:
    • With gfx10/fields.rs reverted to main, vop3_cmpx_writes_exec fails: left: Some(Scalar { code: 5, .. }), right: Some(Scalar { code: 126, .. }).
    • With only the 0x3F arm in gfx10/mod.rs reverted, vop1_without_operands_has_no_extension_word fails.
  • cargo clippy -p victory-shader --target x86_64-pc-windows-msvc: the same 10 warnings as main, none in gfx10/.
  • git merge --no-commit --no-ff into main: merges cleanly.
  • LLVM agrees on both points. llvm-mc --disassemble -triple=amdgcn -mcpu=gfx1030:
    • v_nop, v_pipeflush and v_clrexcp with SRC0 = 0xFF, 0xFA or 0xF9, followed by s_endpgm, decode as one 4-byte instruction each, then s_endpgm.
    • The test's VOP3 word 0xD4110005 0x0001E501 decodes as v_cmpx_lt_f32_e64 v1, 1.0, with no SGPR destination. LLVM re-encodes VDST as 0x7e and warns "potentially undefined instruction encoding" for VDST = 5, so EXEC is the right destination to report.

Notes (non-blocking)

  1. gfx10/mod.rs:215 uses the opcode numbers 0x000 | 0x01B | 0x041, while gfx10/fields.rs:436 uses the names "v_nop" | "v_pipeflush" | "v_clrexcp". Both lists say the same thing. Matching on name(Encoding::Vop1, opcode as u16) here, or sharing one list, would keep the length decode and the operand decode from drifting apart.
  2. For context on risk: the main consumers already special-case v_cmpx and ignore v.dst (ir.rs:987, structure.rs:1049, emit/lower.rs:10090). The VOP3 half mostly makes Fields consistent with the VOPC arm. It is unlikely to change generated code. The VOP1 length fix is the part that changes behaviour: every instruction after a hashed v_nop was shifted before.

Not verified

  • No translation of a real title shader and no GPU run.

Reviewed with Claude Code.

**@⁠lcg007xd-c** on GitHub · 2026-11-25 21:13 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/180#pullrequestreview-6065065938) · **approved these changes** ### Verified on Linux (Rust 1.98.1) - `cargo test -p victory-shader --lib` on 4d291d4: 187 passed, 0 failed, 6 ignored. Merged into current main with `--no-commit`: 198 passed, 0 failed (main alone: 196). - Fail-without-fix, one half at a time, keeping both new tests: - With `gfx10/fields.rs` reverted to main, `vop3_cmpx_writes_exec` fails: `left: Some(Scalar { code: 5, .. })`, `right: Some(Scalar { code: 126, .. })`. - With only the `0x3F` arm in `gfx10/mod.rs` reverted, `vop1_without_operands_has_no_extension_word` fails. - `cargo clippy -p victory-shader --target x86_64-pc-windows-msvc`: the same 10 warnings as main, none in `gfx10/`. - `git merge --no-commit --no-ff` into main: merges cleanly. - LLVM agrees on both points. `llvm-mc --disassemble -triple=amdgcn -mcpu=gfx1030`: - `v_nop`, `v_pipeflush` and `v_clrexcp` with SRC0 = `0xFF`, `0xFA` or `0xF9`, followed by `s_endpgm`, decode as one 4-byte instruction each, then `s_endpgm`. - The test's VOP3 word `0xD4110005 0x0001E501` decodes as `v_cmpx_lt_f32_e64 v1, 1.0`, with no SGPR destination. LLVM re-encodes VDST as `0x7e` and warns "potentially undefined instruction encoding" for VDST = 5, so EXEC is the right destination to report. ### Notes (non-blocking) 1. `gfx10/mod.rs:215` uses the opcode numbers `0x000 | 0x01B | 0x041`, while `gfx10/fields.rs:436` uses the names `"v_nop" | "v_pipeflush" | "v_clrexcp"`. Both lists say the same thing. Matching on `name(Encoding::Vop1, opcode as u16)` here, or sharing one list, would keep the length decode and the operand decode from drifting apart. 2. For context on risk: the main consumers already special-case `v_cmpx` and ignore `v.dst` (`ir.rs:987`, `structure.rs:1049`, `emit/lower.rs:10090`). The VOP3 half mostly makes `Fields` consistent with the VOPC arm. It is unlikely to change generated code. The VOP1 length fix is the part that changes behaviour: every instruction after a hashed `v_nop` was shifted before. ### Not verified - No translation of a real title shader and no GPU run. Reviewed with Claude Code.
Author
Owner

@⁠Yoshi-233 on GitHub · 2026-11-26 03:57 UTC · original

@⁠KernelSmoker I checked the v_clrexcp case you mentioned on this fork, comparing the parent 000ffdd with 4d291d4. I put s_endpgm directly after each instruction and swept all 512 SRC0 encodings for each of v_nop, v_pipeflush, and v_clrexcp. On the parent, all three swallowed the next word for the same five values: 0xe9, 0xea, 0xf9, 0xfa, and 0xff. On the PR all 1,536 decoded with the end instruction at byte 4. An ordinary v_mov_b32 control kept its correct length for all 512 encodings on both revisions.

I also checked the decoded destination for 95 named VOP3 CMPX opcodes, wave32/wave64, and four encoded destinations. All 760 disagreed with the expected EXEC destination on the parent and all 760 matched on the PR. The SSA writes and subsequent reads of EXEC already agreed on both revisions. Linux CPU-only; the PR's shader library suite passed 187 with 6 ignored.

**@⁠Yoshi-233** on GitHub · 2026-11-26 03:57 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/180#issuecomment-7182166295) @⁠KernelSmoker I checked the `v_clrexcp` case you mentioned on this fork, comparing the parent `000ffdd` with `4d291d4`. I put `s_endpgm` directly after each instruction and swept all 512 SRC0 encodings for each of `v_nop`, `v_pipeflush`, and `v_clrexcp`. On the parent, all three swallowed the next word for the same five values: `0xe9`, `0xea`, `0xf9`, `0xfa`, and `0xff`. On the PR all 1,536 decoded with the end instruction at byte 4. An ordinary `v_mov_b32` control kept its correct length for all 512 encodings on both revisions. I also checked the decoded destination for 95 named VOP3 CMPX opcodes, wave32/wave64, and four encoded destinations. All 760 disagreed with the expected EXEC destination on the parent and all 760 matched on the PR. The SSA writes and subsequent reads of EXEC already agreed on both revisions. Linux CPU-only; the PR's shader library suite passed 187 with 6 ignored.
Author
Owner

@⁠MamaLeVrai on GitHub · 2026-11-26 05:00 UTC · original

RDNA2 data point. This PR (4d291d4) merged on main 4f62c2a, cargo test --release -p victory-shader --lib on an RX 6950 XT (Windows 11 build 26300, Rust 1.98.1):

  • main: 275 passed, 2 failed.
  • This PR: 277 passed, 2 failed, in 2 runs out of 2. The 2 new tests pass.

The 2 failures are the same as on main: the RDNA2 wave-size tests scalar_counted_in_a_divergent_loop_read_after_it and scalar_counted_in_nested_divergent_loops, fixed by #110 and #204. No regression here. Not run in the game.

harness machine: rx6950xt-w11 | AMD Radeon RX 6950 XT (RDNA2), driver 32.0.21045.29003 | 32 GB RAM | Windows 11 build 26300

AI-assisted (Claude Code); no game data.

**@⁠MamaLeVrai** on GitHub · 2026-11-26 05:00 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/180#issuecomment-7183093558) RDNA2 data point. This PR (`4d291d4`) merged on `main` `4f62c2a`, `cargo test --release -p victory-shader --lib` on an RX 6950 XT (Windows 11 build 26300, Rust 1.98.1): - `main`: 275 passed, 2 failed. - This PR: 277 passed, 2 failed, in 2 runs out of 2. The 2 new tests pass. The 2 failures are the same as on `main`: the RDNA2 wave-size tests `scalar_counted_in_a_divergent_loop_read_after_it` and `scalar_counted_in_nested_divergent_loops`, fixed by #110 and #204. No regression here. Not run in the game. harness machine: rx6950xt-w11 | AMD Radeon RX 6950 XT (RDNA2), driver 32.0.21045.29003 | 32 GB RAM | Windows 11 build 26300 AI-assisted (Claude Code); no game data.
Author
Owner

@⁠adrianmjim on GitHub · 2026-11-26 19:41 UTC · original

Data from the title, on how much this changes in practice. I tested 4d291d4 on native Windows 11 (26300) with an RX 7900 XT (RDNA3) and Rust 1.98.1.

Unit tests. cargo test -p victory-shader --lib -- --test-threads=1 gives 268 passed, 0 failed and 6 ignored, against 266 on the base 000ffdd.

The title's shaders. I ran victory translate --validate --host-lanes 32-64 over the game's whole shaders.rpf, and nothing changes against 000ffdd:

  • VS/PS 14247/14247, CS 2682/2682 and MS 8694 of 8765 validate, with the same 195 + 71 refusals and the same 40601701 IR instructions.
  • With a local per-program DXIL hash, 0 of 25623 programs change.
  • victory shader-info decodes the same 26698 programs and 44386798 instructions before and after.

Why nothing changes, from a full disassembly of the archive. The review above expected the VOP1 length fix to change behaviour, because instructions after a hashed v_nop would have been shifted. In this title they aren't:

  • All 127972 VOP1-encoded v_nop have SRC0 = 0, so they already decoded as one dword. There are no v_pipeflush or v_clrexcp at all.
  • The per-program hash is in two VOP3-encoded v_nop, at offsets 0x0 and 0xC of every program. Each has SRC2 = 0xFF and a literal, so each is 3 dwords, and all 53396 of them already decode as 3 dwords. This PR does not touch that path.
  • All 3821 VOP3 v_cmpx encode VDST as 126 (EXEC_LO), so the fields.rs change gives the same operand as before.

So both halves are correct guards, but this title has no instruction that needs either one.

Not tested: the current main (4f62c2a), other titles, in-game runs.

**@⁠adrianmjim** on GitHub · 2026-11-26 19:41 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/180#issuecomment-7201854021) Data from the title, on how much this changes in practice. I tested `4d291d4` on native Windows 11 (26300) with an RX 7900 XT (RDNA3) and Rust 1.98.1. **Unit tests.** `cargo test -p victory-shader --lib -- --test-threads=1` gives 268 passed, 0 failed and 6 ignored, against 266 on the base `000ffdd`. **The title's shaders.** I ran `victory translate --validate --host-lanes 32-64` over the game's whole `shaders.rpf`, and nothing changes against `000ffdd`: - VS/PS 14247/14247, CS 2682/2682 and MS 8694 of 8765 validate, with the same 195 + 71 refusals and the same 40601701 IR instructions. - With a local per-program DXIL hash, 0 of 25623 programs change. - `victory shader-info` decodes the same 26698 programs and 44386798 instructions before and after. **Why nothing changes, from a full disassembly of the archive.** The review above expected the VOP1 length fix to change behaviour, because instructions after a hashed `v_nop` would have been shifted. In this title they aren't: - All 127972 VOP1-encoded `v_nop` have SRC0 = 0, so they already decoded as one dword. There are no `v_pipeflush` or `v_clrexcp` at all. - The per-program hash is in two VOP3-encoded `v_nop`, at offsets 0x0 and 0xC of every program. Each has SRC2 = 0xFF and a literal, so each is 3 dwords, and all 53396 of them already decode as 3 dwords. This PR does not touch that path. - All 3821 VOP3 `v_cmpx` encode VDST as 126 (EXEC_LO), so the `fields.rs` change gives the same operand as before. So both halves are correct guards, but this title has no instruction that needs either one. Not tested: the current main (`4f62c2a`), other titles, in-game runs.
Author
Owner

@⁠Yoshi-233 on GitHub · 2026-11-27 01:11 UTC · original

I rechecked the current default branch, a-publier at 4eb6cfd, since #180 targets main. Both decoder cases still reproduce on that branch. The distinction matters for testing the build people currently get from a fresh clone.

  • Out of 1,536 synthetic VOP1 streams, base consumed the following s_endpgm for 15 (the five ignored SRC0 values on each of v_nop, v_pipeflush and v_clrexcp). All 512 ordinary MOV length controls were correct.
  • For 95 VOP3 CMPX opcodes × two wave widths × four VDST encodings, base reported the encoded destination in all 760 cases, while the IR already wrote EXEC. Ordinary VOP3 CMP and VOPC controls matched throughout.

The patch from 4d291d4 does not apply as a plain patch against a-publier (the test hunk in gfx10/mod.rs has different context). I tried the backport of your fix in CGBJ #4 on 4eb6cfd: it applies cleanly, all 1,536 instruction boundaries and 760 CMPX destinations match, and the Linux victory-shader --lib suite reports 212 passed, 2 ignored. This gives maintainers a tested option for the default branch. These are synthetic CPU cases; the title-corpus observation above is compatible with this result.

AI-assisted testing on native x86-64 Linux, Rust 1.98.1.

**@⁠Yoshi-233** on GitHub · 2026-11-27 01:11 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/180#issuecomment-7207093547) I rechecked the current default branch, `a-publier` at `4eb6cfd`, since #180 targets `main`. Both decoder cases still reproduce on that branch. The distinction matters for testing the build people currently get from a fresh clone. - Out of 1,536 synthetic VOP1 streams, base consumed the following `s_endpgm` for 15 (the five ignored SRC0 values on each of `v_nop`, `v_pipeflush` and `v_clrexcp`). All 512 ordinary MOV length controls were correct. - For 95 VOP3 CMPX opcodes × two wave widths × four VDST encodings, base reported the encoded destination in all 760 cases, while the IR already wrote EXEC. Ordinary VOP3 CMP and VOPC controls matched throughout. The patch from `4d291d4` does not apply as a plain patch against `a-publier` (the test hunk in `gfx10/mod.rs` has different context). I tried [the backport of your fix in CGBJ #4](https://github.com/carlm125/cool_fox/pull/4) on `4eb6cfd`: it applies cleanly, all 1,536 instruction boundaries and 760 CMPX destinations match, and the Linux `victory-shader --lib` suite reports 212 passed, 2 ignored. This gives maintainers a tested option for the default branch. These are synthetic CPU cases; the title-corpus observation above is compatible with this result. AI-assisted testing on native x86-64 Linux, Rust 1.98.1.
Author
Owner

@⁠gut0to on GitHub · 2026-11-27 14:57 UTC · original · reviewed

AI-assisted static review; I inspected the decoder change and its fixtures, but did not run the test suite. One boundary case is not covered yet:

**@⁠gut0to** on GitHub · 2026-11-27 14:57 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/180#pullrequestreview-6089999280) · **reviewed** AI-assisted static review; I inspected the decoder change and its fixtures, but did not run the test suite. One boundary case is not covered yet:
@ -212,0 +212,4 @@
let opcode = (w >> 9) & 0xFF;
// These VOP1s take no source, so the field is not a literal
// (the console compiler stores a shader hash there).
let no_source = matches!(opcode, 0x000 | 0x01B | 0x041);
Author
Owner

@⁠gut0to on GitHub · 2026-11-27 14:57 UTC · original

AI-assisted static review; I did not run tests. The no-source table also includes opcode 0x041 (v_clrexcp), but the fixture covers only v_nop and v_pipeflush. Could it add v_clrexcp with SRC0 = 0xFF followed immediately by s_endpgm? That would verify the third opcode stays one dword and that the decoder does not consume the next instruction as a false literal.

**@⁠gut0to** on GitHub · 2026-11-27 14:57 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/180#discussion_r4720865117) AI-assisted static review; I did not run tests. The no-source table also includes opcode `0x041` (`v_clrexcp`), but the fixture covers only `v_nop` and `v_pipeflush`. Could it add `v_clrexcp` with `SRC0 = 0xFF` followed immediately by `s_endpgm`? That would verify the third opcode stays one dword and that the decoder does not consume the next instruction as a false literal.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
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/180/head:github-bot/gh-180'
git switch 'github-bot/gh-180'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-180'
git switch 'github-bot/gh-180'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-180'
git switch 'github-bot/gh-180'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-180'
git switch 'main'
git merge --squash 'github-bot/gh-180'
git switch 'main'
git merge --ff-only 'github-bot/gh-180'
git switch 'main'
git merge 'github-bot/gh-180'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.