Shaders: lower v_pk_fmac_f16 #90

Open
Ingenioeren wants to merge 1 commit from upstream-pr/90 into main
Ingenioeren commented 2026-11-25 10:11:22 +00:00 (Migrated from github.com)
First-time contributor

Imported from Zettrox/ztrx. Originally posted by Ingenioeren on 2026-11-25T10:07:22Z.


What

v_pk_fmac_f16 (VOP2, opcode 0x3C) is lowered now. Until now any program containing it was refused with "a packed 16-bit operation". The instruction goes through the existing packed16 path. Each 16-bit half of the destination (the accumulator) gains the product of the matching halves of src0 and src1, computed through f32 with FMad like v_pk_fma_f16.

A new helper, fmac_half, reads the operands:

  • Source 2 is the destination register.
  • With DPP, source 0 is the value of the lane that DPP selects (self.src0), as for every other VOP2 operation here.
  • Constant operands are refused, and so are DPP/SDWA neg/abs modifiers and SDWA. Which halves those apply to isn't modelled, so the program is refused rather than lowered with a guess.

Why

The lowering comes from upstream VIctory (0b35b7f). Upstream reads source 0 directly and so drops the DPP-selected lane, which was reported there as Marvisak/VIctory#2228 (fixes are open upstream). This port reads the DPP lane from the start, so ztrx doesn't pick up that bug.

How tested

Windows 11, AMD Radeon RX 6750 XT plus WARP, Rust stable MSVC, on 90b529f:

  • cargo test --locked --offline -p victory-shader --lib packed_fmac: 2 passed.
    • packed_fmac_accumulates_each_half: (2.0, 1.0) * (3.0, 4.0) + (1.0, 0.5) = (7.0, 4.5) on the hardware adapter and WARP.
    • packed_fmac_with_dpp8_reads_the_selected_lane: 8 lanes, each lane's src0 is (lane, lane) in f16, and DPP8 makes lane i read lane i^1. Lane 0's result is read back through v_readfirstlane_b32, so which lane's store lands doesn't matter. It runs on hardware only. The cross-lane read declares WaveSize(32), which WARP's pipeline creation refuses; the existing LDS tests in this file are hardware-only for the same reason.
  • Before the fix, both tests fail at lower (the instruction is refused). With the fix but source 0 read directly (the upstream behaviour), the DPP8 test fails with 0x38003C00, the lane's own src0, instead of 0x44804400.
  • cargo test --locked --offline -p victory-shader: 210 passed, 2 failed, 2 ignored. The two failures are emit::rect::tests::the_rectangle_stage_is_a_geometry_shader and emit::rect::tests::rectangles_are_drawn_whole (dxil.dll: "Container part 'Pipeline State Validation' does not match expected"). Unmodified main on this machine fails the same two (208 passed, 2 failed), so they come from the local validator and not from this change.
  • cargo clippy --locked --offline -p victory-shader --all-targets -- -D warnings: clean.
  • cargo fmt -p victory-shader --check: no diffs in the lines this PR touches.
  • cargo run -p xtask -- policy --staged: 2 files ok.

Not tested: NVIDIA hardware (this machine has an AMD GPU, so this is a code-level change proven by synthetic tests only), DPP16 row controls (they use the same self.src0 path, but no test covers them here), and no game run.

AI assistance: prepared with Claude Code, reviewed by Ingenioeren.

🤖 Generated with Claude Code

