Faster shader compiles: one window switch per four dwords, every core, --precompile builds the cache titles use #113

Manually merged
github merged 3 commits from gh-pr/113/head into gh-pr/113/base 2026-11-26 04:10:40 +00:00
Owner

@⁠Foniass on GitHub · 2026-11-23 12:34 UTC · original
Foniass:t3/faster-shader-compile → main · +226 −54 · 5 files · 3 commits · merged 2026-11-23 12:51 UTC

Shader compile time. A title's ~24 000 shaders took 30–40 min, so I looked at where DXC spends its time. Measured with the retail shaders.rpf, translated the way a title translates them.

What was slow

  1. Memory-window switches. With a title's unified memory, every mem access is a [branch] switch between the 4 windows (xcl_m*), and the translator emitted one per dword. An s_load_dwordx8 of a descriptor was 8 switches, and an s_buffer_load_dwordx16 was 16 switches plus 16 ?: branches (HLSL 2021's ?: is a branch). In a 1 % random sample (253 programs), 88 % of the switches came from scalar loads. Translated the way a title translates them (4 windows), the same programs took DXC 2.3× as long as with one window, and the slowest went from 24 s to 130 s.
  2. 6 compile threads. MAX_COMPILE_THREADS = 6 capped DXC and the PSO workers. A 16-thread CPU sat mostly idle.
  3. --precompile built the wrong cache. The DXIL cache is keyed by the HLSL. --precompile translated with 1 window and no split wave64 form, but a title translates VS / PS / CS with its 4 windows (and on a 32-lane GPU, compute in the split form). So a title asked for other HLSL and compiled everything again.

Changes

  • Emitter (emit.rs):
    • s_load: Load4 / Load2 for the contiguous dwords.
    • s_buffer_load and buffer_load: bounds checks as selects. A dword that is out of range, or belongs to an inactive lane, reads offset 0 (always inside the window) and is discarded. Four dwords share one switch (xcl_loadx4).
    • ld_raw: one Load4 plus one Load, with no branch.
    • Image results, v_interp, s_cselect / s_cmov / s_ff1 / s_flbit, v_bfm and DPP lane sources: select instead of if / ?:.
  • Threads (dxc.rs, pso_async.rs): every core but one (XCL_DXC_THREADS overrides). wait_for_memory now wants 6 GB of commit plus 1 GB per compile already running before it lets another start right away. Peak DXC commit on the pack's biggest translations is about 0.7 GB (typically 0.1–0.3 GB), so "gigabytes each" no longer holds. Priority stays normal: a title thread can wait for a pipeline (resolve_wait, a compute pipeline's first bind) and must not end up waiting behind its own threads. The driver compiles on the xcl-pso workers are still not memory-gated.
  • --precompile (shaders.rs): translates exactly as pso does: 4 windows for VS / PS / CS, 1 for MS, and the split form when the GPU runs only 32-lane waves. --windows N and --split 0|1 override. There are also measurement helpers: XCL_DUMP_HLSL=<dir> (with --recomp) writes every XCL_DUMP_EVERY-th translation, XCL_RECOMP_WINDOWS translates with that many windows, and XCL_RECOMP_ONLY=<hash> translates one program.

Numbers (Ryzen 7 7800X3D, 8 cores / 16 threads, DXC 1.9.2602)

main this PR
1 % random sample, standalone dxc.exe CPU time (4 windows) 771 s 424 s
slowest program in that sample 130 s 33 s
--precompile, first 10 % of the pack (2 650 records), 4 windows, wall time 327–378 s (6 threads) 176 s (15 threads)
same, CPU time at 6 threads 2 257 s 1 922 s
  • Thread count: most of the wall-time gain comes from here.
  • Emitter: how much it saves depends on the mix. It saves 45 % on the random sample, which the big compute programs dominate, and 15 % on the first 10 %.
  • Variance: main measured 327 s and 378 s on two runs of the same slice, so wall-time differences of a few percent between runs are noise.
  • Full pack: I didn't time it end to end.

Checked

  • Tests: cargo test --workspace --release on an RTX 5070 Ti: 527 passed, 0 failed (2 no wave64 skips, as on main). The GPU tests also pass with XCL_SPLIT_WAVE64=1.
  • New test: gpu_grouped_loads_bounds_and_inactive_lanes covers an unaligned s_load_dwordx8, s_buffer_load_dwordx8 / x16 / x2 straddling num_records, and buffer_load_dwordx3 (idxen) / x2 (offen) with lanes past the end and inactive lanes that keep their registers.
  • Window switch: gpu_memory_windows_above_4_gib gains an s_buffer_load_dwordx4 from window 1, which goes through the multi-window xcl_loadx4.
  • Whole pack: all 26 698 programs translate (100 %, 0 errors). Every shader in the 10 % precompile compiled with 0 DXC errors.
  • Rebase: rebased on 58309b9. v_interp keeps its (float) conversion as a select, and ps_interp_converts_integer_inputs_and_compiles passes.
  • Minecraft: menu renders correctly with the new translations, 60 fps.

