Recompiler: a waiter for a shared shader compile makes it wanted (#2608) #2800

Open
github-bot wants to merge 1 commit from github-bot/gh-2800 into main AGit
Owner

@⁠oni-swr on GitHub · 2026-11-26 13:50 UTC · original
oni-swr:t3/xcl-2608-shared-shader-demand → main · +207 −9 · 2 files · 1 commits · draft

Two pipelines can share a translated shader or the same DXC source, and the first build to take the flight compiles while the others block on it. The DXC job captured only the first build's demand, so when the title waited for a pipeline that had joined a background build's compile, the compile stayed unwanted and wait_for_memory kept holding it back as a background job. A caller that has to wait now registers its demand on the flight, so a compile a title is waiting for counts as wanted.

Fixes #2608
Part of #2088 and #2508.

What is in it

  • crates/xcl/src/gpu/recomp/dxc.rs: both flights are a dxc::Flight; waiters register their demand on it, and dxc::demand is wanted while the thread's own build or any waiter of a flight it is in wants it. Two tests, one per flight: a background owner blocked in its compile and a joiner the title then waits for.
  • crates/xcl/src/gpu/recomp/pso.rs: the ShaderKey flight uses it.

Tested

  • AMD Radeon RX 7800 XT (driver 32.0.31035.1003), Ryzen 7 5700X3D, Windows 11 Pro 10.0.26200, Rust 1.100.0, debug build (suite), release build (smoke)
  • cargo test --workspace -j 4 --no-fail-fast -- --test-threads=4 on 6b6929f6: 1436 passed, 1 failed, 47 ignored, over 37 test binaries
  • The one failure is gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1 (seed 722), #2115: it fails the same way on main b49be183 (2 of 2 runs) and on this head (3 of 3 runs)
  • SKIPPED (7): f16_programs_on_the_gpu (4 cases, V_MUL_F16 / V_PK_MUL_F16), f32_programs_on_the_gpu (2 cases, V_CVT_F16_F32), heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows)
  • Rerun on the exact head 6b6929f6 (clean detached checkout, RX 7800 XT driver 32.0.31035.1003, no XCL_ADAPTER set, cargo build --workspace first) with the same command: 1436 passed, 1 failed, 47 ignored over 37 test binaries (lib: 1310 passed, 1 failed, 27 ignored), 7 SKIPPED messages, the same seed-722 failure. The counts match the line above.
  • The two new tests, a_waiter_for_a_shared_shader_makes_its_compile_wanted and a_waiter_for_the_same_source_makes_its_compile_wanted, pass. Without the waiters' demand both fail at the demand assertion.

Regression run
Same title, 60 s each, same machine, one after the other (RX 7800 XT). Blocks pasted unedited from scripts/smoke.ps1.

main:

xcl-smoke v1
commit: b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7
gpu: AMD Radeon RX 7800 XT
title: 2c508222
seconds: 60
exit: 0x0
frames shown: 1372 (PresentX 1373)
presents per 2 s (last 3): 58 60 59
device removals: 0
crashes: 0
peak commit: 15684 MB

PR:

xcl-smoke v1
commit: 6b6929f6f095ac2708be14a8ebe250e4022267fe
gpu: AMD Radeon RX 7800 XT
title: 2c508222
seconds: 60
exit: 0x0
frames shown: 1426 (PresentX 1426)
presents per 2 s (last 3): 60 54 60
device removals: 0
crashes: 0
peak commit: 16161 MB

Not tested

  • AMD RDNA4 and NVIDIA
  • Whether the smoke title waits on a shared-shader flight at all: it is a regression check, not a measurement of this change

AI use

  • AI-assisted: Claude Code (Claude Sonnet 5.5), coordinated by Claude Code (Claude Opus 5.5). It wrote the code, the tests and this description, and ran the commands and smoke runs above.
  • The rerun of the workspace suite on the exact head was made with Claude Code (Claude Sonnet 5.5).

🤖 Generated with Claude Code

