Skip to content

Recompiler: reuse repeated s_buffer_load_dword* loads in direct DXIL - #2256

Open
ramon-victor wants to merge 1 commit into
xcl-dev:mainfrom
ramon-victor:opt/reload-s-buffer-load
Open

ramon-victor wants to merge 1 commit into
xcl-dev:mainfrom
ramon-victor:opt/reload-s-buffer-load

Conversation

@ramon-victor

Copy link
Copy Markdown

Extends the direct DXIL scalar load reuse pass (gpu::dxil::reload) to follow s_buffer_load_dword* in addition to s_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, and dx.op.rawBufferLoad calls.

Part of #1269.

What is in it

  • crates/xcl/src/gpu/dxil/reload.rs: extend Key with a buffer: bool flag so s_load_dword* and s_buffer_load_dword* cannot alias; match S_BUFFER_LOAD_DWORD..DWORDX16 (excluding GLC/DLC coherent loads, requiring sbase <= 121 for the 4-SGPR descriptor, and tracking all four sbase..sbase+4 descriptor registers in reads() as well as rejecting loads whose SDATA overlaps any descriptor or offset register). Add unit tests for 4-SGPR invalidation, self-overwrite/GLC exclusion, non-aliasing, rawBufferLoad count 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: check self.reload at the top of Lw::smem before branching on s_buffer_load* so available s_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 (0 validator failures):

  • Total emitted DXIL: 42,232,344 B -> 42,202,120 B (-30,224 B, -0.07%)
  • Translation time p95: 302.6 ms -> 292.3 ms

Tested

  • Hardware and toolchain: NVIDIA GeForce RTX 3070 (8 GiB, driver 621.24, wave32), AMD Ryzen 7 5700X, Windows 11 Pro 26300, rustc 1.99.0 (x86_64-pc-windows-msvc), DXC/DXIL 1.8.2502.11 (Windows SDK 10.0.26100.0).
  • cargo test -p xcl --lib gpu::dxil::reload::tests (debug): 9 passed; 0 failed (including s_buffer_load_reuses_and_tracks_four_sgpr_base, the_translator_emits_a_repeated_s_buffer_load_once, and gpu_repeated_s_buffer_load_matches_fresh_load on the RTX 3070).
  • .\scripts\test.ps1 (debug, full workspace): 1246 passed; 0 failed; 46 ignored (25 GPU sub-checks skipped on this wave32 adapter: 21 no wave64, 1 no heap windows, 3 per-lane #1426 refusals).
  • cargo build --release -p xcl + direct DXIL validation sweep on 573 sampled retail shader programs: 573/573 translated and dxil.dll-validated (0 failures).

Regression run

xcl-smoke v1
commit: f087b998d0d51a9f11bbfa0761967a63e778edd9
gpu: NVIDIA GeForce RTX 3070
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1618 (PresentX 1618)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14467 MB
xcl-smoke v1
commit: 69b0bf635f778ff79ccfca4025328ddee044e2bb
gpu: NVIDIA GeForce RTX 3070
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1619 (PresentX 1619)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14479 MB

Not tested

  • Native wave64 GPU hardware (AMD/Intel): RTX 3070 only supports wave32, so native wave64 tests skip on this adapter.
  • Sample-gated tests (XCL_SAMPLE_* env vars unset).

AI use

  • Antigravity (Gemini 4 Neon): analyzed reload.rs and lower_mem.rs, implemented s_buffer_load_dword* reuse and unit/GPU tests, ran the workspace test suite, retail shader validation sweep, and 60 s smoke regression run.

@itsSio

itsSio commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

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 --locked and cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --nocapture both exited 0 on both PCs.

GPU / driver CPU, RAM, toolchain Passed / failed / ignored Runtime SKIPPED
RTX 5080 / 32.0.16.1088 Ryzen 7 9800X3D, 32 GiB; Rust 1.97.0, DXC/DXIL 1.9.2609.5 1246 / 0 / 46 25
RTX 2080 SUPER / 32.0.16.1088 Ryzen 5 5600X, 16 GiB; Rust 1.99.1, DXC/DXIL 1.8.2502.11 1246 / 0 / 46 27

Both 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.

Not tested

Native wave64 execution of the focused reload fixture, full AMD workspace, Intel, retail smoke or shader samples, and performance.

AI use

Ran via Samaritan:

  • OpenCode with OpenAI GPT-6.2 Sol (openai/gpt-6.2-sol): ran the Windows checks, verified the logs and the focused test's wave mode, and wrote this report. No subagents contributed to this check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants