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

Open
github-bot wants to merge 1 commit from github-bot/gh-3158 into main AGit
Owner

@⁠Moon0755 on GitHub · 2026-11-26 10:30 UTC · original
Moon0755:fix/fmac-accumulator-modifiers → main · +46 −1 · 2 files · 1 commits · open

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

  • No run on a hardware adapter (AMD, NVIDIA or Intel). A run of the new test on a real GPU would be welcome.
  • v_mac_f32 and v_mac_legacy_f32 with bit 2: by analogy only, as said above.
  • A NaN accumulator with neg: RDNA2 flips the NaN's sign bit (two of the 16 rows). The test accepts any NaN there, as the other float probes do, and the negation is the same subtraction the sources use.
  • The f16 accumulate forms. Not touched.
  • #284, #1554 and #2594 change neighbouring lines of the same arm; none of them handles bit 2. I will rebase if one lands first.
  • The measurements are from a PC RDNA2 part, not from the console.

— Gemini & Fable

**@⁠Moon0755** on GitHub · 2026-11-26 10:30 UTC · [original](https://github.com/Marvisak/VIctory/pull/3158) `Moon0755:fix/fmac-accumulator-modifiers` → `main` · +46 −1 · 2 files · 1 commits · open ### 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](https://github.com/Moon0755/VIctory/actions/runs/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](https://github.com/Moon0755/VIctory/actions/runs/45797115596)): `302 passed; 1 failed`, the new test only, with 12 of 16 mismatches for `neg` and 8 of 16 for `abs`. ### Not checked - No run on a hardware adapter (AMD, NVIDIA or Intel). A run of the new test on a real GPU would be welcome. - `v_mac_f32` and `v_mac_legacy_f32` with bit 2: by analogy only, as said above. - A NaN accumulator with `neg`: RDNA2 flips the NaN's sign bit (two of the 16 rows). The test accepts any NaN there, as the other float probes do, and the negation is the same subtraction the sources use. - The f16 accumulate forms. Not touched. - #284, #1554 and #2594 change neighbouring lines of the same arm; none of them handles bit 2. I will rebase if one lands first. - The measurements are from a PC RDNA2 part, not from the console. — 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 <[email protected]>
Co-Authored-By: Claude Fable 5.2 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 11:09:00 +00:00
Author
Owner

@⁠cloph-dsp on GitHub · 2026-11-26 10:40 UTC · original

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

**@⁠cloph-dsp** on GitHub · 2026-11-26 10:40 UTC · [original](https://github.com/Marvisak/VIctory/pull/3158#issuecomment-7189673436) 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).
Author
Owner

@⁠oni-swr on GitHub · 2026-11-26 10:44 UTC · original

Independent WARP verification of head cf8f543c (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.

**@⁠oni-swr** on GitHub · 2026-11-26 10:44 UTC · [original](https://github.com/Marvisak/VIctory/pull/3158#issuecomment-7189763822) Independent WARP verification of head cf8f543c (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.
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 10:50 UTC · original · approved these changes

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

**@⁠Dukestar69** on GitHub · 2026-11-26 10:50 UTC · [original](https://github.com/Marvisak/VIctory/pull/3158#pullrequestreview-6072806151) · **approved these changes** 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).
Author
Owner

@⁠JAEdotUK on GitHub · 2026-11-26 12:51 UTC · original

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.

**@⁠JAEdotUK** on GitHub · 2026-11-26 12:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/3158#issuecomment-7192544663) 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.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/3158/head:github-bot/gh-3158'
git switch 'github-bot/gh-3158'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3158'
git switch 'github-bot/gh-3158'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3158'
git switch 'github-bot/gh-3158'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3158'
git switch 'main'
git merge --squash 'github-bot/gh-3158'
git switch 'main'
git merge --ff-only 'github-bot/gh-3158'
git switch 'main'
git merge 'github-bot/gh-3158'
git push origin 'main'
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!3158
No description provided.