Shaders: XCL_PREP_QUEUE_MB bounds the translated DXIL --precompile --pipelines holds #3212

Open
oni-swr wants to merge 1 commit from upstream-pr/3212 into main
oni-swr commented 2026-11-28 20:10:05 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by oni-swr on 2026-11-28T20:10:05Z.


Offline --precompile --pipelines translates every compute record into one Vec<PipelineJob> and starts the driver builds only after the last record is translated, so all translated DXIL is resident at once (#3043 frees a job after its build, not before the builds start). Related to the peak-commit work around #2088.

With XCL_PREP_QUEUE_MB=<MiB> the builders start during translation and a translator waits when queued plus in-build bytes would pass the cap. A program over the cap is admitted only into an empty queue (it runs alone). Builders take used-earlier programs first, then the largest, among what is queued. Unset (default): unchanged behaviour. No overlapping open PR found (searched precompile memory, queue bytes, DXIL queue, peak commit, run_pipeline_jobs; #2070 only changes the builders' stack).

What is in it

  • crates/xcl/src/shaders.rs: ByteQueue (push/take/close/cancel, byte high-water mark), prep_queue_cap, wiring in the precompile loop (builders spawned beside translators, queue closed or cancelled after they join), one "held at most" line.
  • crates/xcl/src/shaders.rs tests: slow-consumer cap, exactly-once completion, oversized job alone, used-first-then-largest order, cancel frees blocked pushes, cap parsing, a numbers fixture.
  • README.md: the variable.

Tested

  • CPU, debug build, stable msvc: cargo test -j 4 -p xcl --lib pipeline_selection_tests -- --test-threads=2: 9 passed, 0 failed, 0 ignored (run before the rebase onto current main).
  • Fixture (400 jobs of about 1 MiB, 2 translators, 2 builders sleeping 2 ms each): high water 400 MiB with no cap vs 7 MiB with an 8 MiB cap; wall time 460 ms vs 462 ms. It compares the streaming queue with and without a cap, not the old translate-everything-first path.
  • RX 7800 XT (RDNA3), Windows 11 build 26200, release builds of both commits, same title, 60 s each, default settings (the cap is not set in these runs): head shows 1607 frames vs 1586 on main and a peak commit of 14647 MB vs 14565 MB, no device removal, no crash.
  • Offline prep on the same GPU, a window of every 5th shader record (538 compute programs, about 360 MiB of translated DXIL, translation already cached so it took 1.6 s), --precompile --windows 4 --only cs --pipelines, each arm stopped at 7 min (not finished: 25 to 75 of 538 pipelines built, the largest first, 16 driver builds at once): peak process commit 25.4 GiB on main, 26.1 GiB on this head without the variable, 23.4 GiB on this head with XCL_PREP_QUEUE_MB=256; peak system commit rise 28.7 / 27.3 / 23.5 GiB. One run each, no repeats, no device removal. So the peak in this window is the driver builds, not the queued DXIL; the cap's 360 MiB at most is inside the run-to-run noise here, and no gain is claimed.

Regression run

main:

xcl-smoke v1
commit: 7db2f391cefd748d47c7de63d50dd43ebb852185
gpu: AMD Radeon RX 7800 XT
title: title-1128n
seconds: 60
exit: 0x0
frames shown: 1586 (PresentX 1586)
presents per 2 s (last 3): 60 61 60
device removals: 0
crashes: 0
peak commit: 14565 MB

this PR's head:

xcl-smoke v1
commit: dc6df62c1558b38f1e519472bd16803bf4c31ff5
gpu: AMD Radeon RX 7800 XT
title: title-1128n
seconds: 60
exit: 0x0
frames shown: 1607 (PresentX 1607)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14647 MB

Not tested

  • The whole workspace suite on a GPU. The smoke runs above do not reach this code (the variable is unset and they do not run offline preparation).
  • A complete --precompile --pipelines run (the arms above were stopped early) and runs where translation is not already cached; with the variable set, driver builds overlap DXC compiles, which is untested.
  • Driver cache: the driver's own blob cache lies outside XCL_DXIL_CACHE, so any later arm of such a comparison may start warm; on AMD XCL's driver-blob disk cache is off by default.
  • NVIDIA, wave32-only GPUs, other titles.

AI use

  • Claude Code, Claude Sonnet 5.5: wrote the code, tests and this description, and ran the CPU tests and the smoke and prep runs above.

🤖 Generated with Claude Code

<!-- greyfinch-sync:ivall/xcl:issue:5544134226 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3212). Originally posted by [oni-swr](https://github.com/oni-swr) on 2026-11-28T20:10:05Z. --- Offline `--precompile --pipelines` translates every compute record into one `Vec<PipelineJob>` and starts the driver builds only after the last record is translated, so all translated DXIL is resident at once (#3043 frees a job after its build, not before the builds start). Related to the peak-commit work around #2088. With `XCL_PREP_QUEUE_MB=<MiB>` the builders start during translation and a translator waits when queued plus in-build bytes would pass the cap. A program over the cap is admitted only into an empty queue (it runs alone). Builders take used-earlier programs first, then the largest, among what is queued. Unset (default): unchanged behaviour. No overlapping open PR found (searched precompile memory, queue bytes, DXIL queue, peak commit, `run_pipeline_jobs`; #2070 only changes the builders' stack). **What is in it** - `crates/xcl/src/shaders.rs`: `ByteQueue` (push/take/close/cancel, byte high-water mark), `prep_queue_cap`, wiring in the precompile loop (builders spawned beside translators, queue closed or cancelled after they join), one "held at most" line. - `crates/xcl/src/shaders.rs` tests: slow-consumer cap, exactly-once completion, oversized job alone, used-first-then-largest order, cancel frees blocked pushes, cap parsing, a numbers fixture. - `README.md`: the variable. **Tested** - CPU, debug build, stable msvc: `cargo test -j 4 -p xcl --lib pipeline_selection_tests -- --test-threads=2`: 9 passed, 0 failed, 0 ignored (run before the rebase onto current `main`). - Fixture (400 jobs of about 1 MiB, 2 translators, 2 builders sleeping 2 ms each): high water 400 MiB with no cap vs 7 MiB with an 8 MiB cap; wall time 460 ms vs 462 ms. It compares the streaming queue with and without a cap, not the old translate-everything-first path. - RX 7800 XT (RDNA3), Windows 11 build 26200, release builds of both commits, same title, 60 s each, default settings (the cap is not set in these runs): head shows 1607 frames vs 1586 on `main` and a peak commit of 14647 MB vs 14565 MB, no device removal, no crash. - Offline prep on the same GPU, a window of every 5th shader record (538 compute programs, about 360 MiB of translated DXIL, translation already cached so it took 1.6 s), `--precompile --windows 4 --only cs --pipelines`, each arm stopped at 7 min (not finished: 25 to 75 of 538 pipelines built, the largest first, 16 driver builds at once): peak process commit 25.4 GiB on `main`, 26.1 GiB on this head without the variable, 23.4 GiB on this head with `XCL_PREP_QUEUE_MB=256`; peak system commit rise 28.7 / 27.3 / 23.5 GiB. One run each, no repeats, no device removal. So the peak in this window is the driver builds, not the queued DXIL; the cap's 360 MiB at most is inside the run-to-run noise here, and no gain is claimed. **Regression run** main: ``` xcl-smoke v1 commit: 7db2f391cefd748d47c7de63d50dd43ebb852185 gpu: AMD Radeon RX 7800 XT title: title-1128n seconds: 60 exit: 0x0 frames shown: 1586 (PresentX 1586) presents per 2 s (last 3): 60 61 60 device removals: 0 crashes: 0 peak commit: 14565 MB ``` this PR's head: ``` xcl-smoke v1 commit: dc6df62c1558b38f1e519472bd16803bf4c31ff5 gpu: AMD Radeon RX 7800 XT title: title-1128n seconds: 60 exit: 0x0 frames shown: 1607 (PresentX 1607) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14647 MB ``` **Not tested** - The whole workspace suite on a GPU. The smoke runs above do not reach this code (the variable is unset and they do not run offline preparation). - A complete `--precompile --pipelines` run (the arms above were stopped early) and runs where translation is not already cached; with the variable set, driver builds overlap DXC compiles, which is untested. - Driver cache: the driver's own blob cache lies outside `XCL_DXIL_CACHE`, so any later arm of such a comparison may start warm; on AMD XCL's driver-blob disk cache is off by default. - NVIDIA, wave32-only GPUs, other titles. **AI use** - Claude Code, Claude Sonnet 5.5: wrote the code, tests and this description, and ran the CPU tests and the smoke and prep runs above. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
andrewDoing commented 2026-11-28 22:17:02 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by andrewDoing on 2026-11-28T22:17:02Z.


The production admission charge on dc6df62c uses only job.compiled.dxil.len(). A split compute job also retains dispatch_chain.pieces, the DXIL buffers that make_selected actually feeds to make_chain_pieces. Those bytes never enter the queue's accounting.

I ran the exact ByteQueue and build_from_queue implementation on Windows with two builders, a gated first build, and 8 MiB capacity. The synthetic jobs allocated real byte vectors with these lengths:

Job Whole DXIL Pieces Total
A 2 MiB 5 + 3 MiB 10 MiB
B 3 MiB 6 + 4 MiB 13 MiB

With the production charge, both builders entered simultaneously. 23 MiB of payload was live in the two builders while the queue reported a 5 MiB high-water mark. Charging the whole plus all pieces instead kept the second job out until the first finished. Both oversized jobs made progress and completed once; the resulting high-water mark was 13 MiB, consistent with admitting a single oversized job.

I'd count all retained DXIL lengths at the production push site and use that charge for scheduling and reporting. Document the metric as admitted queued + in-build DXIL: completed translations waiting inside push also still own their buffers. The fixture exercised actual scheduling with synthetic payloads; I did not run a title or measure process peak RSS/commit.

AI assistance: OpenAI Codex traced the production paths, wrote and ran the CPU controls, and drafted this report.

<!-- greyfinch-sync:ivall/xcl:comment:7246626483 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3212#issuecomment-7246626483). Originally posted by [andrewDoing](https://github.com/andrewDoing) on 2026-11-28T22:17:02Z. --- The production admission charge on `dc6df62c` uses only `job.compiled.dxil.len()`. A split compute job also retains `dispatch_chain.pieces`, the DXIL buffers that `make_selected` actually feeds to `make_chain_pieces`. Those bytes never enter the queue's accounting. I ran the exact `ByteQueue` and `build_from_queue` implementation on Windows with two builders, a gated first build, and **8 MiB** capacity. The synthetic jobs allocated real byte vectors with these lengths: | Job | Whole DXIL | Pieces | Total | |---|---:|---:|---:| | A | 2 MiB | 5 + 3 MiB | 10 MiB | | B | 3 MiB | 6 + 4 MiB | 13 MiB | With the production charge, both builders entered simultaneously. **23 MiB of payload was live in the two builders while the queue reported a 5 MiB high-water mark.** Charging the whole plus all pieces instead kept the second job out until the first finished. Both oversized jobs made progress and completed once; the resulting high-water mark was 13 MiB, consistent with admitting a single oversized job. I'd count all retained DXIL lengths at the production push site and use that charge for scheduling and reporting. Document the metric as admitted queued + in-build DXIL: completed translations waiting inside `push` also still own their buffers. The fixture exercised actual scheduling with synthetic payloads; I did not run a title or measure process peak RSS/commit. AI assistance: OpenAI Codex traced the production paths, wrote and ran the CPU controls, and drafted this report.
Foniass commented 2026-12-01 09:39:08 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T09:39:08Z.


Review (head dc6df62c, diff read, not a merge-check; draft, conflicts with main):

  • Main moved underneath it.
    • Main's offline build threads now use worker_thread with the pipeline workers' stack (WORKER_STACK, shaders.rs ~1388-1394), because driver builds overflowed a default stack (#1269). The PR's queue build threads (s.spawn, ~3635) use the default stack, so with the variable set they lose that fix.
    • Main also has two more places that add build jobs (mesh producer passes and recorded GS pairs). Those would still bypass the bound.
  • The byte count misses most of the memory. It counts only job.compiled.dxil.len() (~3718). It doesn't count the DXIL pieces of split programs (dispatch_chain.pieces), or finished translations waiting to enter the queue. That fits andrewDoing's measurement: 23 MiB held while the queue reported 5 MiB.
  • If every build thread panics, the translators wait at push forever and the run hangs instead of reporting the panic. Otherwise it can't deadlock: a waiting translator holds no other lock, and an oversized job gets in once the queue is empty.
  • The description's own measurement shows the driver builds dominate peak memory, and it claims no gain, so the case for the switch is thin.

Fine: it is off by default (unset or 0), and off for mandatory and startup preparation. Cancel and close on a translator panic are right, and the ordering and cap-parsing tests are good.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

<!-- greyfinch-sync:ivall/xcl:comment:7307008557 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3212#issuecomment-7307008557). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T09:39:08Z. --- Review (head dc6df62c, diff read, not a merge-check; draft, conflicts with main): - **Main moved underneath it.** - Main's offline build threads now use `worker_thread` with the pipeline workers' stack (`WORKER_STACK`, `shaders.rs` ~1388-1394), because driver builds overflowed a default stack (#1269). The PR's queue build threads (`s.spawn`, ~3635) use the default stack, so with the variable set they lose that fix. - Main also has two more places that add build jobs (mesh producer passes and recorded GS pairs). Those would still bypass the bound. - **The byte count misses most of the memory.** It counts only `job.compiled.dxil.len()` (~3718). It doesn't count the DXIL pieces of split programs (`dispatch_chain.pieces`), or finished translations waiting to enter the queue. That fits andrewDoing's measurement: 23 MiB held while the queue reported 5 MiB. - If every build thread panics, the translators wait at `push` forever and the run hangs instead of reporting the panic. Otherwise it can't deadlock: a waiting translator holds no other lock, and an oversized job gets in once the queue is empty. - The description's own measurement shows the driver builds dominate peak memory, and it claims no gain, so the case for the switch is thin. Fine: it is off by default (unset or `0`), and off for mandatory and startup preparation. Cancel and close on a translator panic are right, and the ordering and cap-parsing tests are good. AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Foniass commented 2026-12-01 09:44:37 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T09:44:37Z.


Triage (#1607) – head dc6df62

No open or merged PR adds XCL_PREP_QUEUE_MB or a byte-bounded queue between translation and driver builds in shaders::precompile.
Minor: with the queue on, make_pipelines still runs afterwards on the empty pipeline_jobs and prints "pipelines: 0 compute programs"; the return value of ByteQueue::push is ignored at the call site (only false after a cancel, so harmless). Ordering matches order_pipeline_jobs (used first, then largest) per take.
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

<!-- greyfinch-sync:ivall/xcl:comment:7307139715 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3212#issuecomment-7307139715). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T09:44:37Z. --- **Triage (#1607)** – head dc6df62 No open or merged PR adds `XCL_PREP_QUEUE_MB` or a byte-bounded queue between translation and driver builds in `shaders::precompile`. Minor: with the queue on, `make_pipelines` still runs afterwards on the empty `pipeline_jobs` and prints "pipelines: 0 compute programs"; the return value of `ByteQueue::push` is ignored at the call site (only false after a cancel, so harmless). Ordering matches `order_pipeline_jobs` (used first, then largest) per take. Recommendation: keep open. AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3212:upstream-pr/3212'
git switch 'upstream-pr/3212'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3212'
git switch 'upstream-pr/3212'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3212'
git switch 'upstream-pr/3212'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3212'
git switch 'main'
git merge --squash 'upstream-pr/3212'
git switch 'main'
git merge --ff-only 'upstream-pr/3212'
git switch 'main'
git merge 'upstream-pr/3212'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!3212
No description provided.