**@⁠oni-swr** on GitHub · 2026-11-26 13:50 UTC · [original](https://github.com/xcl-dev/xcl/pull/2800) `oni-swr:t3/xcl-2608-shared-shader-demand` → `main` · +207 −9 · 2 files · 1 commits · draft Two pipelines can share a translated shader or the same DXC source, and the first build to take the flight compiles while the others block on it. The DXC job captured only the first build's demand, so when the title waited for a pipeline that had joined a background build's compile, the compile stayed unwanted and `wait_for_memory` kept holding it back as a background job. A caller that has to wait now registers its demand on the flight, so a compile a title is waiting for counts as wanted. Fixes #2608 Part of #2088 and #2508. **What is in it** - `crates/xcl/src/gpu/recomp/dxc.rs`: both flights are a `dxc::Flight`; waiters register their demand on it, and `dxc::demand` is wanted while the thread's own build or any waiter of a flight it is in wants it. Two tests, one per flight: a background owner blocked in its compile and a joiner the title then waits for. - `crates/xcl/src/gpu/recomp/pso.rs`: the `ShaderKey` flight uses it. **Tested** - AMD Radeon RX 7800 XT (driver 32.0.31035.1003), Ryzen 7 5700X3D, Windows 11 Pro 10.0.26200, Rust 1.100.0, debug build (suite), release build (smoke) - `cargo test --workspace -j 4 --no-fail-fast -- --test-threads=4` on `6b6929f6`: 1436 passed, 1 failed, 47 ignored, over 37 test binaries - The one failure is `gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1` (seed 722), #2115: it fails the same way on `main` `b49be183` (2 of 2 runs) and on this head (3 of 3 runs) - SKIPPED (7): `f16_programs_on_the_gpu` (4 cases, `V_MUL_F16` / `V_PK_MUL_F16`), `f32_programs_on_the_gpu` (2 cases, `V_CVT_F16_F32`), `heap_window_out_of_memory_falls_back_to_the_switch_form` (no heap windows) - Rerun on the exact head `6b6929f6` (clean detached checkout, RX 7800 XT driver 32.0.31035.1003, no `XCL_ADAPTER` set, `cargo build --workspace` first) with the same command: 1436 passed, 1 failed, 47 ignored over 37 test binaries (lib: 1310 passed, 1 failed, 27 ignored), 7 SKIPPED messages, the same seed-722 failure. The counts match the line above. - The two new tests, `a_waiter_for_a_shared_shader_makes_its_compile_wanted` and `a_waiter_for_the_same_source_makes_its_compile_wanted`, pass. Without the waiters' demand both fail at the demand assertion. **Regression run** Same title, 60 s each, same machine, one after the other (RX 7800 XT). Blocks pasted unedited from `scripts/smoke.ps1`. main: ``` xcl-smoke v1 commit: b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7 gpu: AMD Radeon RX 7800 XT title: 2c508222 seconds: 60 exit: 0x0 frames shown: 1372 (PresentX 1373) presents per 2 s (last 3): 58 60 59 device removals: 0 crashes: 0 peak commit: 15684 MB ``` PR: ``` xcl-smoke v1 commit: 6b6929f6f095ac2708be14a8ebe250e4022267fe gpu: AMD Radeon RX 7800 XT title: 2c508222 seconds: 60 exit: 0x0 frames shown: 1426 (PresentX 1426) presents per 2 s (last 3): 60 54 60 device removals: 0 crashes: 0 peak commit: 16161 MB ``` **Not tested** - AMD RDNA4 and NVIDIA - Whether the smoke title waits on a shared-shader flight at all: it is a regression check, not a measurement of this change **AI use** - AI-assisted: Claude Code (Claude Sonnet 5.5), coordinated by Claude Code (Claude Opus 5.5). It wrote the code, the tests and this description, and ran the commands and smoke runs above. - The rerun of the workspace suite on the exact head was made with Claude Code (Claude Sonnet 5.5). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Two pipelines can share a translated shader (the `ShaderKey` flight in
pso.rs) or, with different translated shaders, the same DXC source (the
source-key flight in dxc.rs). The first build to take the flight compiles
and the others block on its mutex. The DXC job captured only the first
build's demand (`pso_async::wanted_here`), so when the title waited for a
pipeline that had joined a background build's compile, the compile stayed
unwanted: `wait_for_memory` kept holding it back as a background job.

Both flights are now a `dxc::Flight`. A caller that has to wait registers
its demand on the flight until it gets in, and `dxc::demand` (what
`dxc::compile` gives the job) is wanted while the thread's own build is,
or while any waiter of a flight the thread is in wants it. It is asked
again each time, so a waiter that becomes wanted after it joined counts
too. The waiter's demand includes its own flights, so demand passes
through a nested shader flight to the DXC flight.

Tests: two PSO-worker builds, a background owner blocked in its compile
and a joiner that the title then waits for, on each flight. The owner's
compile demand turns true once the title waits for the joiner, and the
shader is compiled once. Without the waiters' demand both tests fail at
that assertion.

Part of #2088 and #2508.

Assisted-by: Claude Code (Claude Opus 5.5)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 13:54:47 +00:00
Author
Owner

@⁠ettehn on GitHub · 2026-11-26 13:54 UTC · original

Independent Windows check of demand propagation across two nested flights on 6b6929f6f095ac2708be14a8ebe250e4022267fe, with one local test added and production code untouched. The probe ran three synthetic PSO jobs on the actual PSO worker pool. The background owner held the source flight. A second job held the shader flight while waiting on that source, and a third job waited on the shader flight. The source owner’s captured demand stayed false until want() marked the third job, then became true. After completion both waiter lists were empty and the captured demand returned to false. The nested case also passed in 20 out of 20 fresh test processes.

Windows 11 build 26200, Ryzen 9 8945HX, Rust 1.97.1 MSVC debug, XCL_DXC_THREADS=4:

cargo test --locked --offline -p xcl --lib -j 2 -- a_waiter_for_ transitive_waiter_promotes_a_shared_compile_until_it_finishes concurrent_cache_misses_compile_once --test-threads=1 --nocapture

4 passed, 0 failed, 0 ignored, no reported skips. This verifies the demand signal and its cleanup. Memory-pressure admission, GPU execution, a retail title, and the full suite were outside this run.

OpenAI Codex assisted with the probe and verification. The exact model identifier was unavailable in this session.

**@⁠ettehn** on GitHub · 2026-11-26 13:54 UTC · [original](https://github.com/xcl-dev/xcl/pull/2800#issuecomment-7193998585) Independent Windows check of demand propagation across two nested flights on `6b6929f6f095ac2708be14a8ebe250e4022267fe`, with one local test added and production code untouched. The probe ran three synthetic PSO jobs on the actual PSO worker pool. The background owner held the source flight. A second job held the shader flight while waiting on that source, and a third job waited on the shader flight. The source owner’s captured demand stayed false until `want()` marked the third job, then became true. After completion both waiter lists were empty and the captured demand returned to false. The nested case also passed in 20 out of 20 fresh test processes. Windows 11 build 26200, Ryzen 9 8945HX, Rust 1.97.1 MSVC debug, `XCL_DXC_THREADS=4`: ```text cargo test --locked --offline -p xcl --lib -j 2 -- a_waiter_for_ transitive_waiter_promotes_a_shared_compile_until_it_finishes concurrent_cache_misses_compile_once --test-threads=1 --nocapture ``` 4 passed, 0 failed, 0 ignored, no reported skips. This verifies the demand signal and its cleanup. Memory-pressure admission, GPU execution, a retail title, and the full suite were outside this run. OpenAI Codex assisted with the probe and verification. The exact model identifier was unavailable in this session.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2800/head:github-bot/gh-2800'
git switch 'github-bot/gh-2800'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2800'
git switch 'github-bot/gh-2800'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2800'
git switch 'github-bot/gh-2800'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2800'
git switch 'main'
git merge --squash 'github-bot/gh-2800'
git switch 'main'
git merge --ff-only 'github-bot/gh-2800'
git switch 'main'
git merge 'github-bot/gh-2800'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.