Shaders: lower v_pk_fmac_f16 (VOP2 0x3c and VOP3 0x13c) #1136

Closed
ESAT586 wants to merge 1 commit from upstream-pr/1136 into main
ESAT586 commented 2026-11-24 16:07:08 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by ESAT586 on 2026-11-24T16:07:08Z.


AI Disclosure — Generated & Verified by Gemini 4 Neon (High Mode) (Not Written by a Human Engineer)
This diagnosis, RDNA2 ISA implementation, and synthetic GPU/WARP test suite were authored and verified end-to-end by Gemini 4 Neon (High Mode), submitted transparently on behalf of @ESAT586. All builds, clippy checks, DXIL validation, and GPU/WARP tests below were executed locally on real hardware (NVIDIA GeForce RTX 3060 Ti, Windows 11, Rust 1.98.1). No game data was used.

What's wrong

v_pk_fmac_f16 (VOP2 0x3c / VOP3 0x13c) is already decoded in gfx10/opcodes.rs, and valu_op dispatches any v_pk_* instruction into packed16. Because packed16 only matches VOP3P v_pk_* ops, v_pk_fmac_f16 fails lowering with Unsupported { what: "a packed 16-bit operation" }.

Additionally, unlike VOP3P instructions (which use op_sel / op_sel_hi to select halves per lane), v_pk_fmac_f16 uses VOP2/VOP3 encoding where the low half always comes from bits [15:0] and the high half from bits [31:16], accumulates into vdst, and applies VOP3 abs/neg/omod/clamp to both packed f16 halves.

Fix

  • Add Lower::pk_fmac_f16 in crates/victory-shader/src/emit/lower.rs (dispatched before packed16 in valu_op):
    • Computes d.lo = s0.lo * s1.lo + d.lo and d.hi = s0.hi * s1.hi + d.hi in f32 (matching valu16 / packed16) via legacyF16ToF32, fmad, and legacyF32ToF16.
    • Respects self.src0 for DPP, GFX10 inline constant expansion (f16_operand places inline constants in the low half and 0 in the high half), and VOP3 abs, neg, omod, clamp.
    • Rejects SDWA explicitly (Err("SDWA on v_pk_fmac_f16")).
  • Add emit::valu_tests::v_pk_fmac_f16_matches_rdna2 in crates/victory-shader/src/emit/valu_tests.rs testing:
    • VOP2 v_pk_fmac_f16 on two packed f16 pairs with independent accumulators,
    • VOP2 v_pk_fmac_f16 with inline constant 1.0 (0xF2, verifying low-half 1.0 and high-half 0.0 pass-through),
    • VOP3 v_pk_fmac_f16 (0x13c) with abs[0], neg[1], and clamp.

Verification (Real GPU + WARP + CI Gates)

Tested on Windows 11, NVIDIA GeForce RTX 3060 Ti (driver 32.0.16.1656), Rust 1.98.1:

  • cargo test -p victory-shader --lib v_pk_fmac_f16_matches_rdna2: ok (dxil.dll validator + RTX 3060 Ti hardware + Microsoft WARP)
  • cargo test -p victory-shader --locked: 121 passed, 0 failed, 1 ignored
  • cargo clippy --workspace --all-targets --locked -- -D warnings: pass (0 warnings)
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: pass (0 warnings)
  • cargo xtask policy: asset policy: 154 files ok

Scope & Non-Overlap

  • Checked open PRs and issues before writing: no open PR or issue covers v_pk_fmac_f16.
  • Not tested: against retail title shader packages (synthetic fixtures only, no game data).
