Shaders: v_fmac_f16 in VOP3 applies abs and neg to its accumulator #3192
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!3192
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@Moon0755 on GitHub · 2026-11-26 11:48 UTC · original
Moon0755:fix/fmac16-accumulator-modifiers→main· +87 −2 · 2 files · 3 commits · openThe 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
@AurumCarlos on GitHub · 2026-11-26 11:57 UTC · original · reviewed
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.@Moon0755 on GitHub · 2026-11-26 12:01 UTC · original
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
@steven-seagull27 on GitHub · 2026-11-26 12:06 UTC · original
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.
@oni-swr on GitHub · 2026-11-26 12:06 UTC · original
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).
@Moon0755 on GitHub · 2026-11-26 12:13 UTC · original
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
@Moon0755 on GitHub · 2026-11-26 12:21 UTC · original
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
@JAEdotUK on GitHub · 2026-11-26 13:00 UTC · original
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.
@Dukestar69 on GitHub · 2026-11-26 13:09 UTC · original · approved these changes
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).
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.