Repository navigation
Recompiler: read shader rodata on sub-dword global/flat loads in HLSL and Direct DXIL - #3607
Conversation
… Direct DXIL HLSL's xcl_gload_u32 looks up each of the two dwords on its own, as Direct DXIL's rodata_loads does: through xcl_gload2 it decided with the first dword's address only, so a 16-bit load starting 1 byte before a rodata block took its upper byte from memory in HLSL and from the block in Direct DXIL. The test adds 16-bit loads across the block's start and end edges. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
subdword_global_loads_read_rodata_in_hlsl_and_direct_dxil expected the
ushort that straddles the start and end of the rodata block to take its
outer byte from window 0's decoy words (BEFORE / AFTER) on the 2-window
and heap-window paths too. With several memory windows an address in the
shader's code range lies in no window, and a load from no window reads 0
(emit.rs's window lookup and lower_window.rs); main's own
gpu_loads_read_the_constant_data_after_the_program relies on the same
rule. So the HLSL 2-window run failed ("ushort across the block's start
edge", 1024 against 1185) although the loads were right.
The check now takes whether the run uses several windows and expects
0 for the byte beside the block then. The 1-window paths keep BEFORE /
AFTER. The test still fails with emit.rs and lower_mem.rs reset to main.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
merge-check claim |
|
merge-check
|
|
merge-check |
Replaces #3368 so it can be merged as is: it carries Kalmarv's commit from #3368 unchanged (same SHA, author kept) plus one test-only commit that fixes the new test's expectation (with several memory windows a code address reads 0 beside the block, in both backends; details in #3368 (comment)). All credit for the fix goes to Kalmarv.
Sub-dword global/flat loads (
flat_small) skipped the lookup in the shader's embedded.rodatathat dword loads already do, so a shader indexing a byte or 16-bit constant table placed after its program read the wrong bytes. This routes them through the same lookup in HLSL and Direct DXIL.What is in it
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.crates/xcl/src/gpu/recomp/tests.rs(second commit,Tests: expect 0 beside the rodata block with several memory windows): with several memory windows a code address is in no window and reads 0 (the window lookup inemit.rs/lower_window.rs; main'sgpu_loads_read_the_constant_data_after_the_programrelies on the same rule), so the ushort that straddles the block's start or end takes 0 there, not window 0's decoy word. Before it, the test failed on the HLSL 2-window run ("ushort across the block's start edge", 1024 against 1185) although the loads were right.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
Run by Foniass on head
fb986aecec94a839d72cf5bcaf2d5f26fabf6edcmerged into main6bfb5c5153ccc23517daf30aa1071ddb0fadb53c(clean merge): NVIDIA GeForce RTX 5070 Ti (driver 621.14), AMD Ryzen 7 7800X3D, Windows 11 Pro build 26300,rustc 1.100.0 (0ef1bc386 2026-11-09)(stable-x86_64-pc-windows-msvc), DXC 1.9.2602.17, debug tests / release smoke.cargo build --workspace: ok.cargo test --workspace --no-fail-fast -- --test-threads=4: 2905 passed, 0 failed, 51 ignored (43 test binaries).subdword_global_loads_read_rodata_in_hlsl_and_direct_dxilpasses on all five paths. A first run lost the lib binary to a 0xc0000005 in the NVIDIA driver right aftergpu::agility::tests::create_device_sets_dred_first, a crash this machine also has on main; the rerun passed.no wave64(the GPU runs wave64 split;lower_dxil,lower,kerneland tworecomp::testsGPU comparisons), 2 ×no heap windows(heap_window_out_of_memory_falls_back_to_the_switch_form,two_pass_binds_set_the_shared_view_heap), 3 × no D3D12 debug layer (uploads_start_from_each_subresources_state, the title under the debug layer with and without DRED), 1 ×pso_measurement_compiles_an_exact_synthetic_record(cannot disable the driver cache without Developer Mode).emit.rsandlower_mem.rsat main it stops at "expected xcl_gload_u32 in HLSL"; with onlylower_mem.rsat main it fails on the GPU at "Direct DXIL 1-window lane 0 off 0: ubyte" (0 against 5).8645f312(before the rebase):cargo check --workspace --all-targets, the two targeted GPU tests, the full suite (exit 0) andcargo build --release -p xclon an RTX 5070 Ti (driver32.0.16.1074), Ryzen 9 9950X, Windows 11 build 26200,rustc 1.99.0; a 150 s smoke run withXCL_DIRECT_DXIL=all,XCL_HEAP_WINDOWS=1,XCL_DRED=1showed 1587 frames against 1695 on mainf0e8fdd5, no device removal, no crash.Regression run
The same title for 60 s, release builds of main and of this PR's head with no uncommitted changes. Both blocks were made with main's
scripts/smoke.ps1: the branch's own copy predates main's fix that handsXCL_PREPARE=0/XCL_RUN_SECONDSto the process, so with it the title ran without a time limit and was killed.main:
this PR:
Not tested
no wave64tests above did not run)..rodataload.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.The test fix (second commit), the test run and the smoke pair above were done with Claude Code (Claude Opus 5.5) for Foniass.
🤖 Generated with Claude Code