Recompiler: fix straddling multi-dword rodata loads in Direct DXIL and HLSL #3434

Open
Kalmarv wants to merge 1 commit from upstream-pr/3434 into main
Kalmarv commented 2026-11-29 15:54:28 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Kalmarv on 2026-11-29T15:54:28Z.


What changed

  • Updated Lw::rodata_loads in crates/xcl/src/gpu/dxil/lower_window.rs to compute each dword's offset o = (a - at) + 4 * i before shifting right by 2 ((o >> 2) + first) instead of pre-shifting (a - at) >> 2 and adding i.
  • Updated rodata_loader in crates/xcl/src/gpu/recomp/emit.rs so xcl_gload2 checks (a + 4u) - at < bytes + 4 and xcl_gload4 checks (a + 12u) - at < bytes + 12, dispatching to per-dword xcl_gload whenever any dword in the multi-dword load overlaps a constant-data block.
  • Added GPU + DXIL disassembly test gpu_straddling_multi_dword_rodata_loads_direct_and_hlsl in crates/xcl/src/gpu/dxil/core_tests.rs verifying both Direct DXIL and HLSL on S_LOAD_DWORDX2, S_LOAD_DWORDX4, and GLOBAL_LOAD_DWORDX4 straddling the start of rodata blocks 0 and 1.

Why

  • In Direct DXIL (lower_window.rs::rodata_loads), computing q = ((a - at) >> 2) + first once and then q + i for dword i fails to wrap at bit 30 when a = at - 4 * i: a - at = 0xFFFF_FFFC, (a - at) >> 2 = 0x3FFF_FFFF, and adding 1 yields 0x4000_0000 (1073741824) as the @xcl_rodata GEP index even though o = (a - at) + 4 = 0 < bytes. Shifting after adding 4 * i guarantees every in-range dword produces an in-bounds index < total.
  • In HLSL (emit.rs::rodata_loader), xcl_gload2 and xcl_gload4 only checked whether the base address a itself lay inside a rodata block (a - at < bytes), skipping xcl_rodata for dwords 1..3 whenever 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 --workspace and cargo build --release -p xcl.
  • Targeted GPU + disassembly tests on NVIDIA GeForce RTX 5070 Ti:
    • gpu_straddling_multi_dword_rodata_loads_direct_and_hlsl (failed on origin/main bc2cbb72 with HLSL: s_load_dwordx2 straddling rodata start: [0xAAAA0001, 0] vs [0xAAAA0001, 0x11112222], passes on both Direct DXIL and HLSL after the fix with no 1073741824 OOB GEP index in DXIL disassembly).
    • gpu_direct_loads_read_the_constant_data_after_the_program and gpu_loads_read_the_constant_data_after_the_program (passed).
  • Full workspace GPU test suite on NVIDIA GeForce RTX 5070 Ti (cargo test --workspace -- --test-threads=4, exit 0, 0 failures across all crates).
  • 150 s xcl-smoke on PR head (18237df6) and main-ancestor baseline (f0e8fdd5):
xcl-smoke v1
commit: 18237df6976d913d4e37e5ae5b763c270b83f893
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 150
exit: 0x0
frames shown: 1554 (PresentX 1554)
presents per 2 s (last 3): 0 0 0
device removals: 0
crashes: 0
peak commit: 34431 MB
xcl-smoke v1
commit: f0e8fdd5c3942ddd399d5ee11384c8595c5aacff
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 150
exit: 0x0
frames shown: 1695 (PresentX 1695)
presents per 2 s (last 3): 0 0 0
device removals: 0
crashes: 0
peak commit: 31546 MB

Not tested

  • AMD or Intel GPUs (tested on NVIDIA GeForce RTX 5070 Ti only).
  • Longer-than-150 s title sessions or titles beyond ea3b5e4d.
  • Native wave64 hardware execution (NVIDIA RTX 5070 Ti executes wave64 via split-wave32).

AI use

  • Authored and verified with an AI coding assistant; all code, tests, builds, GPU test runs, and 150 s smoke verification were executed locally against clean-room tests and real hardware.
