Skip to content

Shaders: v_pk_fmac_f16 with DPP reads src0 from the selected lane - #2229

Open
BastienRodz wants to merge 1 commit into
Marvisak:mainfrom
BastienRodz:shader/pk-fmac-dpp-src0
Open

BastienRodz wants to merge 1 commit into
Marvisak:mainfrom
BastienRodz:shader/pk-fmac-dpp-src0

Conversation

@BastienRodz

Copy link
Copy Markdown
Contributor

What's wrong

For a VOP1/VOP2 instruction with DPP, Lower::valu fetches src0 from the selected lane and leaves it in self.src0; fsrc, src, half_src and v_cndmask_b32 use it for source 0. Lower::fmac_half, which reads the halves of v_pk_fmac_f16, called self.operand instead, so v_pk_fmac_f16_dpp multiplied the lane's own src0 in both halves. RDNA 2 ISA §12.7 defines the operation on S0, and §6.9 says DPP selects VOP1/VOP2 operands "from different lanes (threads) rather than just using a thread's own lane".

What the fix does

fmac_half takes self.src0 for source 0 when it is set, like the other readers. Nothing changes without DPP.

Tests

New emit::valu_tests::packed_fmac_dpp_reads_the_swizzled_lane: a pixel program on a 2x2 target packs a per-pixel pair of halves, runs v_pk_fmac_f16_dpp quad_perm:[1,0,3,2], and checks each pixel got its horizontal neighbour's product. A pixel program is used because quad permutes behave the same at any wave size, so the test also runs on WARP (a compute version would declare the console's wave of 32, which WARP and llvmpipe refuse).

  • On main (940d32f) it fails: every pixel gets its own product (left: [[6.5, 6.0, …], [10.5, 8.0, …], …], right: [[10.5, 8.0, …], [6.5, 6.0, …], …]).
  • With the fix it and packed_fmac_accumulates_each_half pass.
  • Run under Wine 10 with vkd3d-proton 3.1 on llvmpipe (VKD3D_FEATURE_LEVEL=12_2 VKD3D_SHADER_MODEL=6_6).
  • windows-latest run on the fork: https://github.com/BastienRodz/VIctory/actions/runs/45575808602

Not tested

Not run on an AMD/NVIDIA GPU. No dxil.dll here, so the new program was not run through the validator locally. Whether title shaders use v_pk_fmac_f16 with DPP is not measured.

Fixes #2228

AI-assisted (Gemini 4 Neon found and wrote it, Claude Code reviewed, trimmed and verified it). No game data used.

🤖 Generated with Claude Code

Lower::valu puts a DPP instruction's cross-lane src0 in self.src0 before
lowering the operation; fsrc, src, half_src and v_cndmask_b32 read it for
source 0, but fmac_half read the operand directly, so v_pk_fmac_f16_dpp
multiplied the lane's own src0 in both halves. Read self.src0 for source
0 as the other readers do.

The test draws a 2x2 quad whose pixels swap their packed src0 through
quad_perm:[1,0,3,2].

Co-Authored-By: Gemini 4 Neon <noreply@google.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

v_pk_fmac_f16 with DPP reads src0 from the lane's own value. Tested locally: merged into main 940d32f, cargo test -p victory-shader --locked on macOS arm64 — 144 passed, 0 failed, 2 ignored. Approving.

@andrewpozdnakov7-jpg

Copy link
Copy Markdown
Contributor

I ran the same quad-permute fixture on 940d32f and exact head 754e60e on native Windows. I made DXIL validation and the software-device creation mandatory. The DXC 1.9.2609 validator accepted both shaders on both revisions.

The render used Agility 1.620.2 and packaged WARP 1.0.22, with both loaded module paths checked. Reading the 2x2 target gave these low/high pairs in pixel order.

  • 940d32f: (6.5, 6), (10.5, 8), (14.5, 14), (18.5, 16). This failed the test because both halves used their own lane.
  • 754e60e: (10.5, 8), (6.5, 6), (18.5, 16), (14.5, 14). All four readbacks passed and matched the horizontal neighbour.

The inbox WARP device reported SM 6.2 and could not run this fixture. AI-assisted. Synthetic shaders only.

@DenRakEiw DenRakEiw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified locally merged onto origin/main (940d32f, Windows 11 x64, NVIDIA GeForce RTX 5090 + WARP, Rust 1.98.1 MSVC, with dxil.dll validator):

  • cargo test -p victory-shader --lib packed_fmac_dpp_reads_the_swizzled_lane — passed on both RTX 5090 hardware and VICTORY_D3D12_WARP=1
  • cargo clippy -p victory-shader --all-targets — 0 warnings
  • cargo xtask policy — ok (183 files ok)

Clean fix reading src0 from the DPP-selected lane in v_pk_fmac_f16, verified end-to-end on RTX 5090 + WARP. Looks great.

AI-assisted (Gemini 4 Neon).

@andrewpozdnakov7-jpg

Copy link
Copy Markdown
Contributor

