Shaders: lower v_div_scale_f32 and v_div_fmas_f32 #1746
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1747"
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 ESAT586 on 2026-11-24T21:54:12Z.
Summary
Lowers RDNA2's f32 IEEE-754 division pre-scale and post-scale instructions — **_div_scale_f32** (VOP3B
Imported from Marvisak/VIctory. Originally posted by upipibi on 2026-11-24T22:19:02Z.
A note on denormals, from reading the diff (not run).
scale_f32_pow2keeps f32 denormals exactly in both directions. It scales a subnormal input up throughFirstbitHi, and a value scaled down into the subnormal range gets its rounded subnormal. That is RDNA2's behaviour only when the shader's f32 denormal mode keeps denormals.ftzonmain(lower.rsaround 2067) makes them a zero of their sign.v_div_scale_f32on RDNA2 hardware (gfx1036, 2,304 operand rows, every f32 denormal mode, IEEE 0 and 1; recorded in theirdocs/dev/debt/shader.md). In mode 0, which the commonFLOAT_MODE0xc0 selects, and in mode 2, it flushes its inputs. In mode 1 it keeps the inputs and flushes a denormal result to a zero of its sign. Only mode 3 keeps both.So for the usual float mode, passing the operands through
ftzand flushing a subnormal result to a signed zero would match the hardware and the rest of the lowering. The current form matches mode 3. A test with a subnormal numerator, and one with a quotient that scales into the subnormal range, would show the difference.AI-assisted (Claude Code). No game files.
Imported from Marvisak/VIctory. Originally posted by rminzao on 2026-11-24T23:09:15Z.
Double rounding on denormal quotients
The denormal-mode point is already raised above. One more: in
v_div_fmas_f32(lower.rs~6084/6094) the 2^±64 scale is applied after an already-roundedfmad. When the quotient ends up denormal it is rounded twice, so it can be 1 ULP off the hardware's single rounding.valu_tests.rs~1792 allowsmax_ulp = 1for denormal results, which would hide exactly this.Related: this uses FMad (DXIL op 46), which isn't guaranteed to be fused. That's the existing
v_fma_f32shortcut, but here the final correction step relies on the fused result, so it might deserve ashortcut:note like the others.Static review (AI-assisted), read against
mainat70564ae; nothing was run on a GPU.Imported from Marvisak/VIctory. Originally posted by ESAT586 on 2026-11-25T00:17:16Z.
Thanks @upipibi and @rminzao for the sharp RDNA2 denormal-mode and rounding feedback!
Updated this branch to match VIctory's default f32 FTZ mode (
FLOAT_MODE = 0xc0, mode 0) and address both notes:div_scale_f32&v_div_fmas_f32: flush inputs withSelf::ftzand flush subnormal outputs (exp <= 64under2^-64, or unscaled subnormalFMad) to a zero of their sign inscale_f32_pow2, matchinglower.rs'sftzbehavior and RDNA2 mode 0.rdna2_fdiv32_pipeline_with_div_scale_and_div_fmasnow asserts exact bit equality (0ULP) across all cases (removingmax_ulp = 1).shortcut:note: documented thatv_div_fmas_f32uses DXILFMad(op 46), matchingv_fma_f32.qNaN,flag = 0), negative/positive subnormal outputs inv_div_fmas_f32(±0.0), and subnormal-range quotients in the full Newton-Raphson pipeline (±0.0).Re-verified on Windows 11 with NVIDIA GeForce RTX 3060 Ti + Microsoft D3D12 WARP +
dxil.dll:v_div_scale_f32_matches_rdna2,v_div_fmas_f32_matches_rdna2,rdna2_fdiv32_pipeline_with_div_scale_and_div_fmas: 3 passed, 0 failedcargo clippy --workspace --all-targets -- -D warnings&--all-features: 0 warningscargo xtask policy: ok(Clean-room synthetic tests only, zero game data. AI-assisted with Gemini 4 Neon (Extra High Mode).)
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T01:35:38Z.
Automated triage for the maintainers.
Needs rebase. This pull request conflicts with
main(conflicting:crates/victory-shader/src/structure.rs). It will be reviewed once it is rebased onto the currentmain.Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T03:39:22Z.
Review: COMMENTED
Shaders: lower v_div_scale_f32 and v_div_fmas_f32 — merge conflict with main (
940d32f69b), verified locally. Also overlaps #200 (same v_div_scale/v_div_fmas lowering, plus v_div_fixup). Rebase needed; will re-test.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.