shader: implement v_cvt_f32_f64 instruction lowering #416
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/416"
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 bitzin-dev on 2026-11-24T03:08:38Z.
This PR implements lowering for the RDNA2 VOP1 opcode
v_cvt_f32_f64(0x00f) converting double-precision 64-bit float registers into 32-bit single-precision floats.Changes
Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T05:41:19Z.
Review: APPROVED
Tested
7516f94on Windows 11, RTX 5070, MSVC:cargo test --workspace --no-fail-fastpasses (265 passed, 0 failed). The newcvt_f32_f64_matches_rdna2passes on hardware and WARP.victory translate <title exe> --validate --pipelinesgives the same counts before and after: 12 of 12 programs emitted, 12 validated, 12 pipelines. None of these use the new opcode.Checked the encodings against LLVM 3.7 bitcode:
TYPE_CODE_DOUBLE= 4.CAST_FPTRUNC= 7.ShaderFlagsbit 2 is EnableDoublePrecision, and SFI00x1is Doubles. Neither collides with the existingflagsconstants.Not blocking: the PR description lost characters (
itcode.rs,lags::DOUBLES,_cvt_f32_f64,loat,alu_tests.rs). A NaN case would also be a useful addition to the test (a quiet NaN payload truncated to f32).AI-assisted (Claude Code).
Imported from Marvisak/VIctory. Originally posted by jeremygold02 on 2026-11-24T04:37:37Z.
Thanks @bitzin-dev for adding
v_cvt_f32_f64lowering. I tested head7516f947b2e5d92c42b557b90459a0ba3265132bwith:Result: 70 passed, 0 failed, 0 ignored. The new
cvt_f32_f64_matches_rdna2case covers normal and edge f64 inputs, including negative zero and pi; the full suite also exercises bitcode/container generation and shader lowering. This run does not measure console hardware behavior.Imported from Marvisak/VIctory. Originally posted by upipibi on 2026-11-24T05:30:16Z.
One gap in
7516f94, from reading the code (not run):v_cvt_f32_f64reads its source withsrc64(lower.rs:3789), the 64-bit integer reader. Registers are fine, but constants aren't:_arm, which zero-extends the 32-bit float bits. For a 64-bit float operand they stand for the double: 1.0 is0x3FF0000000000000. Sov_cvt_f32_f64 v0, 1.0reads0x000000003F800000, a denormal double, and gives 0.0 instead of 1.0;0.5,-2.0and1/(2π)likewise.0x40000000should be 2.0. Zero-extended it's the low dword, a tiny denormal, and gives 0.0.Compilers usually fold these, but here they're silently wrong rather than refused. Options: a double source reader that maps 240–248 to the double encodings and puts a literal in the high dword, or refuse float constants and literals for this opcode until one exists. A test with
1.0and a literal would pin it.AI-assisted (Claude Code), read-only review.
Imported from Marvisak/VIctory. Originally posted by Lyrnc on 2026-11-24T06:26:47Z.
RDNA2 hardware measurement of
v_cvt_f32_f64, as a reference for whatfptrunchas to match: round to nearest even, with the f32 denormal mode deciding denormal results and NaNs quieted with their top payload bits.Setup. AMD Radeon iGPU of a Ryzen 7 9800X3D, gfx1036 (RDNA2), AMD driver 32.0.21042.62, Windows 11 Pro 26200. Hand-written instructions in a HIP kernel (assembled by the AMD driver's amd_comgr). RDNA2 desktop silicon, not the console's. No game data. 32 doubles, each under f32 denormals kept / flushed, f64 denormals kept / flushed, and round-to-nearest / toward-zero.
0x3ff0000010000000(1 + 2^-24, tie)0x3f8000000x3f8000000x3ff0000030000000(1 + 3·2^-24, tie)0x3f8000020x3f8000010x47effffff0000000(just over FLT_MAX)0x7f8000000x7f7fffff0x3800000000000000(2^-127)0x004000000x000000000x004000000x36a0000000000000(2^-149)0x000000010x000000000x000000010x36a8000000000000(1.5·2^-149)0x000000020x000000000x000000010x37a16c262777579c(1e-40)0x000116c20x000000000x000116c20x7ff0000000000001(sNaN)0x7fc000000x7ff4000000000000(sNaN, payload)0x7fe000000x7ff8000020000000(qNaN, payload)0x7fc000010xfff8000000000000(-qNaN)0xffc000000x400921fb54442d18(π)0x40490fdb0x40490fda0x7fc00000 | sign | payload >> 29.Things to check against the host's
fptrunc: D3D lets the f32 result flush denormals (the first four bold rows, if the console runs with f32 denormals kept), and NaN payloads may not survive. Your test's normal values, ±0 and π are rows where the host and the hardware agree.AI use: Claude Code (Claude Opus 5.5) wrote the probes, ran them on the GPU above and drafted this comment; the numbers come from the hardware run.
Imported from Marvisak/VIctory. Originally posted by slint6614-dev on 2026-11-24T10:16:43Z.
AMD hardware check, Windows 11, Adrenalin driver: RX 9070 (RDNA4) and Ryzen 9600X iGPU (RDNA2, gfx1036), each picked as the hardware device of
run_cases(local adapter-selection patch, not part of this PR);cargo test -p victory-shader --release valu_testsat the PR head. Negative control: the PR's non-test files reverted to its merge base, its new tests kept.cvt_f32_f64_matches_rdna2pass on both AMD GPUs.Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T13:19:32Z.
Review: COMMENTED
Test-merge with current main (
ffe310e) conflicts — needs a rebase. Main moved recently (PR #566 waterfall loops touchedlower.rs/resource.rs/valu_tests.rs), so shader PRs opened before it need rebasing. I'll re-review once it merges cleanly.Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-24T13:48:22Z.
On
7516f94, the register-pair cases pass, but I reproduced two operand decoding errors with synthetic shaders on Windows hardware. FP64 inline operand240(0.5) and the literal high dword0x40080000(3.0) both read back as0.0.Follow-up commit uses DXIL
MakeDoublewith the two source words, decodes the FP64 inline constants and high-word literals per the RDNA 2 ISA, section 6.2.1, and applies e64 source sign modifiers before conversion. Output scaling and clamp use the existing float write path.All four focused tests passed on the hardware adapter and WARP, with 25 readbacks on each. They cover register pairs, inline constants, literals including signed zero, and e64 modifiers on finite inputs. The
victory-shadersuite passed all 73 tests.Imported from Marvisak/VIctory. Originally posted by bitzin-dev on 2026-11-24T15:34:27Z.
Thanks everyone for the extensive testing, hardware traces and reviews! Special shoutout to @upipibi and @fuzeofficlal for pointing out and testing the FP64 inline constant & high-dword literal mappings.
Rebased on upstream main (fe310e) and updated the PR head (
16d2166):eg) on the high word before conversion.
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:16:37Z.
Automated triage for the maintainers.
Needs rebase. This PR does not merge cleanly into current
main(ac2525d). Conflicting files:crates/victory-shader/src/emit/valu_tests.rs.The content has not been reviewed yet; it will be once the branch is rebased onto
main.Generated by Claude Code
upstream-sync referenced this pull request2026-11-25 02:05:53 +00:00
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.