DXIL: saturate 16-bit integer valu16 ops when CLAMP=1 #2398
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!2398
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2398"
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?
@Decodere on GitHub · 2026-11-25 17:44 UTC · original
Decodere:fix-valu16-int-clamp→main· +128 −0 · 1 files · 1 commits · openPart of #1401
Part of #1833
What is in it
Implement RDNA2
CLAMP=116-bit integer saturation in Direct DXILLw::valu16(crates/xcl/src/gpu/dxil/lower_wide.rs):m.clamp):v_add_nc_u16,v_add_u16, andv_mad_u16compute the exact 32-bit unsigned sum/product-sum (0xFFFF * 0xFFFF + 0xFFFF = 0xFFFF_0000, nou32overflow and zeroInt64Ops) and saturate withumin(t, 0xFFFF).v_sub_nc_u16,v_sub_u16,v_subrev_nc_u16, andv_subrev_u16saturate underflow to0viaselc(cmp(ULt, lhs, rhs), 0, lhs - rhs).m.clamp):v_add_nc_i16,v_sub_nc_i16, andv_mad_i16sign-extend 16-bit inputs toi32(si(self, i)), compute the exact 32-bit signed result ([-1_073_741_824, 1_073_774_591], noi32overflow and zeroInt64Ops), masklow = t & 0xFFFFupfront, and select0x7FFF/0x8000viaicmp sgt i32 %t, 32767/icmp slt i32 %t, -32768, preservingOP_SELhigh-half merging and SDWA writeback.and 0xFFFF+icmp sgt/slt+selectinstead ofIMax(IMin(t, 0x7FFF), -32768) & 0xFFFFavoids an NVIDIA Ampere driver miscompilation reported by@DarkPanda69(RTX 3060 driver32.0.16.1088), where the driver dropped& 0xFFFFafterIMax(IMin(...))on negative results (-2 = 0xFFFF_FFFE), clobbering the preserved upper 16 bits (0xBEEF_0000 | 0xFFFF_FFFE -> 0xFFFF_FFFE).valu16_clamp_tests):valu16_int_clamp_emits_32bit_saturation_without_i64: pure-CPU DXC 1.9 validation and disassembly test confirming0Int64Ops/i64ops in@main, thatUMin(op 40),icmp ult i32,icmp sgt i32, andicmp slt i32are emitted iffCLAMP=1, and thatIMax/IMin(ops 37/38) are not emitted on the signed clamp path.gpu_valu16_int_clamp_matches_reference:wave32_supported()-guarded GPU execution test across 8 overflow/underflow/boundary lanes covering all six RDNA2 VOP3 16-bit integer ops (V_ADD_NC_U16,V_SUB_NC_U16,V_ADD_NC_I16,V_SUB_NC_I16,V_MAD_U16,V_MAD_I16) withCLAMP=0,CLAMP=1, andOP_SEL=0b1011high-half/low-half preservation.(Rebased onto
origin/mainbe67bfcf.)Tested
cargo test -p xcl --lib gpu::dxil::lower_wide::valu16_clamp_tests::valu16_int_clamp_emits_32bit_saturation_without_i64 -- --exact --nocaptureon68a284a5):0 passed, 1 failed(CLAMP=1 must emit @dx.op.binary.i32(i32 40,).cargo test --release -p xcl --lib gpu::dxil::lower_wide::valu16_clamp_tests -- --test-threads=1 --nocaptureon NVIDIA GeForce RTX 4060 (driver621.14, DXC1.9.2609.5):2 passed, 0 failed, 0 ignored(0.46 s,0skipped).XCL_ADAPTER="Microsoft Basic Render Driver"cargo test --release -p xcl --lib gpu::dxil::lower_wide::valu16_clamp_tests -- --test-threads=1 --nocapture:2 passed, 0 failed, 0 ignored(0.05 s; pure-CPU/DXC 1.9 test ran with0skips, GPU test cleanlySKIPPED).cargo test --release --workspace --no-fail-fast -- --test-threads=4 --nocaptureon RTX 4060):24test binaries,1318 passed, 4 failed, 46 ignored— all170/170gpu::dxil::*tests passed (0failures); the 4 failures areorigin/mainbe67bfcf's pre-existing#2074test (a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier, tracked by #2379) plus 3 unrelated parallel#1978title_textures/vramglobal-mutex flakes (placed_title_textures_share_vram_and_preserve_pixelspoisoningtransitions_apply_when_their_list_is_submittedandd32s8_targets_take_their_own_size_of_video_memory);29pre-existing hardware/debug-layerSKIPPEDlines (0invalu16_clamp_tests).Regression run
Base (
origin/mainbe67bfcfe8143e21a62bbfd5d279d292229e27f9):PR head (
e9d7aefc3a18bc5223790a9d928b1574bc1198c9):Not tested
621.14, where both the original and updated lowering pass; re-verification on Ampere driver32.0.16.1088is welcome).d3d12SDKLayers.dllis not installed on this host).AI use
Google Antigravity (Gemini 4 Neon) assisted with implementing 32-bit saturating integer
CLAMP=1lowering inLw::valu16, switching the signed clamp to Ampere-safeicmp sgt/slt+ pre-maskedselect, adding DXIL disassembly and GPU execution tests, and running the verification suite.@emirduran707 on GitHub · 2026-11-25 18:00 UTC · original
Independent AMD RDNA4 (native wave64) test report on exact head
b9efbd932b48607b0366a7c0a822143efda17035(clean detached checkout, no local changes).Tested
stable-x86_64-pc-windows-msvc), DXC 1.9.2602.17; tests debug, smoke release.cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4: 1289 passed, 3 failed, 46 ignored; 8 SKIPPED (6 inlower_dxil::tests::{f16,f32}_programs_on_the_gpurefused by per-lane form;heap_window_out_of_memory_falls_back_to_the_switch_form;pso_measurement_compiles_an_exact_synthetic_record). All native wave64 GPU tests ran and passed.gpu::dxil::lower_wide::valu16_clamp_tests::valu16_int_clamp_emits_32bit_saturation_without_i64andgpu_valu16_int_clamp_matches_reference.main68a284a:gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1(seed 722) andfuzz_validate_and_gpu_3(seed 1599) on this GPU, plusgpu::recomp::lower_dxil::tests::a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier(from50a9fde/ #2074).Regression run (60 s retail-title smoke,
XCL_NETWORK=0, release)(Matched
main68a284abaseline on the same machine today: 1573 frames, 14420 MB peak, 0 device removals, 0 crashes.)Not tested
AI use
@Decodere on GitHub · 2026-11-25 18:46 UTC · original
Thanks for testing on Ampere
@DarkPanda69— great catch!Looking closely at the failing case (
op=3V_SUB_NC_I16,lane=0:-1 - 1 = -2 = 0xFFFF_FFFE, first negative signed-clamped value in lane 0): the previous signed clamp emittedIMax(IMin(t, 0x7FFF), -32768) & 0xFFFFbeforeor(cur & 0xFFFF_0000, r). Returning0xFFFF_FFFEinstead of0xBEEF_FFFEwhileCLAMP=0'sand(sub, 0xFFFF)passed shows that the Ampere32.0.16.1088driver dropped the post-clamp& 0xFFFFonIMax(IMin(...)), leaving sign-extended0xFFFF_FFFEto clobber0xBEEF_0000.Updated the branch to
e9d7aefc(rebased ontobe67bfcf):CLAMP=1lowering inLw::valu16to masklow = t & 0xFFFFupfront and select unsigned 16-bit constants0x7FFF/0x8000viaicmp sgt i32 %t, 32767/icmp slt i32 %t, -32768(zeroIMax/IMinintrinsics, everyselectbranch is already in0x0000..=0xFFFF).valu16_int_clamp_emits_32bit_saturation_without_i64to asserticmp sgt/icmp sltand noIMax/IMin(op 37/38), verified2/0on RTX 4060 & WARP,170/170gpu::dxil::*, and paired 60 s smoke (1525 -> 1468,0removals/crashes).If you have a moment to re-run
valu16_clamp_testson the RTX 3060 ate9d7aefc, that would confirm the Ampere driver workaround directly!@DarkPanda69 on GitHub · 2026-11-25 18:02 UTC · original · edited 2026-11-25 18:59 UTC
Update for head
e9d7aef(rerun as asked by @Decodere): fixed on the RTX 3060.cargo test -p xcl --lib -- valu16_clamp_tests --test-threads=1at the head as is: RTX 3060 (Ampere, 32.0.16.1088) 2 passed, 0 failed, in 3 of 3 runs in debug and 3 of 3 in release; RX 9070 XT 2 passed in both. So theicmp/selectform withoutIMax/IMinkeeps the upper half on this driver. The failure below is fromb9efbd9.The new GPU test fails on an RTX 3060 (Ampere), passes on an RX 9070 XT. On the 3060 the 16-bit result is right but the destination's upper half is overwritten instead of kept.
Head
b9efbd9applied onmain68a284a, Windows 11 Pro 26200, DXC 1.9.2602.17,cargo test -p xcl --lib -- valu16_clamp_tests --test-threads=1:gpu_valu16_int_clamp_matches_referencefails, 3 of 3 runsThe failure (
lower_wide.rs:1609), identical in every run:So the low half
0xFFFEmatches, and the expected upper half0xBEEFof the destination comes back as0xFFFF: on this driver the clamped 16-bit write forop=3(withopsel=0) doesn't preserve the other half.valu16_int_clamp_emits_32bit_saturation_without_i64passes on both. Your RTX 4060 (Ada) passes, so this looks specific to the Ampere driver, or to how it compiles the saturating path.Whole
gpu::filter with this PR: RTX 3060 650 passed, 2 failed (this test, plusa_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier, which fails onmaintoo, fixed by #2379); RX 9070 XT 649 passed, 3 failed (the samemaintest and the #2115 fuzz seeds).Not tested: other ops / lanes past the first failing assertion on the 3060, other NVIDIA generations.
AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.
@SlopTart on GitHub · 2026-11-25 19:18 UTC · original
Tested: current PR head merged onto current
origin/main(clean), Linux (Arch, kernel 7.2.15), Mesa 26.2.5 RADV, Radeon RX 7900 XT (NAVI31), cargo targetx86_64-pc-windows-gnurun under wine-11.0 (Proton), rustc 1.94.0, vkd3d-proton 3.1 with the XCL patch, official MS DXC (binaries 2026-09-29).gpu_suite, cold cache: 161 passed / 4 failed. Three are the known baseline trio on this lane; the fourth is the newgpu_promoted_uav_clear_values_pass_create_committed_resourcefailure that current main carries (reported here), not caused by this PR. Everything else is green.Targeted run of
gpu_valu16_int_clamp_matches_referenceandvalu16_int_clamp_emits_32bit_saturation_without_i64: 2 passed.Not tested: retail titles (no title data on this lane, counts only).
AI use: Hermes agent (local Qwen-class) ran both machines and drafted this; I checked it before posting.
@DavidM1911 on GitHub · 2026-11-25 19:27 UTC · original
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: 1038 passed, 1 failed in one parallel run; the failing test passes on a single-threaded rerun (1039/0). Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.Thanks!
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.