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
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!2094
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2094"
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?
@geiyiliyabumo on GitHub · 2026-11-25 04:43 UTC · original
geiyiliyabumo:feat/shader-v-add-sub-nc-i→main· +148 −3 · 2 files · 1 commits · openSummary
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)@upipibi on GitHub · 2026-11-25 05:01 UTC · original
Ran on Windows 11 with an RTX 3070 (Ampere, driver 616.56), debug build, at
ab4db4d.victory-shader: 245 passed, 4 failed, 3 ignored. Three are #1744's NVIDIA failures onmain. The fourth is this PR's new test:The low half is right (-20 + -3 = -23). The high half should be the destination's old
0xA5A5but comes back sign-extended. The unclamped cases and clamped case 0 (a positive result) pass.What I checked:
dxc -dumpbinof that shader shows the clamp select chain, thenand %32, 65535, thenand %old, -65536, thenor, the same tail as the unclamped shader, which passes.run_casesto run WARP first, locally. That matches your RX 9060 XT and WARP results. It fails alone, too, without the i32 test in the process.dx.opIMax/IMin (37/38) instead of compare/select, or clamping onr + 0x8000in [0, 0xFFFF] and flipping the sign bit back, give the same0xFFFFFFE9. NVIDIA's compiler appears to fold any of these into a saturating 16-bit add, and then dropswrite_half's0xFFFFmask on its sign-extended result. It's a driver bug, but titles run on NVIDIA, so it's worth avoiding.victory-shadersuite is 246 passed with only #1744's 3, the same asmain:Overlap, from reading: #92 (open, conflicting) lowers
v_add_nc_i32/v_sub_nc_i32and the signed 16-bit add and sub too.AI-assisted (Claude Code). Synthetic tests only.
@sinan-cmyk on GitHub · 2026-11-25 08:53 UTC · original
Offline measurement on a retail dump
Result: no count change against
main.I merged head ab4db4db onto
main940d32f(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).
@sinan-cmyk on GitHub · 2026-11-25 09:21 UTC · original
Same failure on Ada, and the suggested fix passes there too
On an RTX 4070 SUPER (Ada, driver 32.0.16.1088, default adapter,
VICTORY_WARPunset), with head ab4db4d merged ontomain940d32f,cargo test --locked -p victory-shader --libgives 245 passed and 4 failed. Three failures are the NVIDIA ones from #1835 thatmainhas too. The fourth is this PR's test, with the same values as on the RTX 3070 above: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
0x8000,i16::MAXor the masked value). With it, bothvalu_tests::v_add_sub_nc_i32_wrap_and_saturateandvalu_tests::v_add_sub_nc_i16_wrap_and_saturate_with_op_selpass on this card.Offline, on the retail dump, this PR does not change the counts (posted above).
AI-assisted (Claude Code). Synthetic tests only.
@Marvisak on GitHub · 2026-11-25 10:35 UTC · original · edited 2026-11-25 14:48 UTC
Automated triage for the maintainers.
Merge candidate. This lowers
v_add_nc_i32/v_sub_nc_i32(VOP3 0x37f/0x376) andv_add_nc_i16/v_sub_nc_i16(0x30d/0x30e) inemit/lower.rs, with clamp as signed saturation, in 32-bit DXIL (the tests assertInt64stays off). The i32 overflow test is(a^r)&(b^r)for add and(a^r)&(a^b)for sub, saturating toward the sign ofa. The i16 operands are sign-extended by the existing_i16path, and the clamped form now uses the mask-before-select shape, so the selects pick0x8000,0x7fffor the masked low half. At4859090the NVIDIA failure is gone: the RTX 3070 re-run posted here passes both new tests, and the rest of the suite matchesmain. CI check: passing.Overlap: #92 covers the same opcodes but conflicts with
main. This one merges cleanly.Reply to @geiyiliyabumo: thanks, the workaround is in as asked. The credit to upipibi (and to andrewpozdnakov7-jpg's
d3df9ee, which carried it first) is worth keeping in the commit message.Generated by Claude Code
@andrewpozdnakov7-jpg on GitHub · 2026-11-25 11:51 UTC · original
I put @upipibi's mask-before-select workaround in d3df9ee, directly on top of
ab4db4d. The commit credits @upipibi for the workaround and expands the readback test to all eight source and destination half selections.Both expanded tests passed on software WARP on
ab4db4dand ond3df9ee(192 signed 16-bit cases and 28 signed 32-bit cases). With the workaround, all 30 VALU tests passed with DXIL validation, and strict shader Clippy and the asset policy passed. The RTX 3070 and 4070 SUPER results in this thread are the hardware evidence for the masking change.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.
@geiyiliyabumo on GitHub · 2026-11-25 13:20 UTC · original
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 (\
@upipibi on GitHub · 2026-11-25 13:54 UTC · original
@geiyiliyabumo Re-run at
4859090(as-is, onmain940d32f), RTX 3070 (616.56) plus WARP, Windows 11, debug,cargo test -p victory-shader --locked: the failure I reported is gone.v_add_sub_nc_i16_wrap_and_saturate_with_op_selandv_add_sub_nc_i32_wrap_and_saturateboth pass.mainhas too (a_heap_buffer_read_where_no_buffer_view_is_reads_zeros,a_heap_buffer_read_by_element_takes_the_views_stride,gathers_at_a_level_match_the_hardware).One run only. Thanks also to andrewpozdnakov7-jpg, whose
d3df9eecarried the workaround first.AI-assisted (Claude Code). Synthetic tests only.
@DenRakEiw on GitHub · 2026-11-25 04:49 UTC · original · approved these changes
Verified locally merged onto
origin/main(940d32f, Windows 11 x64, NVIDIA GeForce RTX 5090 + WARP, Rust 1.98.1 MSVC, withdxil.dllvalidator):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, andv_sub_nc_i16with saturation andop_sel, verified end-to-end on hardware and WARP. Looks good.AI-assisted (Gemini 4 Neon).
@catminou4 on GitHub · 2026-11-25 05:16 UTC · original · approved these changes
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_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.
@fuzeofficlal on GitHub · 2026-11-26 17:23 UTC · original · approved these changes
Verified head
48590903d4ce14cb3c1d2e9de12b86339ce8dd48merged ontomain(63bcca43) on Windows 11 (RTX 5090 Blackwell + WARP, Rust 1.98.1 MSVC, SDKdxil.dll).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.(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:i32corner pairs (0, ±1, ±2, i32::MIN/MAX, MIN+1, MAX-1, ±0x4000_0000x add/sub xclamp0/1), allINT64-free.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.omod,abs,neg) across all four opcodes.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.