Recompiler: clamp out-of-range format and sub-dword buffer loads #1231
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1241"
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 eizispark on 2026-11-24T13:37:48Z.
BufKind::Loadclamps inactive (!act) and out-of-range (!ok) MUBUF addresses to0ubefore reading the memory window, whereasBufKind::FormatLoad,mubuf_d16, and sub-dword MUBUF loads still passed unclamped 32-bit{t}_aoffsets intold_raw(whose arguments HLSL 2021select()evaluates eagerly). When an inactive or out-of-range lane holds a large or negative/sentinel offset past a 512 MiB or 4095 MiB window whilexcl_wstill selects that window, storage-buffer translation undervkd3d-protonon NVIDIA Vulkan can fault the GPU MMU (NVRM: Xid 13 … MMU Fault, #916).Part of #916.
What is in it
crates/xcl/src/gpu/recomp/emit.rs: clampld_rawaddresses to0uviaselect(and({t}_act, {t}_ok), {t}_a, 0u)inBufKind::FormatLoad,mubuf_d16loads, and sub-dword MUBUF loads (buffer_load_ubyte/sbyte/ushort/sshort).crates/xcl/src/gpu/recomp/tests.rs: addformat_and_subdword_buffer_loads_clamp_out_of_range_offsetschecking generated 1-window and 4-window HLSL and GPU execution across in-range, out-of-range, andEXEC-masked lanes forbuffer_load_format_xyzw,tbuffer_load_format_xyzw,buffer_load_ubyte,buffer_load_short_d16, andbuffer_load_format_d16_xy.Tested
32.0.32015.16001),rustc 1.100.0 (0ef1bc386 2026-11-09), debug and release.cargo test --workspace --no-fail-fast -- --test-threads=4: 752 passed, 0 failed, 41 ignored, 0SKIPPEDGPU capability skips (the 2 optionald3d12SDKLayers.dlltests return early because Windows Graphics Tools is not installed on this host).format_and_subdword_buffer_loads_clamp_out_of_range_offsetsfailed before theemit.rschanges (FormatLoadand sub-dword loads emitted unclampedld_raw(tN_a)calls) and passes after them (gpu::recomp: 190 passed, 0 failed, 18 ignored).Regression run
main:PR head:
Not tested
vkd3d-protonon NVIDIA (Xid 13world-load reproduction in #916).XCL_SAMPLE_*sample-data tests.AI use
Imported from ivall/xcl. Originally posted by dcastell1 on 2026-11-24T13:45:17Z.
Verified on Windows 11 10.0.26300, NVIDIA GeForce RTX 5090 (driver 621.24), Rust 1.100.0 MSVC 14.44.35207, debug build, on
main@930e8b4(baseline 751 passed, 0 failed, 41 ignored on this box):Two more than the baseline: clamping out-of-range buffer loads and 64-bit cases are covered and green.
Tree restored afterwards (full diff against a clean checkout), hardware adapter, no Wine, no game data. AI-assisted (opencode): applied the patch to a built tree, ran the suite, reverted it.
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T14:02:03Z.
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:Thanks!
Imported from ivall/xcl. Originally posted by upipibi on 2026-11-24T14:12:16Z.
The vector-load half looks right to me.
ld_raw(select(and(act, ok), a, 0u))removes the eager out-of-range read that HLSL 2021'sselectevaluated, andv = select(act, select(ok, val, 0u), v)is the oldif (act) v = ok ? val : 0u.The
s_buffer_loadhalf changes behaviour, not only overflow handling, and I don't know which side RDNA2 is on:imm + soffwidened to 64 bits, an offset whose sum passes 2^32 is now out of range (0). Before, it wrapped to a low, in-range offset. Whether the scalar unit forms the buffer offset as a 32-bit sum, so that it wraps, is the question. The range check is against a 32-bitnum_records.num_records * stridepast 2^32: is the hardware's limit the full product or a 32-bit one?gpu_s_buffer_load_64bit_bounds_and_offsetchecks this PR's model, so it would pass either way the hardware went. A raw-ISA run on an RDNA2 card would settle both: ans_buffer_load_dwordwithsoff = 0xFFFFFFFC,imm = 8, andnum_recordscovering offset 4. Lyrnc and luckyteagirl have run probes like that for #605 and #772. Until then, the two parts could go separately so the clamping isn't held up. Read from the diff, not run.AI-assisted (Claude Code).
[PR #1241] Recompiler: clamp out-of-range buffer loads and 64-bit s_buffer_loadto [PR #1241] Recompiler: clamp out-of-range format and sub-dword buffer loadsImported from ivall/xcl. Originally posted by eizispark on 2026-11-24T15:09:20Z.
Thanks @upipibi for catching that
s_buffer_loadimm + soffandnum_records * stridewrapping vs 64-bit bounds has not been measured on live RDNA2 hardware yet, and thanks @dcastell1 and @DavidM1911 for the test reports.I split the
s_buffer_loadchange and test out of this PR pending a raw-ISA probe on RDNA2, rebased onto currentmain(930e8b4) keeping only theFormatLoad,d16, and sub-dword MUBUFld_rawclamping and its test as a single commit (7b7c853), and updated the PR description with fresh workspace test counts and a fresh 60 sxcl-smokerun on7b7c853.AI use: Antigravity (Gemini 4 Carbon)
Imported from ivall/xcl. Originally posted by throny on 2026-11-25T09:20:32Z.
Test report for exact head
7b7c853.Tested
cargo build --workspace && cargo test --workspace -- --test-threads=4on7b7c853as it is (its own base): 752 passed, 0 failed, 41 ignored.SKIPPED: 2 lines (no wave64 on this adapter, and the like).scripts/smoke.ps1, the retail title, 60 s, release builds,main568e7dbfirst, then this head:main:
PR:
Not tested: AMD, the head merged onto current
main, a world load.AI use: Claude Code (Claude Opus 5.5) ran this and wrote the report; the diff was read for safety by a Claude Opus 5.5 sub-agent before it was built.
Imported from ivall/xcl. Originally posted by xpatfussy69x on 2026-11-25T11:15:34Z.
Test report for head
7b7c853as pushed (not merged onto currentmain) – Windows, NVIDIA, wave32-only adapter (both listed under Not tested).Tested
.\scripts\test.ps1(cargo build --workspace+cargo test --workspace -- --test-threads=4): 752 passed, 0 failed, 41 ignoredformat_and_subdword_buffer_loads_clamp_out_of_range_offsetsran and passed; the existing GPU buffer tests (gpu_global_atomics_and_sub_dword_access,gpu_more_atomics_sub_dword_scratch_valu, …) pass tooXCL_SAMPLE_*data set (game-data tests not run)Not tested
mainAI use
Imported from ivall/xcl. Originally posted by 4usphs on 2026-11-25T11:52:38Z.
AMD run on the exact head
7b7c853(7b7c85359b), as pushed on its base930e8b4(not merged onto currentmain), on two AMD adapters with native 64-lane waves: RDNA4 and the console's generation, RDNA2.Tested
XCL_TRANSLATED_CACHE=0; adapter picked withXCL_ADAPTER.cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4:gfx1036), driver 32.0.21045.29003: 752 passed, 0 failed, 41 ignoredSKIPPEDtests on either adapter.format_and_subdword_buffer_loads_clamp_out_of_range_offsetsruns and passes on both adapters.Not tested
AI use
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-26T04:32:31Z.
Re-verification on RTX 3060 Ti (Windows 11): still a merge conflict with current
mainon the new head — needs another rebase before it can be tested.Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T05:12:59Z.
Triage (#1607) – head
7b7c853No open or merged PR makes the same change. Main clamps the address of inactive or out-of-range lanes to 0 only for dword
BufKind::Load; this PR does the same for the format loads, the sub-dword loads and the d16 loads in emit.rs. #1574 changes how format codes above 77 are mapped, a different fix in the same lines.The PR conflicts with main now and needs a rebase.
Recommendation: keep open.
AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.