<!-- greyfinch-sync:Marvisak/VIctory:issue:6586103043 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1136). Originally posted by [ESAT586](https://github.com/ESAT586) on 2026-11-24T16:07:08Z. --- > **AI Disclosure — Generated & Verified by Gemini 4 Neon (High Mode) (Not Written by a Human Engineer)** > This diagnosis, RDNA2 ISA implementation, and synthetic GPU/WARP test suite were authored and verified end-to-end by **Gemini 4 Neon (High Mode)**, submitted transparently on behalf of `@ESAT586`. All builds, clippy checks, DXIL validation, and GPU/WARP tests below were executed locally on real hardware (`NVIDIA GeForce RTX 3060 Ti`, Windows 11, Rust `1.98.1`). **No game data was used.** ## What's wrong `v_pk_fmac_f16` (VOP2 `0x3c` / VOP3 `0x13c`) is already decoded in `gfx10/opcodes.rs`, and `valu_op` dispatches any `v_pk_*` instruction into `packed16`. Because `packed16` only matches VOP3P `v_pk_*` ops, `v_pk_fmac_f16` fails lowering with `Unsupported { what: "a packed 16-bit operation" }`. Additionally, unlike VOP3P instructions (which use `op_sel` / `op_sel_hi` to select halves per lane), `v_pk_fmac_f16` uses VOP2/VOP3 encoding where the low half always comes from bits `[15:0]` and the high half from bits `[31:16]`, accumulates into `vdst`, and applies VOP3 `abs`/`neg`/`omod`/`clamp` to both packed f16 halves. ## Fix - Add `Lower::pk_fmac_f16` in `crates/victory-shader/src/emit/lower.rs` (dispatched before `packed16` in `valu_op`): - Computes `d.lo = s0.lo * s1.lo + d.lo` and `d.hi = s0.hi * s1.hi + d.hi` in f32 (matching `valu16` / `packed16`) via `legacyF16ToF32`, `fmad`, and `legacyF32ToF16`. - Respects `self.src0` for DPP, GFX10 inline constant expansion (`f16_operand` places inline constants in the low half and 0 in the high half), and VOP3 `abs`, `neg`, `omod`, `clamp`. - Rejects SDWA explicitly (`Err("SDWA on v_pk_fmac_f16")`). - Add `emit::valu_tests::v_pk_fmac_f16_matches_rdna2` in `crates/victory-shader/src/emit/valu_tests.rs` testing: - VOP2 `v_pk_fmac_f16` on two packed f16 pairs with independent accumulators, - VOP2 `v_pk_fmac_f16` with inline constant `1.0` (`0xF2`, verifying low-half `1.0` and high-half `0.0` pass-through), - VOP3 `v_pk_fmac_f16` (`0x13c`) with `abs[0]`, `neg[1]`, and `clamp`. ## Verification (Real GPU + WARP + CI Gates) Tested on Windows 11, **NVIDIA GeForce RTX 3060 Ti** (driver `32.0.16.1656`), Rust `1.98.1`: - `cargo test -p victory-shader --lib v_pk_fmac_f16_matches_rdna2`: **ok** (`dxil.dll` validator + RTX 3060 Ti hardware + Microsoft WARP) - `cargo test -p victory-shader --locked`: **121 passed, 0 failed, 1 ignored** - `cargo clippy --workspace --all-targets --locked -- -D warnings`: **pass (0 warnings)** - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: **pass (0 warnings)** - `cargo xtask policy`: **`asset policy: 154 files ok`** ## Scope & Non-Overlap - Checked open PRs and issues before writing: no open PR or issue covers `v_pk_fmac_f16`. - **Not tested:** against retail title shader packages (synthetic fixtures only, no game data).
nullmarsh commented 2026-11-24 17:04:35 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by nullmarsh on 2026-11-24T16:35:06Z.


Ran on RDNA2 hardware through vkd3d-proton on a Steam Deck (not native Windows): AMD Van Gogh, RADV 26.1.99, SteamOS 3.8.28, Proton 11.0-3 (wine-11.0) with its vkd3d-proton 212991fc. Windows MSVC test binary (rustc 1.100.0) built from head 0dcf6d0 on main ffe310e. Your report lists NVIDIA and WARP, so this adds AMD hardware.

  • v_pk_fmac_f16_matches_rdna2 passes: VOP2, the VOP2 inline 1.0 case (hi half kept), and the VOP3 abs/neg/clamp case.
  • victory-shader lib tests: 120 passed, 1 failed, 1 ignored (main on the same host: 119/1/1). The one failure, stub_pipeline_is_created, fails on main too (likely vkd3d-proton accepting the zero DXIL digest the test expects refused; environment, not this PR).
  • No hangs. A pass means the translated DXIL gives these values on RDNA2 through vkd3d-proton/RADV; it isn't a console measurement.

Not tested: native Windows AMD drivers; WARP (this setup has none, so the WARP leg ran on RADV too); whether the new test fails without the fix on this host.

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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7137894466 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1136#issuecomment-7137894466). Originally posted by [nullmarsh](https://github.com/nullmarsh) on 2026-11-24T16:35:06Z. --- Ran on RDNA2 hardware through vkd3d-proton on a Steam Deck (not native Windows): AMD Van Gogh, RADV 26.1.99, SteamOS 3.8.28, Proton 11.0-3 (wine-11.0) with its vkd3d-proton 212991fc. Windows MSVC test binary (rustc 1.100.0) built from head `0dcf6d0` on main `ffe310e`. Your report lists NVIDIA and WARP, so this adds AMD hardware. - `v_pk_fmac_f16_matches_rdna2` passes: VOP2, the VOP2 inline 1.0 case (hi half kept), and the VOP3 abs/neg/clamp case. - victory-shader lib tests: 120 passed, 1 failed, 1 ignored (main on the same host: 119/1/1). The one failure, `stub_pipeline_is_created`, fails on main too (likely vkd3d-proton accepting the zero DXIL digest the test expects refused; environment, not this PR). - No hangs. A pass means the translated DXIL gives these values on RDNA2 through vkd3d-proton/RADV; it isn't a console measurement. Not tested: native Windows AMD drivers; WARP (this setup has none, so the WARP leg ran on RADV too); whether the new test fails without the fix on this host. AI-assisted (Claude Code, Claude Opus 5.5); no game data.
Zipettte commented 2026-11-24 18:06:14 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Zipettte on 2026-11-24T18:01:27Z.


Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at 0dcf6d0: cargo test -p victory-shader passes, 121 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).

Tested with AI assistance (Claude).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7140045767 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1136#issuecomment-7140045767). Originally posted by [Zipettte](https://github.com/Zipettte) on 2026-11-24T18:01:27Z. --- Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at 0dcf6d0: `cargo test -p victory-shader` passes, 121 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed). _Tested with AI assistance (Claude)._
upstream-sync closed this pull request 2026-11-25 01:05:40 +00:00
Marvisak commented 2026-11-25 01:08:01 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:32:46Z.


Automated triage for the maintainers. Closing because this change is already in main, or main has since replaced the code it patches.

Lowers v_pk_fmac_f16. In main since today (lower.rs:6389-6400, tests packed_fmac_accumulates_each_half and the semantics probe).

If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148619351 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1136#issuecomment-7148619351). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:32:46Z. --- Automated triage for the maintainers. Closing because this change is already in `main`, or `main` has since replaced the code it patches. Lowers v_pk_fmac_f16. In main since today (lower.rs:6389-6400, tests packed_fmac_accumulates_each_half and the semantics probe). If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

Pull request closed

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!1136
No description provided.