Skip to content

[upstream #1826] Shaders: xcl pipelines --shard k/n splits the journal over processes - #312

Open
ufoptg wants to merge 16 commits into
mainfrom
upstream-pr/1826
Open

ufoptg wants to merge 16 commits into
mainfrom
upstream-pr/1826

Conversation

@ufoptg

@ufoptg ufoptg commented Nov 25, 2026

Copy link
Copy Markdown
Owner

Stacked on xcl-dev#759; only the top commit (Shaders: xcl pipelines --shard k/n splits the journal over processes) belongs here. Part of xcl-dev#1269; the same idea as xcl-dev#1502 for xcl shaders --precompile, with the same --shard k/n syntax.

NVIDIA's driver builds about one big compute pipeline at a time per process, however many threads ask (xcl-dev#1502 measured it for xcl shaders --precompile; S1m0ne1997 on xcl-dev#505 for xcl pipelines). With one xcl pipelines process, XCL_PIPELINE_THREADS=10 and XCL_BIG_COMPILES=10 on the retail title's journal, 10 big builds were in flight but the process kept 2.1 of 12 cores busy (1.7 threads running on average). --shard k/n lets n processes share the journal: four of them kept 9.6–10.6 cores busy on the same journal.

What is in it

  • crates/xcl/src/pipelines.rs: --shard k/n. A process takes the pipelines whose hash % n is k − 1 (Queue::mine, in next and left), the ones the title used first as before, and keeps its own pipelines.shard{k}of{n}.done / .trying, so each process can be stopped and resumed on its own. Help text. Test: shards_split_the_pipelines_without_overlap (every pipeline in exactly one share, fair shares, left counts only the share).

Tested

  • NVIDIA GeForce RTX 4060 Ti 16 GB (driver 32.0.16.1088), Intel Core i7-8700 (6 cores / 12 threads), 32 GB RAM, Windows 11 build 26200, rustc 1.94.1 MSVC, release.
  • cargo build --release --workspace, then cargo test --release --workspace --no-fail-fast -- --test-threads=4: 867 passed, 0 failed, 42 ignored. SKIPPED: gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware (no wave64), heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).
  • On the retail title's journal (58 748 pipelines), --shard 1/2 and --shard 2/2 run together with --limit 400 each: both made 400 and ended cleanly (no .trying left); every hash in pipelines.shard1of2.done is even and in pipelines.shard2of2.done odd, with no overlap. Note: the start line's count of a share (30 254 and 30 260 here) uses left(), which counts a pipeline the title used twice when it is also in rest (1 766 here); that is as on Shaders: xcl pipelines compiles a run's queued pipelines outside the title xcl-dev/xcl#759 without --shard.
  • The core numbers above are from the same change on a local tree (Shaders: xcl pipelines compiles a run's queued pipelines outside the title xcl-dev/xcl#759's earlier head + main 930e8b4): one process 2.1 cores; four processes (--threads 4, XCL_PIPELINE_THREADS=3, XCL_BIG_COMPILES=2 each) 9.6–10.6 cores, 14–20 GB of RAM free. Big compute pipelines (0.8–1.3 MB of DXIL) took 140–530 s each in the driver either way; sharding runs more of them at once, it does not make one faster.

Regression run

main is c160d86, the commit xcl-dev#759 merged last: a run on today's main (e9e94ce, with xcl-dev#1321) peaked at 17.6 GB against 39.9 GB here, because this branch's base still has xcl-dev#1307's 148 MB program; c160d86 has the same base, so the two runs compare the change and not the base.

main:

xcl-smoke v1
commit: c160d86ef2efe3a07e4dfb473e4fa72eafb413c0
gpu: NVIDIA GeForce RTX 4060 Ti
title: ea3b5e4d
seconds: 60
exit: 0x0
frames shown: 1288 (PresentX 1289)
presents per 2 s (last 3): 59 60 60
device removals: 0
crashes: 0
peak commit: 41493 MB

PR:

