Shaders: honor FP32 rounding when packing a byte #1839
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1841"
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 AlanQiang0418 on 2026-11-24T23:13:33Z.
A shader that switches FP32 rounding upward expects packing 0.5 into the low byte of 0xAABBCCDD to produce 0xAABBCC01. Main produces 0xAABBCC00 on both an RTX 5080 and WARP. The four rounding modes have been measured on RDNA2. Native hardware measurements
The existing control-flow pass now tracks the four rounding bits in MODE together. Literal bitfield writes update only the selected bits. A join keeps bits on which the incoming paths agree.
v_cvt_pk_u8_f32uses the FP32 field to round before saturating and inserting the result into the destination byte. Unknown rounding at runtime still uses nearest-even. The pack follows the translator's existing assumption of flushed FP32 inputs. Explicit denormal-preserve modes remain outside this change.Verification
cargo clippy -p victory-shader --all-targets --locked -- -D warningsand the staged asset-policy check passed.This extends the mode coverage discussed in #1804. Coordination claim. AI-assisted implementation and testing using synthetic programs.
Full-suite comparison
Both Clippy configurations passed in Actions. The new join test, the extended byte-packing test and the existing FP16 mode test passed there. The full shader suite had the same two failures as CI on the exact base commit, in the explicit-level gather and lane permute tests. The PR run had 208 passed, 2 failed and 2 ignored, compared with 207 passed, 2 failed and 2 ignored on the base. PR CI · Base CI
I also ran the full shader crate locally, serially, on both revisions. The same three tests failed on both revisions here: the two heap-buffer stride tests and the explicit-level gather test. This branch had 207 passed, 3 failed and 2 ignored. The base had 206 passed, 3 failed and 2 ignored.
Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T23:52:16Z.
Review: APPROVED
Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (
70564ae), cargo test -p victory-shader --locked → 119 passed, 0 failed. GPU execution tests are #[cfg(all(test, windows))] and run only on Windows.FP32 rounding honored when packing a byte: cvt/pack rounding-mode fix — matches DXBC pack semantics.
Imported from Marvisak/VIctory. Originally posted by upipibi on 2026-11-24T23:20:47Z.
Ampere run alongside your RTX 5080 one: RTX 3070 8 GB, driver 616.56, plus WARP, Windows 11, debug,
ee2cf26(onmain70564ae).cargo test -p victory-shader --locked: 207 passed, 3 failed, 2 ignored. The new rounding cases insemantics_testspass, and the 3 failures are #1744's NVIDIA heap-cap failures onmain.AI-assisted (Claude Code). Synthetic tests only.
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T07:25:28Z.
Automated triage for the maintainers.
Needs rebase. This PR no longer merges cleanly into
main:mainhas moved since the last triage, and the branch now conflicts incrates/victory-shader/src/emit/lower.rs. It will be reviewed again once it is rebased onto currentmain.Previous verdict for this head: merge candidate.
Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-25T12:14:52Z.
Offline measurement on a retail dump
Result: no count change against
main.I merged head
ea1f55f4ontomain940d32f(clean merge) and ranvictory translate --validate --listonshaders.rpf(1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result withmainprogram by program (25,889 programs). Validated: 23,918 onmain, 23,918 with this PR.No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right.
No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T23:55:13Z.
Review: APPROVED
LGTM — verified
rustfmton the changed hunks,cargo xtask policy,cargo clippy(--all-targetsand--all-features),emit::lower::tests(34 passed, includinga_join_preserves_the_rounding_field_its_paths_agree_on),emit::valu_testson hardware (35 passed), andemit::semantics_testson both hardware and WARP (34 passed, 1 pre-existing ignored, including the expandedbyte_packing_matches_the_hardware).Checked
RoundModes(MODE[3:0]per-bit join and partials_setreg_imm32_b32updates),v_cvt_pk_u8_f32(round_ne/round_pi/round_ni/round_z+[0.0, 255.0]clamp + NaN->0), and the updated test assertions: existing nearest-even and NaN/saturation checks are intact (r as u8saturates and maps NaN to0), and all four FP32 rounding modes plus partialMODEwrites now match hardware.Two small non-blocking notes:
RoundModes::after(lower.rs:327) only treatsOperand::Literalas constant, so as_setreg_b32with an inline constant (Operand::Const) clears the written field's known bits and falls back to nearest-even (same documented fallback as conflicting joins).byte_packing_matches_the_hardwarecurrently leavessrc0abs/negmodifiers untested on GPU.Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-27T20:15:17Z.
I tested this PR at
2e06840with #35929a62538on63bcca4. The merge keeps the FP32 rounding analysis and the Bfi insertion from their original commits. Integration branch2137695An additional synthetic compute matrix checked 1,024 inputs per WARP path across the four rounding modes, all four byte positions with and without the high selector bits set, and two destination words. Both harness paths used app-local WARP 1.0.22 and the CPU reference checked the whole destination dword.
mainThe original 250-tuple byte-pack test, rounding-field join test, FP16 rounding test and all three tests from #3592 passed. The default-mode fixture still emits 25 DXIL instructions. Strict shader Clippy and the asset policy passed. The extra matrix was local. AI-assisted with Codex.
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.