Shaders: lower v_cvt_f32_f64 #2348
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!2348
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2348"
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?
@Calvix2k on GitHub · 2026-11-25 11:18 UTC · original
Calvix2k:codex/shader-cvt-f32-f64→main· +128 −13 · 4 files · 3 commits · openThree of the compute shaders this title's frame runs once per frame —
5dc3b259…,6f225b64…,926c46ba…, the shape of full-screen post-processing passes — do not translate, and the reason isv_cvt_f32_f64:What the fix does
The VGPR pair is read as 64 bits (
src64), bitcast to adouble, and truncated with the host'sfptrunc— round to nearest even, which is MODE's default for 64-bit ops. MODE's toward-zero mode has no DXIL form and is refused by name rather than mis-rounded.The IR had no 64-bit float type, so it gains
double(bitcode type 4) and thefptrunccast (LLVM opcode 7); a module that uses it declares the doubles feature — SFI00x1and the module feature-info bit 2. Both are needed: without the feature-info bitdxil.dllsaysFlags must match usage, and without the SFI0 bit the container no longer matches the module.Verification
a_64_bit_value_converts_to_f32_round_to_nearest: ten cases run on the card (Windows 10 / RX 7800 XT, SM 6.6 through the Agility runtime for the test binaries) and checked against Rust'sas f32— 1.0, −2.5, 0.1, a tie that rounds to even, the two smallest subnormals (→ 0), f64 max (→ inf), ±inf, and a NaN (a NaN out with a payload). WARP here tops out at SM 6.2, so hardware is the device exercised; the DXIL is validated bydxil.dll.cargo test -p victory-shader --lib: 248 passed, 0 failed, 3 ignored;clippy -D warningsclean.@DrDarkDK on GitHub · 2026-11-25 11:46 UTC · original
I checked the
f32output underflow boundary on91fa9ddwith an RTX 4070 Ti (621.01) and WARP. All 16 synthetic inputs matched the round-to-nearest-even reference bit for bit on both adapters.The smallest and largest
f32subnormals survived with both signs. At the positive zero-to-subnormal boundary,2^-150rounded to0x00000000, and the next binary64 value above it rounded to0x00000001. The negative cases preserved the sign bit.This extends the existing underflow-to-zero cases to inputs that must produce a nonzero subnormal. Default rounding only. No game data used.
AI-assisted with Codex.
@Calvix2k on GitHub · 2026-11-25 12:19 UTC · original
Third hardware vendor, and the boundary cases are the ones I wanted checked:
2^-150to zero and the next value up to the smallest subnormal (0x00000001) is exactly where a naivefptrunc-free conversion would be wrong, and the sign-preserving negatives close it.For the record, the AMD result on the same head (
91fa9dd) matches: the ten synthetic cases (including the two smallest subnormals, f64 max at ±inf bounds and a NaN) are bit-for-bit against Rust'sas f32on the RX 7800 XT, and WARP tops out at SM 6.2 here so it skips. Your WARP run is the one that covers the software path on a device that can take SM 6.6.@tyr0nsur on GitHub · 2026-11-25 13:37 UTC · original
Two source-authored cases exposed operand and rounding issues while integrating this revision. On an RTX 4060, a literal operand of
0xC0020000represents the high word of binary640xC002000000000000(−2.25). The current path returned f32 bits0x00000000. Placing the literal in bits 63:32 and zeroing the low word returned the expected0xC0100000. The register-pair control already worked. AMD RDNA 2 ISA §6.2.1 describes the literal convention.The
mode16 == Some(3)guard also admits positive-infinity rounding, negative-infinity rounding and a dynamically written mode, although the subsequentfptruncstill uses nearest-even. We now accept onlySome(0)for this lowering. Our regression sets the two DP rounding bits withs_setreg_imm32_b32for each directed mode and usess_setreg_b32for an unknown value. Both tests are independent of the underflow boundary cases covered above.@Calvix2k on GitHub · 2026-11-25 14:07 UTC · original
Both findings hold, and both are fixed in
6f8acac:The literal source. You are right that a literal in a 64-bit operand is the high word of the binary64:
src64reads a literal as the sign-extended integer its bits are, which is correct for 64-bit integer operands and wrong here. The lowering handles the literal itself now — zero-extend the literal, shift it into bits 63:32, low word zero — anda_64_bit_literal_source_is_the_high_wordruns exactly your case (0xC0020000→0xC0100000) on the card, so the convention is pinned by a test rather than by the comment.One detail that fell out of it: the literal form builds the 64 bits with integer shifts, so the module has to declare the 64-bit integer feature as well (
dxil.dll: "Flags must match usage" otherwise). That is set with the float feature now.The mode check. Tightened to
mode16 == Some(0): directed (1, 2), toward-zero (3) and a mode written at run time (None) are refused by name. Thank you for thes_setreg_imm32_b32/s_setreg_b32regression — that is the case mySome(3)check would have let through as "nearest even", which is exactly the silent mis-rounding this PR exists to avoid.Lib suite after both: 249 passed, 0 failed, 3 ignored (the new literal case included); clippy clean. If your two regressions are on top of
6f8acacthey should now pass unchanged; if either still fails I would like the case, since it would mean a third convention.@Marvisak on GitHub · 2026-11-25 15:30 UTC · original · edited 2026-11-25 22:22 UTC
Automated triage for the maintainers.
Needs rebase. This PR no longer merges cleanly into
main(conflicts incrates/victory-shader/src/emit/lower.rsandemit/valu_tests.rs). It will be reviewed again once it is rebased.From the earlier needs-work note, still open: refuse or apply VOP3
abs/negon the new literal and inline-constant arms ofv_cvt_f32_f64(they bypasssrc64), ideally with a test.Generated by Claude Code
@Calvix2k on GitHub · 2026-11-25 16:05 UTC · original
The gap is fixed in
f956a66(rebased ontomain 67e8ae1):v_cvt_f32_f64now maps inline float constants 240-248 to the binary64 of the same value (0.5, -0.5, 1.0, -1.0, 2.0, -2.0, 4.0, -4.0, 1/(2π)) and builds the bits with an integer constant, instead of zero-extending the f32 pattern throughsrc64.a_64_bit_inline_constant_source_is_the_same_valueconverts code 242 (1.0) and expects 1.0; on the old code it got 0.One note on verification: this Windows 10 machine's test harness reaches SM 6.5 on hardware and 6.2 on WARP (no Agility opt-in in the test binary), so the GPU-backed cases skip locally and CI runs them; local
cargo check --all-targetsand clippy are clean.@zed6000 on GitHub · 2026-11-26 02:04 UTC · original
Measured offline on the title's shaders (the method in #1247): head
f956a66merged ontomain63bcca4. It conflicts in two places, both "keep both": yourv_cvt_f32_f64arm next tomain's newv_cvt_f32_u32arm inlower.rs, and the tests at the end ofvalu_tests.rs.The result is 0 gained, 0 lost. Exactly 5 programs change, all compute shaders, and they are the only ones on
mainthat refuse withemit: v_cvt_f32_f64. With this PR they get past the conversion, then stop at:emit: a whole-wave section step the simulation does not followI added a local diagnostic at that refusal, and it says why. The values the conversion needs come out of whole-wave sections that are 64-bit float wave reductions:
v_add_f64steps over register pairs, fed by the usual DPP /v_permlanex16/v_readlanemoves on both halves.emit/wave.rsonly models 32-bit (and 16-bit) operations, so it leaves everyv_add_f64result unknown. The same programs also have wave64 f32 reductions whose results come out unknown, possibly only downstream of those.So on this title, the conversion counts only once the whole-wave simulation can follow an f64 add over lane pairs, giving a
Redover a 64-bit value that lowers to a doubleWaveActiveSum/prefix. That's the next step for these 5 programs, whichever of #2348 / #416 / #1262 lands. Offline counts only; no program names or data.@Anzymanz on GitHub · 2026-11-26 02:04 UTC · original
From a tester working with Claude (AI-assisted, Claude Code): #2978 stacks on this PR. In this title the five programs that stop at
v_cvt_f32_f64convert a double that comes out of a whole-wave section (aWaveActiveSumof a double). With this PR alone they stop one step later, at that section. #2978 follows the section, so one of the five translates and the other four move on to a lane-mask join. In case it saves you time: on main63bcca4this PR conflicts inlower.rs(main splitv_cvt_f32_u32into its own arm; keep main's arm and add yours before it) and invalu_tests.rs(two tests added at the same place; keep both). #2978's branch has it resolved that way: https://github.com/Anzymanz/VIctory/commits/wave-f64-sums@Anzymanz on GitHub · 2026-11-26 02:32 UTC · original
Passing on a review finding from #2978 (which stacks on this PR), since it's in this PR's code: @fuzeofficlal notes that in
v_cvt_f32_f64theOperand::Const(240..=248)andOperand::Literal(_)arms return beforeself.src64(...), sov.abs/v.neg(andsdwa/dpp) aren't checked for those sources. A VOP3v_cvt_f32_f64_e64 v0, -1.0would drop thenegsilently. Refusing modifiers in those two arms (assrc64_dwordsdoes) or applying them would cover it. Details in their review on #2978. (AI-assisted, Claude Code.)@zed6000 on GitHub · 2026-11-26 02:33 UTC · original
An addition to my note above: I missed that #2978 (stacked on this PR, linked by Anzymanz above) already models exactly that step, the binary64 sums in whole-wave sections. I measured it on
main63bcca4. #2978 alone gives +1, 0 lost. #2978 + #385 + #1065 gives +766, 0 lost, and all 5 programs that refuse withemit: v_cvt_f32_f64onmainvalidate. Details, including a keep-both conflict with #385 and a test that fails only on the built-in WARP, are on #2978.@steven-seagull27 on GitHub · 2026-11-26 04:13 UTC · original
Confirmed the source-modifier issue reported by @fuzeofficlal and @Anzymanz on
f956a66. On RTX 5080 and Windows inbox WARP10.0.26100.10068,absof the high-word literal0x80000000returned f32 −0 instead of +0, andnegof inline +0.5 returned +0.5. Of 96 synthetic input/modifier combinations, 45 reached dispatch on the PR and 14 of those returned incorrect bits on each adapter. Nine modified shader forms (51 inputs across VGPR, SGPR and inline integer zero) stopped during lowering. Original review findingCherry-pick
5b841a2on this PR head applies ABS then NEG to the binary64 sign bit before truncation. All 96/96 matched on each adapter, covering all four modifier combinations, both signed zeros, infinities, finite rounding boundaries, inline constants, high-word literals and register pairs. The three existing conversion tests passed too. SDK DXIL validation andcargo clippy -p victory-shader --all-targets -- -D warningspassed.The same commit cherry-picks cleanly onto the #2978 stack. Its three wave-sum readback tests, including the full-width sparse-mask regression, passed on RTX 5080 and app-local WARP 1.0.22. The combined stack also passed
xtask policy. Full-width wave testFor the outstanding main conflict, fast-forward
1790222adds the fix and merges63bcca43while keeping your original commits. Its tree matches #2978’s rebased parent plus the modifier fix. I reran the modifier regression and all three existing conversion tests on this version as well.f956a6699etofd01035095@DenRakEiw on GitHub · 2026-11-25 11:25 UTC · original · approved these changes
Verified against
origin/main(940d32f) on Windows 11 + NVIDIA GeForce RTX 5090 and WARP:v_cvt_f32_f64viadoublebitcast +FpTruncwithflags::FLOAT64and PSV feature bit0x1, refusing toward-zero mode (mode16 == Some(3)).cargo test -p victory-shader a_64_bit_value_converts_to_f32_round_to_nearest: 1/1 passed on RTX 5090, 1/1 passed on WARP.cargo clippy -p victory-shader --all-targets -- -D warnings: 0 warnings.cargo xtask policy: 183 files ok.AI-assisted (Gemini 4 Neon).
@catminou4 on GitHub · 2026-11-25 11:51 UTC · original · approved these changes
Tested locally: merged into main
940d32f69b,cargo test -p victory-shader --lockedon macOS arm64 — 144 passed, 0 failed, 2 ignored (Windows-gated hardware execution tests not run here). Approving — v_cvt_f32_f64 lowered.@Xvania7 on GitHub · 2026-11-25 11:54 UTC · original · approved these changes
Static review and local verification of
91fa9dd:v_cvt_f32_f64todx.op.unary(80, ...)/fptruncto floatemit::lower::tests::(21 passed)cargo clippy -p victory-shader --all-targets -- -D warnings: 0 warningscargo xtask policy: 182 files okApproving.
@Calvix2k on GitHub · 2026-11-26 13:53 UTC · original
Rebased on today's main. Upstream's dedicated
v_cvt_f32_u32arm is kept,u32is dropped from the shared arm, and thev_cvt_f32_f64arm now sits before it. Both tests are kept.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.