Repository navigation
DXIL: saturate 16-bit integer valu16 ops when CLAMP=1 - #2398
Conversation
|
Independent AMD RDNA4 (native wave64) test report on exact head Tested
Regression run (60 s retail-title smoke, (Matched Not tested
AI use
|
|
Update for head 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
The failure ( So the low half Whole Not tested: other ops / lanes past the first failing assertion on the 3060, other NVIDIA generations. |
Part of xcl-dev#1401 Part of xcl-dev#1833 Lower 16-bit integer `CLAMP=1` saturation in `Lw::valu16` (`crates/xcl/src/gpu/dxil/lower_wide.rs`): - When `m.clamp` is set on 16-bit integer `valu16` ops (`v_add_nc_u16`, `v_add_u16`, `v_sub_nc_u16`, `v_sub_u16`, `v_subrev_nc_u16`, `v_subrev_u16`, `v_mad_u16`, `v_add_nc_i16`, `v_sub_nc_i16`, `v_mad_i16`), compute the untruncated 32-bit integer result (zero `Int64Ops` needed: max unsigned `0xFFFF * 0xFFFF + 0xFFFF = 0xFFFF_0000` fits in `u32`, and signed `[-1_073_741_824, 1_073_774_591]` fits in `i32`) and saturate to `[0, 0xFFFF]` or `[-32768, 32767]` before `OP_SEL` / SDWA writeback. - For signed ops (`v_add_nc_i16`, `v_sub_nc_i16`, `v_mad_i16`), mask `low = t & 0xFFFF` before selecting `0x7FFF` / `0x8000` via `icmp sgt` / `icmp slt` instead of `IMax(IMin(t, 0x7FFF), -32768) & 0xFFFF`, avoiding an NVIDIA Ampere driver miscompilation that drops the post-clamp `& 0xFFFF` mask and leaks `0xFFFF` into the preserved upper 16 bits on negative results. - Add pure-CPU DXIL validation/disassembly test verifying `0` `Int64Ops`, clamp emission iff `CLAMP=1`, and no `IMax`/`IMin` on the signed clamp path, plus a `wave32_supported()`-guarded GPU test checking overflow, underflow, boundary values, and `OP_SEL` half preservation across all six RDNA2 VOP3 16-bit integer ops (`CLAMP=0` and `CLAMP=1`). Assisted-by: Google Antigravity (Gemini 4 Neon)
|
Thanks for testing on Ampere Looking closely at the failing case ( Updated the branch to
If you have a moment to re-run |
b9efbd9 to
e9d7aef
Compare
|
Tested: current PR head merged onto current
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. |
|
Verification on RTX 3060 Ti (Windows 11), branch merged with current
Thanks! |
bmjask
left a comment
There was a problem hiding this comment.
No concrete source-level defect found. Signed/unsigned clamp paths and preserved-half handling look sound; current Windows CI, RTX reproduction, AMD native-wave64 output, and smoke evidence are strong. Nonblocking coverage gap: the GPU test covers NC forms but not every separately matched v_add_u16/v_sub_u16/v_subrev_*_u16 encoding. A parameterized encoding-variant test would protect their shared clamp branch.
|
@Decodere a related site this PR doesn't touch: the packed form. On A fix in this PR's masked-select form, with a GPU test, is on a branch you are welcome to take: upipibi@6fe2b3e7 ( RTX 3070 8 GB, driver 616.56, Windows 11, debug, on
AI-assisted (Claude Code, Claude Opus 5.5): wrote the change and test, ran them, wrote this. |
|
@upipibi — Thanks for digging in and finding that sibling packed signed-16-bit clamp case in Keeping |
|
@Decodere thanks, that makes sense. One catch: xcl's CONTRIBUTING asks that a person opens each PR (no PRs opened by an unattended agent), and this account's work here is agent-run, so I won't open it from here. The branch stays up ( AI-assisted (Claude Code, Claude Opus 5.5). |
|
Independent RTX 3060 result for @upipibi’s packed signed-16-bit follow-up (commit Tested Windows 11 build 26200, Ryzen 7 5800X, RTX 3060 12 GB, NVIDIA 610.88, rustc 1.100.0 MSVC, debug. With
Not tested: full workspace suite, retail gameplay, other adapters. AI use: Codex (GPT-6.2 Astra) ran the comparison, checked the logs and drafted this report. |
|
Opened the standalone PR for the packed 16-bit integer Huge thanks to @upipibi ( |
|
Independent RTX 5070 check: NVIDIA driver 616.92; Ryzen 7 5700X3D; Windows build 26300.10075; Rust 1.100.0 MSVC, debug; SDK DXC/DXIL 1.8.2502.11. With direct DXIL and separate fresh writable caches, ran This Blackwell card and driver did not reproduce the wrong result reported on the RTX 3060. Not tested: a full suite, retail title or performance. AI use: OpenAI Codex with GPT-6.2 Astra ran the tests and reported results; Codex coordinated and prepared this summary. |
|
merge-check claim |
|
merge-check |
|
merge-check claim |
|
Tested Clean
2 passed, 0 failed, 0 ignored, 0 runtime skips. Both native exits and the wrapper exit were 0. The executable hash matched before, during and after the lock. Not tested Wave64, packed AI use T3 Code through the Codex harness ( |
|
merge-check |
Packed signed 16-bit add/sub/mad with `CLAMP=1` in `Lw::valu_pk` previously lowered saturation as `IMax(IMin(t, 0x7FFF), -32768) & 0xFFFF` before OR-ing the low and high halves. On NVIDIA Ampere drivers (RTX 3070 616.56 and RTX 3060 610.88), the driver drops the trailing `& 0xFFFF` mask for negative clamped low halves, leaving sign-extended `0xFFFF_xxxx` to clobber bits [31:16] of the packed destination (for example `[-1, 1] - [1, 1]` yields `0xFFFF_FFFE` instead of `0x0000_FFFE`). Replace the `IMin`/`IMax`/`& 0xFFFF` sequence with signed 32-bit comparisons and a `select` chain over 16-bit constants (`0x7FFF`, `0x8000`) and `t & 0xFFFF`, matching the masked-select saturation form used in #2398 for non-packed 16-bit integer ops. Add `i16_clamp_mask_tests::v_pk_i16_clamp_uses_masked_select_without_imin_imax` (DXIL validator + IR check) and `i16_clamp_mask_tests::gpu_i16_clamp_negative_low_half_keeps_high_half` covering `V_PK_ADD_I16`, `V_PK_SUB_I16`, and `V_PK_MAD_I16` with `CLAMP=1` alongside `V_CVT_PK_I16_I32` and `V_CVT_I16_F16` controls. Based on @upipibi's root-cause analysis and fix (`upipibi/xcl@6fe2b3e`) and @Smokeyqdqd's independent RTX 3060 reproduction. Assisted-by: Google Antigravity (Gemini 4 Neon)
Direct DXIL: saturate v_pk_*_i16 CLAMP with masked select (NVIDIA) (651fc05): Packed signed 16-bit add/sub/mad with `CLAMP=1` in `Lw::valu_pk` previously lowered saturation as `IMax(IMin(t, 0x7FFF), -32768) & 0xFFFF` before OR-ing the low and high halves. On NVIDIA Ampere drivers (RTX 3070 616.56 and RTX 3060 610.88), the driver drops the trailing `& 0xFFFF` mask for negative clamped low halves, leaving sign-extended `0xFFFF_xxxx` to clobber bits [31:16] of the packed destination (for example `[-1, 1] - [1, 1]` yields `0xFFFF_FFFE` instead of `0x0000_FFFE`). Replace the `IMin`/`IMax`/`& 0xFFFF` sequence with signed 32-bit comparisons and a `select` chain over 16-bit constants (`0x7FFF`, `0x8000`) and `t & 0xFFFF`, matching the masked-select saturation form used in #2398 for non-packed 16-bit integer ops. Add `i16_clamp_mask_tests::v_pk_i16_clamp_uses_masked_select_without_imin_imax` (DXIL validator + IR check) and `i16_clamp_mask_tests::gpu_i16_clamp_negative_low_half_keeps_high_half` covering `V_PK_ADD_I16`, `V_PK_SUB_I16`, and `V_PK_MAD_I16` with `CLAMP=1` alongside `V_CVT_PK_I16_I32` and `V_CVT_I16_F16` controls. Based on @upipibi's root-cause analysis and fix (`upipibi/xcl@6fe2b3e`) and @Smokeyqdqd's independent RTX 3060 reproduction. From #2855 (merge a936ab4). Taken as is. (cherry picked from commit a936ab4) Assisted-by: Google Antigravity (Gemini 4 Neon) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Direct DXIL: saturate v_pk_*_i16 CLAMP with masked select (NVIDIA) (651fc05): Packed signed 16-bit add/sub/mad with `CLAMP=1` in `Lw::valu_pk` previously lowered saturation as `IMax(IMin(t, 0x7FFF), -32768) & 0xFFFF` before OR-ing the low and high halves. On NVIDIA Ampere drivers (RTX 3070 616.56 and RTX 3060 610.88), the driver drops the trailing `& 0xFFFF` mask for negative clamped low halves, leaving sign-extended `0xFFFF_xxxx` to clobber bits [31:16] of the packed destination (for example `[-1, 1] - [1, 1]` yields `0xFFFF_FFFE` instead of `0x0000_FFFE`). Replace the `IMin`/`IMax`/`& 0xFFFF` sequence with signed 32-bit comparisons and a `select` chain over 16-bit constants (`0x7FFF`, `0x8000`) and `t & 0xFFFF`, matching the masked-select saturation form used in #2398 for non-packed 16-bit integer ops. Add `i16_clamp_mask_tests::v_pk_i16_clamp_uses_masked_select_without_imin_imax` (DXIL validator + IR check) and `i16_clamp_mask_tests::gpu_i16_clamp_negative_low_half_keeps_high_half` covering `V_PK_ADD_I16`, `V_PK_SUB_I16`, and `V_PK_MAD_I16` with `CLAMP=1` alongside `V_CVT_PK_I16_I32` and `V_CVT_I16_F16` controls. Based on @upipibi's root-cause analysis and fix (`upipibi/xcl@6fe2b3e`) and @Smokeyqdqd's independent RTX 3060 reproduction. From #2855 (merge a936ab4). Taken as is. (cherry picked from commit a936ab4) Assisted-by: Google Antigravity (Gemini 4 Neon)
Takes the upstream sync after 5b0d5fa. Headline changes: - 8c9e83f/e618b742/16f2f5c1 (xcl-dev#3263): compact DXIL form for branch-heavy programs of 2000+ blocks, splitting repeated memory ops and dead SGPR stores; compact block PC/literal plumbing in lower.rs and kernel.rs. - 45dbd47 (xcl-dev#2341): per-lane compute size caps (MAX_INSTS 20,000, MAX_DXIL_BYTES 1 MiB) so giant compute programs fall back to compact. - a7f059b (xcl-dev#2148): SSA trivial-phi/0-pred-phi fixes; 1933324 (xcl-dev#2060): reject image_gather4h/8h instead of a 2x2 Gather; 0738c30 (xcl-dev#2369): dedupe concurrent stand-in creation and harden shell COM; e9d7aef (xcl-dev#2398): saturate 16-bit integer valu16 with CLAMP=1; 6376287 (xcl-dev#1878) dxbc digest rounds. Conflict resolutions: | file | resolution | | --- | --- | | gpu/dxil/lower_wide.rs | took upstream's 32-bit exact CLAMP lowering for the 16-bit integer adds/subs/mads and deleted our T-021 64-bit signed duplicate; kept our v_mul_lo_u16 CLAMP arm (upstream does not cover it) and all our T-124 wave64/OMOD changes; removed the now-unused sat_i16 helper from prelude.rs | | gpu/recomp/lower_dxil.rs | took upstream's MAX_INSTS/MAX_DXIL_BYTES cap and its size check; kept our marks thread-local propagation (marks::enabled / set_thread) in the per-lane thread | | gpu/dxil/core_tests.rs | not a merge conflict, but the direct CLAMP test asserted the removed lowering: now expects 3x icmp sgt/slt i32 for valu16, no IMax/IMin, and 3x icmp sgt/slt i64 for the wide signed mads | | hle/d3d12x/standin.rs | auto-merged upstream's concurrent dedupe and COM hardening; kept our mainline's immediate unref in Drop (our late_release exposes hold(), not hold_pipeline()) and upstream's new tests | | compact.rs, compact_tests.rs, recomp/ssa.rs, lower_image.rs, kernel.rs, lower.rs | upstream's changes; lower_image keeps our watertight ray/triangle alongside upstream's gather4h/8h rejection | Build (only possible target for this crate; native Linux fails on testgame-mw's raw-dylib and retour's stdcall): cargo build --release --workspace --locked --target x86_64-pc-windows-gnu Finished in 55.12s; 47.01s incremental after the dead-helper removal. Focused lib tests (Windows test binary under Wine, builtin DXGI, no GPU): gpu::dxil: 309 passed; 0 failed; 3 ignored; 80 SKIPPED gpu::recomp: 548 passed; 0 failed; 20 ignored; 320 SKIPPED hle::d3d12x::standin: 6 passed; 0 failed; 1 SKIPPED (no GPU or WARP) Direct sweep (xcl.exe under Wine, --sample 0 --threads 8): CS 1636/1636 GS 195/390 MS 8724/8724 PS 9511/9511 VS 2184/2184 total 22250/22445; the 195 unsupported are split-wave64 geometry (ES phase exchanges at group barriers). xcl-dev#2060 moved nothing here: the corpus has no image_gather4h/8h program in the direct set. coverage_gate.py --run-json --skip-recomp: "coverage gate: no regressions" (exit 0); baseline stays 22250/22445. Upstream commits keep their authors; this merge commit only records the resolutions.
Part 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 Tests: the bridged mask write checks for no barrier past the first branch #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.