Shaders: lower binary64 scaling with floating-point modes #2743
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!2743
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@andrewpozdnakov7-jpg on GitHub · 2026-11-25 19:27 UTC · original
andrewpozdnakov7-jpg:codex2/ldexp-f64→main· +397 −49 · 3 files · 2 commits · openSummary
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.
@fuzeofficlal on GitHub · 2026-11-25 20:10 UTC · original
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.@oni-swr on GitHub · 2026-11-25 20:15 UTC · original
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).
@kotekompotek on GitHub · 2026-11-25 20:39 UTC · original
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.
@Marvisak on GitHub · 2026-11-25 23:24 UTC · original
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
@HAL9000RELOADED on GitHub · 2026-11-25 23:25 UTC · original
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.
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.