<!-- greyfinch-sync:Zettrox/ztrx:issue:6602017526 --> Imported from [Zettrox/ztrx](https://github.com/Zettrox/ztrx/pull/90). Originally posted by [Ingenioeren](https://github.com/Ingenioeren) on 2026-11-25T10:07:22Z. --- ## What `v_pk_fmac_f16` (VOP2, opcode 0x3C) is lowered now. Until now any program containing it was refused with "a packed 16-bit operation". The instruction goes through the existing `packed16` path. Each 16-bit half of the destination (the accumulator) gains the product of the matching halves of `src0` and `src1`, computed through f32 with FMad like `v_pk_fma_f16`. A new helper, `fmac_half`, reads the operands: - Source 2 is the destination register. - With DPP, source 0 is the value of the lane that DPP selects (`self.src0`), as for every other VOP2 operation here. - Constant operands are refused, and so are DPP/SDWA `neg`/`abs` modifiers and SDWA. Which halves those apply to isn't modelled, so the program is refused rather than lowered with a guess. ## Why The lowering comes from upstream VIctory (0b35b7f). Upstream reads source 0 directly and so drops the DPP-selected lane, which was reported there as Marvisak/VIctory#2228 (fixes are open upstream). This port reads the DPP lane from the start, so ztrx doesn't pick up that bug. ## How tested Windows 11, AMD Radeon RX 6750 XT plus WARP, Rust stable MSVC, on `90b529f`: - `cargo test --locked --offline -p victory-shader --lib packed_fmac`: 2 passed. - `packed_fmac_accumulates_each_half`: `(2.0, 1.0) * (3.0, 4.0) + (1.0, 0.5) = (7.0, 4.5)` on the hardware adapter and WARP. - `packed_fmac_with_dpp8_reads_the_selected_lane`: 8 lanes, each lane's `src0` is `(lane, lane)` in f16, and DPP8 makes lane i read lane i^1. Lane 0's result is read back through `v_readfirstlane_b32`, so which lane's store lands doesn't matter. It runs on hardware only. The cross-lane read declares `WaveSize(32)`, which WARP's pipeline creation refuses; the existing LDS tests in this file are hardware-only for the same reason. - Before the fix, both tests fail at `lower` (the instruction is refused). With the fix but source 0 read directly (the upstream behaviour), the DPP8 test fails with `0x38003C00`, the lane's own `src0`, instead of `0x44804400`. - `cargo test --locked --offline -p victory-shader`: 210 passed, 2 failed, 2 ignored. The two failures are `emit::rect::tests::the_rectangle_stage_is_a_geometry_shader` and `emit::rect::tests::rectangles_are_drawn_whole` (`dxil.dll`: "Container part 'Pipeline State Validation' does not match expected"). Unmodified `main` on this machine fails the same two (208 passed, 2 failed), so they come from the local validator and not from this change. - `cargo clippy --locked --offline -p victory-shader --all-targets -- -D warnings`: clean. - `cargo fmt -p victory-shader --check`: no diffs in the lines this PR touches. - `cargo run -p xtask -- policy --staged`: 2 files ok. Not tested: NVIDIA hardware (this machine has an AMD GPU, so this is a code-level change proven by synthetic tests only), DPP16 row controls (they use the same `self.src0` path, but no test covers them here), and no game run. AI assistance: prepared with Claude Code, reviewed by Ingenioeren. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
hamdog0203 commented 2026-11-25 12:07:13 +00:00 (Migrated from github.com)
Author
First-time contributor

Imported from Zettrox/ztrx. Originally posted by hamdog0203 on 2026-11-25T11:51:53Z.


Independent verification on NVIDIA RTX 4060 (8 GB, Wave32, driver 621.35) + WARP + Windows SDK dxil.dll (10.0.26100.0), Windows 11 x64 (26200.9974), rustc 1.98.1, audited at commit 2918143b920e6754c75fd68b37689a9fc8f12807:

  • Code & security review: Clean diff in crates/victory-shader/src/emit/lower.rs and valu_tests.rs (no unsafe). Properly reads self.src0 for DPP and conservatively refuses constant operands and neg/abs/SDWA modifiers rather than guessing half-selection.
  • CI & hardware checks:
    • cargo clippy --workspace --all-targets --locked -- -D warnings: passed (0 warnings)
    • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: passed (0 warnings)
    • cargo test --locked -p victory-shader --lib packed_fmac -- --nocapture: both tests passed (packed_fmac_accumulates_each_half on RTX 4060 + WARP + dxil.dll, and packed_fmac_with_dpp8_reads_the_selected_lane on RTX 4060 + dxil.dll with no skip)
    • cargo test --workspace --locked: all crates passed with 0 failures (victory_shader: 212 passed, 2 ignored — including both emit::rect::tests passing against SDK dxil.dll 10.0.26100.0; xtask asset-policy: 4 passed)

Looks solid from an NVIDIA Wave32 perspective (synthetic tests + full workspace suite; no game run performed).

<!-- greyfinch-sync:Zettrox/ztrx:comment:7161602319 --> Imported from [Zettrox/ztrx](https://github.com/Zettrox/ztrx/pull/90#issuecomment-7161602319). Originally posted by [hamdog0203](https://github.com/hamdog0203) on 2026-11-25T11:51:53Z. --- Independent verification on NVIDIA RTX 4060 (8 GB, Wave32, driver 621.35) + WARP + Windows SDK `dxil.dll` (`10.0.26100.0`), Windows 11 x64 (`26200.9974`), `rustc 1.98.1`, audited at commit `2918143b920e6754c75fd68b37689a9fc8f12807`: - **Code & security review:** Clean diff in `crates/victory-shader/src/emit/lower.rs` and `valu_tests.rs` (no `unsafe`). Properly reads `self.src0` for DPP and conservatively refuses constant operands and `neg`/`abs`/SDWA modifiers rather than guessing half-selection. - **CI & hardware checks:** - `cargo clippy --workspace --all-targets --locked -- -D warnings`: passed (0 warnings) - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: passed (0 warnings) - `cargo test --locked -p victory-shader --lib packed_fmac -- --nocapture`: both tests passed (`packed_fmac_accumulates_each_half` on RTX 4060 + WARP + `dxil.dll`, and `packed_fmac_with_dpp8_reads_the_selected_lane` on RTX 4060 + `dxil.dll` with no skip) - `cargo test --workspace --locked`: all crates passed with 0 failures (`victory_shader`: 212 passed, 2 ignored — including both `emit::rect::tests` passing against SDK `dxil.dll` `10.0.26100.0`; `xtask` asset-policy: 4 passed) Looks solid from an NVIDIA Wave32 perspective (synthetic tests + full workspace suite; no game run performed).
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/90:upstream-pr/90'
git switch 'upstream-pr/90'

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