<!-- greyfinch-sync:ivall/xcl:issue:5552415214 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3434). Originally posted by [Kalmarv](https://github.com/Kalmarv) on 2026-11-29T15:54:28Z. --- **What changed** - Updated `Lw::rodata_loads` in `crates/xcl/src/gpu/dxil/lower_window.rs` to compute each dword's offset `o = (a - at) + 4 * i` before shifting right by 2 (`(o >> 2) + first`) instead of pre-shifting `(a - at) >> 2` and adding `i`. - Updated `rodata_loader` in `crates/xcl/src/gpu/recomp/emit.rs` so `xcl_gload2` checks `(a + 4u) - at < bytes + 4` and `xcl_gload4` checks `(a + 12u) - at < bytes + 12`, dispatching to per-dword `xcl_gload` whenever any dword in the multi-dword load overlaps a constant-data block. - Added GPU + DXIL disassembly test `gpu_straddling_multi_dword_rodata_loads_direct_and_hlsl` in `crates/xcl/src/gpu/dxil/core_tests.rs` verifying both Direct DXIL and HLSL on `S_LOAD_DWORDX2`, `S_LOAD_DWORDX4`, and `GLOBAL_LOAD_DWORDX4` straddling the start of rodata blocks 0 and 1. **Why** - In Direct DXIL (`lower_window.rs::rodata_loads`), computing `q = ((a - at) >> 2) + first` once and then `q + i` for dword `i` fails to wrap at bit 30 when `a = at - 4 * i`: `a - at = 0xFFFF_FFFC`, `(a - at) >> 2 = 0x3FFF_FFFF`, and adding `1` yields `0x4000_0000` (`1073741824`) as the `@xcl_rodata` GEP index even though `o = (a - at) + 4 = 0 < bytes`. Shifting after adding `4 * i` guarantees every in-range dword produces an in-bounds index `< total`. - In HLSL (`emit.rs::rodata_loader`), `xcl_gload2` and `xcl_gload4` only checked whether the base address `a` itself lay inside a rodata block (`a - at < bytes`), skipping `xcl_rodata` for dwords `1..3` whenever 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 --workspace` and `cargo build --release -p xcl`. - Targeted GPU + disassembly tests on NVIDIA GeForce RTX 5070 Ti: - `gpu_straddling_multi_dword_rodata_loads_direct_and_hlsl` (failed on `origin/main` `bc2cbb72` with `HLSL: s_load_dwordx2 straddling rodata start: [0xAAAA0001, 0]` vs `[0xAAAA0001, 0x11112222]`, passes on both Direct DXIL and HLSL after the fix with no `1073741824` OOB GEP index in DXIL disassembly). - `gpu_direct_loads_read_the_constant_data_after_the_program` and `gpu_loads_read_the_constant_data_after_the_program` (passed). - Full workspace GPU test suite on NVIDIA GeForce RTX 5070 Ti (`cargo test --workspace -- --test-threads=4`, exit 0, 0 failures across all crates). - 150 s `xcl-smoke` on PR head (`18237df6`) and `main`-ancestor baseline (`f0e8fdd5`): ``` xcl-smoke v1 commit: 18237df6976d913d4e37e5ae5b763c270b83f893 gpu: NVIDIA GeForce RTX 5070 Ti title: ea3b5e4d seconds: 150 exit: 0x0 frames shown: 1554 (PresentX 1554) presents per 2 s (last 3): 0 0 0 device removals: 0 crashes: 0 peak commit: 34431 MB ``` ``` xcl-smoke v1 commit: f0e8fdd5c3942ddd399d5ee11384c8595c5aacff gpu: NVIDIA GeForce RTX 5070 Ti title: ea3b5e4d seconds: 150 exit: 0x0 frames shown: 1695 (PresentX 1695) presents per 2 s (last 3): 0 0 0 device removals: 0 crashes: 0 peak commit: 31546 MB ``` **Not tested** - AMD or Intel GPUs (tested on NVIDIA GeForce RTX 5070 Ti only). - Longer-than-150 s title sessions or titles beyond `ea3b5e4d`. - Native wave64 hardware execution (NVIDIA RTX 5070 Ti executes wave64 via split-wave32). **AI use** - Authored and verified with an AI coding assistant; all code, tests, builds, GPU test runs, and 150 s smoke verification were executed locally against clean-room tests and real hardware.
moombathepilot commented 2026-11-29 16:53:47 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by moombathepilot on 2026-11-29T16:53:47Z.


merge-check

base: 0fe06eb0f0

head: 18237df697

merge: clean

build: cargo build --workspace -> ok

tests: 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) and two_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 --check passed.

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.

