Skip to content

Shaders: v_fmac_f32 in VOP3 applies abs and neg to its accumulator - #3158

Open
Moon0755 wants to merge 1 commit into
Marvisak:mainfrom
Moon0755:fix/fmac-accumulator-modifiers
Open

Moon0755 wants to merge 1 commit into
Marvisak:mainfrom
Moon0755:fix/fmac-accumulator-modifiers

Conversation

@Moon0755

Copy link
Copy Markdown

Problem

In the VOP3 encoding v_fmac_f32 (0x12B) has two explicit sources; the accumulator is the destination register. Bit 2 of abs and of neg still acts on RDNA2: it applies to the accumulator. fields.rs decodes the bit, but the arm in lower.rs reads the accumulator without it, so the modifier is dropped with no refusal.

Example: a = 1.0, b = 2.0, accumulator 1.0, neg bit 2. RDNA2 gives 1.0 (0x3f800000), main gives 3.0 (0x40400000).

Source of the expected values

The AnyPS5 project measured this on RDNA2 (RX 6750 XT, gfx1031). Its PR 18285 reports 1,372 rows in each of four float-mode settings: neg bit 2 gives fma(a, b, -d) and abs bit 2 gives fma(a, b, |d|) on every row, and the src2 register field is ignored. It keeps 16 rows in its test core/libs/prx/libSceAgcDriver/tests/execution/VFmacF32AccumulatorModifiers.cpp. The test here uses those 16 rows as numbers, from the table for IEEE mode off with 32-bit denormals flushed (the mode semantics_tests.rs models). No code is taken from that project.

Fix

In the v_fmac_f32 arm of lower.rs the accumulator gets abs and neg bit 2 the way a source gets its bits: the absolute value first, then a subtraction from -0.

The arm is shared with v_mac_f32 and v_mac_legacy_f32, so they get the same treatment. There is no measurement for those two; before this change they dropped the bit as v_fmac_f32 did.

Test

New: semantics_tests::v_fmac_f32_accumulator_modifiers_match_rdna2_oracle, the 16 measured rows through neg bit 2 and through abs bit 2 (signed zeros, infinities, NaN and denormal accumulators, a sum that cancels to zero). No existing test or model changes; the existing probes leave bit 2 out for the two-source forms.

Verification

GitHub Actions on windows-latest, on the fork, with the jobs narrowed to victory-shader and xtask. The runner has no hardware adapter, so the probes ran on WARP only.

  • with the change (run 45797722607): clippy in both profiles passed, 303 passed; 0 failed; 3 ignored; both probes report 0 model mismatches;
  • the new test without the change (run 45797115596): 302 passed; 1 failed, the new test only, with 12 of 16 mismatches for neg and 8 of 16 for abs.

Not checked

— Gemini & Fable

In the VOP3 encoding, bit 2 of abs and of neg names the accumulator of
v_fmac_f32, which is the destination register. RDNA2 computes
fma(a, b, -d) and fma(a, b, |d|) with them; the lowering read the
accumulator without them.

The expected values of the new test are 16 rows measured on RDNA2
(gfx1031) with IEEE mode off and f32 denormals flushed, published by
the AnyPS5 project in VFmacF32AccumulatorModifiers.cpp. No code is
taken from that project.

v_mac_f32 and v_mac_legacy_f32 share the arm and get the same
treatment; there is no measurement for those two.

Co-Authored-By: Gemini 4 Neon <noreply@google.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@cloph-dsp

Copy link
Copy Markdown

Independent local verification of head cf8f543 on Windows 11, Rust 1.100.0/MSVC:

  • VICTORY_WARP=1 cargo test --locked -p victory-shader --lib emit::semantics_tests::v_fmac_f32_accumulator_modifiers_match_rdna2_oracle — 1 passed, 0 failed.
  • git diff --check origin/main HEAD — clean.

Host GPUs: RTX 5060 Laptop (driver 621.24) and Radeon 780M RDNA3; this run used WARP. A worktree-local CARGO_TARGET_DIR was used to avoid a stale shared-target binary. Synthetic operand cases only; no game assets or DRM material used. AI-assisted (Hy4 flash).

@oni-swr

oni-swr commented Nov 26, 2026 •

