Direct DXIL: saturate v_pk_*_i16 CLAMP with masked select (NVIDIA) #2855
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2855"
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 ivall/xcl. Originally posted by Decodere on 2026-11-26T19:02:10Z.
Direct DXIL lowering for packed signed 16-bit add/sub/mad with
CLAMP=1(v_pk_add_i16,v_pk_sub_i16,v_pk_mad_i16inLw::valu_pk,crates/xcl/src/gpu/dxil/lower_wide.rs) previously saturated each half viaIMax(IMin(t, 0x7FFF), -32768) & 0xFFFFbefore OR-ing the low and high halves into the destination register. On NVIDIA Ampere drivers (RTX 3070 driver 616.56 and RTX 3060 driver 610.88), the driver drops the trailing& 0xFFFFmask for negative clamped low halves, leaving sign-extended0xFFFF_xxxxto overwrite bits[31:16]of the packed destination (for example,[-1, 1] - [1, 1]returned0xFFFF_FFFEinstead of0x0000_FFFE).This is the packed-operation sibling to #2398 (which touches non-packed
valu16ops on disjoint lines and merges cleanly alongside this PR). Auditing all otherimin/imax/& 0xFFFFsites acrosscrates/xcl/src/gpu/dxil/confirmedLw::valu_pkwas the only remainingIMax(IMin(t, 0x7FFF), -32768) & 0xFFFFsite;v_cvt_i16_f16(lower_wide.rs) andv_cvt_pk_i16_i32(lower_valu.rs) useIMin(IMax(...))and pass as controls on Ampere.What is in it
IMax(IMin(t, 0x7FFF), -32768) & 0xFFFFin"v_pk_add_i16" | "v_pk_sub_i16" | "v_pk_mad_i16" if clamp(crates/xcl/src/gpu/dxil/lower_wide.rs) with signed 32-bit comparisons (Pred::SGtagainst0x7FFF,Pred::SLtagainst0xFFFF_8000),t & 0xFFFF, and aselectchain yielding 16-bit patterns (0x7FFF,0x8000, orlow), matching the masked-select form used in #2398.i16_clamp_mask_tests::v_pk_i16_clamp_uses_masked_select_without_imin_imax: validates and disassembles Direct DXIL forV_PK_ADD_I16,V_PK_SUB_I16, andV_PK_MAD_I16withCLAMP=1, assertingicmp sgt i32/icmp slt i32/select i1and noIMax,IMin, orInt64Ops.i16_clamp_mask_tests::gpu_i16_clamp_negative_low_half_keeps_high_half: runsV_PK_ADD_I16,V_PK_SUB_I16, andV_PK_MAD_I16withCLAMP=1(distinct source registers across saturation edges, negative in-range low halves, and 32-bit intermediate cancellation) alongsideV_CVT_PK_I16_I32andV_CVT_I16_F16controls on the GPU.@upipibi's root-cause analysis and fix (upipibi/xcl@6fe2b3e7, RTX 3070 616.56 reproduction) and@Smokeyqdqd's independent RTX 3060 610.88 reproduction.Tested
stable-x86_64-pc-windows-msvc), DXC 1.9.2609.5.e120925eclamp withi16_clamp_mask_testsadded):cargo test -p xcl --lib -- v_pk_i16_clamp_uses_masked_select_without_imin_imax --nocapture --test-threads=1: 0 passed, 1 failed (caughtIMaxemission on unmodifiede120925e).cargo test -p xcl --lib -- gpu_i16_clamp_negative_low_half_keeps_high_half --nocapture --test-threads=1(3x Debug RTX 4060) and--release(3x Release RTX 4060): 1 passed, 0 failed in all 6 runs (0 skipped). RTX 4060 Ada driver 621.14 keeps the& 0xFFFFmask onIMax(IMin(...)), consistent with #2398 where Ada passed while Ampere drivers failed 3/3 (RTX 3070 616.56 and RTX 3060 610.88, 33 mismatched lanes).651fc050):cargo clippy --all-targets -- -A clippy::approx_constant: exit 0, 0 new warnings incrates/xcl/src/gpu/dxil/lower_wide.rs.XCL_WARP=1):cargo test -p xcl --lib -- i16_clamp_mask_tests --nocapture --test-threads=1: 2 passed, 0 failed, 0 ignored in 3/3 runs (0 skipped);cargo test -p xcl --lib -- gpu::dxil:: --test-threads=4: 186 passed, 0 failed, 3 ignored (1SKIPPED:dispatch_chain_native_wave64_builds_whole: no wave64).cargo test --release -p xcl --lib -- i16_clamp_mask_tests --nocapture --test-threads=1: 2 passed, 0 failed, 0 ignored in 3/3 runs (0 skipped);cargo test --release -p xcl --lib -- gpu::dxil:: --test-threads=4: 186 passed, 0 failed, 3 ignored (1SKIPPED:dispatch_chain_native_wave64_builds_whole: no wave64).cargo build --release --workspace && cargo test --release --workspace --no-fail-fast -- --test-threads=4: 1444 passed, 0 failed, 47 ignored across 38 top-level test targets (29SKIPPEDnotices: 21 wave64, 3 per-lane refusals, 3 D3D12 debug layer, 1 heap-window fallback, 1 Windows driver-cache toggle).git merge-tree --write-tree(exit 0) against bothmain(8b957bec) and #2398 (e9d7aefc).Regression run
Paired quiet 60 s release runs (
scripts/smoke.ps1 -Seconds 60,XCL_NETWORK=0, RTX 4060 8 GB, driver 621.14) on exact parente120925eand PR head651fc050:Exact parent on
main(e120925e, ancestor of8b957bec):PR (
651fc050):Not tested
V_PK_ADD_I16/V_PK_SUB_I16failure and masked-select fix were independently verified 3/3 on RTX 3070 616.56 by@upipibiand RTX 3060 610.88 by@Smokeyqdqd;V_PK_MAD_I16shares the same clamp block and was verified here on WARP and RTX 4060 Ada).d3d12SDKLayers.dllnot installed).AI use
crates/xcl/src/gpu/dxil/, applied the masked-select fix andi16_clamp_mask_tests(extending@upipibi's6fe2b3e7test withV_PK_MAD_I16and an IR contract test), ran all local builds/tests/smokes, and drafted this PR description.Imported from ivall/xcl. Originally posted by DarkPanda69 on 2026-11-26T19:17:42Z.
AMD run (listed as untested), plus one more Ampere card: no change from
mainon either, and both new tests pass.Tested: pass, head
651fc05applied onmain8b957be, debug, Rust 1.100.0, Windows 11 Pro 26200, Ryzen 7 5800X, DXC 1.9.2602.17, card picked withXCL_ADAPTER.XCL_DIRECT_DXIL=1 cargo test -p xcl --lib -- gpu:: --test-threads=4 --nocapture,mainand this PR one after the other on each card:main708 passed, 2 failed, 6 SKIPPED; this PR 710 passed, 2 failed, 6 SKIPPED. The 2 failures arefuzz_validate_and_gpu_1and_3, the AMD fuzz seeds in #2115, the same onmain.main710 passed, 0 failed, 24 SKIPPED; this PR 712 passed, 0 failed, 24 SKIPPED.On both cards the only result changes are
gpu_i16_clamp_negative_low_half_keeps_high_halfandv_pk_i16_clamp_uses_masked_select_without_imin_imax, both ok. The SKIPPED sets are the same as onmain.The new GPU test uses
KernelOptions { wave64: false, .. }, so it runs as wave32 on the RX 9070 XT too; this does not cover the clamp in native wave64.Not tested: the clamp in a 64-lane wave, D3D12 debug-layer tests (no
d3d12SDKLayers.dllhere either), release, Intel.AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.
Imported from ivall/xcl. Originally posted by andrewDoing on 2026-11-26T20:25:57Z.
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.
Ran
cargo test --locked -p xcl --lib i16_clamp_mask_tests -- --test-threads=1 --nocapturewithXCL_ADAPTER=5070,XCL_DIRECT_DXIL=1, and separate writable caches:e120925e3abc9956a8b9bae631969d32e8ccd43cwith only the PR's test module added: GPU packed arithmetic passed; disassembly assertion failed becauseIMaxwas present.651fc0502da4efd6bbcefa9faa9aed3dafb22d40: both tests passed, 0 failed, 0 ignored, no reported skips.The arithmetic fixture did not reproduce the reported Ampere wrong-result signature on this Blackwell card and driver, including on the parent. This is not a performance or retail-title test; the full suite was not run on this PR.
AI use: OpenAI Codex with GPT-6.2 Astra ran the tests and reported results; Codex coordinated and prepared this summary.
Imported from ivall/xcl. Originally posted by SlopTart on 2026-11-26T21:40:55Z.
Linux (Wine) dual-lane run at head
651fc050- no regressions on either vendor, with one counting note.e120925e, 5 commits behind current8b957bec), so the threepresent::preparationtests that landed with #2555 are absent from this tree - that is why the totals shift, not the CLAMP change itself. Reds = baseline two + thesparse::a_tile_decommitted_and_committed_again_keeps_its_video_memoryload flake we documented separately today (solo 3/3 green; second suite-load appearance).gpu_promoted_uav_clear_values,write_buffer_immediate_on_open_existing_heap_visible_to_cpu,xma2_source_voice). No new NVIDIA reds, and none of the standing ones moved.The masked-select saturation is exercised mainly in paths our Wine lane runs headless without real draw compare (
--skip gpu::), so treat this as "does not break the suite on AMD or NVIDIA Wine" rather than a functional validation of the clamp fix itself.Suite:
cargo test --release --locked -p xcl --lib --target x86_64-pc-windows-gnu -- --test-threads=2 --skip gpu::.AI use: Hermes agent (local Qwen-class) ran the tests and drafted this; I checked it before posting.
Imported from ivall/xcl. Originally posted by SzczepanGrela on 2026-11-27T02:19:39Z.
RX 9070 / RADV / Wine follow-up, including native wave64 and explicit plain/compact direct lowering. All captured GPU outputs match an independent CPU oracle on main, this head, and the head's automatic integration onto main. This is AMD non-regression coverage; the NVIDIA wrong-result case does not reproduce here.
Tested
651fc0502da4efd6bbcefa9faa9aed3dafb22d40, current main8b957bec6f82495aec940944c6bf47faa02db590, and a separate copy with the PR integrated onto that main. The head's parent ise120925e3abc9956a8b9bae631969d32e8ccd43c. Main's productionlower_wide.rsis byte-identical to that parent; the integrated file matches the head. Local edits are test-only observations and the extra fixture described below.26.3.1-arch3.5; Ryzen 7 7700, CachyOS7.3.0-5-cachyos. Windows GNU release executables under GE-Proton11-12 / Wine 11.0 Staging, native D3D12 through vkd3d-proton8293130ebe370b1+(local asserts-disabled build). DXC/DXIL1.9.2602.17, Rust1.97.1.cargo test --offline --locked --release --target x86_64-pc-windows-gnu -p xcl --lib --no-run --message-format=json-render-diagnostics.i16_clamp_mask_tests --nocapture --test-threads=1, then--test-threads=4. Identical original assertions on all three copies; main receives the head's test module. Results for each thread count: main 1 passed, 1 failed; exact head 2 passed, 0 failed; integrated head 2 passed, 0 failed. The main failure is the expected IR-contract assertion about IMax. The original 32-lane GPU test passes in all six runs, including the negative-low-half case. Saved IR confirms IMin/IMax in main and signed compares/select without either intrinsic in the head's original IR fixture.workflow_packed_i16_matrix --nocapture --test-threads=1: three fresh process repetitions per source, 1 passed, 0 failed in every run. Each process executes 96 cases: 16 input batches, native wave32/wave64, HLSL, direct plain and explicitly selected direct compact. Compact selection is confirmed in translator logs; native WaveSize/NumThreads metadata is checked in saved DXIL.V_CVT_PK_I16_I32andV_CVT_I16_F16. Per backend/process, native wave64 checks 1,024 input vectors and wave32 checks 512. Inputs cover signed-i16 edges, saturation, wrapping, MAD cancellation and deterministic random values. No NEG modifiers.Runtime: inherited
XCL_*variables cleared;XCL_NETWORK=0,XCL_ADAPTER=AMD Radeon RX 9070,XCL_REQUIRE_GPU=wave64,XCL_DXC_THREADS=1,XCL_DIRECT_COMPACT=0for the original tests. The extra direct routes select plain/compact explicitly. Each process uses separate enabled XCL/vkd3d/Mesa cache directories.Not tested
NVIDIA, native Windows, forced split wave64, other modifiers/control-flow shapes, full suite, retail workloads,
scripts/smoke.ps1, performance or FPS. These synthetic results do not establish a retail regression run or reproduce the reported NVIDIA driver behavior.AI use
OpenAI Codex (GPT-6; exact serving variant not exposed) prepared the local test-only fixture, ran the tests, independently checked the raw results and drafted this report. Publication authorized by the account owner.
Imported from ivall/xcl. Originally posted by thehollowedone on 2026-11-28T10:03:03Z.
merge-check
base:
e429936c10head:
651fc0502dmerge: clean
build:
cargo build --offline --locked -j 4 --workspace-> oktests:
cargo test --offline --locked -j 4 --workspace --no-fail-fast -- --test-threads=4-> 2,127 passed, 10 failed, 48 ignored; 25 GPU skip notices. The same ten failed on untouched main at this base:dispatch_chain_oversized_loop_matches_whole,dispatch_chain_wave32_live_loops,dispatch_chain_wave64_live_loops_and_exchange,gpu_heap_flat_reads_match_guarded_and_root_output,console_mesh_caches_hlsl_compute_pass_in_memory_and_on_disk,gpu_compute_mode_dispatch_abi,gpu_float_cas_uses_ieee_equality, and the threetest_title_*e2e cases. The two newi16_clamp_mask_testspassed separately on the RTX 3080 Ti (2 passed, 0 failed, 0 ignored, 0 skipped) withcargo test --offline --locked -j 4 -p xcl --lib i16_clamp_mask_tests -- --test-threads=1 --nocapture.review: no blocker found in the full diff. For each signed packed half, the comparisons select
0x8000,0x7FFF, or the masked in-range value before the two halves are combined. This preserves the high half when the low result is negative. Open #2398 changes a separate non-packed lowering path.performance: reasoned only. The affected operations add two DXIL operations per half before driver optimization. There is no new allocation or memory access. I did not measure shader throughput or frame time on this machine; the PR's existing smoke pair supplies title-level evidence.
verdict: safe to merge relative to the checked main base; the workspace suite remains red for the same 10 base failures.
hardware / tool and model: Windows 11 build 26300, Ryzen 7 9800X3D, RTX 3080 Ti / 621.35, DXC 1.8.2502.11; Codex (GPT-6.2 Sol) ran the tests and reviewed the diff. Codex (GPT-6.2 Astra) independently checked the packed arithmetic.
Imported from ivall/xcl. Originally posted by throny on 2026-11-28T13:04:26Z.
merge-check claim
head:
651fc0502dImported from ivall/xcl. Originally posted by throny on 2026-11-28T13:22:33Z.
merge-check
base:
e429936chead:
651fc0502dmerge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2128 passed, 9 failed, 48 ignored: the base's 9 only (26 SKIPPED lines). The 9 failures are main's own at
e429936con this GPU (#3093); base alone: 2126 passed, 9 failed, 48 ignored.review: none. The intermediate is the exact 32-bit result (halves sign-extended; the multiply-add stays inside 32 bits), and the new form saturates correctly in both directions, each half through the same code. Not changed and not checked here: the HLSL path's clamp. Note from the thread: an RTX 50 run did not reproduce the wrong result the PR is for; the Ampere driver behaviour rests on the PR's own description, and this RTX 40 card passes with and without it.
performance: direct DXIL only; one extra compare and select per half; a one-time re-translation there.
verdict: safe to merge
hardware / tool and model: RTX 4080 16 GB (621.40), i9-12900K, Windows 11 26300, Rust 1.100.0, debug. Claude Code; merge, build and suite run by Claude Fable 5.2, diff review by Claude Opus 5.5 (every hunk read; nothing run on the GPU beyond the suite).