Skip to content

Shaders: precompile --pipelines compiles in the driver on its own threads - #256

Closed
1984742628 wants to merge 1 commit into
xcl-dev:mainfrom
1984742628:precompile-pipeline-queue
Closed

1984742628 wants to merge 1 commit into
xcl-dev:mainfrom
1984742628:precompile-pipeline-queue

Conversation

@1984742628

@1984742628 1984742628 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

xcl shaders --precompile --pipelines made each compute pipeline on the thread that translated it, at most four at once (XCL_PIPELINE_THREADS). Once the four slots held programs the driver needs minutes for, every translating thread waited for a slot and the run stopped moving: a retail pack of 26 503 shaders sat at 22 800 for many minutes with about 3.5 cores busy, two driver compiles at about 6 CPU-minutes each. This PR moves the driver's compiles to their own threads and orders them by size and free memory. No issue is linked.

What is in it

  • One commit, crates/xcl/src/shaders.rs only (314 added, 25 removed).
  • The driver's compiles run on their own threads, fed by a queue (BiggestFirst, at most 2 GB of DXIL waiting). The translating threads go on and fill the DXIL cache meanwhile.
  • Each driver thread takes the biggest program whose compile fits in free memory (driver_fits): the big ones start first, the threads left over make small ones. A program is taken to need 1536 bytes per byte of DXIL, between 64 MB and 1.5 GB, with 2 GB kept free.
  • Driver threads: half the cores (at most 16) with memory watched. XCL_PIPELINE_THREADS still works: that many at once, memory not watched.
  • Output: a status line every 15 s and a line for each pipeline the driver took more than 60 s for, instead of one line every 25 pipelines.
  • Unit tests for the queue (order, byte limit, closing, biggest that fits) and for the memory rule.
  • The translation, the DXIL and the pipelines made are unchanged; only their order and how many are made at once change.

Tested

  • hardware (GPU + driver, CPU), Rust version, debug / release: NVIDIA GeForce RTX 3070 Ti (driver 32.0.16.1714), AMD Ryzen 9 7950X, 32 GB, Windows 11 10.0.26100, rustc 1.98.0, debug.
  • cargo test --workspace -- --test-threads=4 on ed5322f with no uncommitted changes: 656 passed, 0 failed, 40 ignored (SKIPPED GPU tests: 2, both "no wave64": gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware). The XCL_SAMPLE_* variables were not set, so the tests on game data did nothing.
  • cargo test -p xcl --release --lib on ed5322f: 616 passed, 0 failed, 20 ignored.

Regression run
Not run. scripts/smoke.ps1 was not run on main or on this PR, so there are no xcl-smoke blocks.

main:

PR:

Not tested

  • No regression run on a real title (see above). The change is in xcl shaders --precompile only; xcl run does not call it.
  • No timed whole --precompile --pipelines run with this version, so no before / after numbers. An earlier version (strictly biggest first, every running compile counted as 1.5 GB) was run on the retail pack: seven big programs took the whole memory allowance and nothing else was made meanwhile. The "biggest that fits" rule is the answer to that and has unit tests only.
  • The memory numbers come from the comment that was there and from this one NVIDIA machine. Not tested on AMD or Intel GPUs.
  • The branch is on 7a033c8, not rebased onto the newest main, and the commit subject is longer than 72 characters.

AI use
Claude Code. Claude Opus 5.5 wrote the first version of the change; Claude Fable 5.2 wrote the final code, the unit tests, the commit message and this description, and ran the tests listed above.

…biggest program that fits in memory first

`xcl shaders --precompile --pipelines` made each compute pipeline on the
thread that translated it, at most four at once. With the four slots
taken by programs the driver needs minutes for, every translating thread
ended up waiting for a slot: a retail pack sat at 22 800 / 26 503 for
many minutes with about 3.5 cores busy, and in file order a big program
could come last and compile alone.

- The driver's compiles run on their own threads, fed by a queue; the
  translating threads go on and fill the DXIL cache meanwhile. The queue
  holds at most 2 GB of DXIL.
- Each driver thread takes the biggest program whose compile fits in the
  memory that is free: the big ones start first, the threads left over
  make small ones instead of waiting. A program is taken to need 1536
  bytes per byte of DXIL, between 64 MB and 1.5 GB, with 2 GB kept free.
- Driver threads: half the cores (at most 16) with memory watched, or
  XCL_PIPELINE_THREADS as before (that many at once, memory not watched).
- A status line every 15 s (made, refused, in the driver with the
  longest-running one, waiting), and a line for each pipeline the driver
  took more than 60 s for. The line every 25 pipelines said nothing for
  minutes.

The translation, the DXIL and the pipelines made are the same: only
their order and how many are made at once change.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@1984742628 1984742628 changed the title Precompile --pipelines: driver compiles on threads of their own, the … Shaders: precompile --pipelines compiles in the driver on its own threads Nov 23, 2026
@1984742628 1984742628 closed this Nov 23, 2026
@1984742628
1984742628 deleted the precompile-pipeline-queue branch November 23, 2026 22:48
wondercrash added a commit to wondercrash/xcl that referenced this pull request Nov 24, 2026
…eads

The compute warm-up (`xcl shaders --precompile --only cs --pipelines`) sat for
20+ minutes at one record range with ~5 cores busy: each translating thread
made its pipeline itself behind a gate of XCL_PIPELINE_THREADS (4), and three
retail programs of 13-28 MB DXIL held 3 slots for 15+ CPU-minutes each. The
other 13 translating threads each held a finished program waiting for the one
slot left, and the DXC pool sat idle.

Port of xcl-dev#256 onto the driver cache of xcl-dev#744:
- A program whose driver blob is cached is made from it on the translating
  thread (a cheap create, no slot). The rest go to a queue served by driver
  threads of their own, XCL_PIPELINE_THREADS or half the logical CPUs. A push
  never waits: the queue holds the DXIL (a pack's compute programs come to a
  few GB at most).
- Each driver thread takes the biggest waiting program that fits: 8 GB of
  commit and memory kept free, a compile counted as 1536 bytes per DXIL byte
  (64 MB - 1.5 GB), 3 GB for one over 8 MB; with nothing running any may go.
- At most 2 programs over 8 MB at once, and one thread always left for the
  rest, so huge programs never hold every driver thread.
- A status line every 15 s while compiles run; programs over 60 s are named.

Assisted-by: omp (Claude Opus 5.5)
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.

1 participant