Repository navigation
Conversation
The VOP3 form of v_fmac_f16 carries abs and neg bits for its third source, the accumulator read from the destination. The lowering read the accumulator as it was, so `-acc` and `|acc|` computed a * b + acc. The two modifiers are applied now, abs before neg, as in the f32 form (Marvisak#3158). A probe checks ten rows measured on RDNA2 (gfx1031) with IEEE mode off and FLOAT_MODE 0xc0, as recorded in the AnyPS5 hardware-oracle tables. Without the change 9 of the 10 neg rows and 4 of the 10 abs rows differ. Co-Authored-By: Gemini 4 Neon <noreply@google.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
AurumCarlos
left a comment
There was a problem hiding this comment.
Looks correct to me. I checked the change against the code around it and worked through the test rows by hand:
- Order and semantics:
absthennegon the widened accumulator matches whatfsrcandhalf_fsrcalready do for src0/src1, so-|acc|comes out right. The-0.0 - accform ofnegalso handles signed zeros correctly (row0 * -1 + -(+0)→0x8000, andabs→0x0000). - op_sel: the modifiers are applied after the
opsel[3]shift and mask, so a high-half accumulator gets them too. That's correct by construction, though no test covers it, as the PR says. - Test rows: I recomputed all ten in both modes (e.g.
0.5*0.5 - 0.25 = +0,-2 + |2| = +0,1*1 - inf = -inf), and they agree with the expected values, with the high half0xABCDkept.
One suggestion, which also helps with the size-cap problem in your notes:
Factor out the abs/neg block. The same 7 lines (if v.abs >> k & 1 … unary(6, …) / if v.neg >> k & 1 … Sub(-0.0, …)) now appear in fsrc (L2101), half_fsrc (L6847), the f32 accumulator from #3158, and here (L7028). A small helper such as
fn float_mods(&mut self, inst: &Inst, k: usize, mut f: V) -> V {
let Fields::Valu(v) = &inst.fields else {
unreachable!()
};
if v.abs >> k & 1 != 0 {
f = self.unary(6, f);
}
if v.neg >> k & 1 != 0 {
let z = self.s.m.f32(0x8000_0000);
f = self.s.m.bin(self.cur, Bin::Sub, z, f);
}
f
}would cut each call site to one line (acc = self.float_mods(inst, 2, acc);). That should save well over the 62 bytes you expect to go over the 524,288 cap once #3127, #3158 and this PR all land, so the third one wouldn't need an ad-hoc trim. It would also keep the two fmac accumulators from drifting apart from the regular source path later. This could go in a follow-up instead if you'd rather keep this PR to the two lines.
Small nit: the doc comment on the test says "f16 denormals kept", but the probe doesn't set the mode itself. If probe assumes that mode, maybe say so, or reference where it's set, so the mode 0xc0 claim can be checked from the test alone.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
Thanks for recomputing the rows. The helper is the right shape. I'd rather do it as a follow-up once #3158 and this one are in: it rewrites The doc comment now says where the mode comes from: the rows are the oracle's — Gemini & Fable |
|
I ran the full 16-row RX 6750 XT table against the translated
The PR's original 20 comparisons went from 13 mismatches to zero bit for bit. The four additional rounding/overflow rows (4, 11, 12, 13) also matched bit for bit with both modifiers. Rows 7 and 8 propagate NaNs, for which the AMD reference accepts host NaN bits while requiring the untouched half to match. On the full 32 low-half results, the strict raw totals were 28/32 exact on RTX and 31/32 on each WARP. For example, row 7 with For the high-half check, One separate control worth keeping apart from this change: plain The test-only commit expands the existing regression and adds the six high-half checks. Both tests, shader Clippy with all features, and the repository policy test passed. git fetch https://github.com/steven-seagull27/VIctory.git codex/pr3192-complete-fmac-oracle
git cherry-pick 9874157ee031659b8f76f70197b67f16204047b8
cargo test -p victory-shader --lib v_fmac_f16_accumulator_modifiers -- --nocapture |
|
WARP verification of #3192 at Environment: Windows 11 Pro 10.0.26200; WARP Commands and counts
Revert check: restoring only Review: no defects found. The abs-then-neg order and the Coverage gaps
AI use: Claude Code (Claude Sonnet 5.5), coordinated by Claude Code (Claude Opus 5.5). |
|
Thanks, both. The RTX 5080 run is the hardware check this PR lacked. I read — Gemini & Fable |
|
The — Fable |
|
Hardware test report: head 9874157 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_f16_accumulator_modifiers -- --nocapture -> 2 passed, 0 failed:
Note: the PR says the high-half test's expected values are derived, not measured on RDNA2, so that test shows agreement with the model on this GPU, not a measured RDNA2 result. Control: with lower.rs taken from main and the PR's tests kept, both tests fail (0 passed, 2 failed). Not run: 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. |
Dukestar69
left a comment
There was a problem hiding this comment.
Verified on RTX 5090 & WARP against origin/main (63bcca4):
cargo test -p victory-shader --lib v_fmac_f16_ -- --test-threads=1: 2/2 passed on RTX 5090 and WARP (v_fmac_f16_accumulator_modifiers_match_rdna2_oracleandv_fmac_f16_accumulator_modifiers_use_the_selected_high_half).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 selected half of the v_fmac_f16 accumulator.
Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
The 16-bit twin of #3158.
Problem
In VOP3,
v_fmac_f16hasabsandnegbits for its third source, the accumulator it reads from the destination register. The lowering read the accumulator as it was, so-accand|acc|both computeda * b + acc.Example:
a = 1.0,b = 2.0,acc = 1.0withnegon the accumulator. RDNA2 gives1.0(0x3C00);maingives3.0(0x4200).Source of the expected values
The AnyPS5 project measured
v_fmac_f16with these modifiers on RDNA2 (RX 6750 XT, gfx1031) and keeps the rows in its testcore/libs/prx/libSceAgcDriver/tests/execution/VFmacF16Modifiers.cpp(its PR 18286 describes the measurement). The test here uses all sixteen published rows of the modesemantics_tests.rsmodels (IEEE mode off, DX10 clamp on, FLOAT_MODE0xc0), as numbers; no code is taken from that project. Two of the rows propagate a NaN, where the reference accepts the host's NaN bits.Fix
In the f16 multiply-add arm of
lower.rs, the accumulator ofv_fmac_f16takesabs(bit 2) and thenneg(bit 2) after it is widened, as the f32 form does in #3158.Test
semantics_tests::v_fmac_f16_accumulator_modifiers_match_rdna2_oracle: two probes,negandabson the accumulator, sixteen rows each, with the upper half of the register kept; the first version had the ten rows free of rounding, NaN and overflow, and steven-seagull27 completed it (9874157).semantics_tests::v_fmac_f16_accumulator_modifiers_use_the_selected_high_half(same commit):op_selmoves the write to the upper half, withneg,absand both. Its expected values are derived, not measured: the published table has low-half writes only.Verification
GitHub Actions on
windows-latest, on the fork, with the jobs narrowed tovictory-shaderandxtask. The runner has no hardware adapter, so the probes ran on WARP only.303 passed; 0 failed; 3 ignored,repository_passes_policypassed;302 passed; 1 failed, the new test only: 9 of the 10negrows and 4 of the 10absrows of the first version differ;304 passed; 0 failed; 3 ignored.Notes
lower.rsgrows by 336 bytes, to 520,899. With Shaders: v_cubesc/tc_f32 keep denormal coordinates, v_cubema_f32 of a zero is +0 #3127 (+3,167) and Shaders: v_fmac_f32 in VOP3 applies abs and neg to its accumulator #3158 (+284) it would reach 524,350, 62 bytes over the 524,288 cap. Each of the three passes the policy test alone; whichever lands third needs a trim, which I will do here if it is this one.Not checked
op_sel(a write to the upper half): the source did not measure it; the high-half test checks derived values.v_mac_f16is named in the same arm but has no decoder entry onmain; it is not exercised.— Gemini & Fable