Shaders: lower v_div_scale_f32 and v_div_fmas_f32 #1747
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!1747
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@ESAT586 on GitHub · 2026-11-24 21:54 UTC · original
ESAT586:shader/div-scale-and-fmas-f32→main· +629 −2 · 4 files · 2 commits · openSummary
Lowers RDNA2's f32 IEEE-754 division pre-scale and post-scale instructions — **_div_scale_f32** (VOP3B
@upipibi on GitHub · 2026-11-24 22:19 UTC · original
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.
@rminzao on GitHub · 2026-11-24 23:09 UTC · original
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.@ESAT586 on GitHub · 2026-11-25 00:17 UTC · original
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).)
@Marvisak on GitHub · 2026-11-25 01:35 UTC · original
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
View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.