Shaders: lower binary64 scaling with floating-point modes #2741
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2743"
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 andrewpozdnakov7-jpg on 2026-11-25T19:27:17Z.
Summary
Lower RDNA 2 V_LDEXP_F64 by adjusting and rounding its binary64 significand and exponent in two 32-bit words. Both register pairs and signed 32-bit scale operands use their normal routes. The translation requires neither host doubles nor int64.
The existing MODE analysis now also tracks the FP16/FP64 denormal field. Scaling handles all four rounding and denormal modes when they are known at translation time. The shader entry uses nearest-even rounding and preserves binary64 subnormals, matching the documented AMDHSA defaults. RDNA 2 ISA · AMDGPU kernel descriptor defaults
Verification
13f91ca, each of the three synthetic shaders fails translation with Unsupported v_ldexp_f64.Coordination claim
Please retain the Git author if cherry-picking or rebasing this commit. If folding it into another commit, add Co-authored-by: andrewpozdnakov7-jpg [email protected].
AI-assisted. Verification used synthetic shaders.
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T20:10:44Z.
Reviewed and verified
99161fd6on Windows 11 (RTX 5090 + WARP + Windows SDK10.0.26100.0dxil.dll) againstmain(13f91ca).Code review
v_ldexp_f64(noDOUBLE/INT64shader capability required).scale_source_wordsappliesabsthennegon the high word, rejectssrc1modifiers andclamp/omod/sdwa/dpp, placesLiteralin the high word, sign-extends inline negative integers, promotes inline floats (with248=0x3fc4_5f30_6dc9_c882), preserves±0.0/±Inf, and quietenssNaNwhile retaining payload.powerto[-4096, 4096]avoids signed overflow withi32::MIN/i32::MAX.FpMode16tracks bothMODE[3:2]rounding andMODE[7:6]FP16/FP64 denorm modes cleanly and explicitly refuses unknown/conflicting modes at CFG joins; subnormal input flush vs.FirstbitHinormalization, cross-wordFirstbitLosticky rounding inround_scaled_subnormal, carry-out from max subnormal to min normal before output flush, and overflow rounding (±Infvs.±f64::MAX) all check out.Verification (Windows 11, RTX 5090 + WARP +
dxil.dll)cargo test --locked -p victory-shader --lib --features host emit::tests: 17/17 passed;emit::lower::tests: 27/27 passed;emit::valu_tests(excluding slow exhaustive tests): 29/29 passed (all 3ldexp_f64_*tests pass on both RTX 5090 and WARP).VICTORY_WARP=1 cargo test --locked -p victory-shader --lib --features host ldexp: 3/3 passed.cargo clippy --locked -p victory-shader --all-targets -- -D warnings(default &--features host): 0 warnings;cargo xtask policy: 185 files ok.git merge-treeagainst13f91ca,#2713, and#2728.Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-25T20:15:42Z.
Independent WARP/CPU verification for head
99161fd6feagainst origin/main13f91caee2. State check at start and again before posting: open, non-draft, mergeable, head unchanged; no prior oni-swr comment.Environment: Windows 11 x64, Rust 1.98.1 (48a229cea 2026-09-01), cargo 1.98.1, Windows SDK dxil.dll 10.0.26100.0 (file version 1.8.2502.11).
VICTORY_WARP=1andVICTORY_D3D12_WARP=1set (WARP only, no physical GPU); no game files.CARGO_TARGET_DIR=D:\victory-warp-2741-target. Tested commit: the PR head itself, which is exactly one commit on top oforigin/main(merge-base =origin/main, so no temporary merge was needed). In victory-shader's host testsVICTORY_WARP=1makes both the "hardware" and "warp" labels run on WARP (Host::new), so no physical GPU was used.Commands/results:
cargo test --locked -p victory-shader— 267 passed, 3 failed, 3 ignored. Pre-existing failures on main:emit::synthetic_tests::a_mask_joined_with_data_at_a_uniform_loop_is_its_number,gathers_at_a_level_match_the_hardware,permutes_read_the_lane_named_and_zero_from_lanes_left_out.cargo clippy --locked -p victory-shader --all-targets -- -D warnings— pass.cargo test --locked -p victory-shader --lib ldexp_f64— 3/3 passed.cargo test --locked -p victory-shader— 270 passed (+3), the same 3 failed (identical names to baseline, so no new failure), 3 ignored.cargo clippy --locked -p victory-shader --all-targets -- -D warnings— pass."v_ldexp_f64"arm removed -> all 3 new tests FAILED. Round-up direction inverted (1 => negative) ->ldexp_f64_uses_the_round_mode_for_underflow_and_overflowFAILED, the other two passed. Subnormal-result flush disabled (if false) ->ldexp_f64_uses_the_denormal_mode_for_both_operands_and_resultsFAILED, the other two passed. So each of the three tests pins a different part of the lowering.Review: no correctness blocker found in the inspected paths. The MODE tracker now follows bits 3:2 and 7:6 independently, joins disagreeing paths to unknown, and
v_ldexp_f64refuses (Err) when either mode is unknown instead of guessing; the test also asserts the SFI0 doubles/int64 feature bits are clear, which is a good guard for the no-native-double goal. Subnormal rounding (sticky across the dword boundary, carry into the minimum normal, flush only if the result is still subnormal), overflow by round mode, NaN quieting and power clamping are all covered by cases. Scope notes:clamp,omod, SDWA, DPP and abs/neg on the exponent operand are rejected as unsupported (explicit errors, not silent); the lowering is only checked against hand-written expected bit patterns, not against a hardware reference, and the new files are not rustfmt-formatted (neither is most of main, so not counted against it).Not tested: physical GPU, retail title/game behavior, release build (debug profile only).
AI disclosure: Claude Code (Claude Sonnet 5.5).
Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T20:39:36Z.
The FpMode16 refactor is the right shape: INITIAL matches the shader-entry convention (nearest-even, preserve subnormals both ways), the s_setreg field overlap check (offset<=start && end>=start+2) handles partial-field writes correctly, and tracking round/denorm independently unblocks ldexp's denorm handling. ldexp_f64 normalizes subnormal inputs by scaling before exponent adjust - the standard approach. Heads up on merge order: #2782's s_getreg reads self.mode16 as Option; whichever lands second needs mode16.round.
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T23:24:40Z.
Automated triage for the maintainers. This adds a lowering for
v_ldexp_f64incrates/victory-shader/src/emit/lower/ldexp.rsusing only 32-bit integer ops, and replacesround16inemit/lower.rswithFpMode16, which tracks MODE bits 3:2 (round) and 7:6 (FP16/64 denorm) on their own. I checked the subnormal normalization (FirstbitHi counted from the MSB), the right shift into subnormal units with sticky bits across the dword boundary, the directed and nearest-even rounding, the flush rules for the RDNA2 denorm field (bit 0 input, bit 1 output), overflow to Inf or max-finite by round mode, NaN quieting, and the 64-bit literal and inline-constant handling. Things to note: the entry assumption that subnormals are preserved comes from the AMDHSA defaults, not from the title's own shader float mode, and #2782 readsmode16asOption<u8>, so whichever lands second needsmode16.round. CI:checkpassing. This is a recommendation for a maintainer to look, not an approval.Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by HAL9000RELOADED on 2026-11-25T23:25:47Z.
First Radeon run of
177f0e5: RX 7900 XTX (RDNA3), driver 32.0.32015.7029, Windows 10 22H2 (19045), Agility SDK 1.620 in the shader test binaries through #486. Base:481d699(main842b0cb+ #486).victory-shader: 304 passed, 1 failed. The three new tests pass on the card:ldexp_f64_scales_normal_and_subnormal_values,ldexp_f64_uses_the_denormal_mode_for_both_operands_and_resultsandldexp_f64_uses_the_round_mode_for_underflow_and_overflow.pops_wait_loop_exits_immediately_for_inactive_lanes, which wants an SM 6.6 WARP device (this Windows 10 WARP reports SM 6.2). It fails the same way on the base without this PR.So the lowered binary64 scaling, denormal and round modes included, matches on RDNA3 hardware as well as on the RTX 5090 and WARP.
Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T04:07:41Z.
Review: APPROVED
Tested merged onto
origin/main(63bcca4) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP,dxil.dllvalidator active):cargo test -p victory-shader --lib emit::valu_tests::ldexp: 3 passed, 0 failed (ldexp_f64_scales_normal_and_subnormal_values,ldexp_f64_uses_the_denormal_mode_for_both_operands_and_results, andldexp_f64_uses_the_round_mode_for_underflow_and_overflowpass on both RTX 5090 hardware and WARP).cargo clippy -p victory-shader --all-targets -- -D warnings: clean.cargo xtask policy: 192 files ok.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-27T01:33:02Z.
Review: APPROVED
Looks good — verified locally at
177f0e52:cargo xtask policy(192 files ok) andcargo clippy --all-targets --all-features -- -D warningspass with 0 warnings.emit::valu_tests::ldexp_f64passes 3/3 on both RTX 5090 (VICTORY_WARP=0) and WARP (VICTORY_WARP=1), verifyingSFI0 & 0x8001 == 0, all 4 rounding modes, and all 4 denormal modes.(Non-blocking notes):
round16_after, the whole-wave section loop (lower.rsaroundfor j in i + 1..end { self.section_inst(b, j, i); }) jumpsi = end; continue;without advancingself.mode16 = self.mode16.after(&p.blocks[b].insts[j]). Advancingself.mode16inside that loop keeps intra-blockmode16tracking consistent withfp_modes16if as_round_mode/s_denorm_modeappears inside a section.rustfmt --edition 2024 --checkflags minor line-wrapping diffs incrates/victory-shader/src/emit/lower/ldexp.rsand the added lines inlower.rs/valu_tests.rs.Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-27T09:17:23Z.
460bea6 tracks the input and output denormal bits independently and processes MODE writes through whole-wave sections.
The new synthetic test exercises both directions. Clearing MODE bit 7 alone preserves a subnormal input that scales into the normal range, and flushes a subnormal result. Clearing bit 6 inside a whole-wave section flushes a subnormal input and still preserves a subnormal result. Both negative cases check the sign bit. The first partial write failed to lower on
177f0e5with unknown floating-point modes. All fourldexp_f64tests passed on the updated head with WARP 1.0.22, as did strict all-features shader Clippy and asset policy.I also tested #2743, #2791 and #2782 together on current main. The integration uses the same separate bits for
ldexpandsqrt, and reads the rounding field fors_getreg_b32. All 46 VALU tests passed on WARP, plus strict shader Clippy and asset policy. The branch keeps the three published PR heads.AI-assisted with Codex. Synthetic shaders only.
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.