D3D12.X: keep the first indirect scaling pipeline per device #3317

Open
KDenKC wants to merge 1 commit from upstream-pr/3317 into main
KDenKC commented 2026-11-29 07:55:26 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by KDenKC on 2026-11-29T07:55:26Z.


scale_indirect_pipeline builds, once per device, the root signature and compute pipeline that scale two-pass ExecuteIndirect arguments, and caches them. When two threads missed the cache at the same time, both built a pair, and the second insert replaced the first. The first pair's last references were then dropped while command lists recorded with it could still be pending or running: a pipeline released while in use.

Now the first pair published wins. A late builder drops its own pair and returns the cached one, so every recording refers to the pair that stays alive.

claudetools-gh found the race and the first-wins fix (#2952 entry 6, https://github.com/xcl-dev/xcl/issues/2952#issuecomment-7214036990) and confirmed it is still in main (https://github.com/xcl-dev/xcl/issues/2952#issuecomment-7246668953).

Related: #2952 (entry 6). The argument-ordering buffer fix that was the second commit here is now its own PR: #3685.

What is in it (hle/d3d12x/bind.rs)

  • D3D12.X: keep the first indirect scaling pipeline per device (8afcf478, review fixes squashed in):
    • The build and the cache policy are split. build_scale_indirect_pipeline makes a pair. cached_scale_indirect_pipeline returns the cached pair, or builds one and inserts it under the lock with entry().or_insert (first wins). scale_indirect_pipeline gives its callers the same pair as before; it is no longer unsafe.
    • A caller whose own build fails takes the pair another caller published meanwhile; the error only when there is none (a failure is not cached).
    • Each entry holds a reference to the device it was made for, so the device address it is keyed by cannot be another device's while the entry exists. XCL already keeps one reference to every device it makes for the process, so this keeps nothing alive that was not kept already.
    • Tests: gpu_scale_indirect_pipeline_keeps_first_pair (two callers that both missed, through scale_indirect_pipeline_in on the real cache: the first to publish wins, and the entry keeps that pair and the caller's device; no thread scheduling involved) and a_failed_scale_indirect_build_takes_the_published_pair (no GPU).

Tested

  • Head 8afcf478, on main 1c8b5514 (the PR split at Foniass's request; this commit is identical to before, git range-diff), NVIDIA GeForce RTX 3090 24 GB, driver 621.24, Intel i7-10700T, Windows 11 build 26300.9974, Rust 1.99.1, debug:
    • cargo test --workspace --no-fail-fast -- --test-threads=4: 2903 passed, 5 failed, 51 ignored. The 5 fail on main 1c8b5514 too (the 4 title_textures tests and e2e test_title_runs_and_game_folder_is_untouched); SKIPPED: 28, as on main.
    • -- gpu_scale_indirect_pipeline_keeps_first_pair --nocapture --test-threads=1: 1 passed (the GPU test ran, no SKIPPED); -- a_failed_scale_indirect_build_takes_the_published_pair: 1 passed.
  • Head 730b5b9b (on 7db2f391), NVIDIA GeForce RTX 3090 24 GB, driver 621.24, Intel i7-10700T, Windows 11 build 26300.9974, Rust 1.99.1, debug:
    • cargo test -p xcl --lib -- scale_indirect --nocapture --test-threads=1: 2 passed, 0 failed; -- argument_order_buffers: 1 passed, 0 failed.
    • cargo test --workspace --no-fail-fast -- --test-threads=4: 2589 passed, 5 failed, 49 ignored. The same 5 failures as main on this machine (below); SKIPPED: 30, as below.
  • Earlier heads:
  • NVIDIA GeForce RTX 3090 24 GB, driver 621.24 (32.0.16.2124), Intel i7-10700T, Windows 11 build 26300.9974, Rust 1.99.1, debug:
    • cargo test -p xcl --lib -- scale_indirect --nocapture --test-threads=1 at d848cc4c: 1 passed, 0 failed, 0 ignored, 2484 filtered out (gpu_scale_indirect_pipeline_keeps_first_pair; the GPU test ran, no SKIPPED: DXC dxcompiler 1.9.2602.17). cargo test -p xcl --lib --no-run debug and release: both build.
    • cargo test --workspace --no-fail-fast -- --test-threads=4 at a83846da (the same change before its test got the no DXC skip; the runtime code is identical): 2587 passed, 5 failed, 49 ignored. Main 7db2f391 on the same machine: 2586 passed, the same 5 failed, 49 ignored. The 5 are main's own: title_textures::tests::placed_title_textures_share_vram_and_preserve_pixels (a subtract overflow) and the 3 stream_recheck_* tests it poisons, plus e2e test_title_runs_and_game_folder_is_untouched. SKIPPED: 30 lines, identical on both (21 no wave64, 3 refused f16/f32 per-lane forms, 2 no heap windows, 1 driver cache cannot be disabled, 3 no debug layer). The run leaves out the 3 uma_driver coherent-window remake tests that kill the lib binary on 621.x, on both.
  • Earlier, on nvidia-dev (d9cf7aec on 54225f58), RTX 5090 32 GB, 621.24, release: -- scale_indirect: 1 passed.

Seen in the title (one occurrence, so read it as a likely reproduction, not proof): on an RTX 5090 (621.24), plain main 7db2f391 crashed in the NVIDIA driver at the world entry (0xc0000005 in nvwgf2umx.dll, a read at 0xe800, rax=0) at the same millisecond (121.430 s) as five title threads made the first two-pass ExecuteIndirect(DispatchMesh) calls of the run at once, i.e. the first uses of this per-device scaling pipeline; the crashing thread was one of them, between its argument scratch and its first call. This head, run the same way from the same cache, reached 2,252 frames over 200 s with no crash (an earlier pair with preparation off, separate from the Regression run below). Setup of both: 16 view windows, mixed UMA, XCL_PREPARE=0, XCL_HUGE_PSO_CONCURRENCY=3. Earlier, on an nvidia-dev-based tree (d1be8103, same card), two runs crashed the same way in the NVIDIA user-mode driver during two-pass ExecuteIndirect at about 102 s, and the tree with this fix did not crash there (https://github.com/xcl-dev/xcl/issues/2952#issuecomment-7228069924; those fixed runs stalled later for another reason).

Once more, independently (2026-12-02, RTX 5090, 621.24): a diagnostic tree of ours based on main 1c8b5514 WITHOUT this change crashed the same way, 80 s in and before the world: five threads made the run's first two-pass ExecuteIndirect(DispatchMesh) calls within a millisecond while a sixth was building the scaling compute pipeline (a 4500-byte compute shader logged one millisecond earlier), and that thread faulted in nvwgf2umx.dll+0x7c89af (a read at 0x4a8). The same tree had run clean before and after; it is one more occurrence, not a reproduction on demand.

Regression run
RTX 5090 32 GB, driver 621.24, Ryzen 7 9800X3D, the retail title, scripts/smoke.ps1, 600 s each, JIT (XCL_PREPARE=0), both from a copy of the same cache. This machine's usual settings (XCL_UMA_WINDOWS=16, mixed UMA, XCL_DIRECT_DXIL=1, XCL_HEAP_WINDOWS=1). The crash this PR fixes did not occur in this pair's main run; it is timing-dependent (see Seen in the title above).

main 1c8b5514:

xcl-smoke v1
commit: 1c8b551475e1e7bfe48f94448492a4c3544a2e0f
gpu: NVIDIA GeForce RTX 5090
title: 9cc6a39e
seconds: 600
exit: 0x0
frames shown: 1724 (PresentX 1725)
presents per 2 s (last 3): 2 1 2
device removals: 0
crashes: 0
peak commit: 47581 MB

this head 8afcf478:

xcl-smoke v1
commit: 8afcf47863b6b20faf4694b57569cf0070fe3a6f
gpu: NVIDIA GeForce RTX 5090
title: 9cc6a39e
seconds: 600
exit: 0x0
frames shown: 1867 (PresentX 1868)
presents per 2 s (last 3): 3 2 2
device removals: 0
crashes: 0
peak commit: 47964 MB

Not tested

  • The race itself in the retail title is not shown directly: it needs two threads building the pair at once. One crash on main matches it (above, one occurrence); the test drives the interleaving directly.
  • AMD, Intel.

AI use

  • Claude Code (Claude Opus 5.5, Claude Sonnet 5.5), Codex (GPT-6.2-Sol), Antigravity (Gemini 4 Neon, Gemini 4 Hydrogen): an agent swarm wrote, tested, reviewed and described this change.

🤖 Generated with Claude Code
https://claude.ai/code/session_013oPUFCA9W9F8Qb5MPK33bR

<!-- greyfinch-sync:ivall/xcl:issue:5548802427 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3317). Originally posted by [KDenKC](https://github.com/KDenKC) on 2026-11-29T07:55:26Z. --- `scale_indirect_pipeline` builds, once per device, the root signature and compute pipeline that scale two-pass ExecuteIndirect arguments, and caches them. When two threads missed the cache at the same time, both built a pair, and the second insert **replaced** the first. The first pair's last references were then dropped while command lists recorded with it could still be pending or running: a pipeline released while in use. Now the first pair published wins. A late builder drops its own pair and returns the cached one, so every recording refers to the pair that stays alive. claudetools-gh found the race and the first-wins fix (#2952 entry 6, https://github.com/xcl-dev/xcl/issues/2952#issuecomment-7214036990) and confirmed it is still in main (https://github.com/xcl-dev/xcl/issues/2952#issuecomment-7246668953). Related: #2952 (entry 6). The argument-ordering buffer fix that was the second commit here is now its own PR: #3685. **What is in it** (`hle/d3d12x/bind.rs`) - `D3D12.X: keep the first indirect scaling pipeline per device` (`8afcf478`, review fixes squashed in): - The build and the cache policy are split. `build_scale_indirect_pipeline` makes a pair. `cached_scale_indirect_pipeline` returns the cached pair, or builds one and inserts it under the lock with `entry().or_insert` (first wins). `scale_indirect_pipeline` gives its callers the same pair as before; it is no longer `unsafe`. - A caller whose own build fails takes the pair another caller published meanwhile; the error only when there is none (a failure is not cached). - Each entry holds a reference to the device it was made for, so the device address it is keyed by cannot be another device's while the entry exists. XCL already keeps one reference to every device it makes for the process, so this keeps nothing alive that was not kept already. - Tests: `gpu_scale_indirect_pipeline_keeps_first_pair` (two callers that both missed, through `scale_indirect_pipeline_in` on the real cache: the first to publish wins, and the entry keeps that pair and the caller's device; no thread scheduling involved) and `a_failed_scale_indirect_build_takes_the_published_pair` (no GPU). **Tested** - Head `8afcf478`, on `main` `1c8b5514` (the PR split at Foniass's request; this commit is identical to before, `git range-diff`), NVIDIA GeForce RTX 3090 24 GB, driver 621.24, Intel i7-10700T, Windows 11 build 26300.9974, Rust 1.99.1, debug: - `cargo test --workspace --no-fail-fast -- --test-threads=4`: 2903 passed, 5 failed, 51 ignored. The 5 fail on `main` `1c8b5514` too (the 4 `title_textures` tests and e2e `test_title_runs_and_game_folder_is_untouched`); SKIPPED: 28, as on `main`. - `-- gpu_scale_indirect_pipeline_keeps_first_pair --nocapture --test-threads=1`: 1 passed (the GPU test ran, no SKIPPED); `-- a_failed_scale_indirect_build_takes_the_published_pair`: 1 passed. - Head `730b5b9b` (on `7db2f391`), NVIDIA GeForce RTX 3090 24 GB, driver 621.24, Intel i7-10700T, Windows 11 build 26300.9974, Rust 1.99.1, debug: - `cargo test -p xcl --lib -- scale_indirect --nocapture --test-threads=1`: 2 passed, 0 failed; `-- argument_order_buffers`: 1 passed, 0 failed. - `cargo test --workspace --no-fail-fast -- --test-threads=4`: 2589 passed, 5 failed, 49 ignored. The same 5 failures as `main` on this machine (below); SKIPPED: 30, as below. - Earlier heads: - NVIDIA GeForce RTX 3090 24 GB, driver 621.24 (32.0.16.2124), Intel i7-10700T, Windows 11 build 26300.9974, Rust 1.99.1, debug: - `cargo test -p xcl --lib -- scale_indirect --nocapture --test-threads=1` at d848cc4c: 1 passed, 0 failed, 0 ignored, 2484 filtered out (`gpu_scale_indirect_pipeline_keeps_first_pair`; the GPU test ran, no SKIPPED: DXC dxcompiler 1.9.2602.17). `cargo test -p xcl --lib --no-run` debug and release: both build. - `cargo test --workspace --no-fail-fast -- --test-threads=4` at a83846da (the same change before its test got the `no DXC` skip; the runtime code is identical): 2587 passed, 5 failed, 49 ignored. Main 7db2f391 on the same machine: 2586 passed, the same 5 failed, 49 ignored. The 5 are main's own: `title_textures::tests::placed_title_textures_share_vram_and_preserve_pixels` (a subtract overflow) and the 3 `stream_recheck_*` tests it poisons, plus e2e `test_title_runs_and_game_folder_is_untouched`. SKIPPED: 30 lines, identical on both (21 no wave64, 3 refused f16/f32 per-lane forms, 2 no heap windows, 1 driver cache cannot be disabled, 3 no debug layer). The run leaves out the 3 `uma_driver` coherent-window remake tests that kill the lib binary on 621.x, on both. - Earlier, on nvidia-dev (d9cf7aec on 54225f58), RTX 5090 32 GB, 621.24, release: `-- scale_indirect`: 1 passed. **Seen in the title** (one occurrence, so read it as a likely reproduction, not proof): on an RTX 5090 (621.24), plain `main` `7db2f391` crashed in the NVIDIA driver at the world entry (`0xc0000005` in `nvwgf2umx.dll`, a read at `0xe800`, `rax=0`) at the same millisecond (121.430 s) as five title threads made the first two-pass `ExecuteIndirect(DispatchMesh)` calls of the run at once, i.e. the first uses of this per-device scaling pipeline; the crashing thread was one of them, between its argument scratch and its first call. This head, run the same way from the same cache, reached 2,252 frames over 200 s with no crash (an earlier pair with preparation off, separate from the Regression run below). Setup of both: 16 view windows, mixed UMA, `XCL_PREPARE=0`, `XCL_HUGE_PSO_CONCURRENCY=3`. Earlier, on an `nvidia-dev`-based tree (`d1be8103`, same card), two runs crashed the same way in the NVIDIA user-mode driver during two-pass `ExecuteIndirect` at about 102 s, and the tree with this fix did not crash there (https://github.com/xcl-dev/xcl/issues/2952#issuecomment-7228069924; those fixed runs stalled later for another reason). Once more, independently (2026-12-02, RTX 5090, 621.24): a diagnostic tree of ours based on `main` `1c8b5514` WITHOUT this change crashed the same way, 80 s in and before the world: five threads made the run's first two-pass `ExecuteIndirect(DispatchMesh)` calls within a millisecond while a sixth was building the scaling compute pipeline (a 4500-byte compute shader logged one millisecond earlier), and that thread faulted in `nvwgf2umx.dll+0x7c89af` (a read at 0x4a8). The same tree had run clean before and after; it is one more occurrence, not a reproduction on demand. **Regression run** RTX 5090 32 GB, driver 621.24, Ryzen 7 9800X3D, the retail title, `scripts/smoke.ps1`, 600 s each, JIT (`XCL_PREPARE=0`), both from a copy of the same cache. This machine's usual settings (`XCL_UMA_WINDOWS=16`, mixed UMA, `XCL_DIRECT_DXIL=1`, `XCL_HEAP_WINDOWS=1`). The crash this PR fixes did not occur in this pair's `main` run; it is timing-dependent (see **Seen in the title** above). main `1c8b5514`: ``` xcl-smoke v1 commit: 1c8b551475e1e7bfe48f94448492a4c3544a2e0f gpu: NVIDIA GeForce RTX 5090 title: 9cc6a39e seconds: 600 exit: 0x0 frames shown: 1724 (PresentX 1725) presents per 2 s (last 3): 2 1 2 device removals: 0 crashes: 0 peak commit: 47581 MB ``` this head `8afcf478`: ``` xcl-smoke v1 commit: 8afcf47863b6b20faf4694b57569cf0070fe3a6f gpu: NVIDIA GeForce RTX 5090 title: 9cc6a39e seconds: 600 exit: 0x0 frames shown: 1867 (PresentX 1868) presents per 2 s (last 3): 3 2 2 device removals: 0 crashes: 0 peak commit: 47964 MB ``` **Not tested** - The race itself in the retail title is not shown directly: it needs two threads building the pair at once. One crash on `main` matches it (above, one occurrence); the test drives the interleaving directly. - AMD, Intel. **AI use** - Claude Code (Claude Opus 5.5, Claude Sonnet 5.5), Codex (GPT-6.2-Sol), Antigravity (Gemini 4 Neon, Gemini 4 Hydrogen): an agent swarm wrote, tested, reviewed and described this change. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_013oPUFCA9W9F8Qb5MPK33bR
Foniass commented 2026-12-01 09:48:54 +00:00 (Migrated from github.com)

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


Triage (#1607) – head d848cc4

No open or merged PR fixes this race (#2952 entry 6); main's scale_indirect_pipeline still inserts last-wins.
cached_scale_indirect_pipeline now inserts with entry().or_insert, so a late builder returns the first pair and the pair recorded lists use is not released. The test builds the race without relying on thread scheduling. No problems found in the diff.
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:7307245705 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3317#issuecomment-7307245705). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T09:48:54Z. --- **Triage (#1607)** – head d848cc4 No open or merged PR fixes this race (#2952 entry 6); main's `scale_indirect_pipeline` still inserts last-wins. `cached_scale_indirect_pipeline` now inserts with `entry().or_insert`, so a late builder returns the first pair and the pair recorded lists use is not released. The test builds the race without relying on thread scheduling. No problems found in the diff. Recommendation: keep open. AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
Foniass commented 2026-12-01 09:51:32 +00:00 (Migrated from github.com)

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


merge-check
base: 493dbd3dd0
head: d848cc4c66
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2901 passed, 0 failed, 51 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on main); failing: none
review: read the whole diff (+62/-7). The bug is a use-after-free, not only a pipeline released while pending. On main, two threads that miss the cache both build a pair, and the second insert replaces the first (bind.rs ~3176 on main). The first thread keeps only raw pointers (prepare_scaled_args treats the pair as "the device's for good"), and make_scaled_args_buffer then runs SetPipelineState on the freed object. That fits the reported crash in nvwgf2umx.dll. The fix is right: the build runs outside the lock, entry().or_insert(pair) under it keeps the first pair stored, and the loser's pair never leaves the function. Findings (minor): (1) the test exercises the new helper, and would fail if or_insert became insert, but nothing checks that scale_indirect_pipeline goes through it; the last_wins block only checks a local map. (2) Two threads can still both compile once; that only costs time. Fine: the hit path costs the same as before, a miss adds one lock and one clone, and dropping unsafe is sound. The cache is still never evicted, as on main. Any ExecuteIndirect of a two-pass mesh pipeline reaches it. The title makes mesh pipelines in the run below, but the log doesn't show whether one goes through ExecuteIndirect in 60 s. #2092 touches the same function but doesn't fix this.
performance: 60 s smoke of a retail title, main 493dbd3d vs this merge (beffe00f): 1670 -> 1673 frames shown (100 %; last presents per 2 s: 60 60 60), peak commit 17083 -> 18047 MB, 0 device removals, 0 crashes. Peak commit is 964 MB (5.6 %) above main in this one run; nothing in this diff allocates per draw, so that looks like run-to-run variation.
verdict: safe to merge
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5

AI-written and posted by Foniass without a human check of each point.

<!-- greyfinch-sync:ivall/xcl:comment:7307308749 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3317#issuecomment-7307308749). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T09:51:32Z. --- merge-check base: 493dbd3dd0cd50b4c3e8d28f73ab9b504fcd8158 head: d848cc4c66905558fa33d017b93d393a1b920d94 merge: clean build: cargo build --workspace -> ok tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2901 passed, 0 failed, 51 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on main); failing: none review: read the whole diff (+62/-7). **The bug is a use-after-free, not only a pipeline released while pending.** On main, two threads that miss the cache both build a pair, and the second `insert` replaces the first (`bind.rs` ~3176 on main). The first thread keeps only raw pointers (`prepare_scaled_args` treats the pair as "the device's for good"), and `make_scaled_args_buffer` then runs `SetPipelineState` on the freed object. That fits the reported crash in `nvwgf2umx.dll`. The fix is right: the build runs outside the lock, `entry().or_insert(pair)` under it keeps the first pair stored, and the loser's pair never leaves the function. Findings (minor): (1) the test exercises the new helper, and would fail if `or_insert` became `insert`, but nothing checks that `scale_indirect_pipeline` goes through it; the `last_wins` block only checks a local map. (2) Two threads can still both compile once; that only costs time. Fine: the hit path costs the same as before, a miss adds one lock and one clone, and dropping `unsafe` is sound. The cache is still never evicted, as on main. Any ExecuteIndirect of a two-pass mesh pipeline reaches it. The title makes mesh pipelines in the run below, but the log doesn't show whether one goes through ExecuteIndirect in 60 s. #2092 touches the same function but doesn't fix this. performance: 60 s smoke of a retail title, main 493dbd3d vs this merge (beffe00f): 1670 -> 1673 frames shown (100 %; last presents per 2 s: 60 60 60), peak commit 17083 -> 18047 MB, 0 device removals, 0 crashes. Peak commit is 964 MB (5.6 %) above main in this one run; nothing in this diff allocates per draw, so that looks like run-to-run variation. verdict: safe to merge hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5 AI-written and posted by Foniass without a human check of each point.
bmjask commented 2026-12-01 23:14:42 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-01T23:14:42Z.

Code review location: crates/xcl/src/hle/d3d12x/bind.rs; line 3124

@@ -3107,23 +3107,38 @@ void main(uint tid : SV_DispatchThreadID) {
 }
 "#;
 
-unsafe fn scale_indirect_pipeline(dev: &ID3D12Device) -> Result<(ID3D12RootSignature, ID3D12PipelineState), String> {
-    static CACHE: Mutex<Option<HashMap<usize, (ID3D12RootSignature, ID3D12PipelineState)>>> = Mutex::new(None);
-    let key = dev.as_raw() as usize;
-    if let Some(pair) = CACHE.lock().unwrap().as_ref().and_then(|m| m.get(&key).cloned()) {
+type ScaleIndirectPair = (ID3D12RootSignature, ID3D12PipelineState);
+
+fn scale_indirect_pipeline(dev: &ID3D12Device) -> Result<ScaleIndirectPair, String> {
+    static CACHE: Mutex<Option<HashMap<usize, ScaleIndirectPair>>> = Mutex::new(None);
+    cached_scale_indirect_pipeline(&CACHE, dev.as_raw() as usize, || build_scale_indirect_pipeline(dev))
+}
+
+fn cached_scale_indirect_pipeline(
+    cache: &Mutex<Option<HashMap<usize, ScaleIndirectPair>>>,
+    key: usize,
+    build: impl FnOnce() -> Result<ScaleIndirectPair, String>,
+) -> Result<ScaleIndirectPair, String> {
+    if let Some(pair) = cache.lock().unwrap().as_ref().and_then(|m| m.get(&key).cloned()) {
         return Ok(pair);
     }

If a late caller's own build() fails, it returns Err even though another thread already published a working pair under the same key, because ? returns before the second lock and re-check. Thread A inserts the pair. Thread B missed at the same time and its CreateComputePipelineState fails (e.g. a transient E_OUTOFMEMORY), so prepare_scaled_args fails and that two-pass ExecuteIndirect is dropped or falls back, although a valid cached pair exists. Re-checking the map on the error path fixes it.

<!-- greyfinch-sync:ivall/xcl:review-comment:4762388895 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3317#discussion_r4762388895). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-01T23:14:42Z. **Code review location:** `crates/xcl/src/hle/d3d12x/bind.rs`; line 3124 ~~~~diff @@ -3107,23 +3107,38 @@ void main(uint tid : SV_DispatchThreadID) { } "#; -unsafe fn scale_indirect_pipeline(dev: &ID3D12Device) -> Result<(ID3D12RootSignature, ID3D12PipelineState), String> { - static CACHE: Mutex<Option<HashMap<usize, (ID3D12RootSignature, ID3D12PipelineState)>>> = Mutex::new(None); - let key = dev.as_raw() as usize; - if let Some(pair) = CACHE.lock().unwrap().as_ref().and_then(|m| m.get(&key).cloned()) { +type ScaleIndirectPair = (ID3D12RootSignature, ID3D12PipelineState); + +fn scale_indirect_pipeline(dev: &ID3D12Device) -> Result<ScaleIndirectPair, String> { + static CACHE: Mutex<Option<HashMap<usize, ScaleIndirectPair>>> = Mutex::new(None); + cached_scale_indirect_pipeline(&CACHE, dev.as_raw() as usize, || build_scale_indirect_pipeline(dev)) +} + +fn cached_scale_indirect_pipeline( + cache: &Mutex<Option<HashMap<usize, ScaleIndirectPair>>>, + key: usize, + build: impl FnOnce() -> Result<ScaleIndirectPair, String>, +) -> Result<ScaleIndirectPair, String> { + if let Some(pair) = cache.lock().unwrap().as_ref().and_then(|m| m.get(&key).cloned()) { return Ok(pair); } ~~~~ --- If a late caller's own `build()` fails, it returns Err even though another thread already published a working pair under the same key, because `?` returns before the second lock and re-check. Thread A inserts the pair. Thread B missed at the same time and its CreateComputePipelineState fails (e.g. a transient E_OUTOFMEMORY), so `prepare_scaled_args` fails and that two-pass ExecuteIndirect is dropped or falls back, although a valid cached pair exists. Re-checking the map on the error path fixes it.
bmjask commented 2026-12-01 23:14:42 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-01T23:14:42Z.

Code review location: crates/xcl/src/hle/d3d12x/bind.rs; line 3114

@@ -3107,23 +3107,38 @@ void main(uint tid : SV_DispatchThreadID) {
 }
 "#;
 
-unsafe fn scale_indirect_pipeline(dev: &ID3D12Device) -> Result<(ID3D12RootSignature, ID3D12PipelineState), String> {
-    static CACHE: Mutex<Option<HashMap<usize, (ID3D12RootSignature, ID3D12PipelineState)>>> = Mutex::new(None);
-    let key = dev.as_raw() as usize;
-    if let Some(pair) = CACHE.lock().unwrap().as_ref().and_then(|m| m.get(&key).cloned()) {
+type ScaleIndirectPair = (ID3D12RootSignature, ID3D12PipelineState);
+
+fn scale_indirect_pipeline(dev: &ID3D12Device) -> Result<ScaleIndirectPair, String> {
+    static CACHE: Mutex<Option<HashMap<usize, ScaleIndirectPair>>> = Mutex::new(None);
+    cached_scale_indirect_pipeline(&CACHE, dev.as_raw() as usize, || build_scale_indirect_pipeline(dev))

Not certain about this one (older issue that the PR keeps): the cache key is the raw ID3D12Device pointer. If a device is released and a new one is created at the same address, cached_scale_indirect_pipeline returns the old device's root signature and PSO, and SetPipelineState binds a PSO from another device. If the cached children keep the old device alive instead, every device ever created leaks for the life of the process.

<!-- greyfinch-sync:ivall/xcl:review-comment:4762388903 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3317#discussion_r4762388903). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-01T23:14:42Z. **Code review location:** `crates/xcl/src/hle/d3d12x/bind.rs`; line 3114 ~~~~diff @@ -3107,23 +3107,38 @@ void main(uint tid : SV_DispatchThreadID) { } "#; -unsafe fn scale_indirect_pipeline(dev: &ID3D12Device) -> Result<(ID3D12RootSignature, ID3D12PipelineState), String> { - static CACHE: Mutex<Option<HashMap<usize, (ID3D12RootSignature, ID3D12PipelineState)>>> = Mutex::new(None); - let key = dev.as_raw() as usize; - if let Some(pair) = CACHE.lock().unwrap().as_ref().and_then(|m| m.get(&key).cloned()) { +type ScaleIndirectPair = (ID3D12RootSignature, ID3D12PipelineState); + +fn scale_indirect_pipeline(dev: &ID3D12Device) -> Result<ScaleIndirectPair, String> { + static CACHE: Mutex<Option<HashMap<usize, ScaleIndirectPair>>> = Mutex::new(None); + cached_scale_indirect_pipeline(&CACHE, dev.as_raw() as usize, || build_scale_indirect_pipeline(dev)) ~~~~ --- Not certain about this one (older issue that the PR keeps): the cache key is the raw `ID3D12Device` pointer. If a device is released and a new one is created at the same address, `cached_scale_indirect_pipeline` returns the old device's root signature and PSO, and `SetPipelineState` binds a PSO from another device. If the cached children keep the old device alive instead, every device ever created leaks for the life of the process.
bmjask commented 2026-12-01 23:14:42 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-01T23:14:42Z.

Review: COMMENTED


Review of d848cc4c: 2 finding(s). 2 are inline.


These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it.

<!-- greyfinch-sync:ivall/xcl:review:6141936054 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3317#pullrequestreview-6141936054). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-01T23:14:42Z. **Review:** COMMENTED --- Review of `d848cc4c`: 2 finding(s). 2 are inline. --- _These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it._
KDenKC commented 2026-12-01 23:22:06 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by KDenKC on 2026-12-01T23:22:06Z.


@bmjask Thanks, both fixed in e54c6d1f (a commit of its own on top, to squash into the first before merge):

  • A late caller's failed build: cached_scale_indirect_pipeline now re-checks the map when its own build fails: it returns the pair another caller published meanwhile, and the error only when there is none (a failure is not cached). Test a_failed_scale_indirect_build_takes_the_published_pair (no GPU): the other caller publishes while this one is still building, then this one fails and gets the published pair; alone, it gets its error, and a later build still fills the slot.
  • The device address as the key: each entry now holds a reference to the device it was made for, so no other device can be made at that address while the entry exists. On the leak side: XCL already keeps one reference to every device it makes for the life of the process (real.rs, where the device is adopted), so the entry keeps nothing alive that was not kept already. Test gpu_scale_indirect_entry_holds_its_device (a device of its own, so other tests do not move its count): the entry holds the caller's device and adds a reference, and dropping the cache releases everything it took.

Both new tests compile; their first run (the 3090 filter run) is queued, and its result goes into the description.

AI use: an agent swarm: Claude Opus 5.5, Claude Sonnet 5.5, GPT-6.2-Sol, Gemini 4 Neon and Gemini 4 Hydrogen.

<!-- greyfinch-sync:ivall/xcl:comment:7329258604 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3317#issuecomment-7329258604). Originally posted by [KDenKC](https://github.com/KDenKC) on 2026-12-01T23:22:06Z. --- @bmjask Thanks, both fixed in `e54c6d1f` (a commit of its own on top, to squash into the first before merge): - **A late caller's failed build:** `cached_scale_indirect_pipeline` now re-checks the map when its own build fails: it returns the pair another caller published meanwhile, and the error only when there is none (a failure is not cached). Test `a_failed_scale_indirect_build_takes_the_published_pair` (no GPU): the other caller publishes while this one is still building, then this one fails and gets the published pair; alone, it gets its error, and a later build still fills the slot. - **The device address as the key:** each entry now holds a reference to the device it was made for, so no other device can be made at that address while the entry exists. On the leak side: XCL already keeps one reference to every device it makes for the life of the process (`real.rs`, where the device is adopted), so the entry keeps nothing alive that was not kept already. Test `gpu_scale_indirect_entry_holds_its_device` (a device of its own, so other tests do not move its count): the entry holds the caller's device and adds a reference, and dropping the cache releases everything it took. Both new tests compile; their first run (the 3090 filter run) is queued, and its result goes into the description. AI use: an agent swarm: Claude Opus 5.5, Claude Sonnet 5.5, GPT-6.2-Sol, Gemini 4 Neon and Gemini 4 Hydrogen.
Foniass commented 2026-12-01 23:27:49 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T23:27:49Z.


Follow-up review (head e54c6d1f, since d848cc4, diff read, not a merge-check; checks red):

  • Triage (keep open, no duplicate on main): still holds; #3590 is the amd-dev port.
  • Nothing checks that scale_indirect_pipeline uses the first-wins helper: partly fixed. gpu_scale_indirect_entry_holds_its_device now goes through scale_indirect_pipeline_in, which scale_indirect_pipeline wraps, but the first-wins test still calls cached_scale_indirect_pipeline directly and the last_wins block (bind.rs ~5486) still checks a local HashMap.
  • Two threads can both compile once: still open, by design; both callers build outside the lock (~3133), which only costs time.

New:

  • gpu_scale_indirect_entry_holds_its_device can fail under the parallel suite. D3D12 keeps one device per adapter in a process, so D3D12CreateDevice(None, ...) at ~5530 returns the same device the other tests create the same way (e.g. bind.rs ~8725, console_heap.rs ~1677), not "a device of its own" (~5522). Under --test-threads=4 they add and drop references between before (~5541) and the exact assert_eq!(refs(&dev), before, ...) (~5551), and the test takes no lock.
  • Evidence is for the old head. Both xcl-smoke blocks and Tested are for d848cc4c (the red PR description check), the two new tests have no reported run, and e54c6d1f is a fixup to squash.

Fine: a late caller whose own build fails now takes the published pair, and a failure is not cached; each entry holds a reference to its device, so its address key cannot be reused. Unlike #3590's test, the first-wins test does not depend on scheduling: the second caller publishes from inside the first caller's build callback, so both always miss the cache.

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

<!-- greyfinch-sync:ivall/xcl:comment:7329375318 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3317#issuecomment-7329375318). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T23:27:49Z. --- Follow-up review (head e54c6d1f, since d848cc4, diff read, not a merge-check; checks red): - **Triage (keep open, no duplicate on `main`):** still holds; #3590 is the `amd-dev` port. - **Nothing checks that `scale_indirect_pipeline` uses the first-wins helper:** partly fixed. `gpu_scale_indirect_entry_holds_its_device` now goes through `scale_indirect_pipeline_in`, which `scale_indirect_pipeline` wraps, but the first-wins test still calls `cached_scale_indirect_pipeline` directly and the `last_wins` block (`bind.rs` ~5486) still checks a local `HashMap`. - **Two threads can both compile once:** still open, by design; both callers build outside the lock (~3133), which only costs time. New: - **`gpu_scale_indirect_entry_holds_its_device` can fail under the parallel suite.** D3D12 keeps one device per adapter in a process, so `D3D12CreateDevice(None, ...)` at ~5530 returns the same device the other tests create the same way (e.g. `bind.rs` ~8725, `console_heap.rs` ~1677), not "a device of its own" (~5522). Under `--test-threads=4` they add and drop references between `before` (~5541) and the exact `assert_eq!(refs(&dev), before, ...)` (~5551), and the test takes no lock. - **Evidence is for the old head.** Both `xcl-smoke` blocks and **Tested** are for `d848cc4c` (the red `PR description` check), the two new tests have no reported run, and `e54c6d1f` is a fixup to squash. Fine: a late caller whose own build fails now takes the published pair, and a failure is not cached; each entry holds a reference to its device, so its address key cannot be reused. Unlike #3590's test, the first-wins test does not depend on scheduling: the second caller publishes from inside the first caller's build callback, so both always miss the cache. AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Foniass commented 2026-12-01 23:32:46 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T23:32:46Z.


Follow-up review (head 9eceb137, since e54c6d1f, diff read, not a merge-check; checks red):

  • gpu_scale_indirect_entry_holds_its_device can fail under the parallel suite: fixed; the test is gone, and the entry's device check moved into gpu_scale_indirect_pipeline_keeps_first_pair as an identity check (held.as_raw() == dev.as_raw(), bind.rs ~5497), with no reference counts.
  • Nothing checks that scale_indirect_pipeline uses the first-wins helper: fixed. The winner now publishes through scale_indirect_pipeline_in from inside the late caller's build (~5485), the later hit goes through the same function (~5501), and the local last_wins map is gone.
  • Fixup commit: fixed; one commit.
  • Evidence is for an old head: still open. Both xcl-smoke blocks and Tested are for d848cc4c / a83846da, which is why PR description is red.

New: none.

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

<!-- greyfinch-sync:ivall/xcl:comment:7329476219 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3317#issuecomment-7329476219). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T23:32:46Z. --- Follow-up review (head 9eceb137, since e54c6d1f, diff read, not a merge-check; checks red): - **`gpu_scale_indirect_entry_holds_its_device` can fail under the parallel suite:** fixed; the test is gone, and the entry's device check moved into `gpu_scale_indirect_pipeline_keeps_first_pair` as an identity check (`held.as_raw() == dev.as_raw()`, `bind.rs` ~5497), with no reference counts. - **Nothing checks that `scale_indirect_pipeline` uses the first-wins helper:** fixed. The winner now publishes through `scale_indirect_pipeline_in` from inside the late caller's build (~5485), the later hit goes through the same function (~5501), and the local `last_wins` map is gone. - **Fixup commit:** fixed; one commit. - **Evidence is for an old head:** still open. Both `xcl-smoke` blocks and **Tested** are for `d848cc4c` / `a83846da`, which is why `PR description` is red. New: none. AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
bmjask commented 2026-12-01 23:46:16 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-01T23:46:16Z.

Review: COMMENTED


Review of 9eceb137: 1 finding(s).

Re-review after the new commits: both points from my earlier review are addressed. A failed late build now takes the published pair, and the entry holds the device. One new finding: These are on lines outside the diff:

crates/xcl/src/hle/d3d12x/bind.rs:4008: A sibling per-device cache still has the bug this PR fixes. argument_order_buffer keeps one (device, buffer) slot and overwrites it (*g = Some(...)) when a list from another device asks, dropping the buffer that already-recorded lists may still use. With two devices, or a recreated one, alternating ExecuteIndirect calls, each switch frees the previous device's ARGUMENT_ORDER buffer while its command lists can still be pending, which is the same freed-while-in-use crash.


These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it.

<!-- greyfinch-sync:ivall/xcl:review:6142260823 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3317#pullrequestreview-6142260823). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-01T23:46:16Z. **Review:** COMMENTED --- Review of `9eceb137`: 1 finding(s). Re-review after the new commits: both points from my earlier review are addressed. A failed late build now takes the published pair, and the entry holds the device. One new finding: These are on lines outside the diff: **`crates/xcl/src/hle/d3d12x/bind.rs:4008`**: A sibling per-device cache still has the bug this PR fixes. `argument_order_buffer` keeps one `(device, buffer)` slot and overwrites it (`*g = Some(...)`) when a list from another device asks, dropping the buffer that already-recorded lists may still use. With two devices, or a recreated one, alternating ExecuteIndirect calls, each switch frees the previous device's ARGUMENT_ORDER buffer while its command lists can still be pending, which is the same freed-while-in-use crash. --- _These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it._
Foniass commented 2026-12-01 23:52:10 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T23:52:10Z.


Follow-up review (head 730b5b9b, since 9eceb137, diff read, not a merge-check; checks red):

  • Evidence is for an old head: still open. Both xcl-smoke blocks and Tested are for d848cc4c / a83846da (the reason PR description is red).

New:

  • A second fix in the PR, and the description no longer matches. 730b5b9b makes ARGUMENT_ORDER (bind.rs ~3956-4012) one buffer per device instead of one global slot. It is the same class of bug and looks right (the entry holds its device, so the address key cannot be reused), with argument_order_buffers_are_kept_per_device (~5529) using the hardware device and WARP. But the title and description cover only the scaling pipeline: What is in it still says "one commit" and still describes the old test ("validates its own check against a last-wins map", removed in 9eceb137). CONTRIBUTING.md asks for one problem per PR; either split it out or update the title and description to cover both.

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

<!-- greyfinch-sync:ivall/xcl:comment:7329868587 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3317#issuecomment-7329868587). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T23:52:10Z. --- Follow-up review (head 730b5b9b, since 9eceb137, diff read, not a merge-check; checks red): - **Evidence is for an old head:** still open. Both `xcl-smoke` blocks and **Tested** are for `d848cc4c` / `a83846da` (the reason `PR description` is red). New: - **A second fix in the PR, and the description no longer matches.** `730b5b9b` makes `ARGUMENT_ORDER` (`bind.rs` ~3956-4012) one buffer per device instead of one global slot. It is the same class of bug and looks right (the entry holds its device, so the address key cannot be reused), with `argument_order_buffers_are_kept_per_device` (~5529) using the hardware device and WARP. But the title and description cover only the scaling pipeline: **What is in it** still says "one commit" and still describes the old test ("validates its own check against a last-wins map", removed in `9eceb137`). CONTRIBUTING.md asks for one problem per PR; either split it out or update the title and description to cover both. AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
KDenKC commented 2026-12-02 00:20:11 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by KDenKC on 2026-12-02T00:20:11Z.


@bmjask Thanks: fixed here as a second commit, 730b5b9b (D3D12.X: keep an argument-ordering buffer per device), since it is the same kind of bug. ARGUMENT_ORDER is now one buffer per device, each entry holding a reference to its device as the scaling pipeline's cache does, so a list of another device gets a buffer of its own and never replaces one that lists recorded on the first device may still use. Test argument_order_buffers_are_kept_per_device: the hardware device and WARP (two devices of one process) each get their own buffer, and the first device's buffer is still the one it gets after the second asked; with the old single slot it fails.

On the RTX 3090 at 730b5b9b: -- scale_indirect 2 passed, -- argument_order_buffers 1 passed, and the whole suite 2589 passed, 5 failed (the same 5 as main on that machine), 49 ignored. The description has the details; a new smoke pair follows when the RTX 5090 is free.

AI use: an agent swarm: Claude Opus 5.5, Claude Sonnet 5.5, GPT-6.2-Sol, Gemini 4 Neon and Gemini 4 Hydrogen.

<!-- greyfinch-sync:ivall/xcl:comment:7330425508 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3317#issuecomment-7330425508). Originally posted by [KDenKC](https://github.com/KDenKC) on 2026-12-02T00:20:11Z. --- @bmjask Thanks: fixed here as a second commit, `730b5b9b` (`D3D12.X: keep an argument-ordering buffer per device`), since it is the same kind of bug. `ARGUMENT_ORDER` is now one buffer per device, each entry holding a reference to its device as the scaling pipeline's cache does, so a list of another device gets a buffer of its own and never replaces one that lists recorded on the first device may still use. Test `argument_order_buffers_are_kept_per_device`: the hardware device and WARP (two devices of one process) each get their own buffer, and the first device's buffer is still the one it gets after the second asked; with the old single slot it fails. On the RTX 3090 at `730b5b9b`: `-- scale_indirect` 2 passed, `-- argument_order_buffers` 1 passed, and the whole suite 2589 passed, 5 failed (the same 5 as `main` on that machine), 49 ignored. The description has the details; a new smoke pair follows when the RTX 5090 is free. AI use: an agent swarm: Claude Opus 5.5, Claude Sonnet 5.5, GPT-6.2-Sol, Gemini 4 Neon and Gemini 4 Hydrogen.
sandivd commented 2026-12-02 08:26:52 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by sandivd on 2026-12-02T08:26:52Z.


merge-check claim
head: 730b5b9b20

<!-- greyfinch-sync:ivall/xcl:comment:7339461829 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3317#issuecomment-7339461829). Originally posted by [sandivd](https://github.com/sandivd) on 2026-12-02T08:26:52Z. --- merge-check claim head: 730b5b9b20eaca33a0eeba145fb0ef84a206fa4f
sandivd commented 2026-12-02 08:58:53 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by sandivd on 2026-12-02T08:58:53Z.


merge-check
base: 1c8b551475
head: 730b5b9b20
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2912 passed, 0 failed, 51 ignored; SKIPPED: 24 (22 no wave64, 2 heap-window opt-ins); failing: none. Run with XCL_DXC_DIR pointing at DXC 1.9.2609; with the machine's default DXC 1.5 the same run gives 2449 passed, 466 failed, 51 ignored, all DxcCreateInstance 0x80004002, with the same failing tests as base 1c8b5514, so that is the toolchain, not the PR.
review: read the whole diff (+136/-11 in crates/xcl/src/hle/d3d12x/bind.rs) and the merged code. The race is real and the fix is right: callers that miss build outside the lock, the first to publish is kept with entry().or_insert, a late caller gets that pair, and a failed build takes a pair published meanwhile or returns its error without caching it. The entry holds the device, so the address key cannot be reused. ARGUMENT_ORDER now keeps one 256-byte buffer per device, also holding the device; the old single slot could drop a buffer that recorded lists on another device still use. The new first-wins test drives the real helper (scale_indirect_pipeline_in for the winner and the hit) and publishes from inside the late caller's build, so it does not depend on scheduling; the argument-order test uses the hardware device and WARP and fails with the old single slot; the existing gpu_scale_args_reports_uncapped_group_count_feedback calls the outer scale_indirect_pipeline. All three pass. Findings (minor): (1) the losing pair is dropped while the cache mutex is held: map.entry(key).or_insert(pair) runs its COM Release under the lock, while #3590's closed helper dropped the loser outside it. The loser was never published, so this is lock hygiene, not a use-after-free; no deadlock seen. (2) The PR now carries two fixes (scaling cache and argument order); CONTRIBUTING asks for one problem per PR, though the description covers both and the author calls them the same class of bug; the title still names only the scaling cache. (3) gpu_scale_indirect_pipeline_keeps_first_pair skips only when dxc::location() fails; with an old DXC that loads but cannot create the compiler (DXC 1.5 here, E_NOINTERFACE) it fails rather than skips, the same pattern as other GPU tests, not a product bug. I found no UAF, missing lock or wrong lifetime in the merged result. The PR's base 7db2f391 has fewer tests than current main; this is the real merge into 1c8b5514.
performance: no per-frame cost: the hit path is the same lock + clone as before; a miss adds one lock and one clone, and the loser's Release under the lock only happens when two callers race on first use. Memory: one 256-byte buffer per device (was one per process) and one device reference per cache entry; XCL already keeps every device for the process, and the cache is still never evicted, as on main. The author's 200 s RTX 5090 smokes are 2194 vs 2201 frames (99.7%) and 35501 vs 35472 MB peak commit (+0.08%) for the earlier head d848cc4c; I did not run a title here.
verdict: not yet: the required regression run on this head is missing. The two xcl-smoke blocks in the description are for d848cc4c, not 730b5b9b, so the PR description check is red; the author says a pair on 730b5b9b follows. The merge is clean, the build passes and the whole suite passes on the merged tree, and I found no code blocker.
hardware / tool and model: NVIDIA GeForce RTX 3050 Ti Laptop GPU (driver 32.0.16.1656; no wave64; the GPU tests ran on it) + AMD Radeon(TM) Graphics (driver 31.0.21925.2001); AMD Ryzen 7 5800H; Windows 11 Home Single Language 10.0.26300; DXC 1.9.2609 via XCL_DXC_DIR / OpenCode, DeepSeek V4.1 Flash

<!-- greyfinch-sync:ivall/xcl:comment:7340194493 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3317#issuecomment-7340194493). Originally posted by [sandivd](https://github.com/sandivd) on 2026-12-02T08:58:53Z. --- merge-check base: 1c8b551475e1e7bfe48f94448492a4c3544a2e0f head: 730b5b9b20eaca33a0eeba145fb0ef84a206fa4f merge: clean build: cargo build --workspace -> ok tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2912 passed, 0 failed, 51 ignored; SKIPPED: 24 (22 no wave64, 2 heap-window opt-ins); failing: none. Run with XCL_DXC_DIR pointing at DXC 1.9.2609; with the machine's default DXC 1.5 the same run gives 2449 passed, 466 failed, 51 ignored, all DxcCreateInstance 0x80004002, with the same failing tests as base 1c8b5514, so that is the toolchain, not the PR. review: read the whole diff (+136/-11 in crates/xcl/src/hle/d3d12x/bind.rs) and the merged code. The race is real and the fix is right: callers that miss build outside the lock, the first to publish is kept with entry().or_insert, a late caller gets that pair, and a failed build takes a pair published meanwhile or returns its error without caching it. The entry holds the device, so the address key cannot be reused. ARGUMENT_ORDER now keeps one 256-byte buffer per device, also holding the device; the old single slot could drop a buffer that recorded lists on another device still use. The new first-wins test drives the real helper (scale_indirect_pipeline_in for the winner and the hit) and publishes from inside the late caller's build, so it does not depend on scheduling; the argument-order test uses the hardware device and WARP and fails with the old single slot; the existing gpu_scale_args_reports_uncapped_group_count_feedback calls the outer scale_indirect_pipeline. All three pass. Findings (minor): (1) the losing pair is dropped while the cache mutex is held: map.entry(key).or_insert(pair) runs its COM Release under the lock, while #3590's closed helper dropped the loser outside it. The loser was never published, so this is lock hygiene, not a use-after-free; no deadlock seen. (2) The PR now carries two fixes (scaling cache and argument order); CONTRIBUTING asks for one problem per PR, though the description covers both and the author calls them the same class of bug; the title still names only the scaling cache. (3) gpu_scale_indirect_pipeline_keeps_first_pair skips only when dxc::location() fails; with an old DXC that loads but cannot create the compiler (DXC 1.5 here, E_NOINTERFACE) it fails rather than skips, the same pattern as other GPU tests, not a product bug. I found no UAF, missing lock or wrong lifetime in the merged result. The PR's base 7db2f391 has fewer tests than current main; this is the real merge into 1c8b5514. performance: no per-frame cost: the hit path is the same lock + clone as before; a miss adds one lock and one clone, and the loser's Release under the lock only happens when two callers race on first use. Memory: one 256-byte buffer per device (was one per process) and one device reference per cache entry; XCL already keeps every device for the process, and the cache is still never evicted, as on main. The author's 200 s RTX 5090 smokes are 2194 vs 2201 frames (99.7%) and 35501 vs 35472 MB peak commit (+0.08%) for the earlier head d848cc4c; I did not run a title here. verdict: not yet: the required regression run on this head is missing. The two xcl-smoke blocks in the description are for d848cc4c, not 730b5b9b, so the PR description check is red; the author says a pair on 730b5b9b follows. The merge is clean, the build passes and the whole suite passes on the merged tree, and I found no code blocker. hardware / tool and model: NVIDIA GeForce RTX 3050 Ti Laptop GPU (driver 32.0.16.1656; no wave64; the GPU tests ran on it) + AMD Radeon(TM) Graphics (driver 31.0.21925.2001); AMD Ryzen 7 5800H; Windows 11 Home Single Language 10.0.26300; DXC 1.9.2609 via XCL_DXC_DIR / OpenCode, DeepSeek V4.1 Flash
Foniass commented 2026-12-02 09:07:40 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T09:07:40Z.


Follow-up review (head 444aa227, since 730b5b9b, diff read, not a merge-check; checks red):

  • A second fix in the PR, and the description did not match: partly fixed. What is in it now lists 444aa227 (the argument-ordering buffer, "same kind of bug") with its test, and the "one commit" text and the old test description are gone. The PR title still names only the scaling pipeline; CONTRIBUTING.md asks for one problem per PR, so splitting it out is still the cleaner route.
  • Evidence is for an old head: still open. Both commits are unchanged (rebase onto main 1c8b5514), the focused tests ran on 444aa227, but the xcl-smoke pair is still from 7db2f391 / d848cc4c and there is no whole-suite run at this head.

New: none.

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

<!-- greyfinch-sync:ivall/xcl:comment:7340417195 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3317#issuecomment-7340417195). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-02T09:07:40Z. --- Follow-up review (head 444aa227, since 730b5b9b, diff read, not a merge-check; checks red): - **A second fix in the PR, and the description did not match:** partly fixed. **What is in it** now lists `444aa227` (the argument-ordering buffer, "same kind of bug") with its test, and the "one commit" text and the old test description are gone. The PR title still names only the scaling pipeline; CONTRIBUTING.md asks for one problem per PR, so splitting it out is still the cleaner route. - **Evidence is for an old head:** still open. Both commits are unchanged (rebase onto `main` `1c8b5514`), the focused tests ran on `444aa227`, but the `xcl-smoke` pair is still from `7db2f391` / `d848cc4c` and there is no whole-suite run at this head. New: none. AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Foniass commented 2026-12-02 09:57:13 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T09:57:13Z.


Follow-up review (head 8afcf478, since 444aa227, diff read, not a merge-check; checks red):

  • A second fix in the PR: fixed; the argument-ordering commit is gone and the PR is again one commit (8afcf478, unchanged since 9eceb137).
  • Evidence is for an old head: still open; the xcl-smoke pair is still from 7db2f391 / d848cc4c.

New: none.

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

<!-- greyfinch-sync:ivall/xcl:comment:7341735360 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3317#issuecomment-7341735360). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-02T09:57:13Z. --- Follow-up review (head 8afcf478, since 444aa227, diff read, not a merge-check; checks red): - **A second fix in the PR:** fixed; the argument-ordering commit is gone and the PR is again one commit (`8afcf478`, unchanged since `9eceb137`). - **Evidence is for an old head:** still open; the `xcl-smoke` pair is still from `7db2f391` / `d848cc4c`. New: none. AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
KDenKC commented 2026-12-02 10:18:26 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by KDenKC on 2026-12-02T10:18:26Z.


@Foniass @sandivd the split is done and the regression pair is in: #3317 is now 8afcf478 (the scaling-pipeline commit only, rebased onto main 1c8b5514); the argument-ordering buffer is its own PR (#3685). Whole suite at 8afcf478 on an RTX 3090: 2903 passed, 5 failed (the same 5 as main), 51 ignored. 600 s smoke on an RTX 5090: main 1c8b5514 1724 frames, 0 removals, 47581 MB peak commit; 8afcf478 1867 frames, 0 removals, 47964 MB. Both xcl-smoke blocks are in the description's Regression run.

AI use: an agent swarm: Claude Opus 5.5, Claude Sonnet 5.5, GPT-6.2-Sol, Gemini 4 Neon and Gemini 4 Hydrogen.

<!-- greyfinch-sync:ivall/xcl:comment:7342274767 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3317#issuecomment-7342274767). Originally posted by [KDenKC](https://github.com/KDenKC) on 2026-12-02T10:18:26Z. --- @Foniass @sandivd the split is done and the regression pair is in: #3317 is now `8afcf478` (the scaling-pipeline commit only, rebased onto `main` `1c8b5514`); the argument-ordering buffer is its own PR (#3685). Whole suite at `8afcf478` on an RTX 3090: 2903 passed, 5 failed (the same 5 as `main`), 51 ignored. 600 s smoke on an RTX 5090: `main` `1c8b5514` 1724 frames, 0 removals, 47581 MB peak commit; `8afcf478` 1867 frames, 0 removals, 47964 MB. Both `xcl-smoke` blocks are in the description's Regression run. AI use: an agent swarm: Claude Opus 5.5, Claude Sonnet 5.5, GPT-6.2-Sol, Gemini 4 Neon and Gemini 4 Hydrogen.
fromthemoonx commented 2026-12-03 05:04:37 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by fromthemoonx on 2026-12-03T05:04:37Z.


merge-check
base: 395405e4c0
head: 8afcf47863
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 3014 passed, 0 failed, 56 ignored (base: 3012 passed, 0 failed, 56 ignored); SKIPPED: 25, the same as base (22 no wave64, 2 no heap windows, 1 no GPU_UPLOAD heaps); failing: none. The first run ended in the #3586 crash after 12 thread dumps, which base has too; these are the rerun's counts
review: read the whole diff (1 file, +95 -7). No finding.

  1. The race is real and this fixes it. A scratch test lets 8 threads call the real scale_indirect_pipeline at once with nothing cached, one process per try, 30 tries each:
callers holding a pipeline the cache did not keep
main's insert put back 7 of 8, in 30 of 30 tries
this PR 0 of 8, in 30 of 30 tries

prepare_scaled_args keeps only raw pointers to the pair, so those 7 point at pipelines that are already released.
2) Each new test passed 30 of 30 runs. gpu_scale_indirect_pipeline_keeps_first_pair fails with main's insert, and a_failed_scale_indirect_build_takes_the_published_pair fails when a failed late build returns its error.
3) The bind tests at 8 threads: 9 of 30 runs failed here and 16 of 30 on base, every time in later_queue_completion_during_sleep_reclaims_before_wait_deadline. That is not this PR (#3609 fixes it).
4) #3711 made the same fix and is closed, so this is the one to take.
5) Not tested: a retail title (none on this machine), AMD.
performance: a cached call still takes the lock once and clones the pair, now with a device reference. Threads that race on the first call still each build a pipeline, as on main. Reasoned, not measured.
verdict: safe to merge
hardware / tool and model: RTX 3060 12 GB (610.88), Ryzen 7 5700X, Windows 11 Pro 26300 / Claude Code (Claude Opus 5.5)

<!-- greyfinch-sync:ivall/xcl:comment:7368348364 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3317#issuecomment-7368348364). Originally posted by [fromthemoonx](https://github.com/fromthemoonx) on 2026-12-03T05:04:37Z. --- merge-check base: 395405e4c0ed814afde0610a724dc96a3af329de head: 8afcf47863b6b20faf4694b57569cf0070fe3a6f merge: clean build: cargo build --workspace -> ok tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 3014 passed, 0 failed, 56 ignored (base: 3012 passed, 0 failed, 56 ignored); SKIPPED: 25, the same as base (22 no wave64, 2 no heap windows, 1 no GPU_UPLOAD heaps); failing: none. The first run ended in the #3586 crash after 12 thread dumps, which base has too; these are the rerun's counts review: read the whole diff (1 file, +95 -7). No finding. 1) The race is real and this fixes it. A scratch test lets 8 threads call the real `scale_indirect_pipeline` at once with nothing cached, one process per try, 30 tries each: | | callers holding a pipeline the cache did not keep | |---|---| | main's `insert` put back | 7 of 8, in 30 of 30 tries | | this PR | **0 of 8**, in 30 of 30 tries | `prepare_scaled_args` keeps only raw pointers to the pair, so those 7 point at pipelines that are already released. 2) Each new test passed 30 of 30 runs. `gpu_scale_indirect_pipeline_keeps_first_pair` fails with main's `insert`, and `a_failed_scale_indirect_build_takes_the_published_pair` fails when a failed late build returns its error. 3) The `bind` tests at 8 threads: 9 of 30 runs failed here and 16 of 30 on base, every time in `later_queue_completion_during_sleep_reclaims_before_wait_deadline`. That is not this PR (#3609 fixes it). 4) #3711 made the same fix and is closed, so this is the one to take. 5) Not tested: a retail title (none on this machine), AMD. performance: a cached call still takes the lock once and clones the pair, now with a device reference. Threads that race on the first call still each build a pipeline, as on main. Reasoned, not measured. verdict: safe to merge hardware / tool and model: RTX 3060 12 GB (610.88), Ryzen 7 5700X, Windows 11 Pro 26300 / Claude Code (Claude Opus 5.5)
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/3317:upstream-pr/3317'
git switch 'upstream-pr/3317'

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/3317'
git switch 'upstream-pr/3317'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3317'
git switch 'upstream-pr/3317'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3317'
git switch 'main'
git merge --squash 'upstream-pr/3317'
git switch 'main'
git merge --ff-only 'upstream-pr/3317'
git switch 'main'
git merge 'upstream-pr/3317'
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!3317
No description provided.