Skip to content

D3D12.X: build masked pipelines for partial DispatchX groups on workers - #3066

Open
KDenKC wants to merge 3 commits into
xcl-dev:mainfrom
KDenKC:dispatchx-runtime
Open

KDenKC wants to merge 3 commits into
xcl-dev:mainfrom
KDenKC:dispatchx-runtime

Conversation

@KDenKC

@KDenKC KDenKC commented Nov 27, 2026 •

Copy link
Copy Markdown

Stacked on #3015 (itself stacked on #2610); review only the last commit, d8a1f5f1.

What is in it

A partial thread-dimension DispatchX selects the masked direct-DXIL compute pipeline. Whole groups keep the original pipeline. A 200-second diagnostic run counted 2,999 partial-group calls out of 3,009 thread-dimension DispatchX calls in the last logged sample, across four pipelines. The first appeared at world load.

Only the first partial dispatch queues the variant. If the list can defer the dispatch, it replays with the same dimensions at submit. Title and submit threads wait for the variant without doing the driver build themselves. A build worker can take an unstarted dependency inline to avoid deadlock when the worker pool is full. For a split variant, the worker prepares the pieces and the whole-program scratch fallback. If the variant fails or exceeds the wait budget, the call is skipped.

Related #1751 / #1833.

Tested

