Shaders: ds_wrap_rtn_b32 reads both of its data operands #2787

Open
lcg007xd-c wants to merge 1 commit from upstream-pr/2789 into main
lcg007xd-c commented 2026-11-25 20:27:26 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by lcg007xd-c on 2026-11-25T20:27:26Z.


What this fixes

ds_wrap_rtn_b32 computes tmp >= DATA0 ? tmp - DATA0 : tmp + DATA1 (RDNA2 ISA), so it reads two data VGPRs. The decoder gave it only one: DATA1 was neither printed in SP3 text nor reported as a register read.

d8d00010 08060402
llvm-mc -mcpu=gfx1030: ds_wrap_rtn_b32 v8, v2, v4, v6 offset:16
VIctory before:        ds_wrap_rtn_b32 v8, v2, v4 offset:16
VIctory after:         ds_wrap_rtn_b32 v8, v2, v4, v6 offset:16

I found it while diffing about 15.5k encodings with valid operands, covering every opcode of every encoding, between gfx10::decode and llvm-mc --disassemble -mcpu=gfx1030. Outside known aliases and already-claimed items, this was one of the few remaining disagreements.

The change

fields.rs: ds_wrap_rtn_b32 joins the two-data branch with cmpst/mskor. The lowering doesn't handle this opcode yet, so nothing that translates today changes.

Tested (Linux, Rust 1.98.1)

  • New gfx10::sp3::tests::ds_wrap_reads_both_data_operands, checked against llvm-mc's text. It fails without the change (v6 missing) and passes with it.
  • cargo test -p victory-shader --lib: 159 passed, 0 failed, 2 ignored. Building the shader tests on Linux needs #2766.
  • cargo clippy -p victory-shader --all-targets --target x86_64-pc-windows-msvc -- -D warnings: clean.
  • rustfmt --check on both files: clean.

