Recompiler: fix straddling multi-dword rodata loads in Direct DXIL and HLSL #3434
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3434"
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 Kalmarv on 2026-11-29T15:54:28Z.
What changed
Lw::rodata_loadsincrates/xcl/src/gpu/dxil/lower_window.rsto compute each dword's offseto = (a - at) + 4 * ibefore shifting right by 2 ((o >> 2) + first) instead of pre-shifting(a - at) >> 2and addingi.rodata_loaderincrates/xcl/src/gpu/recomp/emit.rssoxcl_gload2checks(a + 4u) - at < bytes + 4andxcl_gload4checks(a + 12u) - at < bytes + 12, dispatching to per-dwordxcl_gloadwhenever any dword in the multi-dword load overlaps a constant-data block.gpu_straddling_multi_dword_rodata_loads_direct_and_hlslincrates/xcl/src/gpu/dxil/core_tests.rsverifying both Direct DXIL and HLSL onS_LOAD_DWORDX2,S_LOAD_DWORDX4, andGLOBAL_LOAD_DWORDX4straddling the start of rodata blocks 0 and 1.Why
lower_window.rs::rodata_loads), computingq = ((a - at) >> 2) + firstonce and thenq + ifor dwordifails to wrap at bit 30 whena = at - 4 * i:a - at = 0xFFFF_FFFC,(a - at) >> 2 = 0x3FFF_FFFF, and adding1yields0x4000_0000(1073741824) as the@xcl_rodataGEP index even thougho = (a - at) + 4 = 0 < bytes. Shifting after adding4 * iguarantees every in-range dword produces an in-bounds index< total.emit.rs::rodata_loader),xcl_gload2andxcl_gload4only checked whether the base addressaitself lay inside a rodata block (a - at < bytes), skippingxcl_rodatafor dwords1..3whenever a multi-dword load started immediately before a block and straddled into it.Tested
cargo check --workspace --all-targets(0 errors, 0 new warnings).cargo build --workspaceandcargo build --release -p xcl.gpu_straddling_multi_dword_rodata_loads_direct_and_hlsl(failed onorigin/mainbc2cbb72withHLSL: s_load_dwordx2 straddling rodata start: [0xAAAA0001, 0]vs[0xAAAA0001, 0x11112222], passes on both Direct DXIL and HLSL after the fix with no1073741824OOB GEP index in DXIL disassembly).gpu_direct_loads_read_the_constant_data_after_the_programandgpu_loads_read_the_constant_data_after_the_program(passed).cargo test --workspace -- --test-threads=4, exit 0, 0 failures across all crates).xcl-smokeon PR head (18237df6) andmain-ancestor baseline (f0e8fdd5):Not tested
ea3b5e4d.AI use
Imported from ivall/xcl. Originally posted by moombathepilot on 2026-11-29T16:53:47Z.
merge-check
base:
0fe06eb0f0head:
18237df697merge: clean
build:
cargo build --workspace-> oktests:
cargo test --workspace --no-fail-fast -- --test-threads=4 --nocapture-> 2736 passed, 2 failed, 49 ignored, with 12 explicit SKIPPED notices included in Cargo's pass counts. The new rodata regression test passed on both Direct DXIL and HLSL. Both failures reproduced on unmodified main in targeted reruns:fuzz_validate_and_gpu_1(seed 722, same GPU/CPU mismatch) andtwo_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs(same assertion on releasing two-pass state). The full suite ran on the merge only.review: Read the full PR and trial-merge diffs. Direct DXIL derives each table index from that dword's offset after 32-bit wrapping. HLSL uses per-dword loads when a multi-dword load overlaps a rodata block. The regression test checks scalar x2 and x4 reads and vector x4 reads crossing into two rodata blocks. No blocking findings.
git diff --cached --checkpassed.performance: The HLSL path retains the vector-load fast path for reads outside rodata. Direct DXIL emits per-dword index arithmetic for the affected loads. Frame time and memory impact were not measured. No independent retail smoke run was performed for this Tier 1 check.
verdict: safe to merge
hardware / tool and model: Windows 11 Home build 26300, Ryzen 7 5700X3D, Radeon RX 7800 XT (driver 32.0.32029.2010), Rust 1.100.0 x86_64-pc-windows-msvc. Codex (GPT-6, exact variant unavailable) verified refs, reviewed the diffs, ran the merge build and tests and targeted base reruns, and drafted this report.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T03:09:11Z.
Review (head
18237df6, diff read, not a merge-check; it conflicts with main, so not built or run):core_tests.rs, where main'sf80cc557added a test at the same spot.lower_window.rsandemit.rsmerge cleanly, and main still has the bug in bothrodata_loadsandrodata_loader.HLSL:check, which means the Direct DXIL check (run first) already returned the right values there. The bad index is the right one plus 2^30, and with an 8-dword table a driver that masks the index lands on the right value. The only thing that catches the Direct DXIL bug is the text search for1073741824in the disassembly, which is skipped without DXC and only finds a folded constant (thes_loadcase), not the per-laneglobal_loadone. Checking the DXIL for the GEP index directly (or a table size where masking can't hide it) would cover it.lower_window.rs(~203). Small, but main just cut rodata-probe code size (f80cc557).Fine: the Direct DXIL fix is right (
((off+4i)>>2)+firstonly wheno < bytes, so the index stays in the table). The HLSL ranges(a+4)-at < bytes+4and(a+12)-at < bytes+12match [at-4, at+bytes) and [at-12, at+bytes), unsigned wrap included. Loads crossing a block's end already fell back to memory per dword, and HLSLglobal_loadwas never affected.AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T14:13:49Z.
@Prime1997 could you take a look at this one for review and merge? My automated review notes are above, if any.
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.