Found along the way, not in this PR

  • 13 % of the programs (in the sample) cannot be structured and run as the pc dispatcher, which costs DXC about 1.5× per instruction. Most of them are cold blocks that the console compiler placed after the program, which jump back into it. In address order those look like crossing loops. I have a layout pass that moves them next to their branch; it is not measured enough yet to propose.
  • --precompile still differs from the runtime in two places that predate this PR. A PS's static samplers start after its VS's at run time, but at 0 in --precompile. And the runtime builds the mesh pass-through for its pixel shader, while --precompile builds it without one.
  • translate_mesh / translate_geometry translate with 1 memory window, while VS / PS / CS get the title's 4. Is it intended that NGG and GS programs only reach window 0?

🤖 Generated with Claude Code

**@⁠Foniass** on GitHub · 2026-11-23 12:34 UTC · [original](https://github.com/xcl-dev/xcl/pull/113) `Foniass:t3/faster-shader-compile` → `main` · +226 −54 · 5 files · 3 commits · merged 2026-11-23 12:51 UTC Shader compile time. A title's ~24 000 shaders took 30–40 min, so I looked at where DXC spends its time. Measured with the retail `shaders.rpf`, translated the way a title translates them. ### What was slow 1. **Memory-window switches.** With a title's unified memory, every `mem` access is a `[branch] switch` between the 4 windows (`xcl_m*`), and the translator emitted one per *dword*. An `s_load_dwordx8` of a descriptor was 8 switches, and an `s_buffer_load_dwordx16` was 16 switches plus 16 `?:` branches (HLSL 2021's `?:` is a branch). In a 1 % random sample (253 programs), 88 % of the switches came from scalar loads. Translated the way a title translates them (4 windows), the same programs took DXC **2.3×** as long as with one window, and the slowest went from 24 s to 130 s. 2. **6 compile threads.** `MAX_COMPILE_THREADS = 6` capped DXC and the PSO workers. A 16-thread CPU sat mostly idle. 3. **`--precompile` built the wrong cache.** The DXIL cache is keyed by the HLSL. `--precompile` translated with 1 window and no split wave64 form, but a title translates VS / PS / CS with its 4 windows (and on a 32-lane GPU, compute in the split form). So a title asked for other HLSL and compiled everything again. ### Changes - **Emitter** (`emit.rs`): - `s_load`: `Load4` / `Load2` for the contiguous dwords. - `s_buffer_load` and `buffer_load`: bounds checks as `select`s. A dword that is out of range, or belongs to an inactive lane, reads offset 0 (always inside the window) and is discarded. Four dwords share one switch (`xcl_loadx4`). - `ld_raw`: one `Load4` plus one `Load`, with no branch. - Image results, `v_interp`, `s_cselect` / `s_cmov` / `s_ff1` / `s_flbit`, `v_bfm` and DPP lane sources: `select` instead of `if` / `?:`. - **Threads** (`dxc.rs`, `pso_async.rs`): every core but one (`XCL_DXC_THREADS` overrides). `wait_for_memory` now wants 6 GB of commit plus 1 GB per compile already running before it lets another start right away. Peak DXC commit on the pack's biggest translations is about 0.7 GB (typically 0.1–0.3 GB), so "gigabytes each" no longer holds. Priority stays normal: a title thread can wait for a pipeline (`resolve_wait`, a compute pipeline's first bind) and must not end up waiting behind its own threads. The driver compiles on the `xcl-pso` workers are still not memory-gated. - **`--precompile`** (`shaders.rs`): translates exactly as `pso` does: 4 windows for VS / PS / CS, 1 for MS, and the split form when the GPU runs only 32-lane waves. `--windows N` and `--split 0|1` override. There are also measurement helpers: `XCL_DUMP_HLSL=<dir>` (with `--recomp`) writes every `XCL_DUMP_EVERY`-th translation, `XCL_RECOMP_WINDOWS` translates with that many windows, and `XCL_RECOMP_ONLY=<hash>` translates one program. ### Numbers (Ryzen 7 7800X3D, 8 cores / 16 threads, DXC 1.9.2602) | | `main` | this PR | |---|---|---| | 1 % random sample, standalone `dxc.exe` CPU time (4 windows) | 771 s | **424 s** | | slowest program in that sample | 130 s | **33 s** | | `--precompile`, first 10 % of the pack (2 650 records), 4 windows, wall time | 327–378 s (6 threads) | **176 s** (15 threads) | | same, CPU time at 6 threads | 2 257 s | 1 922 s | - **Thread count:** most of the wall-time gain comes from here. - **Emitter:** how much it saves depends on the mix. It saves 45 % on the random sample, which the big compute programs dominate, and 15 % on the first 10 %. - **Variance:** `main` measured 327 s and 378 s on two runs of the same slice, so wall-time differences of a few percent between runs are noise. - **Full pack:** I didn't time it end to end. ### Checked - **Tests:** `cargo test --workspace --release` on an RTX 5070 Ti: 527 passed, 0 failed (2 `no wave64` skips, as on `main`). The GPU tests also pass with `XCL_SPLIT_WAVE64=1`. - **New test:** `gpu_grouped_loads_bounds_and_inactive_lanes` covers an unaligned `s_load_dwordx8`, `s_buffer_load_dwordx8` / `x16` / `x2` straddling `num_records`, and `buffer_load_dwordx3` (idxen) / `x2` (offen) with lanes past the end and inactive lanes that keep their registers. - **Window switch:** `gpu_memory_windows_above_4_gib` gains an `s_buffer_load_dwordx4` from window 1, which goes through the multi-window `xcl_loadx4`. - **Whole pack:** all 26 698 programs translate (100 %, 0 errors). Every shader in the 10 % precompile compiled with 0 DXC errors. - **Rebase:** rebased on 58309b9. `v_interp` keeps its `(float)` conversion as a `select`, and `ps_interp_converts_integer_inputs_and_compiles` passes. - **Minecraft:** menu renders correctly with the new translations, 60 fps. ### Found along the way, not in this PR - 13 % of the programs (in the sample) cannot be structured and run as the `pc` dispatcher, which costs DXC about 1.5× per instruction. Most of them are cold blocks that the console compiler placed after the program, which jump back into it. In address order those look like crossing loops. I have a layout pass that moves them next to their branch; it is not measured enough yet to propose. - `--precompile` still differs from the runtime in two places that predate this PR. A PS's static samplers start after its VS's at run time, but at 0 in `--precompile`. And the runtime builds the mesh pass-through for its pixel shader, while `--precompile` builds it without one. - `translate_mesh` / `translate_geometry` translate with 1 memory window, while VS / PS / CS get the title's 4. Is it intended that NGG and GS programs only reach window 0? 🤖 Generated with [Claude Code](https://claude.com/claude-code)
With a title's unified memory every access to it is a switch between the four
windows (xcl_m*), and HLSL 2021's ?: is a branch. Scalar loads made one switch
and one branch per dword (an s_load_dwordx8 of a descriptor: 8 switches), and
every vector load, image result and interpolation sat in an if (exec).

- s_load: Load4 / Load2 for the contiguous dwords
- s_buffer_load / buffer_load: bounds checks as selects; a dword out of range or
  of an inactive lane reads offset 0 (always in the window) and is dropped; four
  dwords share one switch (xcl_loadx4)
- ld_raw: one Load4 + one Load, no branch
- image results, v_interp, s_cselect / s_cmov / s_ff1 / s_flbit / v_bfm / DPP
  lane sources: select instead of if / ?:

A 1 % sample of a retail pack (253 programs) translated as a title translates
them (4 windows): DXC 771 s -> 424 s of CPU, the slowest program 130 s -> 33 s.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
DXC and the PSO workers were capped at 6 threads for memory. A retail pack's
biggest translations now take about 0.7 GB in DXC (typical 0.1-0.3 GB).
wait_for_memory now wants 6 GB of commit plus 1 GB per compile already running
before it lets one more in at once. XCL_DXC_THREADS sets the count. The workers
stay at normal priority: a title thread can wait for a pipeline (resolve_wait, a
compute pipeline's first bind) and must not wait behind its own threads.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The DXIL cache is keyed by the HLSL. --precompile translated with one memory
window and no split wave64 form; a title translates VS / PS / CS with its four
windows (pso::mem_windows) and, on a GPU with 32-lane waves, compute in the
split form, so it compiled everything again. --windows N and --split 0|1
override.

Also for measuring DXC on a pack: XCL_DUMP_HLSL=<dir> (with --recomp) writes
every XCL_DUMP_EVERY-th complete translation, XCL_RECOMP_WINDOWS translates
with that many windows, XCL_RECOMP_ONLY=<hash> translates one program.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:10:39 +00:00
github manually merged commit 517d983372 into gh-pr/113/base 2026-11-26 04:10:40 +00:00
Author
Owner

@⁠ivall on GitHub · 2026-11-23 12:51 UTC · original

Merged (f311ca5) – great work, thanks.

Checked on an RX 9070 (16 threads), DXC from SDK 10.0.26100, same random sample (seed 12345, 1 in 100 records, 258 variants) translated with 4 windows (XCL_SURVEY_WINDOWS=4):

main (58309b9) this PR
DXC CPU time, total 1 018 s 422 s
programs with pc blocks (43) 900 s, mean 20.9 s 322 s, mean 7.5 s
slowest (CS_RaytracingResolve_c5cb017e) 170 s 42 s
errors 0 0
  • Whole pack still translates 26 698 / 26 698; cargo test --workspace green with the retail samples (shader pack, console DLLs, texture archive), lib tests also with XCL_SPLIT_WAVE64=1.
  • XDefiant renders its title screen (text included) with this merged.
  • The first version conflicted with 58309b9 (int / uint PS inputs converted again – XDefiant's UI text, #107 regression); your rebase kept the conversion in the select form, which is what I had resolved to as well.
  • Agreed on normal priority: a title thread can wait for a pipeline (resolve_wait).
  • On your question: I don't know of a reason for MS / GS to translate with 1 window – most likely an oversight from when the windows came in (an MS / GS reading title memory above window 0 would read the wrong memory). A PR with a test would be welcome; note it changes those programs' HLSL (cache).
**@⁠ivall** on GitHub · 2026-11-23 12:51 UTC · [original](https://github.com/xcl-dev/xcl/pull/113#issuecomment-7101729948) Merged (f311ca5) – great work, thanks. Checked on an RX 9070 (16 threads), DXC from SDK 10.0.26100, same random sample (seed 12345, 1 in 100 records, 258 variants) translated with 4 windows (`XCL_SURVEY_WINDOWS=4`): | | `main` (58309b9) | this PR | |---|---|---| | DXC CPU time, total | 1 018 s | **422 s** | | programs with `pc` blocks (43) | 900 s, mean 20.9 s | 322 s, mean 7.5 s | | slowest (`CS_RaytracingResolve_c5cb017e`) | 170 s | 42 s | | errors | 0 | 0 | - Whole pack still translates 26 698 / 26 698; `cargo test --workspace` green with the retail samples (shader pack, console DLLs, texture archive), lib tests also with `XCL_SPLIT_WAVE64=1`. - XDefiant renders its title screen (text included) with this merged. - The first version conflicted with 58309b9 (int / uint PS inputs converted again – XDefiant's UI text, #107 regression); your rebase kept the conversion in the `select` form, which is what I had resolved to as well. - Agreed on normal priority: a title thread can wait for a pipeline (`resolve_wait`). - On your question: I don't know of a reason for MS / GS to translate with 1 window – most likely an oversight from when the windows came in (an MS / GS reading title memory above window 0 would read the wrong memory). A PR with a test would be welcome; note it changes those programs' HLSL (cache).
Author
Owner

@⁠Foniass on GitHub · 2026-11-23 13:25 UTC · original

One more measurement: the NVIDIA driver's own compile (pipeline creation) next to DXC's, on the 1 % random sample's 137 compute programs. These are CS plus the compute halves of MS, translated as on a 32-lane GPU (4 windows, split wave64). Times are single-threaded on an RTX 5070 Ti, driver 621.14.

main emitter this PR
DXC 222 s 184 s (−17 %)
driver, CreateComputePipelineState, cold 80.5 s 73.6 s (−9 %)
  • Cold: a harmless salt store in each program kept the driver's shader cache from answering.
  • Excluded: 20 programs with static samplers didn't build, because the test root signature has none. That is my harness, not XCL; its root signature in a title has them.
  • Takeaway: on a cold cache the driver adds about 40 % on top of DXC for these programs, and it also gets a bit faster with this PR.
  • Measurement code: runner::compute_pso_seconds plus an ignored test that reads XCL_PSO_BENCH_DIR. It is not in this PR; I can add it if useful.
**@⁠Foniass** on GitHub · 2026-11-23 13:25 UTC · [original](https://github.com/xcl-dev/xcl/pull/113#issuecomment-7102501470) One more measurement: the NVIDIA driver's own compile (pipeline creation) next to DXC's, on the 1 % random sample's 137 compute programs. These are CS plus the compute halves of MS, translated as on a 32-lane GPU (4 windows, split wave64). Times are single-threaded on an RTX 5070 Ti, driver 621.14. | | `main` emitter | this PR | |---|---|---| | DXC | 222 s | 184 s (−17 %) | | driver, `CreateComputePipelineState`, cold | 80.5 s | 73.6 s (−9 %) | - **Cold:** a harmless salt store in each program kept the driver's shader cache from answering. - **Excluded:** 20 programs with static samplers didn't build, because the test root signature has none. That is my harness, not XCL; its root signature in a title has them. - **Takeaway:** on a cold cache the driver adds about 40 % on top of DXC for these programs, and it also gets a bit faster with this PR. - **Measurement code:** `runner::compute_pso_seconds` plus an ignored test that reads `XCL_PSO_BENCH_DIR`. It is not in this PR; I can add it if useful.
This discussion has been locked. Commenting is limited to contributors.
No description provided.