Recompiler: clamp out-of-range format and sub-dword buffer loads #1241
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!1241
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@eizispark on GitHub · 2026-11-24 13:37 UTC · original
eizispark:fix/916-buffer-load-bounds→main· +95 −8 · 2 files · 1 commits · openBufKind::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
@dcastell1 on GitHub · 2026-11-24 13:45 UTC · original
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.
@DavidM1911 on GitHub · 2026-11-24 14:02 UTC · original
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:Thanks!
@upipibi on GitHub · 2026-11-24 14:12 UTC · original
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).
@eizispark on GitHub · 2026-11-24 15:09 UTC · original
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)
@throny on GitHub · 2026-11-25 09:20 UTC · original
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.
@xpatfussy69x on GitHub · 2026-11-25 11:15 UTC · original
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
@4usphs on GitHub · 2026-11-25 11:52 UTC · original
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
@DavidM1911 on GitHub · 2026-11-26 04:32 UTC · original
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.View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.