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

Closed
github-bot wants to merge 1 commit from gh-pr/1136/head into gh-pr/1136/base
Owner

@⁠ESAT586 on GitHub · 2026-11-24 16:07 UTC · original
ESAT586:shader/pk-fmac-f16 → main · +177 −0 · 2 files · 1 commits · closed without merging

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).
**@⁠ESAT586** on GitHub · 2026-11-24 16:07 UTC · [original](https://github.com/Marvisak/VIctory/pull/1136) `ESAT586:shader/pk-fmac-f16` → `main` · +177 −0 · 2 files · 1 commits · closed without merging > **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).
AI-generated & verified with Gemini 4 Neon (High Mode) — not written by a human engineer.

`v_pk_fmac_f16` (packed 2x f16 multiply-accumulate into the destination VGPR)
is decoded by gfx10 (VOP2 0x3c / VOP3 0x13c) but previously routed into
`packed16`, which rejected it with `Err("a packed 16-bit operation")`.

Add `pk_fmac_f16` in `lower.rs` to compute both f16 halves (`lo` and `hi`) via
`legacyF16ToF32` -> `fmad` -> `legacyF32ToF16`, honoring DPP (`self.src0`),
GFX10 inline-constant expansion (low half = constant, high half = 0), and VOP3
`abs`/`neg`/`omod`/`clamp` modifiers across both halves.

Verified with synthetic GPU + WARP + dxil.dll tests in `valu_tests.rs` on
NVIDIA GeForce RTX 3060 Ti (Windows 11, Rust 1.98.1). No game data used.

Co-Authored-By: Gemini 4 Neon (High Mode) <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:20:53 +00:00
github-bot closed this pull request 2026-11-26 04:20:53 +00:00
Author
Owner

@⁠ghost on GitHub · 2026-11-24 16:35 UTC · original

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.

**@⁠ghost** on GitHub · 2026-11-24 16:35 UTC · [original](https://github.com/Marvisak/VIctory/pull/1136#issuecomment-7137894466) 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.
Author
Owner

@⁠Zipettte on GitHub · 2026-11-24 18:01 UTC · original

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

**@⁠Zipettte** on GitHub · 2026-11-24 18:01 UTC · [original](https://github.com/Marvisak/VIctory/pull/1136#issuecomment-7140045767) 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)._
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 00:32 UTC · original

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.

**@⁠Marvisak** on GitHub · 2026-11-25 00:32 UTC · [original](https://github.com/Marvisak/VIctory/pull/1136#issuecomment-7148619351) 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

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