Shaders: support clamp output modifier on v_cvt_pkrtz_f16_f32 #1339
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1339"
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 AscilCH on 2026-11-24T17:33:08Z.
Bug
In
crates/victory-shader/src/emit/lower.rs,v_cvt_pkrtz_f16_f32(VOP2 0x2f/VOP3 0x12f) finished withint(self, r)→write_i(), which rejects the VOP3clampoutput modifier withUnsupported { what: "integer output modifiers" }.On RDNA2 (GFX10.3),
v_cvt_pkrtz_f16_f32supportsclamp, saturating both convertedf16lanes to[0.0, 1.0](withNaN → +0.0) while preserving round-toward-zero semantics for values in(0.0, 1.0).Reproduction (Before Fix)
Lowering a synthetic RDNA2 compute shader with
v_cvt_pkrtz_f16_f32_e64 ... clamp:Fix
v.omodexplicitly, saturate bothf32operands viadx.op.unary.f32(Saturate)whenv.clampis set before callingf16_toward_zero(), and write the packedu32directly viaself.write(inst, Reg::V(reg), r, guard).dxil.dlltestemit::valu_tests::v_cvt_pkrtz_f16_f32_supports_clamp_and_rtzcovering unclamped RTZ/overflow/infinity/subnormal values, clamped[0.0, 1.0]/NaN/infinity/sub-ULP values, and VOP3abs/neginput modifiers.Verification
Tested on Windows 11, NVIDIA RTX 3050 6GB Laptop GPU, WARP, and Windows SDK
dxil.dll:rustfmt --edition 2024 --checkonvalu_tests.rs: cleancargo xtask policy:154 files okcargo clippy --workspace --all-targets --locked -- -D warnings: cleancargo clippy --workspace --all-targets --all-features --locked -- -D warnings: cleancargo test -p victory-shader --locked -- v_cvt_pkrtz_f16_f32_supports_clamp_and_rtz --nocapture --test-threads=1: passed (hardware + WARP +dxil.dll)VICTORY_WARP=1 cargo test -p victory-shader --locked -- --test-threads=1:121 passed, 0 failed, 1 ignoredImported from Marvisak/VIctory. Originally posted by marquezinii on 2026-11-24T18:33:50Z.
Ran on an RTX 5070 (desktop, driver 621.40, the only adapter), Windows 11 26300, Rust 1.98.1 at
b686bcc.cargo test -p victory-shader --lib -- --test-threads=1 --nocapturegives 121 passed, 0 failed, 1 ignored.v_cvt_pkrtz_f16_f32_supports_clamp_and_rtzpasses on the hardware adapter and WARP.Clamping in f32 before the round-toward-zero conversion gives the same result as clamping after it: 0 and 1 are exact in f16, and DXIL
Saturatemaps NaN to +0, which matches your table.Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T20:09:58Z.
Review: APPROVED
Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (
ffe310e), cargo test -p victory-shader --locked → 96 passed, 0 failed. Execution/valu tests are #[cfg(all(test, windows))] and only run on Windows; macOS covers lowering/structure/IR unit tests.Supports the clamp output modifier on v_cvt_pkrtz_f16_f32 (and rtz); v_cvt_pkrtz_f16_f32_supports_clamp_and_rtz.
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T01:23:10Z.
Automated triage for the maintainers.
Needs rebase. This pull request conflicts with
main(conflicting:crates/victory-shader/src/emit/valu_tests.rs). It will be reviewed once it is rebased onto the currentmain.Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-25T01:48:53Z.
Offline measurement on a retail dump, and the shader tests on Ada
Result: no count change against
main.Offline. I merged head
b686bccontomainffe310e(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: 21,724 onmain, 21,724 with this PR.No program changes its failure reason either. That is the expected result for a fix whose instructions sit behind the earlier failures on
main. The count shows that the change rejects nothing. It does not show whether the output is right.Tests: with the same merge,
cargo test --locked -p victory-shader --libpassed 121, failed 0. The bitcode benchmark is ignored, as onmain, where 120 pass. The run was on an RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter, withVICTORY_WARPunset.No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-28T18:08:44Z.
I resolved the rebase conflict in the test file and replayed your commit on current main (
63bcca4). Rebase 954e814 retains AscilCH's Git authorship and the original clamp/RTZ test alongside the tests added to main.If #3773 lands first, combined 62ab0dd preserves both exact PR heads. The literal fold runs for the unclamped conversion. Clamped operands go through the original saturation and RTZ path.
On WARP 1.0.22 the author's clamp/RTZ regression passed on both branches. All 5,005 generated output words matched across 455 modules, including the 32 added clamped-literal modules. All 66 control modules were byte-identical, including those 32. The unclamped literal modules kept the emitted instruction savings. Strict all-feature shader Clippy and the asset policy passed on both exact trees.
AscilCH can take the rebase for the PR or use the combined branch if the literal change lands first. The next step after that is maintainer review. Please retain both Git authors when taking the combined change, or add
Co-authored-by: andrewpozdnakov7-jpg <[email protected]>if folding my part into another commit.AI-assisted with OpenAI 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.