xcl-smoke v1
commit: c6604385b250c6cd6e679c5dfcbfd114ccb1e581
gpu: NVIDIA GeForce RTX 4060 Ti
title: ea3b5e4d
seconds: 60
exit: 0x0
frames shown: 1355 (PresentX 1355)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 39879 MB

Not tested

  • --watch with --shard beside a running title; AMD and Intel GPUs (where the driver may not serialize, so sharding may gain less); Wine.
  • The smoke runs do not reach xcl pipelines; they check that the runtime is unchanged.

AI use

  • Claude Code with Claude Opus 5.5: wrote the change, the test and this description, and ran the tests, the smoke runs and the shard runs on my PC.

🤖 Generated with Claude Code


Mirror of xcl-dev#1826 (auto-synced, do not edit).

suppai-ringo and others added 16 commits November 24, 2026 09:22
…tion

prep_graphics: what translated_graphics_pso did between its checks and the driver call (the
translated shaders, XCL's ABI root signature with their static samplers, the rect list GS, PC
formats and topology), returned with the DXIL it points at. No change in behaviour; a later
change makes the same desc outside the title (xcl pipelines).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…lines.bin)

Every pipeline with console shaders that goes to pso_async (its DXIL not in the cache yet, or
made lazily: a retail title queues ~58 000 in its first minute) is appended to a journal: its
desc field by field (no pointers, no padding: the same pipeline always hashes the same), its
input layout and its shaders by hash, each shader once, with the run's memory windows. A
pipeline's first build is marked as used. Entries of earlier runs are not written again (found
from the frames' headers, the shaders stay on disk); a torn last frame is cut off. One title
process writes it at a time (others get none). The reader (replay) gives the desc back with
everything it points to owned and no pointer from the file. Another process can compile the
title's pipelines from it; XCL_PSO_JOURNAL=0 turns it off.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…al for the run

A frame is now noted as written only once all of it is on disk; a failed
write (a full disk) is cut back to where it started, so later frames
stay readable, and the journal is off for the rest of the run. An input
layout count read from the file is checked against the bytes there
before anything is allocated for it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Since xcl-dev#680 `pso::mem_windows` carries HEAP_WINDOWS (0x100) when the title's
shaders take the memory windows from the descriptor heap (XCL_HEAP_WINDOWS=1).
The frame's windows byte cut it off, so a heap-window run's pipelines read
as the switch form's. The count stays in the low 7 bits and the flag goes
in the top bit (`windows_byte`, `mem_windows_of`).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013hQzywPUY9kSTPQPh31CWh
…title

