Skip to content

Recompiler: large compute programs share repeated code with DXC and the driver - #1867

Closed
SamG-Coder wants to merge 1 commit into
xcl-dev:mainfrom
SamG-Coder:recomp/shared-compute-code
Closed

SamG-Coder wants to merge 1 commit into
xcl-dev:mainfrom
SamG-Coder:recomp/shared-compute-code

Conversation

@SamG-Coder

Copy link
Copy Markdown

Part of #1269. Large compute programs share code the HLSL path repeated at every use, so DXC and the driver see one copy instead of thousands. On six retail compute programs of 1.3 – 6.7 MB HLSL, pipeline creation is 1.4 – 5.4× faster and the DXIL 11 – 27 % smaller (table below).

Draft: this branch combines the changes so they could be measured together on current main. It will be split into separate PRs per CONTRIBUTING before review (see What is in it), and the regression runs are still missing.

What is in it

  • Buffer bounds: one xcl_buf_in_range helper instead of an inline bounds expression at every buffer access.
  • lanebit is [noinline] in programs of 4 096+ instructions (one copy of the EXEC bit test instead of one per vector write).
  • Typed-buffer format conversions (fmt_*, st_bytes) are shared, [noinline], in compute programs of 256+ instructions; the memory-window accessors and the split-wave64 exchange are out of line from 1 024 instructions (switch windows only; heap windows are unchanged).
  • regions.rs: in compute programs of 4 096+ instructions where repeated blocks are over a third of the code, a repeated single-entry if arm is emitted once as a function.
  • Two behaviour fixes that came with it and will be their own PRs: buffer indices add the lane id when the descriptor's ADD_TID bit (23) is set, and inactive or out-of-range lanes load from address 0 instead of their computed address; unaligned 8- and 16-byte typed stores write every affected dword.
  • 8 new tests in gpu/recomp/tests.rs.

Measurements (xcl shaders <pack> --measure-pso <record> --repeat 3: DXC, then CreateComputePipelineState with the driver cache off; same machine, main c4d37be vs this branch; the first pass and a second pass agree within 3 %)

HLSL DXIL main → PR DXC main → PR PSO median main → PR speed-up
1.30 MB 369 → 274 KB 2.49 → 1.27 s 4.11 → 1.89 s 2.2×
1.92 MB 460 → 368 KB 8.99 → 5.18 s 8.94 → 2.98 s 3.0×
2.73 MB 747 → 543 KB 6.09 → 3.53 s 11.84 → 4.95 s 2.4×
3.40 MB 850 → 725 KB 5.89 → 5.50 s 29.34 → 5.43 s 5.4×
4.21 MB 1 050 → 883 KB 8.07 → 8.43 s 42.41 → 8.53 s 5.0×
6.72 MB 1 642 → 1 468 KB 25.28 → 16.75 s 39.53 → 28.75 s 1.4×

DXC is slower on one of the six (4.21 MB: +4 %). Whole-pack translation (XCL_RECOMP_STAGES=CS xcl shaders <pack> --recomp): 2 689 / 2 689 compute programs translate on both, HLSL 3 542.6 → 3 518.9 MB (the gain is in what DXC and the driver do with it, not in the text).

Tested

  • hardware (GPU + driver, CPU), Rust version, debug / release: NVIDIA GeForce RTX 5080, driver 616.64 (32.0.16.1664), AMD Ryzen 7 9800X3D, Windows 11 (10.0.26300), Rust 1.95.0, release
  • cargo test --workspace -- --test-threads=4: 967 passed, 0 failed, 43 ignored (SKIPPED GPU tests: 12 tests, 22 cases: the wave64 cases of gpu::recomp::lower / lower_dxil and gpu_wave32_program_in_wave64_hardware, gpu_geometry_wave32_prefix_count_over_a_mask for no wave64 on this GPU; heap_window_out_of_memory_falls_back_to_the_switch_form for no heap windows). Release build, after cargo build --workspace --release.

Regression run

main:

PR:

Not tested

  • No scripts/smoke.ps1 regression run yet (main or PR); required before this leaves draft.
  • Only an NVIDIA GPU with 32-lane waves (split wave64). No AMD or native wave64 runs, and no Linux / vkd3d-proton runs.
  • Pipeline times are for six programs from one pack, measured one at a time; no title run with the change.

AI use

  • Claude Code (Claude Opus 5.5): ported the author's changes onto current main (resolving the conflicts with heap windows and the structured-size fallback), ran the tests and measurements, and wrote this description.

…he driver

Buffer bounds checks, typed-buffer conversions, memory-window accessors,
the split-wave64 exchange and the EXEC bit test are emitted once and
called, instead of being repeated at every use in large compute
programs. Repeated single-entry branch arms of very large programs are
outlined into functions. Buffer indices add the lane id when the
descriptor's ADD_TID bit is set, inactive or out-of-range lanes load
from address 0, and unaligned 8- and 16-byte typed stores write every
affected dword.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@HKEY-Funk-Machine

Copy link
Copy Markdown

@SamG-Coder an AMD data point for this draft: on an RX 9070 (RDNA4), every pipeline built from this branch's HLSL suspends the device. CreateComputePipelineState returns 0x887A0005 within seconds, after the driver prints Unknown pointer operation encountered during ParseAddress. That includes a small program that builds in 6 s on the base commit.

Tested

  • 35a3980 and its base c4d37be, release, each with one local-only change in measure_pso: this machine has no Windows Developer Mode, so ShaderCacheControl(DISABLE) fails (0x887A002D). I made that a warning and instead ran every measurement under an xcl.exe copied to a new name, which gives the AMD driver a cold cache.
  • AMD Radeon RX 9070 (RDNA4, native wave64), driver 32.0.32015.7029, Ryzen 9 7945HX3D, 32 GB RAM (page file to ~120 GB of commit), Windows 11 Pro 26300, DXC 1.9.2602.17.
  • xcl shaders <pack>/shaders.rpf --measure-pso <hash> --repeat 1, one process per measurement, default 4 switch windows, process memory sampled every 2 s.
record c4d37be 35a3980
62b584e061c05fc5 (197 280 B DXIL on the base) built in 6.2 s 0x887A0005 (device suspended) after Unknown pointer operation encountered during ParseAddress
56c0cd3b82a00c6e 0x8007000E after ~4 min, peak 105 GB private 0x887A0005, same message, within 4 s
95cc13288a27a96e 0x8007000E after ~5.5 min, peak 105 GB private 0x887A0005, same message, within ~40 s

The 35a3980 result on 56c0cd3b82a00c6e repeated in a second process. The message reads like the AMD compiler meeting a pointer form in the DXIL that it can't parse. My guess is the shared code's calls or memory accessors, but I haven't checked the DXIL.

Not tested

  • DXIL inspection (validator / disassembly of the branch's containers), other AMD generations, a title run, more than one run per base measurement.

AI use: Claude Code (Claude Opus 5.5) built both trees, ran the measurements and wrote this comment.

@SamG-Coder

Copy link
Copy Markdown
Author

Superseded by #1901, which is the shared-helper change from this branch on its own, per CONTRIBUTING's one change per PR.

Measuring each part separately showed that the [noinline] EXEC bit test (lanebit) made the driver slower on every program measured, so #1901 leaves it inline. Without it, the shared helpers are faster than in this draft on all six programs, and also with XCL_HEAP_WINDOWS=1 (numbers in #1901). The other changes here (buffer bounds by the V# out-of-range mode, ADD_TID, inactive-lane loads, single-channel typed loads, unaligned typed stores, the mesh pass-through vertex budget, and outlining repeated branch arms) will follow as their own PRs.

@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11): merge conflict with current main — needs a rebase before it can be tested.

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.

3 participants