🤖 Generated with Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:issue:5498628179 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2789). Originally posted by [lcg007xd-c](https://github.com/lcg007xd-c) on 2026-11-25T20:27:26Z. --- ## What this fixes `ds_wrap_rtn_b32` computes `tmp >= DATA0 ? tmp - DATA0 : tmp + DATA1` (RDNA2 ISA), so it reads two data VGPRs. The decoder gave it only one: DATA1 was neither printed in SP3 text nor reported as a register read. ``` d8d00010 08060402 llvm-mc -mcpu=gfx1030: ds_wrap_rtn_b32 v8, v2, v4, v6 offset:16 VIctory before: ds_wrap_rtn_b32 v8, v2, v4 offset:16 VIctory after: ds_wrap_rtn_b32 v8, v2, v4, v6 offset:16 ``` I found it while diffing about 15.5k encodings with valid operands, covering every opcode of every encoding, between `gfx10::decode` and `llvm-mc --disassemble -mcpu=gfx1030`. Outside known aliases and already-claimed items, this was one of the few remaining disagreements. ## The change `fields.rs`: `ds_wrap_rtn_b32` joins the two-data branch with `cmpst`/`mskor`. The lowering doesn't handle this opcode yet, so nothing that translates today changes. ## Tested (Linux, Rust 1.98.1) - New `gfx10::sp3::tests::ds_wrap_reads_both_data_operands`, checked against llvm-mc's text. It fails without the change (`v6` missing) and passes with it. - `cargo test -p victory-shader --lib`: 159 passed, 0 failed, 2 ignored. Building the shader tests on Linux needs #2766. - `cargo clippy -p victory-shader --all-targets --target x86_64-pc-windows-msvc -- -D warnings`: clean. - `rustfmt --check` on both files: clean. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
kotekompotek commented 2026-11-25 21:03:17 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T20:37:44Z.


Matches the ISA: ds_wrap_rtn_b32 wraps lane indices as (tid + DATA1 - DATA0), so both data operands are live reads. The llvm-mc encoding in the test confirms DATA0/DATA1 map to v4/v6.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7173951346 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2789#issuecomment-7173951346). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-25T20:37:44Z. --- Matches the ISA: ds_wrap_rtn_b32 wraps lane indices as (tid + DATA1 - DATA0), so both data operands are live reads. The llvm-mc encoding in the test confirms DATA0/DATA1 map to v4/v6.
fuzeofficlal commented 2026-11-25 21:03:21 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T20:46:57Z.


Reviewed and verified d80aedfc on Windows 11 against main (13f91ca).

  • Adding name == "ds_wrap_rtn_b32" to the 2-data-operand branch in fields.rs:314-320 matches RDNA2 ISA (DATA0 and DATA1), producing the expected ds_wrap_rtn_b32 v8, v2, v4, v6 offset:16 disassembly and recording both VGPR source reads in ir.rs, while leaving ds_inc_*/ds_dec_* at 1 data operand.
  • cargo test --locked -p victory-shader --lib -- gfx10::: 17/17 passed (including ds_wrap_reads_both_data_operands); ir::: 9/9 passed.
  • cargo clippy --locked -p victory-shader --all-targets -- -D warnings (default & --features host): 0 warnings; cargo xtask policy: 184 files ok; clean git merge-tree vs 13f91ca and #2783.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7174179410 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2789#issuecomment-7174179410). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-25T20:46:57Z. --- Reviewed and verified `d80aedfc` on Windows 11 against `main` (`13f91ca`). - Adding `name == "ds_wrap_rtn_b32"` to the 2-data-operand branch in `fields.rs:314-320` matches RDNA2 ISA (`DATA0` and `DATA1`), producing the expected `ds_wrap_rtn_b32 v8, v2, v4, v6 offset:16` disassembly and recording both VGPR source reads in `ir.rs`, while leaving `ds_inc_*`/`ds_dec_*` at 1 data operand. - `cargo test --locked -p victory-shader --lib -- gfx10::`: **17/17 passed** (including `ds_wrap_reads_both_data_operands`); `ir::`: **9/9 passed**. - `cargo clippy --locked -p victory-shader --all-targets -- -D warnings` (default & `--features host`): **0 warnings**; `cargo xtask policy`: **184 files ok**; clean `git merge-tree` vs `13f91ca` and `#2783`.
oni-swr commented 2026-11-25 21:03:24 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-25T20:58:45Z.


WARP/CPU verification of head d80aedfc43bb539b4e0b95d682864fe5dde873b2

Environment: Windows 11 x64, rustc/cargo 1.98.1, WARP/CPU only (VICTORY_WARP=1, VICTORY_D3D12_WARP=1), no physical GPU, no game files. DXIL validation with Windows SDK 10.0.26100.0 x64 dxil.dll 1.8.2502.11. PR head merged cleanly onto origin/main 13f91caee2.

Tests (cargo test --no-fail-fast -p victory-shader)

  • origin/main baseline: 267 passed, 3 failed, 3 ignored.
  • With this PR: 268 passed, 3 failed, 3 ignored (+1: gfx10::sp3::tests::ds_wrap_reads_both_data_operands).
  • The same 3 failures as on origin/main, unrelated (a_mask_joined_with_data_at_a_uniform_loop_is_its_number, gathers_at_a_level_match_the_hardware, permutes_read_the_lane_named_and_zero_from_lanes_left_out; they compare against hardware lane results and fail on WARP).

Negative control: with the ds_wrap_rtn_b32 clause disabled, the new test fails (ds_wrap_rtn_b32 v8, v2, v4 offset:16 instead of ... v2, v4, v6 ...).

Lint: cargo clippy --all-targets -- -D warnings clean. cargo fmt --check: no new hunks (891 on main, 891 with the PR). Note: cargo fmt --check is already red on origin/main here (891 hunks, none from these PRs), so I compared per-file hunk counts against that baseline.

Review: read the full diff. The change is minimal and the test matches the described operand semantics (DATA0 subtracted, DATA1 added). No game files, dumps, shader names, or retail hashes.

AI disclosure: this verification was done by Claude Code (Claude Sonnet 5.5).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7174445817 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2789#issuecomment-7174445817). Originally posted by [oni-swr](https://github.com/oni-swr) on 2026-11-25T20:58:45Z. --- **WARP/CPU verification of head `d80aedfc43bb539b4e0b95d682864fe5dde873b2`** **Environment:** Windows 11 x64, rustc/cargo 1.98.1, WARP/CPU only (VICTORY_WARP=1, VICTORY_D3D12_WARP=1), no physical GPU, no game files. DXIL validation with Windows SDK 10.0.26100.0 x64 dxil.dll 1.8.2502.11. PR head merged cleanly onto origin/main 13f91caee25f2fdf2c062be5f7a27f058e51cbca. **Tests (`cargo test --no-fail-fast -p victory-shader`)** - `origin/main` baseline: 267 passed, 3 failed, 3 ignored. - With this PR: 268 passed, 3 failed, 3 ignored (+1: `gfx10::sp3::tests::ds_wrap_reads_both_data_operands`). - The same 3 failures as on `origin/main`, unrelated (`a_mask_joined_with_data_at_a_uniform_loop_is_its_number`, `gathers_at_a_level_match_the_hardware`, `permutes_read_the_lane_named_and_zero_from_lanes_left_out`; they compare against hardware lane results and fail on WARP). **Negative control:** with the `ds_wrap_rtn_b32` clause disabled, the new test fails (`ds_wrap_rtn_b32 v8, v2, v4 offset:16` instead of `... v2, v4, v6 ...`). **Lint:** `cargo clippy --all-targets -- -D warnings` clean. `cargo fmt --check`: no new hunks (891 on main, 891 with the PR). Note: `cargo fmt --check` is already red on `origin/main` here (891 hunks, none from these PRs), so I compared per-file hunk counts against that baseline. **Review:** read the full diff. The change is minimal and the test matches the described operand semantics (DATA0 subtracted, DATA1 added). No game files, dumps, shader names, or retail hashes. AI disclosure: this verification was done by Claude Code (Claude Sonnet 5.5).
AwsAli05 commented 2026-11-25 23:15:44 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by AwsAli05 on 2026-11-25T23:15:44Z.

Review: COMMENTED


The focused disassembly test passed at the current 6520dba head on Windows. This fixes the decoder's two source operands. The lowering still has no ds_wrap_rtn_b32 case, so this change is useful for register tracking and decompilation. Please keep the runtime description scoped to decoding, and consider asserting both virtual-register reads in the IR as well as their displayed names.

AI-assisted review and test.

<!-- greyfinch-sync:Marvisak/VIctory:review:6066282603 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2789#pullrequestreview-6066282603). Originally posted by [AwsAli05](https://github.com/AwsAli05) on 2026-11-25T23:15:44Z. **Review:** COMMENTED --- The focused disassembly test passed at the current `6520dba` head on Windows. This fixes the decoder's two source operands. The lowering still has no `ds_wrap_rtn_b32` case, so this change is useful for register tracking and decompilation. Please keep the runtime description scoped to decoding, and consider asserting both virtual-register reads in the IR as well as their displayed names. AI-assisted review and test.
Marvisak commented 2026-11-26 00:03:25 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T23:21:30Z.


Automated triage for the maintainers.

This PR adds ds_wrap_rtn_b32 to the two-data-operand branch in Instruction field decoding (crates/victory-shader/src/gfx10/fields.rs), so DATA1 is printed and reported as a VGPR read. This matches the RDNA2 ISA (the result uses both DATA and DATA2) and llvm-mc's gfx1030 disassembly quoted in the new ds_wrap_reads_both_data_operands test. The opcode is not lowered yet, so nothing that translates today changes. CI passes.

This is a recommendation for a maintainer to look, not an approval.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7177450903 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2789#issuecomment-7177450903). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T23:21:30Z. --- <!-- victory-triage v1 head=6520dbafb6f31d4b0e074a0d47c8715c1fc4d1bf verdict=merge-candidate at=2026-11-25T23:21:25Z --> Automated triage for the maintainers. This PR adds `ds_wrap_rtn_b32` to the two-data-operand branch in `Instruction` field decoding (`crates/victory-shader/src/gfx10/fields.rs`), so DATA1 is printed and reported as a VGPR read. This matches the RDNA2 ISA (the result uses both DATA and DATA2) and llvm-mc's gfx1030 disassembly quoted in the new `ds_wrap_reads_both_data_operands` test. The opcode is not lowered yet, so nothing that translates today changes. CI passes. This is a recommendation for a maintainer to look, not an approval. --- _Generated by [Claude Code](https://claude.ai/code)_
DenRakEiw commented 2026-11-26 00:47:55 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-26T00:47:55Z.

Review: APPROVED


Verified against origin/main (63bcca4) on Windows 11 + NVIDIA GeForce RTX 5090 and WARP:

  • Decoding both data operands for ds_wrap_rtn_b32 is clean and verified.
  • cargo test -p victory-shader ds_wrap: 1/1 passed (ds_wrap_reads_both_data_operands).
  • cargo clippy -p victory-shader --all-targets -- -D warnings: 0 warnings.
  • cargo xtask policy: 192 files ok.

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

<!-- greyfinch-sync:Marvisak/VIctory:review:6067046265 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2789#pullrequestreview-6067046265). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-26T00:47:55Z. **Review:** APPROVED --- Verified against `origin/main` (`63bcca4`) on Windows 11 + NVIDIA GeForce RTX 5090 and WARP: - Decoding both data operands for `ds_wrap_rtn_b32` is clean and verified. - `cargo test -p victory-shader ds_wrap`: 1/1 passed (`ds_wrap_reads_both_data_operands`). - `cargo clippy -p victory-shader --all-targets -- -D warnings`: 0 warnings. - `cargo xtask policy`: 192 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
fuzeofficlal commented 2026-11-27 00:34:52 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-27T00:34:52Z.

Review: APPROVED


LGTM! Verified ds_wrap_rtn_b32 (0x034) against RDNA2 DS encoding: it takes both DATA0 and DATA1 (subtracting DATA0 or adding DATA1), there is no non-_rtn ds_wrap_b32 variant on RDNA2, and the 0xD8D0_0010, 0x0806_0402 test case accurately decodes and formats ds_wrap_rtn_b32 v8, v2, v4, v6 offset:16 while IR tracks both data register reads.

Checks passed:

  • rustfmt --edition 2024 --check on crates/victory-shader/src/gfx10/{fields.rs,sp3.rs}
  • cargo xtask policy (191 files ok)
  • cargo clippy -p victory-shader --locked --all-targets & --all-features (-D warnings)
  • cargo test -p victory-shader --locked --lib gfx10 (17/17 passed, including ds_wrap_reads_both_data_operands)
<!-- greyfinch-sync:Marvisak/VIctory:review:6081993881 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2789#pullrequestreview-6081993881). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-27T00:34:52Z. **Review:** APPROVED --- LGTM! Verified `ds_wrap_rtn_b32` (`0x034`) against RDNA2 DS encoding: it takes both `DATA0` and `DATA1` (subtracting `DATA0` or adding `DATA1`), there is no non-`_rtn` `ds_wrap_b32` variant on RDNA2, and the `0xD8D0_0010, 0x0806_0402` test case accurately decodes and formats `ds_wrap_rtn_b32 v8, v2, v4, v6 offset:16` while IR tracks both data register reads. Checks passed: - `rustfmt --edition 2024 --check` on `crates/victory-shader/src/gfx10/{fields.rs,sp3.rs}` - `cargo xtask policy` (`191 files ok`) - `cargo clippy -p victory-shader --locked --all-targets` & `--all-features` (`-D warnings`) - `cargo test -p victory-shader --locked --lib gfx10` (17/17 passed, including `ds_wrap_reads_both_data_operands`)
lcg007xd-c commented 2026-12-01 13:32:03 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by lcg007xd-c on 2026-12-01T13:32:03Z.


@greptileai Please review the latest changes.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7312775913 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2789#issuecomment-7312775913). Originally posted by [lcg007xd-c](https://github.com/lcg007xd-c) on 2026-12-01T13:32:03Z. --- @greptileai Please review the latest changes. <!-- nexus-review-request:3f8660ba4930 -->
lcg007xd-c commented 2026-12-01 14:24:06 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by lcg007xd-c on 2026-12-01T14:24:06Z.


@Marvisak @Dukestar69 Please review this contribution when you have time.

@greptileai Please review the current changes.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7314190241 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2789#issuecomment-7314190241). Originally posted by [lcg007xd-c](https://github.com/lcg007xd-c) on 2026-12-01T14:24:06Z. --- @Marvisak @Dukestar69 Please review this contribution when you have time. @greptileai Please review the current changes. <!-- nexus-review-pass:20261201-conflicts -->
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/2789:upstream-pr/2789'
git switch 'upstream-pr/2789'

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