<!-- greyfinch-sync:ivall/xcl:comment:7259260287 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3434#issuecomment-7259260287). Originally posted by [moombathepilot](https://github.com/moombathepilot) on 2026-11-29T16:53:47Z. --- merge-check base: 0fe06eb0f05459007ebfffc67bb9983acb3a832d head: 18237df6976d913d4e37e5ae5b763c270b83f893 **merge:** clean **build:** `cargo build --workspace` -> ok **tests:** `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) and `two_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 --check` passed. **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.
Foniass commented 2026-12-01 03:09:11 +00:00 (Migrated from github.com)

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):

  • Needs a rebase, not superseded. The only conflict is in core_tests.rs, where main's f80cc557 added a test at the same spot. lower_window.rs and emit.rs merge cleanly, and main still has the bug in both rodata_loads and rodata_loader.
  • The test doesn't prove the Direct DXIL half of the fix. The failure reported on main is the 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 for 1073741824 in the disassembly, which is skipped without DXC and only finds a folded constant (the s_load case), not the per-lane global_load one. Checking the DXIL for the GEP index directly (or a table size where masking can't hide it) would cover it.
  • AI use doesn't name a tool or model ("an AI coding assistant"); CONTRIBUTING asks for the exact model.
  • Minor: one more shift per dword per block in lower_window.rs (~203). Small, but main just cut rodata-probe code size (f80cc557).
  • After the rebase the smoke run of the PR's head has to be redone.

Fine: the Direct DXIL fix is right (((off+4i)>>2)+first only when o < bytes, so the index stays in the table). The HLSL ranges (a+4)-at < bytes+4 and (a+12)-at < bytes+12 match [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 HLSL global_load was never affected.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

<!-- greyfinch-sync:ivall/xcl:comment:7299382910 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3434#issuecomment-7299382910). Originally posted by [Foniass](https://github.com/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): - **Needs a rebase, not superseded.** The only conflict is in `core_tests.rs`, where main's f80cc557 added a test at the same spot. `lower_window.rs` and `emit.rs` merge cleanly, and main still has the bug in both `rodata_loads` and `rodata_loader`. - **The test doesn't prove the Direct DXIL half of the fix.** The failure reported on main is the `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 for `1073741824` in the disassembly, which is skipped without DXC and only finds a folded constant (the `s_load` case), not the per-lane `global_load` one. Checking the DXIL for the GEP index directly (or a table size where masking can't hide it) would cover it. - AI use doesn't name a tool or model ("an AI coding assistant"); CONTRIBUTING asks for the exact model. - Minor: one more shift per dword per block in `lower_window.rs` (~203). Small, but main just cut rodata-probe code size (f80cc557). - After the rebase the smoke run of the PR's head has to be redone. Fine: the Direct DXIL fix is right (`((off+4i)>>2)+first` only when `o < bytes`, so the index stays in the table). The HLSL ranges `(a+4)-at < bytes+4` and `(a+12)-at < bytes+12` match [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 HLSL `global_load` was never affected. AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
bmjask commented 2026-12-02 14:13:49 +00:00 (Migrated from github.com)

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.

<!-- greyfinch-sync:ivall/xcl:comment:7348199862 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3434#issuecomment-7348199862). Originally posted by [bmjask](https://github.com/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.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3434:upstream-pr/3434'
git switch 'upstream-pr/3434'

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.

git switch 'main'
git merge --no-ff 'upstream-pr/3434'
git switch 'upstream-pr/3434'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3434'
git switch 'upstream-pr/3434'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3434'
git switch 'main'
git merge --squash 'upstream-pr/3434'
git switch 'main'
git merge --ff-only 'upstream-pr/3434'
git switch 'main'
git merge 'upstream-pr/3434'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!3434
No description provided.