shader: implement v_cvt_f32_f64 instruction lowering #416
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!416
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@bitzin-dev on GitHub · 2026-11-24 03:08 UTC · original
bitzin-dev:shader/v-cvt-f32-f64→main· +198 −2 · 4 files · 1 commits · openThis 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
@jeremygold02 on GitHub · 2026-11-24 04:37 UTC · original
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.@upipibi on GitHub · 2026-11-24 05:30 UTC · original
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.
@Lyrnc on GitHub · 2026-11-24 06:26 UTC · original
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.
@slint6614-dev on GitHub · 2026-11-24 10:16 UTC · original
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.@fuzeofficlal on GitHub · 2026-11-24 13:48 UTC · original
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.@bitzin-dev on GitHub · 2026-11-24 15:34 UTC · original · edited 2026-11-24 15:39 UTC
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.
@Marvisak on GitHub · 2026-11-25 00:16 UTC · original
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
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.