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

Open
Moon0755 wants to merge 1 commit from upstream-pr/3158 into main
Moon0755 commented 2026-11-26 10:30:11 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Moon0755 on 2026-11-26T10:30:11Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:issue:6624659207 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3158). Originally posted by [Moon0755](https://github.com/Moon0755) on 2026-11-26T10:30:11Z. --- ### 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
Dukestar69 commented 2026-11-26 11:03:52 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T10:50:53Z.

Review: APPROVED


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

<!-- greyfinch-sync:Marvisak/VIctory:review:6072806151 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3158#pullrequestreview-6072806151). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T10:50:53Z. **Review:** APPROVED --- 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).
cloph-dsp commented 2026-11-26 11:04:03 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-26T10:40:11Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7189673436 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3158#issuecomment-7189673436). Originally posted by [cloph-dsp](https://github.com/cloph-dsp) on 2026-11-26T10:40:11Z. --- 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 commented 2026-11-26 11:04:03 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-26T10:44:08Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7189763822 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3158#issuecomment-7189763822). Originally posted by [oni-swr](https://github.com/oni-swr) on 2026-11-26T10:44:08Z. --- 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.
JAEdotUK commented 2026-11-26 13:04:34 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by JAEdotUK on 2026-11-26T12:51:08Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7192544663 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3158#issuecomment-7192544663). Originally posted by [JAEdotUK](https://github.com/JAEdotUK) on 2026-11-26T12:51:08Z. --- 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 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/3158:upstream-pr/3158'
git switch 'upstream-pr/3158'

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/3158'
git switch 'upstream-pr/3158'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3158'
git switch 'upstream-pr/3158'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3158'
git switch 'main'
git merge --squash 'upstream-pr/3158'
git switch 'main'
git merge --ff-only 'upstream-pr/3158'
git switch 'main'
git merge 'upstream-pr/3158'
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
Marvisak/VIctory!3156
No description provided.