Recompiler: read shader rodata on sub-dword global/flat loads in HLSL and Direct DXIL #3368
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3368"
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-29T10:37:51Z.
What changed
crates/xcl/src/gpu/dxil/lower_mem.rs: passrodata: boolintold_raw_u32_guardedsoflatsub-dword loads (global_load_ubyte,global_load_sbyte,global_load_ushort,global_load_sshort,global_load_short_d16,global_load_short_d16_hi, and the correspondingflat_load_*ops) route their aligned dword reads throughrodata_loadsbefore sub-dword shift/merge, while keepingmubufcallers onrodata = false.crates/xcl/src/gpu/recomp/emit.rs: emit anxcl_gload_u32helper inrodata_loaderthat combinesxcl_gload2(a & ~3u)across aligned and unaligned byte offsets, and use it inflatsub-dword loads whenever shader.rodatais present.crates/xcl/src/gpu/recomp/tests.rs: addsubdword_global_loads_read_rodata_in_hlsl_and_direct_dxil, covering HLSL codegen (with and without.rodata), Direct DXIL translation and validation (1-window and 2-window), and GPU execution across all six sub-dword load opcodes, aligned and unaligned 4-byte boundary crossings,.rodatahits, and non-rodata global memory on HLSL and Direct DXIL paths.Why
Dword-wide global/flat loads (
global_load_dword*,flat_load_dword*) already checked embedded shader.rodata(xcl_gload*in HLSL androdata_loadsin Direct DXIL) when reading constant tables placed after the shader program, because on PC those addresses are not backed by the shader binary in VRAM. Sub-dword global/flat loads (flat_small) bypassed that lookup and readld_rawdirectly, returning wrong bytes whenever a shader indexed a byte or 16-bit constant table in.rodata(including unaligned 16-bit loads spanning two dwords).Tested
Hardware: NVIDIA GeForce RTX 5070 Ti (driver
32.0.16.1074), AMD Ryzen 9 9950X, Windows 11 Pro (Build 26200),rustc 1.99.0, DXC1.9.2609.5(dxil 1.9.2609.5).cargo check --workspace --all-targets: passed with 0 errors and 0 new warnings.cargo test -p xcl --lib rodata_in_hlsl_and_direct_dxil gpu_loads_read_the_constant_data_after_the_program): 2 passed, 0 failed.cargo test --workspace -- --test-threads=4, GPU enabled): exited 0 (0 failed).cargo build --release -p xcl): succeeded.8645f312c3c868b40f25774e3f0055f74db12123(XCL_DIRECT_DXIL=all,XCL_HEAP_WINDOWS=1,XCL_DRED=1; 0 minidumps, 0 System display events):mainancestor baseline smoke run (f0e8fdd5c3942ddd399d5ee11384c8595c5aacff):Not tested
flat_load_*hitting LDS via the flat aperture (unchanged;rodatacheck only matches the shader binary's.rodataGPU VA range).AI use
Used an AI coding assistant to audit
lower_mem.rsandemit.rs, draft the fix and unit/GPU tests, and run the verification suite. All diffs, test assertions, and hardware results were reviewed and verified locally.Imported from ivall/xcl. Originally posted by tiagonleal on 2026-11-30T03:55:11Z.
merge-check
base:
f97120dc19head:
8645f312c3merge: clean
build: cargo build --workspace -> ok (also
cargo build --release -p xcl)tests: cargo test --workspace --no-fail-fast -j 8 -- --test-threads=4 -> 2842 passed, 0 failed, 51 ignored; SKIPPED: 24 lines (22
no wave64, 2no heap windows), the same as on the base; failing: none. Base alone on this PC: 2841 passed, 0 failed, 51 ignored. The new testgpu::recomp::tests::subdword_global_loads_read_rodata_in_hlsl_and_direct_dxilran on this card (noSKIPPEDline for it) and passed.review: whole diff read (+122/-6,
gpu/dxil/lower_mem.rs,gpu/recomp/emit.rs, the test). Byte and word global and flat loads now go through the embedded rodata in both backends, as the dword loads already did; before they read plain memory. Both backends take the two dwords from the aligned address and select the bytes little-endian, and each of the two dwords gets its own rodata range check, so a load at the end of the rodata window reads its upper bytes from memory in both. MUBUF and scratch loads are left alone. The test compiles and runs the HLSL and the direct DXIL explicitly, with 1 and 2 windows and with heap windows, so it covers both backends here. It does not depend on #3434.performance: one extra branch per sub-dword global load, only in programs that have rodata. Measured with
scripts/smoke.ps1, 60 s of a retail title, release: 1707 frames and 16127 MB peak commit against 1635 and 1680 frames, 15366 and 16673 MB on the base. No device removal, no crash.verdict: safe to merge
hardware / tool and model: RTX 5070 Ti 16 GB (617.42, wave32), Ryzen 7 9800X3D, 32 GB, Windows 11 26300, rustc 1.100.0 / Claude Code (Claude Fable 5.2 ran the build, suite, tests and smoke and wrote this; Claude Opus 5.5 read the diff first, and I checked its main points in the merged source)
Imported from ivall/xcl. Originally posted by Edgaras0404 on 2026-11-30T13:11:26Z.
Tested
32.0.21045.29003), AMD Ryzen 5 5600X 6-Core Processor, Windows 10 Pro 22H2 (build 19045)rustc 1.100.1 (20ddd0171 2026-11-25),dxcompiler 1.9.2609.5(01b62ad4) /dxil 1.9.2609.5, D3D12 Agility SDK,debug#3368head8645f312trial-merged ontomain9dfbe3ea(crates/xcl/src/gpu/dxil/lower_mem.rs,crates/xcl/src/gpu/recomp/emit.rs,crates/xcl/src/gpu/recomp/tests.rs:3 files changed, 122 insertions(+), 6 deletions(-))cargo test -p xcl --lib subdword -- --test-threads=1 --nocapture:1 passed; 0 failed; 0 ignored; 0 measured; 2769 filtered out(0 SKIPPED—gpu::recomp::tests::subdword_global_loads_read_rodata_in_hlsl_and_direct_dxilran on RX 6700 XT via DXC)--test-threads=1):cargo test -p xcl --lib gpu::dxil -- --test-threads=1:305 passed; 2 failed; 3 ignored; 0 measured; 2460 filtered out(failures matchmain9dfbe3eabaseline:gpu_compact_form_with_micro_blocks_and_literal_table_runs_as_the_plain_form,gpu_direct_image_get_resinfo_d16)cargo test -p xcl --lib gpu::recomp -- --test-threads=1:521 passed; 3 failed; 21 ignored; 0 measured; 2225 filtered out(failures matchmain9dfbe3eabaseline:f32_programs_on_the_gpu,gpu_f32_compares_with_nan,gpu_float_compares_random)cargo test --workspace --no-fail-fast -- --test-threads=4:0 failed(includingtests\gpu_compute_e2e.rs:9 passed; 0 failedwithSKIPPED heap_window_out_of_memory_falls_back_to_the_switch_form: no heap windows;tests\console_shaders.rs:3 passed; 0 failed; 4 ignored;tests\heap_probe.rs:0 passed; 0 failed; 4 ignored;tests\xg_oracle.rs:6 passed; 0 failed; 12 ignored).tests\gpu_two_pass_cache_e2e.rs:0 passed; 1 failed; 0 ignored(two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs, pre-existing failure onmain9dfbe3ea).-p xcl --lib(2770tests): under--test-threads=4, exited abnormally aftergpu::dxil::cfg::tests::loop_parents_of_a_loop_at_the_entry(exit code: 0xc0000005, STATUS_ACCESS_VIOLATION); when rerun single-threaded above,gpu::dxilandgpu::recompboth completed with only the 5 pre-existing9dfbe3eafailures.Not tested
gpu::dxil/non-gpu::recomp-p xcl --libtests on the merged tree (since-p xcl --libexited early under--test-threads=4)XCL_HEAP_WINDOWS=1testsscripts/smoke.ps1AI use
Imported from ivall/xcl. Originally posted by saintwolf on 2026-11-30T15:02:01Z.
merge-check claim
head:
8645f312c3Imported from ivall/xcl. Originally posted by saintwolf on 2026-11-30T15:16:36Z.
merge-check
base:
9dfbe3ea66head:
8645f312c3merge: clean (trial merge 6be33c1741cc1432b36f8b2325493bcf9506fd72; git diff --check clean; +122/-6 in crates/xcl/src/gpu/dxil/lower_mem.rs, crates/xcl/src/gpu/recomp/emit.rs, tests.rs)
build: cargo build --workspace -> ok (39 pre-existing warnings, none from the PR's files)
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2886 passed, 1 failed, 51 ignored; SKIPPED: 27 (22 "no wave64" — wave32-only GPU, 2 "no heap windows", 1 "cannot disable the driver cache (Developer Mode)", 2 "no xgameruntime.dll"); failing: gpu::dxil::msaa_tests::gpu_direct_image_get_resinfo_d16, pre-existing on this machine (fails identically on base
9dfbe3ea, same "2D D16 resinfo clobbered v2/v3" assertion). The new test subdword_global_loads_read_rodata_in_hlsl_and_direct_dxil ran and passed here (wave64 in split two-wave32 form, 1-window and 2-window, heap windows on and off, decoy bytes planted at the rodata offset in window 0).review: read the whole diff and rodata_loads in the merged tree. Sub-dword global/flat loads (ubyte/sbyte/ushort/sshort/short_d16/short_d16_hi) now go through the embedded shader .rodata like the dword loads already did: in Direct DXIL, ld_raw_u32_guarded takes the loaded dword pair to rodata_loads only for the FLAT_GLBL path (the MUBUF and d16-store callers pass false, unchanged); rodata_loads range-checks each of the two dwords individually, so a load straddling the rodata window boundary reads its out-of-range dword from memory. In HLSL, the d16 global-load path uses a new xcl_gload_u32 (aligned xcl_gload2 + rotate, identical to ld_raw's unaligned extraction) only when a non-empty rodata blob exists; the test asserts xcl_gload_u32 is absent without rodata and present with it. The test's decoy bytes prove the values come from the rodata table, not the raw window. No unsafe, no new dependencies. #3434 (same author, straddling multi-dword rodata loads) is a distinct change that touches the same rodata_loader/lower_window region and will need a small rebase against this one, whichever lands second.
performance: none measurable beyond one extra branch per sub-dword global load in programs that have rodata; author's smoke pair 1707 vs 1635 frames.
verdict: safe to merge
hardware / tool and model: RTX 4070 SUPER (driver 32.0.16.2140), Ryzen 7 7800X3D, Windows 11 build 26300, Rust 1.100.0 / OpenCode, Qwen 3.8 27B
Imported from ivall/xcl. Originally posted by andresd-cerebras on 2026-11-30T21:49:31Z.
Code review location:
crates/xcl/src/gpu/recomp/emit.rs; line 5979xcl_gload2(b)decides with onlyb: for an unaligned 16-bit load atat - 1the second dword (at) is rodata, butinsideis false forb = at - 4, so this reads it frommem, while Direct DXIL (rodata_loads) checks each dword and readsxcl_rodata. Suggestuint2 w = uint2(xcl_gload(b), xcl_gload(b + 4u));.Imported from ivall/xcl. Originally posted by andresd-cerebras on 2026-11-30T21:49:31Z.
Code review location:
crates/xcl/src/gpu/recomp/tests.rs; line 4994All offsets stay inside the block, so the start/end straddles aren't covered. A lane at
block - 1would show the HLSL/DXIL mismatch above.Imported from ivall/xcl. Originally posted by andresd-cerebras on 2026-11-30T21:49:31Z.
Review: COMMENTED
Withdrawn.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T00:20:00Z.
merge-check
base:
d0832e614fhead:
6232c2a006merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2890 passed, 1 failed, 51 ignored (lib binary from a rerun of
cargo test -p xcl --lib --no-fail-fast -- --test-threads=4: on the first full run it aborted with 0xc0000409 after a non-unwinding panic in threadxcl-pso-ahead-1(windows-core interface.rs:41, misaligned pointer dereference); code the PR does not touch, not seen on the rerun, not checked on base); SKIPPED: 28 (22 "no wave64", 2 "no heap windows", 2 "no d3d12SDKLayers.dll", 1 "no D3D12 debug layer", 1 "cannot disable the driver cache (Developer Mode)"); failing: gpu::recomp::tests::subdword_global_loads_read_rodata_in_hlsl_and_direct_dxil, the PR's new test (does not exist on base), fails every run: "HLSL 2-window lane 0: ushort across the block's start edge, left: 1024, right: 1185"review: read the whole diff. (1) The edge lanes added in this push expect, in the 2-window and heap-window runs, the memory bytes next to the rodata block from BEFORE/AFTER, planted at w0 + block - 4 (tests.rs:5047, assertion tests.rs:5015); with several windows a code address is in none of them, so both backends read 0 there. Probed on this GPU: HLSL 2-window, heap windows and Direct DXIL 2-window all return 0x0400 / 0x0011 for the start / end edge, 1-window returns the expected 0x04A1 / 0x0511 in both backends. The backends agree; the test's multi-window expectation is wrong and the test fails on any GPU that runs it (CI has no GPU and skips it). (2) The code is right: xcl_gload_u32 (emit.rs:5981) now looks up each of the two dwords on its own like rodata_loads, which fixes the start-edge HLSL/DXIL mismatch from the earlier review; MUBUF and d16-store callers keep rodata=false (lower_mem.rs:1304, 1321), only FLAT/GLOBAL loads pass true (lower_mem.rs:2021). (3) The PR description check fails: both smoke blocks and the Tested section are for the old head
8645f312; AI use does not name the tool or model; the description still says xcl_gload_u32 uses xcl_gload2. (4) Nits: commit prefix "recomp:" instead of "Recompiler:"; ubyte_d16/sbyte_d16/hi and non-global flat_load* are not exercised by the test. No retail title on this machine, so no smoke run.performance: reasoned only: two rodata branch chains per sub-dword global/flat load, only in shaders that have rodata (replaces one Load4 + Load). No smoke run here (no retail title); the author's smoke pair is for the old head
8645f312, not this one.verdict: not yet: the new GPU test fails at
6232c2a0(wrong multi-window expectation for the bytes outside the block at a code address), and there is no smoke run for the current head (PR description check red)hardware / tool and model: NVIDIA GeForce RTX 5070 Ti (driver 32.0.16.2114 / 621.14), AMD Ryzen 7 7800X3D, Windows 11 Pro 10.0.26300, rustc 1.100.0 MSVC, DXC 1.9.2602.17 / Claude Code, Claude Opus 5.5
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T03:38:38Z.
Review (head
6232c2a0, diff read, not a merge-check: thePR descriptioncheck fails, so not built or run here yet):ld_raw_u32_guarded(lower_mem.rs~516) sends a sub-dword load atat-1..at-3through main'srodata_loads, which for an aligned address ofat-4computes the second dword's index as0x40000000+first, outsidexcl_rodata(mainlower_window.rs~216-228; the bug #3434 fixes). That hits 16-bit loads one byte before a.rodatablock, and the new test asserts exactly that case (even lanes,v11=3), so its result there depends on how the driver treats the bad index. It probably passes on NVIDIA and may read garbage on AMD. Real titles are unlikely to hit it (the bytes before.rodataare code). #3434 should merge first, and the two conflict inrodata_loader(adjacent lines).8645f312, not the head6232c2a0(why the check fails). The What is in it and Regression run headings are missing, AI use names no tool or model, and the full-suite result has no counts. It saysxcl_gload_u32usesxcl_gload2, but the code callsxcl_gloadtwice.Fine: the sub-dword handling is right (u8/i8/u16/i16 with sign extension, d16 hi/lo, the byte offset within the dword), and a load across the end of a block takes its last byte from the block and the next from memory.
buffer_load_*is left alone on purpose, and the HLSL helper is only emitted when.rodatahas data. The checks stay limited to programs withs_getpc_b64(f80cc557). The test fails without the fix, covers both backends with one and two memory windows plus HLSL heap windows, and usesskip_test.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 Foniass on 2026-12-01T15:57:30Z.
Test report (not a merge-check:
PR descriptionred)base:
b2b1f109d2head:
6232c2a006merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2902 passed, 1 failed, 51 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on main); failing: gpu::recomp::tests::subdword_global_loads_read_rodata_in_hlsl_and_direct_dxil
review: not repeated here; my review of this same head is at https://github.com/xcl-dev/xcl/pull/3368#issuecomment-7299917469, and its findings stand. This run adds what reading couldn't: whether the change merges, builds and passes the whole suite on current main.
performance: no smoke run.
assessment: its own new test fails on this GPU:
gpu::recomp::tests::subdword_global_loads_read_rodata_in_hlsl_and_direct_dxilpanics attests.rs~5754, "HLSL 2-window lane 0: ushort across the block's start edge", left 1024, right 1185. Correction to an earlier version of this comment: the PR's code is right and the test's expectation is wrong. With several windows a code address reads 0 outside the block, by design, in both backends. Details, measurements and a test-only fix: https://github.com/xcl-dev/xcl/pull/3368#issuecomment-7320289131. The rest of the suite passes, and the findings in my review standhardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5
AI-written and posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T18:02:03Z.
Follow-up to my test report (head
6232c2a0, merged onto main6bfb5c51): the failing check is in the new test, not in the PR's code or in main.subdword_global_loads_read_rodata_in_hlsl_and_direct_dxil, lane 0's ushort atblock - 1takes its low byte from the word just before the block. That address is a code address (s_getpc_b64, high dword0xC0DE). With several memory windows a code address is in none of them, so it reads 0 by design (emit.rs~2041-2049,lower_window.rs~54-58). Main's own test relies on the same rule (tests.rs~5650, "a code address is in none of them"). So the right value with 2 windows is 0x0400 for lane 0 and 0x0011 for lane 1. The test expects window 0's bytes beside the block (BEFORE/AFTER), which neither backend reads.cargo test -p xcl --lib gpu::recomp -- --test-threads=4gives 530 passed, 0 failed, 21 ignored, with 21 SKIPPED (no wave64). With the PR'semit.rs/lower_mem.rsreset to main, the changed test still fails (first on thexcl_gload_u32check, then on the GPU atHLSL 1-window lane 0 off 0: ubyte, 0 vs 5), so it still covers the fix. Not run on wave64 / AMD.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 Foniass on 2026-12-01T19:12:56Z.
To get this merged without waiting on another round, I opened #3607: it carries your commit from this PR unchanged (same SHA, you stay the author) plus the one test-only commit from my follow-up above, with a full suite run and a smoke pair on that exact head. If you'd rather keep it here, pushing
fb986aecfromFoniass/xclbranchready/3368onto this branch (a fast-forward) gives the same result, and I'll close #3607.AI-assisted: Claude Code (Claude Opus 5.5), posted by Foniass.