Shaders: lower v_cvt_pknorm_{i16,u16}_{f32,f16} in pure 32-bit DXIL #2098
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2100"
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 geiyiliyabumo on 2026-11-25T04:59:07Z.
Summary
v_cvt_pknorm_i16_f32(0x368),v_cvt_pknorm_u16_f32(0x369),v_cvt_pknorm_i16_f16(0x312), andv_cvt_pknorm_u16_f16(0x313) incrates/victory-shader/src/emit/lower.rsusing pure 32-bit DXIL without enablingInt64/WIDE_OPS.f32clamping ([-1.0, 1.0]->32767.0fori16,[0.0, 1.0]->65535.0foru16), ties-to-even rounding, NaN ->0, VOP3abs/negsource modifiers, andop_selhalf selection for_f16, while rejecting unsupportedclampandomod.crates/victory-shader/src/emit/valu_tests.rscovering boundary values (0.0,-0.0,±1.0,±0.5,±2.0,±inf,NaN),abs/negmodifiers,op_selhalf selection, output modifier rejection, and verifyingInt64is not set.Verification
cargo xtask policy: passedcargo clippy -p victory-shader --tests -- -D warnings: passedcargo test -p victory-shader --lib v_cvt_pknorm -- --test-threads=1with Microsoftdxil.dll: 3/3 passed on AMD Radeon RX 9060 XT (RDNA4) and Microsoft Basic Render Driver (WARP)Imported from Marvisak/VIctory. Originally posted by upipibi on 2026-11-25T05:05:26Z.
Ran on Windows 11 with an RTX 3070 (Ampere, driver 616.56), debug build, at
de026e8.victory-shader: 247 passed, 3 failed, 3 ignored. The newv_cvt_pknorm_rounds_clamps_and_packs,v_cvt_pknorm_honors_source_modifiersandv_cvt_pknorm_rejects_output_modifierspass. The 3 failures are #1744's NVIDIA failures onmain. Same asmainon this hardware.Overlap, from reading: #596 (open, conflicting with
main) lowers the same fourv_cvt_pknorm_{i16,u16}_{f32,f16}instructions with exact rounding.AI-assisted (Claude Code).
Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T05:16:27Z.
Review: APPROVED
Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main
940d32f69b,cargo test -p victory-shader --locked.144 passed / 0 failed / 2 ignored. v_cvt_pknorm_{i16,u16}_{f32,f16} lowered in pure 32-bit DXIL — packed-normalization converts.
Imported from Marvisak/VIctory. Originally posted by Dathinel on 2026-11-25T05:08:49Z.
I replayed two of Lyrnc's native gfx1036 measurements on
de026e8with synthetic VOP3 programs. Set both source registers to the input bits and read back the packed destination. RTX 3050 Laptop and WARP returned the same words:v_cvt_pknorm_i16_f323f7334e6799a799a79997999v_cvt_pknorm_u16_f323e2abaab2aae2aae2aaf2aafThese two inputs would make regression cases for a 32-bit implementation that preserves the native result. Rounding the product to f32 first changes each converted half by one.
For the f16 forms, the 422-input native sample in #596 did not distinguish the rounding rules. I compared both models over all 65,536 half encodings on CPU; only four encodings per signedness distinguish them. If someone still has the native probe, one input covers both forms: put half
0x3801in both sources. For signed/unsigned the exact-product predictions are400f400f/801f801f. This PR returned40104010/80208020on both backends. A native readback of those two words would settle this fixture's expectation.AI-assisted. Synthetic inputs only.
Tested f32-only alternative that keeps Int64 off. After NaN handling and clamping, take the magnitude
mand setPto 32768 (signed) or 65536 (unsigned). In f32, computea = m * Pandq = roundEven(a). The integer magnitude isint(q) - int((a - (q - 0.5)) < m); then restore the sign for SNORM. Keep the subtractions in that order. Scaling by the power of two is exact. The only exact halfway input magnitude is 0.5, for which q is even.I checked every nonnegative binary32 encoding from 0 through 1 against an exact-product reference for each scale. An experimental lowering passed 94 packed readbacks each on RTX 3050 Laptop and WARP, including the two native f32 witnesses above. SFI0 Int64 stayed clear. The same probe failed on the unmodified PR at the first native witness. This experiment leaves the f16 decision open.
Imported from Marvisak/VIctory. Originally posted by steven-seagull27 on 2026-11-25T08:38:16Z.
Confirmed the two packed f32 rounding differences on an RTX 5080 (driver 621.40) at
de026e8418ef97cf3531888e4a77204a86f5e5a6. Built-in WARP 10.0.26100.10068 returned the same words on Windows 11 build 26300.10075.Both adapters passed all 56 round/clamp/pack readbacks and all 8 source-modifier readbacks in the PR. I then ran the two additional inputs below, putting the same f32 bit pattern in both source registers and reading back the packed 32-bit destination.
v_cvt_pknorm_i16_f32(0x368)0x3f7334e60x799a799a0x799a799a0x79997999v_cvt_pknorm_u16_f32(0x369)0x3e2abaab0x2aae2aae0x2aae2aae0x2aaf2aafEach adapter completed both extra dispatches. Relative to the native measurements, each signed half is one high and each unsigned half is one low. This reproduces the earlier RTX 3050 Laptop result on Blackwell. Native Radeon measurements · Earlier RTX 3050 Laptop replay
Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-25T08:50:20Z.
Offline measurement on a retail dump
Result: no count change against
main.I merged head
de026e84ontomain940d32f(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 Marvisak on 2026-11-25T10:38:07Z.
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 geiyiliyabumo on 2026-11-25T13:23:38Z.
Updated \cvt_pknorm{i16,u16}_{f32,f16}\ (head $sha) to round from the exact product in pure 32-bit DXIL using @Dathinel's power-of-two scaling method (\ = |x| * P, \q = roundEven(a), \mag = int(q) - int((a - (q - 0.5)) < |x|), keeping \SFI0 Int64\ clear). Added the native RDNA2 f32 witnesses (\
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.