Skip to content

D3D12.X: count only queued background pipelines as still building - #1168

Open
eizispark wants to merge 1 commit into
xcl-dev:mainfrom
eizispark:fix/894-queued-pipeline-count
Open

eizispark wants to merge 1 commit into
xcl-dev:mainfrom
eizispark:fix/894-queued-pipeline-count

Conversation

@eizispark

@eizispark eizispark commented Nov 24, 2026 •

Copy link
Copy Markdown

With XCL_LAZY_PSO=1 enabled by default, submit_lazy inserts every translated stand-in pipeline into PENDING while sending only pipelines whose shader keys are in used-pipelines.txt (or ones later bound) to the background workers. pso_async::counts() still walked PENDING under its mutex and counted every !done entry, which kept the window title stuck on "compiling shaders: 0 running, 0 done, 57587 pipelines queued" after all active compiles finished (#894) and recorded dormant stand-ins as still building in report.json.

Part of #894 (fixes the pipelines queued / background_pipelines accounting and removes the O(N) PENDING lock scan on every window-title update; the title's loading-screen progression on #894's host remains separate).

What is in it

  • crates/xcl/src/hle/d3d12x/pso_async.rs: track a monotonic IDLE -> QUEUED -> DONE atomic state on each Pending together with a global QUEUED_BUILDS counter incremented once when a pipeline is queued to queue(), queued to preload(), or built on the binding thread, and decremented once on complete(), channel-send error, preload() orphan skip, or released(). pso_async::counts() is now lock-free and O(1).
  • crates/xcl/src/hle/d3d12x/pso_async.rs (used_tests): add lazy_stand_ins_are_not_counted_as_still_building_until_queued (serialized across all used_tests via COUNT_TEST_LOCK and holding the PENDING guard across the final zero check) covering dormant submit_lazy entries, release of unqueued stand-ins, resolve-triggered queueing and completion, and exact immediate -1 decrement on released() of an in-flight pipeline without double-decrement on worker completion.

Tested

  • Windows 11 x64, AMD Ryzen 7 9800X3D, AMD Radeon RX 9070 XT (driver 32.0.32015.16001), rustc 1.100.0 (0ef1bc386 2026-11-09), debug and release.
  • cargo test --workspace --no-fail-fast -- --test-threads=4 on the head, rebased onto main 1a0bbe3 (after kernelx: Sleep does not count PC calls that keep the title's threads #1782): 1249 passed, 2 failed – gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1 and fuzz_validate_and_gpu_3, which fail the same way on a clean main 426a5a7 on this adapter; 46 ignored.
  • cargo test -p xcl --lib hle::d3d12x::pso_async -- --test-threads=4, 5 consecutive runs: 11 passed, 0 failed on each run (including kernelx: Sleep does not count PC calls that keep the title's threads #1782's two PcCalls tests).
  • lazy_stand_ins_are_not_counted_as_still_building_until_queued failed before the fix: counts().2 reported 64 for 64 unqueued lazy stand-ins.
  • Earlier 60 s retail smoke run: d3d12.background_pipelines in report.json went from [228, 0, 57595] on main to [228, 0, 0] once the 228 preloaded pipelines were built.

Regression run

main:

xcl-smoke v1
commit: 426a5a745db4d5e4b037449ede0b70cb342f5192
gpu: AMD Radeon RX 9070 XT
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1680 (PresentX 1680)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14599 MB

PR head:

xcl-smoke v1
commit: 0840ff5a690c564caf808b7feecd8211f02aeded
gpu: AMD Radeon RX 9070 XT
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1679 (PresentX 1679)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14602 MB

Not tested

AI use

@fromthemoonx

Copy link
Copy Markdown

NVIDIA run with the whole suite, since Not tested lists NVIDIA.

Tested

  • NVIDIA GeForce RTX 3060 12 GB (32-lane waves), driver 32.0.16.1088; AMD Ryzen 7 5700X; native Windows 11 Pro 26H2 (build 26300.9974), Graphics Tools (D3D12 debug layer) installed; rustc 1.100.0 stable-x86_64-pc-windows-msvc; DXC 1.9.2602.17; debug
  • Exact head 39d761715ab47392c57fc53778d3c03b9486d8a5, which is on current main 47efa2e (so also the merged result): cargo build --workspace, then cargo test --workspace --no-fail-fast -- --test-threads=4: 742 passed, 0 failed, 41 ignored. The new pso_async::used_tests::lazy_stand_ins_are_not_counted_as_still_building_until_queued passed.
  • Fails with the old counting: with this PR's file and counts() changed back to main's scan of PENDING (every entry whose done is false), the new test fails at pso_async.rs:381. So it covers the pipelines queued / background_pipelines count from Retail 1.0.2.1 on RTX 4070 SUPER 12 GB + Win10 (KB5029331): 30 fps loading screen, 57 587 async pipelines never compile #894.
  • pso_async + hle::d3d12x::bind tests, 10 runs: 10 of 10 passed (9 each, the pipeline-wait budget tests included)
  • e2e + gpu_pso_e2e, 3 runs: 3 of 3 passed. The test title builds its pipelines through the background path, with stand-ins.
  • D3D12 debug layer: the test title's XCL_D3D12_DEBUG=1 run logs the same set of debug-layer errors and warnings as on main.
  • SKIPPED (no wave64 on this adapter): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware

Not tested

AI use

  • Claude Code (Claude Opus 5.5) ran the build and tests on the machine above, including the old-counting check, and wrote this report from the output.

@JoaoPauluu

Copy link
Copy Markdown

A run under Wine on Linux: the count changes the same way as in the description's AMD run.

Tested

Regression run

main (first run):

xcl-smoke v1
commit: 47efa2ecea0a12934719ae69b81930cf02a4b1c3
gpu: NVIDIA GeForce RTX 3060
title: GTA6.Xbox.v1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1351 (PresentX 1351)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 0 MB

this PR:

xcl-smoke v1
commit: 39d761715ab47392c57fc53778d3c03b9486d8a5
gpu: NVIDIA GeForce RTX 3060
title: GTA6.Xbox.v1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1376 (PresentX 1376)
presents per 2 s (last 3): 60 60 61
device removals: 0
crashes: 0
peak commit: 0 MB

The second main run: 1382 frames, exit: 0x0, no device removal, no crash. Under Wine, peak commit reads 0 MB, so these blocks do not check memory.

Not tested

  • the test suite on this head, the window title's pipelines queued text, native Windows.

AI use

  • Claude Code (Claude Opus 5.5) built both commits, ran the runs and wrote this report. The account owner asked for test reports to be posted and has not reviewed this one.

@pvfreis pvfreis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of 39d7617 (merge base 47efa2e; current main is 930e8b4), by reading the code; nothing was built or run here. On the head itself I found no path that leaves a queued build counted after it is built or released, and no underflow.

  1. CONFIRMED: merged into current main, pso_async.rs defines BUILDING twice. The head adds static BUILDING: AtomicUsize (pso_async.rs:88). After this PR was opened, main got 25c6f7e, which adds a module-level thread_local! { static BUILDING: RefCell<Option<Arc<Pending>>> } to the same file (pso_async.rs:44-46 on main). The two merge without a textual conflict, but the merged file has both items (lines 51 and 159), used as BUILDING.with(..) and as BUILDING.fetch_add/fetch_sub/load. Two items with one name in a module is E0428, so the merged tree should not compile (by reading; not compiled here). Fix: rebase and give the counter its own name (e.g. QUEUED_BUILDS), then rerun the suite and the smoke block on the new head.

Questions for the author

  • The test's last check drops the PENDING lock before reading the global counter; with --test-threads=4, could another test's submit or released in between make it fail?
  • The comment says a released in-flight pipeline "drops from the building count immediately", but the test only asserts counts().2 < 64; would checking the count before and after released show that?

Verdict: the counting looks right on its own; it needs a rebase and a rename before it can merge.

Review by Claude Code (written by Claude Opus 5.5, second read by Claude Fable 5.2); each point checked by a person before posting.

@eizispark

Copy link
Copy Markdown
Author

Thanks @pvfreis for catching the BUILDING symbol collision with 25c6f7e and the two test questions, and thanks @fromthemoonx and @JoaoPauluu for the Windows and Linux/Wine NVIDIA test reports.

Rebased onto current main (930e8b4) as 47f672e:

  • Renamed the atomic counter to QUEUED_BUILDS (resolving E0428 against the BUILDING thread-local).
  • Serialized the used_tests submit/submit_lazy tests under COUNT_TEST_LOCK, updated submit_as and released so QUEUED_BUILDS transitions while holding PENDING, and kept the PENDING guard across the final zero check.
  • Replaced the loose < 64 check on the orphaned in-flight pipeline with an exact after_release + 1 == before_release check around released(), followed by waiting on done and verifying worker completion leaves counts().2 == after_release.
  • Updated the PR description with fresh workspace test counts and a fresh 60 s xcl-smoke run on 47f672e.

AI use: Antigravity (Gemini 4 Carbon)

@pvfreis

pvfreis commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Thanks. Checked at 47f672e (read only): the counter is QUEUED_BUILDS and the PR now merges into main 930e8b4 with a single BUILDING (the thread-local), the count tests run under COUNT_TEST_LOCK, and the release check is exact. All three points are addressed.

Reply by Claude Code (Claude Opus 5.5); checked by a person before posting.

@eizispark
eizispark force-pushed the fix/894-queued-pipeline-count branch from 47f672e to ad5ff40 Compare November 24, 2026 20:15
@ivall ivall added the goal:world-load Bears on the retail title getting past world loading label Nov 24, 2026
@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.

@throny

throny commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

Test report for exact head ad5ff40.

Tested

  • Windows 11 Pro 10.0.26300, NVIDIA GeForce RTX 4080 (driver 610.88, 32-lane waves), Intel i9-12900K, 64 GB; Rust 1.100.0 MSVC; DXC 1.9.2602.17; tests in debug, title runs in release.
  • cargo build --workspace && cargo test --workspace -- --test-threads=4 on ad5ff40 as it is (its own base): 876 passed, 0 failed, 42 ignored. SKIPPED: 4 lines (no wave64 on this adapter, and the like).
  • scripts/smoke.ps1, the retail title, 60 s, release builds, main 568e7db first, then this head:

main:

xcl-smoke v1
commit: 568e7db7729c8fa6c8f0f4b32d798faaf11462bb
gpu: NVIDIA GeForce RTX 4080
title: 21222967
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: 15820 MB

PR:

xcl-smoke v1
commit: ad5ff4058ad8f4b64eea4702fe342de6598628e7
gpu: NVIDIA GeForce RTX 4080
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1604 (PresentX 1604)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15833 MB

Not tested: AMD, the head merged onto current main, a world load.

AI use: Claude Code (Claude Opus 5.5) ran this and wrote the report; the diff was read for safety by a Claude Opus 5.5 sub-agent before it was built.

@eizispark
eizispark force-pushed the fix/894-queued-pipeline-count branch from ad5ff40 to 532ee56 Compare November 25, 2026 11:44
@eizispark

Copy link
Copy Markdown
Author

Rebased onto main 426a5a7 as 532ee56 (thanks @DavidM1911 for flagging the conflict, and @throny for the RTX 4080 run on ad5ff40).

The conflict came from #972's a_released_queued_pipeline_is_not_built_by_normal_workers (b4d7482), which was added in the same spot as this PR's test. Both are kept. That test now takes COUNT_TEST_LOCK, because it fills every normal worker and holds a stand-in in flight, which would throw off this PR's counts() checks if the two ran together. The accounting still holds with the new orphan skip in queue(): released() already calls finish_queued() before a worker can drop the job.

On the RX 9070 XT: pso_async, 5 runs × 9 tests, all passed. Full workspace: 1241 passed; the 3 failures also fail on a clean main 426a5a7 here. New smoke pair in the description: 1680 frames on main, 1678 on the PR.

With XCL_LAZY_PSO=1 on by default, submit_lazy places every translated
stand-in pipeline in PENDING while sending only pipelines from
used-pipelines.txt (or ones bound later) to the workers. pso_async::counts
walked PENDING under its mutex and counted every !done entry, keeping
the window title stuck on ~57,500 "pipelines queued" (xcl-dev#894) and
reporting dormant lazy stand-ins as still building in report.json.

Track a monotonic IDLE -> QUEUED -> DONE state per Pending with an
atomic QUEUED_BUILDS counter updated when a pipeline is queued (or built
on the binding thread) and cleared on completion or release, making
pso_async::counts() lock-free and O(1).

Part of xcl-dev#894.

Assisted-by: Antigravity (Google DeepMind, Gemini 4 Carbon)
@eizispark
eizispark force-pushed the fix/894-queued-pipeline-count branch from 532ee56 to 0840ff5 Compare November 25, 2026 11:51
@eizispark

Copy link
Copy Markdown
Author

Main moved again a few minutes after the rebase (#1782 added its PcCalls tests to used_tests right next to COUNT_TEST_LOCK), so this is now 0840ff5 on top of main 1a0bbe3. Both are kept and nothing else changed. pso_async: 5 runs × 11 passed. Full workspace: 1249 passed; the 2 DXIL fuzz failures also fail on a clean main here. The new smoke pair is in the description (1679 frames on the PR, 1680 on main).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

goal:world-load Bears on the retail title getting past world loading

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants