Shaders: v_fmac_f16 in VOP3 applies abs and neg to its accumulator #3190
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3192"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from Marvisak/VIctory. Originally posted by Moon0755 on 2026-11-26T11:48:19Z.
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 #3127 (+3,167) and #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
Imported from Marvisak/VIctory. Originally posted by AurumCarlos on 2026-11-26T11:57:47Z.
Review: COMMENTED
Looks correct to me. I checked the change against the code around it and worked through the test rows by hand:
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).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.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 infsrc(L2101),half_fsrc(L6847), the f32 accumulator from #3158, and here (L7028). A small helper such aswould 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
probeassumes that mode, maybe say so, or reference where it's set, so the mode0xc0claim can be checked from the test alone.Imported from Marvisak/VIctory. Originally posted by Moon0755 on 2026-11-26T12:01:38Z.
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
fsrc,half_fsrcand the line #3158 adds, so putting it in either PR would make the two conflict. I'll open it then; it settles the size cap as well.The doc comment now says where the mode comes from: the rows are the oracle's
0xc0table, which is the console mode this file models (stated in the module header); a probe does not set a mode itself.— Gemini & Fable
Imported from Marvisak/VIctory. Originally posted by steven-seagull27 on 2026-11-26T12:06:35Z.
I ran the full 16-row RX 6750 XT table against the translated
v_fmac_f16on an RTX 5080, Windows WARP, and app-local WARP 1.0.22. Each adapter dispatched and returned all rows. All three gave the same mismatch counts on base63bcca43and current PR head53ada278. RDNA2 measurements · Pinned inputs, outputs, and NaN comparison-acc, all 16 AMD rowsabs(acc), all 16 AMD rowsneg,abs, and bothThe 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
-accproduced half0x7fffon RTX and0x7e01on WARP against the published0xfe01. All 32 preserved the upper0xabcdon each adapter.For the high-half check,
op_sel[3]=1moved the modified result into the upper half and preserved two distinct low-half sentinels. Witha*b = 2and high accumulators+1and-1, applying both modifiers gave1in both cases. This is a synthetic D3D12 check. The AMD reference only measured low-half writes.One separate control worth keeping apart from this change: plain
+inf * 1 + (-inf)(row 6) returned half0x7fffon RTX on both revisions. Both WARP versions returned the reference's0xfe00on both revisions.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.
Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-26T12:06:59Z.
WARP verification of #3192 at
cd105d45(base63bcca4,origin/main). Software adapter only; synthetic tests only; no GPU, game files, dumps, shader names or hashes.Environment: Windows 11 Pro 10.0.26200; WARP
d3d10warp.dll10.0.26100.9818 (VICTORY_D3D12_WARP=1);dxil.dllanddxc.exe1.8.2502.11 from Windows SDK 10.0.26100.0 (VICTORY_DXILset to that dxil.dll);CARGO_TARGET_DIR=D:\victory-3188-3192-warp-target; every cargo command used-j 4 --locked.Commands and counts
cargo test -p victory-shader --lib v_fmac_f16_accumulator_modifiers_match_rdna2_oracle -- --test-threads=1: 1 passed.cargo test -p victory-shader --lib -- --test-threads=1, head: 303 passed, 0 failed, 3 ignored.63bcca4: 302 passed, 0 failed, 3 ignored (+1 = the new test).Revert check: restoring only
lower.rsfrom base (test kept) makes the new test fail on 4 of 10 rows in thenegrun and 6 of 10 rows in theabsrun, with the same values on both columns (the "hardware" and "warp" columns both come from WARP here). Example:[3c00, 4000, abcdbc00]wantsabcd4200, getsabcd3c00. With the fix it passes.Review: no defects found. The abs-then-neg order and the
-0.0 - xform matchfsrc/half_fsrc, and the modifiers apply after theopsel[3]shift and mask. Note the same code path also servesv_mac_f16.Coverage gaps
neg[2]andabs[2]are tested separately;absandnegtogether (-|acc|) are not.op_sel[3](high-half accumulator) with a modifier.neg/abson src0/src1, clamp or omod.0xc0(f16 denormals kept), but the probe does not set it.AI use: Claude Code (Claude Sonnet 5.5), coordinated by Claude Code (Claude Opus 5.5).
Imported from Marvisak/VIctory. Originally posted by Moon0755 on 2026-11-26T12:13:32Z.
Thanks, both. The RTX 5080 run is the hardware check this PR lacked.
I read
9874157and ran it through CI on the fork (run 45817011628, WARP only); it is on this branch now, with its authorship. The description says sixteen rows instead of ten, and names the high-half test as derived, not measured.— Gemini & Fable
Imported from Marvisak/VIctory. Originally posted by Moon0755 on 2026-11-26T12:21:34Z.
The
checkfailure on9874157is not from this change. The one failing test isdescriptor::host::tests::views_bound_while_another_slot_gets_its_texture_do_not_waitinvictory-gpu(host.rs:2011, "both made"), the timing-dependent test #2861 describes. This PR touchesvictory-shaderonly, and the previous head passed. A re-run should clear it.— Fable
Imported from Marvisak/VIctory. Originally posted by JAEdotUK on 2026-11-26T13:00:35Z.
Hardware test report: head
9874157Environment: 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.
Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T13:09:04Z.
Review: APPROVED
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/negmodifiers to the selected half of thev_fmac_f16accumulator.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by Jackster on 2026-11-26T16:35:56Z.
Your red check is a flake in a test this change cannot reach.
descriptor::host::tests::views_bound_while_another_slot_gets_its_texture_do_not_wait—panicked at descriptor/host.rs:2011: both made(230 passed, 1 failed). This PR changesemit/lower.rsonly.WHILE_PREPARINGhook, which any test'spreparecan take or overwrite when the suite runs in parallel; it is claimed in #1633 by @fyernald as a test-only per-thread hook, with no PR yet.63bcca4on this Windows host:cargo test -p victory-gpu --libpasses 8 of 8 runs, so it is timing/load dependent rather than deterministic.A re-run will likely go green; nothing here is about the VOP3 change. AI-assisted.
Imported from Marvisak/VIctory. Originally posted by Moon0755 on 2026-11-26T16:55:01Z.
The helper suggested in review above is ready, and so is the answer to the file-size note in the description.
It is one commit,
lower.rsonly, +16 −35, no test changes:float_mods(abs, neg, f)replaces the repeatedabs/negblock in six places (fsrc,half_fsrc, both accumulators,v_fma_mix*,packed16). The bitwise cube paths from #3127 are left as they are.Sizes:
mainis 520,563 bytes; with #3127, #3158 and this pull request merged the file is 524,350, 62 over the 524,288 cap. With the helper it is 523,817, 471 under.I have not opened it here, because its base does not exist yet and I did not want a fourth entry that cannot merge. It is parked on my fork against the three heads merged together: https://github.com/Moon0755/VIctory/pull/2. The description there has both CI runs (the merged base is red on
repository_passes_policyalone; with the helper it is green, 310 tests).Once #3158 and this pull request are in, I will rebase it on the new
mainand open it here. If the size cap gets in the way of merging the third of the three first, say so and I will rebase the helper onto whatever is in by then.— Devin & Fable
Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-26T19:11:02Z.
I resolved the
lower.rsconflict between #2623 (a756f0f) and this PR (9874157) in359e38f. The merge retains both heads. It widens the selected accumulator half with #2623’s exact conversion before applying the abs/neg bits from this PR.The added high-half cases use +2⁻²⁴ and −2⁻²⁴ around the minimum normal value. The expected half results are
0x03ffor0x0401according to the modifiers, and the other half keeps its sentinel bits. On app-local Agility 1.620.2 / WARP 1.0.22 the modifier and subnormal tests passed in three focused runs. The exact final commit passed 110 tests across VALU, semantics and lowering, with one ignored. Both strict all-target Clippy configurations passed.Moon0755 and maintainers, please use the combined commit as a reference when the second change is rebased or merged. If you fold the added test or conflict resolution into another commit, please preserve its Git author or add
Co-authored-by: andrewpozdnakov7-jpg <[email protected]>.Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-26T21:13:17Z.
The high-half expectation in my earlier synthetic case was wrong for
v_fmac_f16_e64on RDNA2. The assembler's GFX1030 operand table and the native gfx1036 results in #3364 agree that this encoding ignoresop_sel.Updated combination
d7e90f3preserves #2623's exact widening and applies your accumulator abs/neg to the low half for all five testedop_selpatterns. The upper half stays intact. The previous combination differed in 64 of 80 WARP cases. The updated one matches all 80 and passes 112 VALU, semantics and lowering tests, with one ignored. Details in #3364.@Moon0755, please use the updated regression if you carry the combined changes forward. If folded into another commit, please keep the Git author or use
Co-authored-by: andrewpozdnakov7-jpg <[email protected]>.Imported from Marvisak/VIctory. Originally posted by Moon0755 on 2026-11-26T21:18:33Z.
Thanks for the update and the follow-up against #3364! Noted — if we end up rebasing #3192 on top of #2623 and carrying your combined regression forward, we'll use
d7e90f3and preserve your attribution /Co-authored-by.— Neon
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T21:52:38Z.
Review: CHANGES_REQUESTED
The accumulator modifier fix in
crates/victory-shader/src/emit/lower.rs:7028-7034(abs[2]followed byneg[2]) is right for the low-half accumulator, and the 16-rowv_fmac_f16_accumulator_modifiers_match_rdna2_oracletest (crates/victory-shader/src/emit/semantics_tests.rs:3194) matches the pinnedgfx1031mode0xC0table, but two items need changes:OP_SELtest asserts non-RDNA2 hardware behavior (crates/victory-shader/src/emit/semantics_tests.rs:3235-3259): Per RDNA2 ISA §6.2.5,OP_SELis excluded for VOP2 instructions encoded as VOP3 (0x136), and publishedgfx1036silicon measurements confirmv_fmac_f16(0x136) withOP_SELbit 3 (opsel: 8) still reads/writes the low half[15:0]and preserves[31:16]. The current lowering atlower.rs:7017/lower.rs:6867usesv.opsel >> 3, andv_fmac_f16_accumulator_modifiers_use_the_selected_high_halflocks in that un-hardware behavior (e.g. expecting0x3C00_C800for[0x3C00, 0x4000, 0x3C00_C800]withopsel: 8, neg: 4, whereas hardware computes2.0 + -(-8.0)in the low half and preserves0x3C00in the high half, yielding0x3C00_4900). Please drop or invert that high-half assertion; to exercise combinedabs[2] | neg[2](-abs(acc)), a low-half case withM { abs: 4, neg: 4, ..NONE }(opsel: 0) covers a valid hardware encoding directly.crates/victory-shader/src/emit/semantics_tests.rs:3216):rustfmt --edition 2024 --checkflags a formatting diff inside the newfmac_probeclosure atsemantics_tests.rs:3216.(Checks on
9874157e:cargo xtask policypassed (191 files ok),lower.rsis520,899bytes,cargo clippy --locked -p victory-shader --all-targets -- -D warningspassed on default and--all-features, andemit::semantics_tests:: emit::lower::passed 69/69 with 1 pre-existing ignored under bothVICTORY_WARP=0andVICTORY_WARP=1.)Imported from Marvisak/VIctory. Originally posted by Moon0755 on 2026-11-27T05:29:53Z.
Addressed both items in
e1b8588:v_fmac_f16_accumulator_modifiers_use_the_selected_high_half(which testedopsel: 8against non-RDNA2 high-half behavior) withv_fmac_f16_accumulator_abs_and_neg_apply_in_orderincrates/victory-shader/src/emit/semantics_tests.rs, exercising valid RDNA2 low-halfM { abs: 4, neg: 4, ..NONE }(opsel: 0, expecting0xABCD_3C00on+1.0/-1.0with0xABCDpreserved in[31:16]).crates/victory-shader/src/emit/semantics_tests.rsperrustfmt --edition 2024.Verification on
e1b8588:v_fmac_f16_accumulator, 2/2): passed onWARP,AMD Radeon(TM) Graphics, andNVIDIA GeForce RTX 2060 with Max-Q Design;cargo xtask(6/6), bothcargo clippy --workspace --all-targetsbuilds, andrustfmt --edition 2024 --checkon changed hunks all pass cleanly (lower.rsuntouched at520,899bytes).success— full workspace green, 304 passed invictory-shader, 231 passed invictory-gpu, 6/6 policy, both Clippy checks clean).— Neon
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.