Recompiler: reuse repeated s_buffer_load_dword* loads in direct DXIL #2256
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!2256
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2256"
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?
@ramon-victor on GitHub · 2026-11-25 11:34 UTC · original
ramon-victor:opt/reload-s-buffer-load→main· +129 −29 · 2 files · 1 commits · openExtends the direct DXIL scalar load reuse pass (
gpu::dxil::reload) to follows_buffer_load_dword*in addition tos_load_dword*, so repeated non-coherent constant-buffer loads reuse their earlier post-bounds-check values instead of re-emitting buffer bounds checks, window selection, anddx.op.rawBufferLoadcalls.Part of #1269.
What is in it
crates/xcl/src/gpu/dxil/reload.rs: extendKeywith abuffer: boolflag sos_load_dword*ands_buffer_load_dword*cannot alias; matchS_BUFFER_LOAD_DWORD..DWORDX16(excludingGLC/DLCcoherent loads, requiringsbase <= 121for the 4-SGPR descriptor, and tracking all foursbase..sbase+4descriptor registers inreads()as well as rejecting loads whoseSDATAoverlaps any descriptor or offset register). Add unit tests for 4-SGPR invalidation, self-overwrite/GLC exclusion, non-aliasing,rawBufferLoadcount reduction, and a wave32 GPU execution test checking repeated load reuse (including OOB zeroing) and fresh reload after a global store.crates/xcl/src/gpu/dxil/lower_mem.rs: checkself.reloadat the top ofLw::smembefore branching ons_buffer_load*so availables_buffer_load_dword*repeats read their saved SSA variables directly.On a seeded 600-program sample (
xcl shaders <archive> --direct --sample 600 --seed 3 --max-bytes 40000 --validate --threads 8, 573 programs within the cap), all 573/573 validate cleanly (0validator failures):42,232,344 B -> 42,202,120 B(-30,224 B,-0.07%)302.6 ms -> 292.3 msTested
621.24, wave32), AMD Ryzen 7 5700X, Windows 11 Pro26300,rustc 1.99.0(x86_64-pc-windows-msvc), DXC/DXIL1.8.2502.11(Windows SDK10.0.26100.0).cargo test -p xcl --lib gpu::dxil::reload::tests(debug):9 passed; 0 failed(includings_buffer_load_reuses_and_tracks_four_sgpr_base,the_translator_emits_a_repeated_s_buffer_load_once, andgpu_repeated_s_buffer_load_matches_fresh_loadon the RTX 3070)..\scripts\test.ps1(debug, full workspace):1246 passed; 0 failed; 46 ignored(25 GPU sub-checks skipped on this wave32 adapter: 21no wave64, 1no heap windows, 3 per-lane#1426refusals).cargo build --release -p xcl+ direct DXIL validation sweep on 573 sampled retail shader programs:573/573translated anddxil.dll-validated (0failures).Regression run
Not tested
XCL_SAMPLE_*env vars unset).AI use
reload.rsandlower_mem.rs, implementeds_buffer_load_dword*reuse and unit/GPU tests, ran the workspace test suite, retail shader validation sweep, and 60 s smoke regression run.@itsSio on GitHub · 2026-11-25 11:43 UTC · original · edited 2026-11-25 11:49 UTC
Tested
Independent Windows verification on clean
69b0bf635f778ff79ccfca4025328ddee044e2bb. Windows 11 Pro 26200 and x64 MSVC on both PCs, unoptimized dev/test with debug info off.cargo build --workspace --lockedandcargo test --workspace --locked --no-fail-fast -- --test-threads=4 --nocaptureboth exited 0 on both PCs.SKIPPED32.0.16.108832.0.16.1088Both logged 20 native-wave64 skips, three per-lane f16/f32 refusals, unavailable driver-cache control and unavailable heap windows. The RTX 2080 SUPER also logged two skips for the missing D3D12 debug layer.
cargo test -p xcl --lib --locked gpu::dxil::reload::tests -- --test-threads=1 --nocapture: 9 / 0 / 0, no runtime skips, on both RTX cards and the Radeon RDNA2 iGPU (32.0.21043.5001, same Ryzen 7 system and toolchain). This includes the Direct DXIL load-reuse GPU test: the reused load matched the first load and the load after a store saw the updated value. That fixture explicitly uses wave32, including on Radeon.Wave64 follow-up (test-only overlay): In separate scratch checkouts at the same head, I changed only the existing
#[cfg(test)]fixture: usewave64_programs_supported(), requestdirect_kernel_full(&code, true), initialize all 64 lanes, and print the adapter andsplit_wave64()result. All shader instructions and result assertions were unchanged. The modifiedreload.rswas byte-identical on both PCs (SHA-25608422f00d39710c94bd0404562fcbab6d50114ee2c4fd53b970231b0ef19e880). No runtime code changed; the clean-head results above are separate.cargo test --locked -p xcl --lib gpu::dxil::reload::tests::gpu_repeated_s_buffer_load_matches_fresh_load_wave64_probe -- --exact --test-threads=1 --nocapture, with the same per-PC hardware and toolchains above: 1 passed / 0 failed / 0 ignored / 0 skipped on the Radeon RDNA2 iGPU (native wave64,split_wave64=false) and on each RTX card (split wave64,split_wave64=true). The modified fixture passed the same expected-value, bounds and post-store reload assertions in both wave64 forms.Not tested
Full AMD workspace, Intel, retail smoke or shader samples, and performance.
AI use
Ran via Samaritan:
openai/gpt-6.2-sol): ran the Windows checks, prepared and ran the test-only wave64 overlay, verified the logs and wave modes, and wrote this report. No subagents contributed to this check.@nnonno91 on GitHub · 2026-11-25 15:24 UTC · original
Independent Windows check of
69b0bf635f778ff79ccfca4025328ddee044e2bb. Repeated shader loads returned the original value, and the load after a store read the updated value on both adapters.Tested
cargo test --locked -p xcl --lib gpu::dxil::reload::tests -- --nocapture --test-threads=1on each selected adapter: 9 passed, 0 failed, 0 ignored, no logged skips per adapter. The stock GPU test uses wave32.cargo test --locked -p xcl --lib gpu_repeated_s_buffer_load_matches_fresh_load -- --nocapture --test-threads=1: 1 passed, 0 failed, 0 ignored, no logged skips per adapter. The logs identified native wave64 on Radeon and split wave64 on RTX 5090. The fixture also confirmed that the out-of-bounds fourth word returned zero before and after reuse. Restored the clean checkout.Not tested
Parent revision, performance, retail titles, or the full workspace suite.
AI use
OpenAI Codex (GPT-6.2 Sol) prepared and ran the tests, verified the results, and wrote this report.
@DavidM1911 on GitHub · 2026-11-25 16:53 UTC · original
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)Thanks!
@luckyteagirl on GitHub · 2026-11-26 09:07 UTC · original · reviewed
On
69b0bf6, this PR extends available-load reuse toS_BUFFER_LOAD_DWORD*, butreload::changesstill missesVOPCSDWA'sSD=1, SDSTSGPR write. For example, two identicalS_BUFFER_LOAD_DWORDinstructions using descriptors[4:7], separated byV_CMP_EQ_U32SDWA writings4, can reuse the first load's value for the second even though the descriptor base changed. The new buffer-load key makes this instruction family subject to the existing missed invalidation; the base emits two loads.#2479 fixes the SDWA invalidation for the same analysis. Could this PR be stacked/rebased on that fix, or include it before buffer-load reuse is merged? Extending its CPU analysis fixture to a changed buffer descriptor would pin down this new instruction family. Source review only; I did not run the synthetic program.
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.