Copy link
Copy Markdown

Independent WARP verification of head cf8f543 (parent main 63bcca4). Synthetic only, no game data.

Setup: VICTORY_D3D12_WARP=1, VICTORY_WARP=1; DXGI adapter reported "Microsoft Basic Render Driver" (software, 0 video memory); the physical GPU was not opened. Both the "hardware" and "warp" labels in the semantics harness resolve to WARP under VICTORY_WARP=1. dxil.dll 1.8.2502.11 validated every module. rustc: rustc 1.98.1 (48a229cea 2026-09-01). cargo test -j 4.

Result: no defect found in the change.

  • emit::semantics_tests::v_fmac_f32_accumulator_modifiers_match_rdna2_oracle passes on head. With lower.rs taken from main and the PR's test kept, it fails: neg row set 12 of 16 mismatches, abs row set 8 of 16 (e.g. neg with [1.0, 2.0, 1.0] wants 0x3f800000, main gives 0x40400000). So the test discriminates the fix.
  • Local extra check (not pushed): abs[2] and neg[2] together, 24 inputs (acc in ±0, ±large, ±fractional; a in 2, -3, 0.25), expected fma(a, b, -|acc|) from an independent f32 model: 0 mismatches on WARP.
  • The neg lowering (-0.0 - acc) is the same form used for the other VOP3 source modifiers in lower.rs; abs is applied before neg, as the modifier order requires.
  • cargo test -p victory-shader --no-fail-fast -- --test-threads=1: head 299 passed, 4 failed, 3 ignored; main 298 passed, 4 failed, 3 ignored. The same 4 fail on both (synthetic_tests: a_mask_joined_with_data_at_a_uniform_loop_is_its_number, gathers_at_a_level_match_the_hardware, permutes_mask_high_address_bits_and_divergent_branches, permutes_read_the_lane_named_and_zero_from_lanes_left_out), so none comes from this PR.

Limits: the 16 expected rows in the PR's test are quoted from an external hardware measurement; I did not have that source or RDNA2 hardware, so I checked WARP against the PR's rows and my own model, not against a console. The edit sits in the arm shared by v_mac_f32 and v_mac_legacy_f32; VOP2 encodings carry no abs/neg bits so they are unaffected, and I did not look for or add a VOP3 test of those two.

AI use: Claude Code (Claude Sonnet 5.5) ran this verification; Claude Code (Claude Opus 5.5) coordinated. No game files, dumps, shader names or hashes were used.

@Dukestar69 Dukestar69 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 5090 & WARP against origin/main (63bcca4):

  • cargo test -p victory-shader --lib v_fmac_f32_accumulator_modifiers_match_rdna2_oracle -- --test-threads=1: passed on RTX 5090 and WARP.
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Clean fix applying VOP3 abs/neg modifiers to the v_fmac_f32 accumulator.

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

@JAEdotUK

Copy link
Copy Markdown

Hardware test report: head cf8f543

Environment: AMD Radeon RX 9070 XT (RDNA4), driver 32.0.32015.7029, Windows 11 (10.0.26200.9974), rustc 1.98.1. WARP not forced. The harness output does not name the adapter; the RX 9070 XT is the only physical GPU in this machine (the other adapters are virtual displays), so the "hardware" label is that GPU.

cargo test -p victory-shader --lib --locked v_fmac_f32_accumulator_modifiers_match_rdna2_oracle -> 1 passed, 0 failed. Both probes: 16 inputs, model mismatches hardware 0, warp 0, hardware/warp differ on 0.

Control: with lower.rs taken from main and the PR's test kept, the same test fails. Neg probe: hardware 13 and warp 12 of 16 mismatches. Abs probe: hardware 9 and warp 8 of 16. Hardware and warp also disagree on 2 rows in each probe on main (for example inputs 7f7fffff, 40000000, ff7fffff: hardware 7f7fffff, warp 7f800000); with the PR applied they agree on all rows.

Not run: v_mac_f32 / v_mac_legacy_f32 with bit 2, Clippy, xtask policy, any game files. Synthetic tests only.

AI use: this report was prepared with Claude (Claude Sonnet 5.5); the test run was done by me on my own machine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants