Shaders: lower v_cvt_f32_f64 #2346
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/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?
Imported from Marvisak/VIctory. Originally posted by Calvix2k on 2026-11-25T11:18:51Z.
Three 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.Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T11:25:18Z.
Review: APPROVED
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).
Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T11:51:54Z.
Review: APPROVED
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.Imported from Marvisak/VIctory. Originally posted by Xvania7 on 2026-11-25T11:54:11Z.
Review: APPROVED
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.
Imported from Marvisak/VIctory. Originally posted by DrDarkDK on 2026-11-25T11:46:05Z.
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.
Imported from Marvisak/VIctory. Originally posted by Calvix2k on 2026-11-25T12:19:55Z.
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.Imported from Marvisak/VIctory. Originally posted by tyr0nsur on 2026-11-25T13:37:28Z.
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.Imported from Marvisak/VIctory. Originally posted by Calvix2k on 2026-11-25T14:07:00Z.
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.Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T15:30:06Z.
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
Imported from Marvisak/VIctory. Originally posted by Calvix2k on 2026-11-25T16:05:26Z.
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.Imported from Marvisak/VIctory. Originally posted by zed6000 on 2026-11-26T02:04:02Z.
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.Imported from Marvisak/VIctory. Originally posted by Anzymanz on 2026-11-26T02:04:48Z.
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-sumsImported from Marvisak/VIctory. Originally posted by Anzymanz on 2026-11-26T02:32:21Z.
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.)Imported from Marvisak/VIctory. Originally posted by zed6000 on 2026-11-26T02:33:36Z.
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.Imported from Marvisak/VIctory. Originally posted by steven-seagull27 on 2026-11-26T04:13:47Z.
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.Imported from Marvisak/VIctory. Originally posted by Calvix2k on 2026-11-26T13:53:15Z.
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.Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-27T12:58:28Z.
@Calvix2k I tested Steven's source-modifier fix on the rebased PR head (
fd01035, which already contains current main63bcca4). Cherry-pick 757b196 applied cleanly and retains Steven's Git authorship.On
fd01035, his unchanged regression fails on the first modified register pair during lowering:64-bit operand modifiers. The cherry-pick passes all 96 cases on app-local WARP 1.0.22, including both register types, inline constants, high-word literals and all four ABS/NEG settings. All 39 VALU tests passed with SDK DXIL validation enabled. Shader Clippy with all targets, all features and warnings denied passed, as did the asset check.The commit is ready for this PR, after which #2978 can pick it up from the parent. Thanks @steven-seagull27 for the fix and regression.
AI-assisted with Codex. Synthetic compute shaders only.
Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-27T15:38:02Z.
The red CI job at
fd01035failed inframe::tests::waits_end_on_ticks_and_count_frames, at the zero-timeout origin poll. It returned S_OK (0) where the test expected TIMEOUT (1). The failingframe.rsis byte-identical tomainat63bcca4.I tested that issue separately in combined branch
7997261, which carries Steven's conversion fix from757b196and #2877's deterministic clock tests. All three frame tests passed in 25 isolated processes, using three test threads in each. All 39 VALU tests passed on app-local WARP 1.0.22 with DXIL validation, including the 96 conversion cases. Strict Clippy and asset policy passed.The clock change stays in #2877. The original
757b196commit is still available to take on its own for the conversion review.Imported from Marvisak/VIctory. Originally posted by pablogonz12 on 2026-11-27T17:26:43Z.
I checked two affected programs offline on an RX 9070 XT with RADV. With this PR applied to current main, both move past the
v_cvt_f32_f64refusal, but both then stop at a whole-wave simulation step; pipeline creation remains 0/2 before and after. This confirms progress on the conversion refusal, not end-to-end pipeline success. Not tested on NVIDIA hardware.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.