Repository navigation
Shaders: lower v_add_nc_i32, v_sub_nc_i32, v_add_nc_i16, and v_sub_nc_i16 in pure 32-bit DXIL - #2094
geiyiliyabumo wants to merge 1 commit into
Conversation
DenRakEiw
left a comment
There was a problem hiding this comment.
Verified locally merged onto origin/main (940d32f, Windows 11 x64, NVIDIA GeForce RTX 5090 + WARP, Rust 1.98.1 MSVC, with dxil.dll validator):
cargo test -p victory-shader --lib v_add_sub_nc_— 2 passed, 0 failed on both RTX 5090 hardware andVICTORY_D3D12_WARP=1(v_add_sub_nc_i32_wrap_and_saturateandv_add_sub_nc_i16_wrap_and_saturate_with_op_sel, both verifiedINT64-free)cargo clippy -p victory-shader --all-targets— 0 warningscargo xtask policy— ok (183 files ok)
Clean pure-32-bit DXIL lowering of v_add_nc_i32, v_sub_nc_i32, v_add_nc_i16, and v_sub_nc_i16 with saturation and op_sel, verified end-to-end on hardware and WARP. Looks good.
AI-assisted (Gemini 4 Neon).
|
Ran on Windows 11 with an RTX 3070 (Ampere, driver 616.56), debug build, at The low half is right (-20 + -3 = -23). The high half should be the destination's old What I checked:
@@ -6514,10 +6514,16 @@ impl<'a> Lower<'a> {
let r = self.s.m.bin(c, op, a, b);
if v.clamp {
+ // The selects pick the 16-bit patterns, never a clamped i32: NVIDIA
+ // (616.56) turns a clamped i32 into a saturating 16-bit add whose
+ // sign-extended result then skips write_half's 0xFFFF mask.
let lo = self.s.m.i32(i32::from(i16::MIN) as u32);
let hi = self.s.m.i32(i16::MAX as u32);
+ let mask = self.s.m.i32(0xFFFF);
+ let low = self.s.m.bin(c, Bin::And, r, mask);
let below = self.s.m.cmp(c, pred::SLT, r, lo);
- let r = self.s.m.select(c, below, lo, r);
+ let min = self.s.m.i32(0x8000);
+ let x = self.s.m.select(c, below, min, low);
let above = self.s.m.cmp(c, pred::SGT, r, hi);
- self.s.m.select(c, above, hi, r)
+ self.s.m.select(c, above, hi, x)
} else {
rOverlap, from reading: #92 (open, conflicting) lowers AI-assisted (Claude Code). Synthetic tests only. |
catminou4
left a comment
There was a problem hiding this comment.
Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main 940d32f, cargo test -p victory-shader --locked.
144 passed / 0 failed / 2 ignored. v_add_nc_i32/v_sub_nc_i32/v_add_nc_i16 lowered — no-carry add/sub variants; check the NC (no-carry-out) semantics match the ISA.
Offline measurement on a retail dumpResult: no count change against I merged head ab4db4d onto 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). |
Same failure on Ada, and the suggested fix passes there tooOn an RTX 4070 SUPER (Ada, driver 32.0.16.1088, default adapter, So it is not limited to Ampere or to driver 616.56. Then I applied @upipibi's change from the comment above (mask the low 16 bits first; the selects pick Offline, on the retail dump, this PR does not change the counts (posted above). AI-assisted (Claude Code). Synthetic tests only. |
|
Automated triage for the maintainers. Merge candidate. This lowers Overlap: #92 covers the same opcodes but conflicts with Reply to @geiyiliyabumo: thanks, the workaround is in as asked. The credit to upipibi (and to andrewpozdnakov7-jpg's Generated by Claude Code |
|
I put @upipibi's mask-before-select workaround in d3df9ee, directly on top of Both expanded tests passed on software WARP on The commit is ready to cherry-pick. Please keep the Git authorship and co-author trailer if you take it. Claim. AI-assisted with Codex. Synthetic shaders only. |
…_i16 in pure 32-bit DXIL
ab4db4d to
4859090
Compare
|
Applied @upipibi's mask-before-select workaround for clamped \�_add_nc_i16\ / \�_sub_nc_i16\ (head $sha) so the selects pick 16-bit masked patterns (\ |
|
@geiyiliyabumo Re-run at
One run only. Thanks also to andrewpozdnakov7-jpg, whose AI-assisted (Claude Code). Synthetic tests only. |
…c_i32, v_add_nc_i16, and v_sub_nc_i16 in pure 32-bit DXIL
…c_i32, v_add_nc_i16, and v_sub_nc_i16 in pure 32-bit DXIL
fuzeofficlal
left a comment
There was a problem hiding this comment.
Verified head 48590903d4ce14cb3c1d2e9de12b86339ce8dd48 merged onto main (63bcca43) on Windows 11 (RTX 5090 Blackwell + WARP, Rust 1.98.1 MSVC, SDK dxil.dll).
- Clean merge onto
main;crates/victory-shader/src/emit/lower.rsis523,385bytes (under the 512 KiB limit; also co-merges cleanly with#465at523,479bytes, passingcargo xtask policy). cargo xtask policy(191 files ok),cargo clippy --locked -p victory-shader --all-targets -- -D warnings(default and--all-features), and both newv_add_sub_nc_i*tests pass on RTX 5090 and WARP withdxil.dllvalidation andSFI0INT64clear.- Checked the pure 32-bit overflow formulas (
(a ^ r) & (b ^ r)for add,(a ^ r) & (b ^ a)for sub, saturating towarda's sign) and mask-before-select 16-bit clamping (emit/lower.rs:6522) with an expanded probe on RTX 5090 and WARP:- 484/484
i32corner pairs (0, ±1, ±2, i32::MIN/MAX, MIN+1, MAX-1, ±0x4000_0000x add/sub xclamp0/1), allINT64-free. - 448/448
i16cases covering all 8(opsel[0], opsel[1], opsel[3])combinations xclamp0/1 x 14 boundary pairs (including0 - i16::MIN,i16::MIN + i16::MIN,i16::MAX - i16::MIN, and negative non-overflowing sums), confirming the mask-before-select workaround preserves the untouched destination half on Blackwell as well. - 20/20 modifier rejection checks (
omod,abs,neg) across all four opcodes.
- 484/484
Summary
v_add_nc_i32(0x37f),v_sub_nc_i32(0x376),v_add_nc_i16(0x30d), andv_sub_nc_i16(0x30e) incrates/victory-shader/src/emit/lower.rsusing pure 32-bit DXIL without enablingInt64/WIDE_OPS.clamp = 0) forms wrap naturally; clamped (clamp = 1) forms saturate to signedi32::MIN..=i32::MAX/i16::MIN..=i16::MAX.op_selfor source and destination half selection while preserving the untouched half ofvdst.crates/victory-shader/src/emit/valu_tests.rscovering normal results, positive and negative signed overflow, bothclampmodes,op_selhalf preservation, and verifyingInt64is not set.Verification
cargo xtask policy: passedcargo clippy -p victory-shader --tests -- -D warnings: passedcargo test -p victory-shader --lib v_add_sub_nc_i -- --test-threads=1with Microsoftdxil.dll: 2/2 passed on AMD Radeon RX 9060 XT (RDNA4) and Microsoft Basic Render Driver (WARP)