shader: lower the f64 conversions to and from f32, i32 and u32 #101
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/101"
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 uiliannn/VItoriaBr. Originally posted by lcg007xd-c on 2026-11-25T22:51:00Z.
What is broken
The f64 conversions decode, but a program using one fails to translate with
v_cvt_f64_f32 is not supported(or the matching name):v_cvt_f64_f32v_cvt_f64_i32v_cvt_f64_u32v_cvt_i32_f64v_cvt_u32_f64Only
v_cvt_f32_f64lowers today. It is built on the bits, without host doubles (f64_to_f32_bits), and these now follow the same approach.Semantics (AMD's RDNA2 ISA, §12.8, opcodes 3, 4, 16, 21, 22)
The change (
emit/lower.rs)f32_to_f64_bits: rebiases a normal f32. A denormal is normalized from its leading one (DXILFirstbitHi). Zero and infinity carry over. A NaN keeps its payload and comes out quiet.i32_to_f64_bits: the magnitude's leading one becomes the implicit bit, with exponent1054 − lz.|i32::MIN|= 2³¹ is handled as unsigned.f64_bits_to_i32: the 53-bit significand is shifted right by1075 − ein i64. Below 1 the result is 0. 2³¹ and up (signed) or 2³² and up (unsigned), infinities included, saturate. Negatives give 0 for the unsigned form, and NaN gives 0.DOUBLESfeature. The f64→int path usesINT64.Tests
emit::lower::tests::f64_conversions_translate(every host): all five decode, and a program that stores the result translates (for an f64 result, its high dword). Without thelower.rschange it fails:v_cvt_f64_f32 [7e0a2101, 7e000306]: GFX10 code at 0x24: v_cvt_f64_f32 is not supported.valu_tests::f64_conversions_match_ieee(Windows/GPU): both dwords of each to-f64 conversion for 8 inputs (0, 1,i32::MIN, −1/u32::MAX, 1.5f, a denormal, inf, a pattern). The from-f64 conversions get 14 inputs (±0, ±2.9, thei32/u32edges just inside and outside, ±inf, NaN, tiny), checked against Rust'sas, which has the same truncate/saturate/NaN→0 rule.lli. I compared both dwords against Rust'sf64::fromon 96 inputs (including f32 denormals and a signalling NaN, which comes out quiet as on x86), and againstason 81 f64 values. All match.Run here (Linux, Rust 1.98.1):
cargo test -p victory-shader --lib --locked: 188 passed, 0 failed, 2 ignored.CARGO_FEATURE_PURE=1 cargo clippy -p victory-shader --all-targets --target x86_64-pc-windows-msvc -- -D warnings: clean.Not run here: the GPU case, since I have no Windows machine.
🤖 Generated with Claude Code
Imported from uiliannn/VItoriaBr. Originally posted by lmouz823-lang on 2026-11-27T14:59:02Z.
I can take the native Windows/NVIDIA validation of the two conversion tests at exact head
9e19fa0973b6239e06fbbb6746fb61ec627aef95:f64_conversions_translateandf64_conversions_match_ieee. I will run the unmodified head first on an RTX 4060 Laptop (8 GiB, driver 610.88), Windows 11/MSVC, with the SDK DXIL validator and strict test mode; I will report hardware and WARP execution and the tested input limits here.AI-assisted with Codex.
Imported from uiliannn/VItoriaBr. Originally posted by lmouz823-lang on 2026-11-27T15:04:50Z.
Completed native Windows/NVIDIA validation on the unchanged head
9e19fa0973b6239e06fbbb6746fb61ec627aef95. Both exact tests pass:Environment: Windows 11 build 26200, RTX 4060 Laptop 8 GiB, driver 610.88, Rust 1.98.1 MSVC.
VICTORY_STRICT_TESTS=1;VICTORY_WARPunset;VICTORY_DXILexplicitly set to the Windows SDKdxil.dll1.8.2502.11. WARP is the additional backend exercised by the test; the physical NVIDIA adapter also executed. No device skips were printed. The helper's validator-loading branch remains optional; this reports the explicit configuration and actual GPU result, not a change to that helper.Commands, in an isolated worktree after a package-only rebuild of
victory-shaderto avoid reusing another worktree's shared target artifact:This checks the five conversion instructions and the authored input set (76 result-word comparisons per backend). It does not establish AMD behavior, source-register overlap cases, or all conversion boundary cases. No source patch was needed; I did not run the game or the full workspace suite.
AI-assisted validation with Codex.
Pull request closed