`xcl pipelines <game | data folder | pipelines.bin> [--watch]` reads the journal a run wrote
and makes each pipeline on its own D3D12 device as the title would (prep_graphics for VS / PS,
the compute path with XCL's ABI root signature), on the GPU the title's xcl.toml names. The
DXIL cache, the driver's cache and driver_cache (compute blobs) then hold what the title asks
for: before its next run, or during this one with --watch (following the journal; the
pipelines the title used first). Translation and DXC run on half the cores at below-normal
priority, the driver's compiles a few at once (XCL_PIPELINE_THREADS). What was made is kept in
pipelines.done for this binary; a failure is tried again by the next run. GS / HS / DS and
mesh pipelines are left to the title.

The memory windows of the run come from the journal (pso::set_mem_windows: prep_graphics
translates through console_to_dxil_for like the title), and shader::readable no longer creates
the UMA (uma::existing): a process without a title reserved 12 GiB of windows and a 512 MB
coherent window for a pointer check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The progress file was opened for appending, and on Windows an append
handle cannot be truncated: the set_len(0) for a new binary failed
unseen and its key was appended after the old records. It is now opened
for writing; a file of another binary starts over and a torn last record
is cut off, and an open error ends the run (2).

Reported by @anes66 on xcl-dev#759.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…newest run's windows and runs once per journal

- --watch: the bytes after the last whole frame are read again on each
  poll, so a torn frame the next run cut off and wrote over no longer
  misaligns every frame after it.
- The memory windows to build are the last run's, not the first's: a
  journal kept across a change of uma_mb built the stale run's set.
- pipelines.done is opened without write sharing, so a second tool on
  the same journal is refused instead of interleaving its records.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…goes past one it crashed on

- A big compute pipeline (256 KB of DXIL and more) now takes the title's
  BIG_COMPILES turn and waits for 3 GB of free commit, as the title's own
  background compiles do. The tool's threads (xcl-warm-*) missed that rule
  and ran up to four of these at once, 1.5 to 3 GB each in the driver.
- The pipelines being made are noted in pipelines.trying, which a run that
  ends by itself removes. A run that died (a crash in the driver or DXC on
  one pipeline, reported under Wine on xcl-dev#759) leaves it behind, and the next
  run leaves those pipelines to the title instead of ending the same way.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…hout --watch

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… in .trying

From the test reports on the tool:
- `pipelines.done` was keyed by the xcl binary only: after a driver update
  the pipelines the driver dropped still counted as done. The key now holds
  the adapter's vendor and device ID and its driver version.
- `.trying` held every pipeline a run started until a clean exit, so after
  Ctrl+C (the end of --watch) the next run left the failed ones to the
  title. It now holds the pipelines being made at the moment.
- The workers' stacks: 64 MB overflowed under Wine in the driver's compile
  of a title's biggest compute programs. They reserve 512 MB.
- Progress every 10 s, with the pipelines being made; the biggest compute
  programs take 30 s or more each in the driver, and the line said nothing
  for minutes.

Reported-by: claudetools-gh, JoaoPauluu, milas6669, S1m0ne1997

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…form fallback

The tool sets the run's `mem_windows` with its HEAP_WINDOWS flag from the
journal (`mem_windows_of`), so a heap-window run's pipelines get the same
HLSL and cache keys as in the title. A pipeline the driver refuses with
E_OUTOFMEMORY in that form is made again in the switch form through
`with_switch_fallback`, as the title makes it since xcl-dev#680.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013hQzywPUY9kSTPQPh31CWh
Ctrl+C is how --watch ends, and it left `.trying` behind as a crash does: the
next run wrote the pipelines being made at that moment to `pipelines.done`
as left to the title, most often the biggest compute programs, the ones most
worth making ahead. A console control handler now removes `.trying` before
the default handler ends the process, so the next run makes them again; a
crash in the driver or DXC still leaves it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013hQzywPUY9kSTPQPh31CWh
main.rs: the help of `xcl shaders --direct` (xcl-dev#1426) and `xcl pipelines` both
kept, the shaders lines first.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013hQzywPUY9kSTPQPh31CWh
…s only to append

The first pipeline the title noted read the frame headers of every earlier
run (about 63 000 for a 123 MB journal) with the journal's lock held, and
each later one hashed its shaders and desc under the same lock, so the
title's pipeline threads waited on one another. An entry is now built and
hashed with no lock held, and the lock covers its append only. The journal
is opened on a thread of its own; what is noted meanwhile waits in memory,
each frame once (up to 256 MB, past which the journal is off for the run),
and is written in order once it is open. `XCL_PSO_JOURNAL` is read once,
and a journal turned off stops entries being built at all. A panic on
another thread while it held the lock no longer ends the journal.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013hQzywPUY9kSTPQPh31CWh
… threads) into pipelines-3-tool

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013hQzywPUY9kSTPQPh31CWh
NVIDIA's driver builds about one big compute pipeline at a time per
process, however many threads ask (xcl-dev#1502 measured the same for
`xcl shaders --precompile`). With one `xcl pipelines` process and 10
driver compiles at once, the big ones of the retail title's journal kept
2.1 of 12 cores busy here; four processes on shares of the journal kept
9.6 - 10.6 busy.

`--shard k/n` makes a process take the pipelines whose hash % n is k - 1,
the used ones first as before, with its own `.done` / `.trying`
(`pipelines.shard2of4.done`), so n processes run side by side and each
can be stopped and resumed on its own. Same syntax as xcl-dev#1502's
`xcl shaders --shard`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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