At this head, d8a1f5f1, release, XCL_NETWORK=0, RTX 5090 (621.24) and the Ryzen 7 9800X3D's AMD Radeon iGPU (RDNA2), Windows 11:

  • cargo test --workspace --no-fail-fast -- --test-threads=4 (RTX 5090): 1,438 passed, 4 failed, 47 ignored, 27 SKIPPED. The 4 failures are the known fuzz_validate_and_gpu_0..3 (DXIL GPU fuzz tests reproducibly fail with E_OUTOFMEMORY on RTX 5060 #1905). The SKIPPED include dispatchx_native_wave64_masks_excess_lanes (no native wave64 on this GPU).
  • gpu::dxil::dispatchx_tests::: 7 passed on both adapters. The native-wave64 case ran and passed on the iGPU.
  • hle::d3d12x::pso_async:: (the worker queue): 19 passed on both adapters.
  • Earlier, on revision 224706a6: bypassing the selection returned the original PSO for a partial group and failed the regression test. With selection, a GPU readback had 100 expected writes and 28 untouched elements.
  • In the retail title, in the smoke run below: the two DispatchX flag kinds the title used were both partial groups and took this path (0x8020, a 1×1×1 group with thread limits [1,0,0]; 0x20, 45 threads launched as 1 group with limits [45,0,0]). There were 0 masked-pipeline-unavailable errors and 0 skipped DispatchX. The code logs the flags line once per kind and nothing per variant selection, so the number of masked dispatches isn't in the log.

Tested by others (thank you):

Not tested

Full wrapped-list replay; the in-title first-use wait and the rendered result of the masked dispatches (the frames are grey on this tree); a count of masked dispatches in the title; runtime selection on AMD in the title. The HLSL and per-lane paths are outside this change.

Regression run

main (08db8020, the base under #2610, #3015 and this change; the same block as in #2610 and #3015):

xcl-smoke v1
commit: 08db8020d323bf478964fcc586152cce54959cfc
gpu: NVIDIA GeForce RTX 5090
title: 9cc6a39e
seconds: 200
exit: 0x0
frames shown: 2034 (PresentX 2034)
presents per 2 s (last 3): 0 0 0
device removals: 0
crashes: 0
peak commit: 31275 MB

This PR (d8a1f5f1):

xcl-smoke v1
commit: d8a1f5f1fc30b8640afb76266d24d4a7b79896c5
gpu: NVIDIA GeForce RTX 5090
title: 9cc6a39e
seconds: 200
exit: 0x0
frames shown: 2205 (PresentX 2205)
presents per 2 s (last 3): 0 0 0
device removals: 0
crashes: 0
peak commit: 32342 MB

Both: the retail title, -Seconds 200, RTX 5090, a copy of the same precompiled cache, the same scripted input, full-size frame dumps. The main run used a never-used exe name; this head's run reused a warm one.

AMD testing requested

Run from this source checkout in PowerShell with DXC available. Report the adapter, driver, and whether any focused case printed SKIPPED.

$env:XCL_NETWORK = '0'
$env:XCL_ADAPTER = 'amd'
cargo test -p xcl --lib shaders_key_tests::dispatchx_ -- --test-threads=1 --nocapture
cargo test -p xcl --lib hle::d3d12x::pso_async:: -- --test-threads=1 --nocapture
cargo test -p xcl --lib gpu::dxil::dispatchx_tests:: -- --test-threads=1 --nocapture

AI use

Codex (GPT-6.2-Sol) wrote the change, tests and description. Claude Code (Claude Opus 5.5) independently reviewed and validated the change at this head on both adapters, ran the smoke and in-title check, and finalised this description.

🤖 Generated with Claude Code

https://claude.ai/code/session_013oPUFCA9W9F8Qb5MPK33bR

KDenKC and others added 3 commits November 25, 2026 18:15
DispatchX(x, y, z, flags) dropped its flags. With USE_THREAD_DIMENSIONS
(0x20; 0x8020 with the wave32 bit) x, y, z are thread counts: the console
launches ceil(count / numthreads) groups and leaves the lanes past the count
out of EXEC. XCL launched the counts as groups: 32-64x the groups for the
retail title's BVH builder (its rehydration and reload passes pass node and
primitive counts), past D3D12's 65,535 groups for a large mesh, and every
extra thread of the unguarded Box32/Box16 rehydration shaders wrote outside
its node array.

The flags now reach the dispatch (also one put off to the submit). With
0x20 the counts become whole groups of the pipeline's console numthreads
(kept with its user SGPRs at creation); a pipeline whose group shape is not
known is not launched, skipped and counted as an untranslated one. The
thread count of an axis that does not end on a whole group goes to io
slots 114..116 (IO_THREAD_LIMIT), where the compute prologue will leave
the lanes past it out of EXEC in a following change: until then the last
group still runs whole. Each kind of flags is logged once.

Part of a stack: EXEC masking of the last group follows.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Intersect the existing entry EXEC mask with DispatchX thread bounds in a separate compute entry. Keep ordinary compute emission unchanged. Cover excess-lane stores in 1-D, 2-D and 3-D, split and native wave modes, and ordinary translation byte identity. Runtime selection and precompile integration are separate work.

Assisted-by: Codex (GPT-6.1-Sol)
@JJAutoCompare

Copy link
Copy Markdown

Tested

Clean detached d8a1f5f1fc30b8640afb76266d24d4a7b79896c5 on Windows 11 build 26200.9974, Ryzen 7 3800X, Arc A770 (8086:56a0, driver 32.0.101.9175), Rust 1.100.0 MSVC debug, and DXC/DXIL 1.9.2602.17. I reran the pinned stock libtest executable with --test-threads=1 --nocapture, an isolated DXIL cache, and PSO disk caching disabled.

  • CPU (8 passed): hle::d3d12x::pso_async::used_tests::worker_only_, dispatchx_failed_variant_is_built_once_and_never_selects_its_token, dispatchx_pending_variant_can_defer_and_replay_reports_failure, and dispatch_x_with_thread_dimensions_launches_whole_groups.
  • Arc runtime selection (1 passed): exact hle::d3d12x::real::shaders_key_tests::dispatchx_runtime_selects_and_reuses_a_masked_pipeline_only_for_partial_groups. Partial groups selected and reused a worker-built, unsplit wave32 masked direct-DXIL PSO. Whole groups kept the base token. The partial-group readback checked all 128 words: 100 expected writes and 28 untouched zeros.
  • Arc direct kernels (2 passed, 1 explicit skip): masks_excess_lanes passed its wave32 and split-wave64 readbacks. The native wave64 case logged a skip for unavailable wave size. Libtest included the early return in its pass count.

11 exercised passes, 0 failures, 0 ignores, 1 explicit skip. The Arc probe confirmed the actual adapter and an 8–32 wave-lane range. Both native GPU children and the shared lock wrapper exited 0. The executable hash matched before, under, and after the lock.

Not tested

Full wrapped command-list recording, submission and replay, runtime selection of a split PSO, retail smoke, and the full workspace suite.

AI use

T3 Code / Codex (gpt-6.2-sol) independently reran the stock tests and wrote this report.

@DarkPanda69

Copy link
Copy Markdown

AMD run (runtime selection on AMD was untested), with an RTX 3060 in the same PC. The 13 new tests pass on both, and the native wave64 one ran on the RX 9070 XT. One thing first: applied on today's main the PR doesn't build.

Doesn't build on current main: the diff applies cleanly on main 6089122 (GitHub also shows no conflict), but cargo test -p xcl --lib --no-run fails:

error[E0308]: mismatched types
  --> crates\xcl\src\hle\d3d12x\real.rs:5662:106
5662 | if compute_container(device.as_raw(), create, &desc, rs, &compiled.dxil, record, &iid, &mut out, false).0 < 0 {
     |                                                                                                   ^^^^^ expected `ComputeBuild`, found `bool`

main has 34 commits since this PR's base 08db802, and a call there still passes false where the PR changes the parameter to ComputeBuild. At the PR head it builds, so the results below are from the head.

Tested: at the PR head d8a1f5f against its merge-base with main, 08db802. Debug, Rust 1.100.0, Windows 11 Pro 26200, Ryzen 7 5800X, card picked with XCL_ADAPTER.
cargo test -p xcl --lib -- dispatchx dispatch_x gpu::dxil::kernel hle::d3d12x::bind pso_async --test-threads=4 --nocapture, 3 runs each:

  • AMD RX 9070 XT (RDNA4), driver 32.0.32029.2010: merge-base 23 passed, 0 failed; PR 36 passed, 0 failed, 3 of 3 runs. dispatchx_native_wave64_masks_excess_lanes ran and passed (no SKIPPED line for it).
  • NVIDIA RTX 3060, driver 32.0.16.1088: merge-base 23 passed; PR 36 passed, 0 failed, 3 of 3. As expected it skips the native wave64 cases: SKIPPED ...dispatchx_native_wave64_masks_excess_lanes: required wave size unavailable and SKIPPED ...dispatch_chain_native_wave64_builds_whole: no wave64 (libtest still lists both as ok).

New and ok on both: dispatchx_wave32_masks_excess_lanes, dispatchx_split_wave64_masks_excess_lanes, dispatchx_native_wave64_masks_excess_lanes (RX 9070 XT), dispatchx_base_translation_stays_byte_identical, dispatchx_runtime_selects_and_reuses_a_masked_pipeline_only_for_partial_groups, dispatch_x_with_thread_dimensions_launches_whole_groups and the worker_only_* tests. dispatch_x_with_thread_dimensions_launches_whole_groups (rarely flaky at 4 threads on #2817) passed in all 6 runs.

Not tested: the masked dispatches in a title, release, Intel.

AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.

@Anon64

Anon64 commented Nov 27, 2026 •

Copy link
Copy Markdown

RTX 3060 12 GB, retail title, 300 s: clean, but 1 722 frames against 2 234 on main (77 %), from one run that stopped presenting earlier. This PR's head d8a1f5f1 against main 2c717a04, release, XCL_ACTIVITY=1 XCL_NETWORK=0, 8 preparation threads, A pressed every 4 s from 20 s.

Both exit 0x0 with no device removals or crashes. Peak commit is 34 649 MB against 38 242 MB, and peak local video memory 15 762 MB against 18 893 MB. Both are lower because this run stopped earlier.

Presenting stops at ~92 s here, against ~338 s on main. The stop looks like the one described in #2595 on this card: one 2 s window with ~14 000 dispatches, then no submits while driver compiles of huge pipelines run with driver blob absent (1.4 MB compute, 0.3–0.6 MB graphics) to the timer. This PR branches from an older main than 2c717a04, so some pipelines may have compiled cold that the main build found in the blob cache. I can't separate that from the change with one run each, and I haven't rerun it.

Regression run

main:

xcl-smoke v1
commit: 2c717a043c8488938179fca81da4bb9e7913a358
gpu: NVIDIA GeForce RTX 3060
title: retail-1
seconds: 300
exit: 0x0
frames shown: 2234 (PresentX 2234)
presents per 2 s (last 3): 6 6 5
device removals: 0
crashes: 0
peak commit: 38242 MB

this PR:

xcl-smoke v1
commit: d8a1f5f1fc30b8640afb76266d24d4a7b79896c5
gpu: NVIDIA GeForce RTX 3060
title: retail-1
seconds: 300
exit: 0x0
frames shown: 1722 (PresentX 1722)
presents per 2 s (last 3): 0 0 0
device removals: 0
crashes: 0
peak commit: 34649 MB

Edit: one more run of each, same setup, warm caches. This PR's second run stops at ~94 s again (1 766 frames, exit 0x0, no device removals or crashes, peak commit 34 597 MB). But main's second run doesn't repeat its first either: its device is removed at ~187 s (0x887a0006, device hung; 2 device removals and 2 crashes in the smoke block), like the base runs on this card on #3025. So main varies here from presenting to ~338 s to a device hang at ~187 s. The PR's two runs both stop at ~93 s, but against that spread I can't say whether the change causes it. Neither PR run had a device removal.

RTX 3060 12 GB (driver 581.80), i9-14900KF, 64 GB RAM, Windows 11 26200.

AI use: Claude Code (Claude Opus 5.5) built both commits, ran the title, read the logs and wrote this report.

@KDenKC

KDenKC commented Nov 28, 2026

Copy link
Copy Markdown
Author

Thank you @JJAutoCompare, @DarkPanda69 and @Anon64. Added to the description. The native-wave64 run on the RX 9070 XT and the Arc readback were the coverage this needed.

@DarkPanda69, you're right about the build: main changed compute_container's last argument from bool to ComputeBuild, so build_masked_compute needs ComputeBuild::Whole there. The branch needs a rebase onto current main. That fixes the build and also makes a smoke against main like-for-like (@Anon64's point: this head predates main's startup preparation).

AI use: Claude Code (Claude Opus 5.5).

@akimfomin

Copy link
Copy Markdown

AnyPS5 #26196 shows why it matters that a first visit does not compile on the caller before the deferred path takes it. For your partial DispatchX variant, use a fresh cache and then one warm-cache run. Record worker and caller build counts and the number of partial calls skipped. That separates a faster preparation path from silently dropping work, without assuming the graphics and compute mechanisms are interchangeable.

@KDenKC

KDenKC commented Nov 28, 2026

Copy link
Copy Markdown
Author

@akimfomin, thanks. By construction, the masked variant never builds on the caller: it's queued with pso_async::submit_worker_only (the worker-only path from this series), and a waiting title or submit thread doesn't take an unstarted worker-only job. That's covered by worker_only_wait_does_not_take_an_unstarted_job and worker_only_submission_keeps_the_budget_and_used_key. If the variant isn't ready within the budget, or fails, the call returns an error ("DispatchX masked pipeline unavailable") and that dispatch is skipped rather than run with the extra lanes.

So the numbers that separate faster preparation from dropped work are the count of skipped partial calls on a fresh cache against a warm one. That's a fair ask. We'll add it with the next in-title run on the rebased head, rather than hold the rebase for it.

AI use: Claude Code (Claude Opus 5.5).

@thehollowedone

Copy link
Copy Markdown
Contributor

Source review of head d8a1f5f: there is a partial-DispatchX path where excess lanes can still execute when XCL_DIRECT_DXIL=1 XCL_PER_LANE=1.

The compute translator tries per-lane first and, on refusal, can successfully make the base pipeline with the per-instruction direct translator. But remember_masked_source returns whenever lower_dxil::enabled() is true, even when that translator refused the shader. A later partial DispatchX rounds up its group count, finds no registered source, and masked_dispatch_pso returns the unmasked base. The PR's GPU fixture establishes that the base ignores thread limits; a request for 100 threads in 32-thread groups can therefore run 28 extra lanes.

Please make registration follow the actual compiled translation, including its cached form, rather than the per-lane preference flag. For partial limits with no masked implementation available, masked_dispatch_pso must not silently return the unmasked base. A discriminating regression is to prepend V_MOV_B32 v9, exec_lo to the existing wave32 store fixture: that scalar-mask read refuses the per-lane lowering but is supported by the per-instruction path. Assert those two translation outcomes, then create the PSO through the normal production hook and dispatch 100 threads with 28 canary words beyond them. Check the canaries with both cold and warm translation caches. The current runtime selection test inserts the source into MASKED_COMPUTE itself, so it cannot detect the missing-registration path.

This is a source-traced finding; I did not run that regression or a GPU test. AI use: Codex (GPT-6.2 Sol) checked the call path and drafted this review; Codex (GPT-6.2 Astra) independently audited the translator and fixture.

@KDenKC

KDenKC commented Nov 28, 2026

Copy link
Copy Markdown
Author

@thehollowedone, confirmed, thank you. The same path is in the rebase onto current main that's ready locally. remember_masked_source returns whenever lower_dxil::enabled() is true, not when per-lane actually translated the shader. And masked_dispatch_pso treats "no source registered" as "use the base", so a per-lane refusal that falls back to the per-instruction translator runs the extra lanes under XCL_DIRECT_DXIL=1 XCL_PER_LANE=1.

The fix will go in with the rebase, along the lines you describe:

  • registration follows the translation actually used, including its cached form;
  • a partial DispatchX whose base can't honour thread limits and has no masked variant returns an error and is skipped, never the unmasked base;
  • your regression: V_MOV_B32 v9, exec_lo ahead of the wave32 store fixture. It asserts that per-lane refuses and per-instruction accepts, creates the pipeline through the production hook, and dispatches 100 threads with 28 canary words, on cold and warm translation caches.

AI use: Claude Code (Claude Opus 5.5) checked the path at the rebased head and wrote this reply.

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.

6 participants