Shaders: f16 results ignore their output modifier, as RDNA2 does with half denormals kept #2913
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2915"
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 0xkn0wh3r3 on 2026-11-25T23:52:53Z.
What
A VOP3 f16 result with an output modifier (×2, ×4 or ×0.5) is now translated with the modifier ignored. The clamp still applies, in f32, and the result is rounded to a half once, as before. On main these programs are refused with "an output modifier on a 16-bit operation".
This covers
float_result(the f16 VALU operations andv_cvt_f16_f32), the exactly roundedv_fma_f16path, andhalf_modifiers(v_interp_p2_f16), which on main multiplied the interpolated half by the modifier.Why: the ISA rule
AMD's RDNA2 ISA reference guide (30 November 2020), §6.2.2 "Instruction Outputs", p. 44:
The same section says output modifiers are also ignored when the IEEE mode bit is set. §6.4, Table 24 (p. 47) gives MODE bits [7:6] as the "Double/Half-precision denormal mode", so f16 shares its denormal setting with f64.
The translator's float model (header of
emit/semantics_tests.rs) is IEEE mode off, 32-bit denormals flushed, 16- and 64-bit denormals kept. With f16 output denormals kept, the hardware ignores the output modifier on an f16 result, so the result is the same as with OMOD 0. CLAMP is a separate field and still applies.If a title's program ran with f16 denormals flushed, the modifier would apply. The translator assumes the fixed mode, as it does for the rest of the float model.
Where it came from
Started from DexNom's fork, DexNom/VIctory@570a941, which applied the modifier in
float_result. Credited withCo-authored-by: DexNom. Following the triage, the change now follows the ISA guide and ignores the modifier.Tested
valu_tests::f16_results_ignore_their_output_modifier, on the hardware adapter and WARP:v_add_f16of 1.5 and 0.25 gives 1.75 under each of the three modifiers, and 1.0 withdiv:2plus clamp (0.875 if the modifier applied).v_mul_f16andv_fma_f16(1.5 × 0.25 + 0) give 0.375 undermul:2. On main each of these programs is refused.emit::tests::interpolated_f16_writes_the_op_sel_half_with_modifiersnow checks thatv_interp_p2_f16withmul:2and clamp has the clamp but no ×2 in the DXIL.output_mods()) are all f32 operations.cargo test -p victory-shader --lib(withVICTORY_DXILset todxil.dll): 299 passed, 3 ignored. The 3 failures also fail on main on this machine: twostride_testsandgathers_at_a_level_match_the_hardware.heap_direct_texture_reads_mark_their_heap_indexwas skipped because it crashes.cargo clippy -p victory-shader --all-targets -- -D warnings: clean.cargo xtask policy: ok (emit/lower.rsis 520,268 bytes).Not tested
Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T23:54:28Z.
Review: COMMENTED
Verified: omod factors [1,2,4,0.5] applied as an f32 multiply before clamp and the single half-rounding matches
half_modifiers' interpolation semantics exactly — and the test arithmetic checks (1.75: x2=3.5, x4=7, x0.5=0.875, clamp 7->1.0; mul 0.375x2=0.75). The old refusal becomes unreachable dead weight no more. LGTM.Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T23:59:17Z.
Review: COMMENTED
Verified head
dcf36ffbcleanly onorigin/main(63bcca43) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + D3D12 WARP + Windows SDK 10.0.26100.0dxil.dll).Code & Semantics Review
float_result(crates/victory-shader/src/emit/lower.rs:6986-6997) appliesomod(2.0/4.0/0.5) on thef32intermediate, thenclamp(Saturate), thennarrow16(RNE or RTZ permode16), matchinghalf_modifiersandwrite_fwithout double-rounding or prematuref16overflow.INT),v_pk_*(packed16), and RNEv_fma_f16(TwoSumpath) continue to explicitly rejectv.omod != 0, whilev_cvt_f16_f32andFLOAT1/FLOAT2/FLOAT3route cleanly throughfloat_result.emit/lower.rsis520,848B (+285 B vs63bcca43,3,440B below the 512 KiB policy cap).Local Verification
victory-shadertests (valu_tests::f16_results_take_their_output_modifier_then_clamp,emit::lower::tests,emit::semantics_tests,emit::tests::interpolated_f16_writes_the_op_sel_half_with_modifiers) on RTX 5090 + WARP +dxil.dll: 69/69 passed (1 pre-existing ignored).cargo clippy --locked -p victory-shader --all-targets -- -D warnings(default and--all-features) &cargo xtask policy(191 files ok): clean.Looks clean and ready to merge.
Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-26T00:05:42Z.
Local verification on Windows / rustc 1.100.0 / MSVC, no game data, no clippy/rustup.
842b0cb: 3 files, +35/-4. Negative control:f16_results_take_their_output_modifier_then_clampis absent from the base commit.cargo test --locked -p victory-shader --lib -- emit::valu_tests::f16_results_take_their_output_modifier_then_clamp --exact --quiet-> 1 passed (GPU/WARP harness, no game files).cargo test --locked -p victory-shader --lib -- emit::valu_tests --quiet-> 36 passed, 0 failed, 270 filtered out.git diff --checkflags one trailing whitespace in README.md line 17 (displayed.); worth removing before merge.AI-assisted (Hy4 flash).
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T02:22:33Z.
Automated triage for the maintainers.
Needs work, but close. Thanks for finding the reference. The ISA rule you quote (RDNA2 §6.2.2: output modifiers are ignored when output denormals are enabled) is the evidence we asked for.
de177bdfollows it infloat_result, thev_fma_f16path andhalf_modifiers(emit/lower.rs): the clamp still applies in f32, the modifier is dropped, and there is a single rounding to half. CIcheckpasses.One gap left. The rule depends on the program's f16 denormal mode, and the translator assumes that mode instead of reading it. The mode a program starts in comes from the FLOAT_MODE field of its RSRC1 register (
native.rsalready readsCOMPUTE_PGM_RSRC1for the VGPR count).s_denorm_modeis accepted and ignored inir.rs. A compiler would also normally only emit an f16 output modifier when f16 denormals are flushed, because otherwise the modifier does nothing. So the programs that actually carry one may well be the ones where the hardware applies it. Please read the f16/f64 denormal bits from FLOAT_MODE:s_denorm_mode/s_setregof MODE[7:6]: refuse, asmaindoes.A count of how many of the title's f16-omod programs fall into each case would settle it.
Generated by Claude Code
[PR #2915] Shaders: an f16 result takes its output modifierto [PR #2915] Shaders: f16 results ignore their output modifier, as RDNA2 does with half denormals keptImported from Marvisak/VIctory. Originally posted by 0xkn0wh3r3 on 2026-11-26T07:34:25Z.
Thanks. The public RDNA2 ISA guide settles this, and it points the other way from what the PR did.
Evidence. AMD RDNA2 ISA Reference Guide (30 Nov 2020), §6.2.2 "Instruction Outputs", p. 44: "if output denormals are enabled, then output modifiers are ignored." The same paragraph says they are also ignored with IEEE mode set. §6.4 Table 24 (p. 47) puts half precision in the same denormal field as double (MODE[7:6]).
Reasoning. The translator's float model (
emit/semantics_tests.rsheader) is IEEE mode off, 32-bit denormals flushed, 16- and 64-bit denormals kept. So f16 output denormals are enabled, and the hardware ignores OMOD on an f16 result: the result is as if OMOD were 0. CLAMP is a separate field and still applies. If a title's program ran with f16 denormals flushed, OMOD would apply. The translator assumes the fixed mode, as it does for the rest of the float model.What changed (
de177bd3). f16 VALU results (float_result, including the exactly roundedv_fma_f16path) now translate with OMOD ignored: no multiply, clamp in f32, one rounding to half. On main these programs are refused; the earlier PR head applied the modifier. The test is nowf16_results_ignore_their_output_modifier. Itsdiv:2+ clamp case tells the two readings apart (1.0 if OMOD is ignored, 0.875 if it applies). It passes on the hardware adapter and WARP.half_modifiers(v_interp_p2_f16). On main it applied OMOD to the f16 interpolation result. No hardware-sourced test pins that: the semantics probes that use output modifiers are all f32 operations, andinterpolated_f16_writes_the_op_sel_half_with_modifiersis a DXIL-structure check from an audit. So I changed it the same way (clamp only), and that test now asserts there is no ×2 in the DXIL.I haven't counted how many of the title's programs this unblocks. I can't run the title.
Imported from Marvisak/VIctory. Originally posted by Lyrnc on 2026-11-26T18:52:45Z.
The RDNA2 hardware check this PR's "Not tested" asks for, on gfx1036: with f16 denormals kept, f16 results ignore the output modifier, and
clampstill applies. The PR matches the hardware on every row below, on an AMD and an NVIDIA host.Setup.
v_add_f16,v_mul_f16andv_fma_f16withmul:2,mul:4anddiv:2;v_add_f16 div:2 clamp;v_mul_f16 mul:2 clamp;v_cvt_f16_f32withmul:2anddiv:2; and the three plain operations.±0, denormals,0x0400,±1,1.5,0.25,0x7bff,±inf, NaNs) against1.0,-0or themselves; some f32 values for the conversion; random halves.build_valu_cs, on that Radeon and on an RTX 5080 (driver 610.88), one adapter at a time with a local switch.PC RDNA2 silicon, not the console's GPU. No game data.
gfx1036, low halves:
mul:2/mul:4/div:2on add, mul, fmaclampv_cvt_f16_f32mul:2of 1.5div:2 clampof1.0 + 1.0is0x3c000x3e00(1.5)0x3e001.0 + 1.0gives0x4400withmul:2,0x3c00withdiv:20x4200(3.0)So the rule in §6.2.2 holds for f16 results,
v_cvt_f16_f32included: the output modifier applies only with IEEE off and f16 denormals flushed. The high half of D is written as 0 in every case.Translator, rows that differ (of 132), the same on the Radeon and the 5080:
main63bcca4de177bd)NaN payloads aside, which differ the same way in the plain forms: the hardware keeps a signalling NaN (
0x7c01 + 1.0 = 0x7c01), while the Radeon host quiets it (0x7e01) and the 5080 writes0x7fff. I ran the PR on a local merge with #1327 and #3124, which touch other code.For the mode reading the triage asks for, the hardware gives three cases. With f16 denormals kept, the modifier is ignored (this PR). With them flushed and IEEE off, it applies (the earlier head's code). With IEEE on, it is ignored whatever the denormal mode, so the IEEE bit of RSRC1 matters as well as FLOAT_MODE[7:6].
AI use: Claude Code (Claude Opus 5.5) wrote the probe and ran it on the GPUs above; the numbers come from those runs.
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.