I also checked the DPP8 encoding from #2228 with a separate compute fixture. The existing pixel test covers DPP16. This fixture dispatches one group of 32 threads, swaps adjacent lanes within each eight-lane DPP8 group, and reads back both packed halves from every thread.

  • 940d32f: lane 0 returned [2, 1], its own-lane result. It should have returned [3, 5] from lane 1.
  • 754e60e: both halves matched the selected lane across all 32 readback words.

Native DXIL validation passed for both. The execution used app-local Agility 1.620.2 and WARP 1.0.22. The test-only b940374 sits directly on your current head and passes strict shader Clippy. If you fold in the test, please retain Co-authored-by: andrewpozdnakov7-jpg <andrewpozdnakov7-jpg@users.noreply.github.com>.

@BastienRodz

Copy link
Copy Markdown
Contributor Author

Thanks for running the DPP8 case. I'll keep the PR to the one test: DPP16 and DPP8 both go through Lower::dpp before fmac_half reads self.src0, so the fix doesn't depend on the encoding, and your results here already record that DPP8 behaves the same. If the maintainer would rather have both encodings covered, I'm happy to fold in b940374 with your co-author line.

@sinan-cmyk

Copy link
Copy Markdown

Offline measurement on a retail dump

Result: no count change against main.

I merged head 754e60e onto main 940d32f (clean merge) and ran victory translate --validate --list on shaders.rpf (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with main program by program (25,889 programs). Validated: 23,918 on main, 23,918 with this PR.

No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right.

No shader names or data are included, per the asset policy. AI-assisted (Claude Code).

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Merge candidate (worth a look). The head is unchanged (754e60e). Lower::fmac_half (crates/victory-shader/src/emit/lower.rs) reads source 0 of v_pk_fmac_f16 from the DPP lane-selected self.src0, as the other source helpers do; main still reads self.operand there. The new pixel test fails on main and passes with the fix on WARP and on an RTX 4070 (per a tester). CI check passes and it still merges cleanly into the current main.

On your reply: agreed. DPP src0_neg/src0_abs on a packed op is a separate question that needs AMD hardware evidence, and keeping it out of this PR doesn't change the verdict.


Generated by Claude Code

@Mericas77

Copy link
Copy Markdown

Tested on NVIDIA hardware (RTX 4070, Ada, wave32), Windows 11, Agility 1.620.2, on base 940d32f. Earlier runs here were WARP only.

#2229 (head 754e60e): packed_fmac_dpp_reads_the_swizzled_lane passes on the 4070 and on WARP. Without the lower.rs change it fails on the hardware with the rows unswapped ([6.5, 6], [10.5, 8], ... instead of [10.5, 8], [6.5, 6], ...).

Cross-check with #2266 (head 1483d37): the two fixes are equivalent. Each PR's test fails on main's lower.rs and passes with either PR's fix. #2266's test (row_shr:1 with bound_ctrl) gives 0x44004400 (2.0 × 2.0 in both halves) without a fix and 0 with one. Its comment says WARP refuses the pipeline. Here I only ran it on the hardware, as written. #2229's test does run on WARP on this machine.

Full crate (victory-shader --lib): 245 passed, 3 failed, 3 ignored with either PR. That is the same 3 failures main has on this card (stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride, stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros, synthetic_tests::gathers_at_a_level_match_the_hardware, see #1835). Neither PR adds a failure.

So #2229 looks fine to merge from the NVIDIA side, and #2266 is a duplicate of it.

One adjacent point, not covered by either PR: the DPP16 dword's src0_neg/src0_abs bits are decoded into v.neg/v.abs (gfx10/fields.rs, the 0xFA arm). For v_pk_fmac_f16, packed16 applies v.neg to the low half only (neg_hi stays 0 for a VOP2) and never reads v.abs. So a v_pk_fmac_f16_dpp with abs would silently lose it, and one with neg would negate only the low half. I can't check what RDNA 2 does with those bits on a packed op from NVIDIA hardware. Refusing modifiers with DPP on v_pk_fmac_f16 might be the safer choice until someone checks on an AMD card. That is only worth doing if the title actually emits that form.

AI-assisted.

@BastienRodz

Copy link
Copy Markdown
Contributor Author

Thanks @Mericas77, it's useful to have it confirmed on Ada hardware, and the cross-check with #2266 too. On the DPP src0_neg/src0_abs bits for v_pk_fmac_f16: agreed, that's a separate question from the lane selection fixed here. I'd rather keep this PR to the one-line fix and leave modifier handling for a check on an AMD card, if the title turns out to emit that form.

@fyernald fyernald left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified on RTX 3080 (617.42), Windows 10 (19045) plus WARP, main 67e8ae1 + #486 + #2596 (the suite crashes on NVIDIA without #2596, #2571). cargo test -p victory-shader --lib --locked -- --test-threads=1: 268 passed, 3 failed (the #1835 ones, also on the base). packed_fmac_dpp_reads_the_swizzled_lane passes on both adapters.

#2266 makes the identical change (self.src0 for k == 0 in the packed-operand read). This PR came first and has the more thorough test, so I'd take this one.

github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 25, 2026
github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Shaders: v_pk_fmac_f16 with DPP ignores the lane DPP selects for src0

8 participants