Skip to content

D3D12.X: switch KickoffX onto an idle spare PC list when the submitted list is in flight - #2320

Open
Decodere wants to merge 4 commits into
xcl-dev:mainfrom
Decodere:fix-2163-kickoff-in-flight-spare
Open

Decodere wants to merge 4 commits into
xcl-dev:mainfrom
Decodere:fix-2163-kickoff-in-flight-spare

Conversation

@Decodere

@Decodere Decodere commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

What is in it

Follow-up to #2163 (Part of #1452). Updated in fast-forward commits 9d9e09fc and bc3c0423f0dc4f14223aeb9472a418f54a5571eb (onto 7f4c1fc6ea2156317bfcda0a1dfb4cb6ad16f60e) to address pre-merge re-review feedback: gates KickoffX spare switching and empty-batch skipping strictly behind opt-in XCL_KICKOFF_SWAP=1 (default OFF, preserving 6d12f58a's exact hand-over-then-reset path), adds a bounded 5000 ms fence-wait fallback returning 0x80070102 (HRESULT_FROM_WIN32(ERROR_WAIT_TIMEOUT)) on expiration, caps per-wrapper spares at MAX_KICKOFF_SPARES = 8, and reverts unrelated hunks against merge-base 6d12f58a.

list_x::kickoff_x() previously closed and submitted the active PC command list (this) — plus any earlier split segments — and immediately called Reset on that same PC list (or on primary after a mid-list split), even when its submission was still in flight on the GPU. When a title issues back-to-back KickoffX calls or follows KickoffX with Close + ExecuteCommandLists before the previous kickoff retires, PC D3D12 rejects resubmitting an in-flight command list (debug layer ID 553, EXECUTECOMMANDLISTS_COMMANDLIST_STILL_IN_FLIGHT) and strict drivers can trigger device removal.

  • crates/xcl/src/hle/d3d12x/alloc_pool.rs:
    • Added wait_idle(list, dev, timeout_ms): snapshots (fence, value) from STATE.last_submit, releases STATE before blocking, and waits up to timeout_ms via crate::gpu::fence::wait.
  • crates/xcl/src/hle/d3d12x/title_list.rs:
    • Added primary_of(wrapper), switch_active_for_kickoff(wrapper, old_active, new_active), mark_kickoff_unreset(wrapper), clear_kickoff_unreset(wrapper), and spare_count(wrapper) (backed by SegmentBook::kickoff_unreset, cleared on reset / switch_active_for_kickoff / in-place fallback recovery) to update F_BACKING, WRAPPER_OF, book.first, and book.spares only after Reset succeeds, keep F_PRIMARY out of book.first and book.spares, track non-primary spares for the per-wrapper cap, and suppress push_segments until the title's next Reset only if both spare acquisition and the bounded fence-wait fallback fail.
    • Added pure-CPU unit tests switch_active_for_kickoff_keeps_primary_out_of_spares and kickoff_unreset_suppresses_push_segments_until_reset.
  • crates/xcl/src/hle/d3d12x/list_x.rs:
    • Gated KickoffX spare switching behind opt-in XCL_KICKOFF_SWAP=1 (kickoff_swap_enabled_val / kickoff_swap_enabled, default OFF, leaving XCL_ALLOC_SWAP unaffected). When unset/off (!swap_enabled), kickoff_x_with branches directly to 6d12f58a's exact hand-over-then-reset path (running inherit_for_split, bind::reset, clear_segment_state, and the LISTS update without modifying list_type or last_queue before calling Reset, with zero wrapper_of, in_flight, spare scanning/creation, fence waiting, or mark_kickoff_unreset), and execute_with_waits_on preserves 6d12f58a's exact empty-batch submit(lists) call.
    • Under XCL_KICKOFF_SWAP=1, acquire_kickoff_target(...) + private create_kickoff_spare(...) (leaving reset_stand_in untouched against 6d12f58a, with unrelated COPY and dred hunks reverted) prefers returning to primary once idle, otherwise reuses any idle pooled spare or creates a fresh closed spare up to MAX_KICKOFF_SPARES = 8. When no idle spare is available (cap reached or creation/reset fails), falls back to a bounded 5000 ms alloc_pool::wait_idle on current_target and resets current_target in place so subsequent commands are not dropped; only marks kickoff_unreset and returns 0x80070102 (HRESULT_FROM_WIN32(ERROR_WAIT_TIMEOUT)) if that bounded wait expires (or the Reset HRESULT if Reset fails).
    • Gated execute_with_waits_on's empty-batch early return behind kickoff_swap_enabled() (execute_with_waits_on_with) so mark_kickoff_unreset never passes a 0-list batch to ExecuteCommandLists when opted in while leaving default-OFF behavior identical to 6d12f58a.
    • Added/updated gated-queue D3D12/WARP and unit tests: kickoff_x_while_in_flight_switches_to_idle_spare_and_preserves_state, kickoff_x_after_midlist_split_switches_to_idle_spare, kickoff_x_default_off_split_list_matches_main_handover, kickoff_x_failure_paths_never_reset_in_flight_target, kickoff_x_spare_cap_and_fence_wait_fallback_recovers_without_dropping_commands, kickoff_swap_enabled_val_defaults_off_and_enables_on_one, and kickoff_swap_disabled_keeps_current_target_without_spares.

Tested

Hardware / toolchain: Windows 11 Home 26200, Intel Core i5-11400F, 32 GB RAM, NVIDIA GeForce RTX 4060 8 GB (Ada, Wave32, driver 32.0.16.2114), rustc 1.100.0, DXC 1.9.2609.5.

  • Pre-fix failing-first (initial gated tests against unmodified kickoff_x on RTX 4060, --test-threads=1):
    • cargo test -p xcl --lib kickoff_x_ -- --test-threads=1 --nocapture: 0 passed; 2 failed (reproduced live in-flight command-list resubmission warnings #1..#3 and failed assertions).
  • Updated head bc3c0423f0dc4f14223aeb9472a418f54a5571eb (fast-forward onto 9d9e09fc8f3ac44a7f8bfd9726109c74a163913d, merge-base 6d12f58a229bc73889878a448c64dc3af25eeba0):
    • cargo clippy --tests -p xcl -- -A clippy::approx_constant -A clippy::while_immutable_condition: exit 0, 0 new warnings in alloc_pool.rs, title_list.rs, or touched regions of list_x.rs.
    • cargo test --lib -p xcl -- hle::d3d12x::list_x:: hle::d3d12x::title_list:: hle::d3d12x::alloc_pool:: --test-threads=1 --nocapture (3x Debug): 56 passed; 0 failed; 0 ignored; 0 skipped.
    • cargo test --release --lib -p xcl -- hle::d3d12x::list_x:: hle::d3d12x::title_list:: hle::d3d12x::alloc_pool:: --test-threads=1 --nocapture (3x Release): 56 passed; 0 failed; 0 ignored; 0 skipped (includes new kickoff_x_default_off_split_list_matches_main_handover, opt-in vs default-OFF execute_with_waits_on_with empty-batch checks, 0x80070102 timeout HRESULT verification, MAX_KICKOFF_SPARES = 8 cap + live threaded alloc_pool::wait_idle fallback, and all title_list:: tests).
    • cargo build --release -p xcl: exit 0, 0 new warnings in touched files.
  • Earlier independent community verification on 62f6d473 in this thread:
    • thehollowedone (RTX 3080 Ti, Windows 11, Graphics Tools D3D12 debug layer + ID3D12InfoQueue): all 3 gated kickoff_x_* tests passed in separate processes (1/0 each) with 0 ID 553 messages; full workspace 1428 passed; 0 failed; 46 ignored.
    • andrewDoing (RTX 5070, Windows 11): live gated COPY-queue KickoffX test switched across 2 distinct spares and back to primary with verified 4-segment readback (11111111 22222222 33333333 44444444), 0 resubmits, and clean live D3D12 info queue.
    • ClosetPie107 (AMD Radeon RX 9070 RDNA4 / Mesa RADV Wine/Proton): list_x:: 43/0, title_list:: 5/0, 3/4 clean 300 s retail runs (1 removal at 294 s noted as inconclusive vs 4/4 clean on main).
    • oni-swr (AMD Radeon RX 7800 XT, Windows 11): all 3 kickoff_x_* GPU tests and both title_list:: tests passed natively on RX 7800 XT with 0 skips.
    • upipibi (RTX 3070, Windows 11) and DavidM1911 (RTX 3060 Ti, Windows 11): d3d12x:: / --lib passed on --test-threads=1.
  • KickoffX activity check on title 29640639: a temporary local counter probe inside list_x::kickoff_x (reverted cleanly) recorded 0 KickoffX calls during the 60 s startup window of title 29640639; keeping XCL_KICKOFF_SWAP=1 opt-in ensures zero default behavior change until world-run measurements on a KickoffX-using title are collected.

Regression run

Quiet 60 s retail smoke runs on RTX 4060 (scripts/smoke.ps1 -Seconds 60, XCL_NETWORK=0, title: 29640639; note title 29640639 issued 0 KickoffX calls in this 60 s startup window):

Exact merge-base (main ancestor 6d12f58a229bc73889878a448c64dc3af25eeba0):

xcl-smoke v1
commit: 6d12f58a229bc73889878a448c64dc3af25eeba0
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1581 (PresentX 1581)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14018 MB

PR head (bc3c0423f0dc4f14223aeb9472a418f54a5571eb, default OFF — XCL_KICKOFF_SWAP unset):

xcl-smoke v1
commit: bc3c0423f0dc4f14223aeb9472a418f54a5571eb
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1605 (PresentX 1605)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14042 MB

Not tested

  • World-run frame times on a retail title that actively invokes KickoffX (verified via temporary local probe that title 29640639 issued 0 KickoffX calls during the 60 s startup window; accordingly the swap is off by default behind XCL_KICKOFF_SWAP=1).
  • AMD, Intel, and wave64 GPUs on this host (bc3c0423 has not yet been re-run on AMD; earlier 62f6d473 was tested independently on RX 9070 and RX 7800 XT), and live D3D12 debug layer validation on this host (d3d12SDKLayers.dll is not installed here; live ID 553 debug-layer verification on 62f6d473 was provided independently by thehollowedone).
  • Retail COPY-queue KickoffX (synthetic live RTX 5070 COPY-queue verification on 62f6d473 was provided independently by andrewDoing).

AI use

Assisted by Google Antigravity (Gemini 4 Neon) for code analysis, implementation (opt-in XCL_KICKOFF_SWAP=1, exact default-OFF parity, MAX_KICKOFF_SPARES = 8 cap, alloc_pool::wait_idle fallback, scope cleanup, and original spare-switching fix), test authoring, and RTX 4060 verification.

@thehollowedone

Copy link
Copy Markdown
Contributor

Independent check of 4db9383. Windows 11 build 26300, Ryzen 7 9800X3D, RTX 3080 Ti / 621.35, Rust 1.99.1 MSVC, DXC 1.8.2502.11.

  • The clean head built with cargo build --offline --locked --workspace -j 6. cargo test --offline --locked --workspace --no-fail-fast -j 6 -- --test-threads=4 --nocapture finished with 1,268 passed, 0 failed, 46 ignored, including 26 runtime skips in the pass count. All four stock KickoffX and spare-list bookkeeping tests passed.
  • I ran cargo test --offline --locked -p xcl --lib -j 6 kickoff_x_ -- --test-threads=1 --nocapture in separate processes with test-only changes that selected the RTX 3080 Ti and Microsoft WARP explicitly and read the D3D12 debug queue. Both runs passed 3/3 with zero skips. Each adapter completed the two gated-queue cases (back-to-back kickoff and mid-list split) with zero ID 553 messages, zero D3D12 warnings or errors, and a healthy device. Runtime code was unchanged.

Synthetic input only. No retail smoke on this machine.

AI-assisted. Codex (GPT-6, exact variant unavailable) added the temporary test instrumentation, ran the tests and drafted this report.

@luckyteagirl

Copy link
Copy Markdown
Contributor

Independent RX 6800M verification of exact PR head 4db9383acea69d0c355ce5d2cb339a9f6ad1d2bb.

Environment: Windows 11 build 26200; Ryzen 9 5980HX; discrete AMD Radeon RX 6800M driver 30.0.13002.13003 alongside integrated Radeon graphics; Rust 1.99.0 MSVC; DXC/DXIL 1.9.2609.5. Isolated debug Cargo target.

On the unchanged head, cargo test --locked -p xcl --lib kickoff_x_ -- --test-threads=1 --show-output passed 3 passed, 0 failed, 0 ignored, with no skips. Its test_device_or_warp helper does not print or select the adapter, so that run alone is not attributable to the RX 6800M.

For an attributable GPU check, I changed only that test helper locally to use gpu::adapter::Selector::from_env_or("auto") plus candidates, then ran the same filter with XCL_ADAPTER=6800M. It again passed 3/0/0, no skips. Both new in-flight tests printed KickoffX test adapter: AMD Radeon RX 6800M: back-to-back gated KickoffX switched to distinct idle spares and returned to primary after draining; the mid-list Write64/Wait64 split resumed on an idle spare. Their built-in checks reported no in-flight resubmits and a healthy device. The third passing test is the existing render-target binding check. I removed the test-only selector edit and verified the worktree is clean.

Limits: Focused synthetic tests only. I did not run the full workspace suite, a paired title smoke, or a live D3D12 debug-layer check on this head. A separate title smoke attempt for another PR had stopped under the available-commit memory guard. This does not cover an actual title's back-to-back KickoffX sequence.

AI use: OpenAI Codex (GPT-6; exact variant unavailable in this session) ran the Windows checks, made and restored the test-only selector, and drafted this report. No game data was used.

@throny throny added the goal:world-load Bears on the retail title getting past world loading label Nov 25, 2026
@oni-swr

oni-swr commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Independent AMD report for 4db9383acea69d0c355ce5d2cb339a9f6ad1d2bb.

Tested

  • AMD Radeon RX 7800 XT (driver 32.0.31035.1003), Ryzen 7 5700X3D, Windows 11 build 26200, rustc 1.100.0, debug profile for tests, release for smoke. Tested at the exact PR head (not a local merge onto main).
  • cargo test -p xcl --lib kickoff: 4 passed, 0 failed. switch_active_for_kickoff: 1 passed. Both new in-flight scenarios ran on the RX 7800 XT (no SKIPPED line).
  • cargo test --workspace --no-fail-fast -- --test-threads=4: 1267 passed, 1 failed, 46 ignored. The one failure is gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1 (seed 722: res[30] = 0x1, CPU 0x7fffffff). It fails identically on main 06c9f550 on this adapter (cargo test -p xcl --lib fuzz_validate_and_gpu_1), so it is not caused by this PR.
  • SKIPPED lines in the log: 7 (6 of them f16_programs_on_the_gpu / f32_programs_on_the_gpu per-lane cases refused for V_MUL_F16, V_PK_MUL_F16 or V_CVT_F16_F32, plus heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).
  • scripts/smoke.ps1 -Seconds 60 on a real title (same title, same time), release build. main 06c9f550: 1531 frames, last presents per 2 s 60 36 38, peak commit 17752 MB, no device removal, no crash. PR head 4db9383a: 1571 frames, last presents per 2 s 59 61 59, peak commit 15155 MB, no device removal, no crash. Both exit 0x0.

Not tested

Retail title with a before/after reproduction of the #1452 debug-layer error, other adapters, NVIDIA.

AI use

Claude Code (Claude Sonnet 5.5) ran the tests and the smoke runs and wrote this report. No game files, dumps or shader names are included.

gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 25, 2026
…#2296, xcl-dev#2297, xcl-dev#2320, xcl-dev#2323, xcl-dev#2329, xcl-dev#2333

Integrates shader heap-base addresses (xcl-dev#1803), fenced superseded texture unmaps (xcl-dev#2270), cross-queue VRAM heap reclamation fencing (xcl-dev#2275, using create_raw_fence under Wine), PcCall frame clamping and orphan PSO drop (xcl-dev#2296), PSO pointer guards (xcl-dev#2297), KickoffX idle spare list switching (xcl-dev#2320, preserving UnadoptGuard), console-list descriptor heap binding (xcl-dev#2323), ClearUnorderedAccessView PC handles (xcl-dev#2329), and dispatch_chain PSO retention (xcl-dev#2333).
@thiagocalile

Copy link
Copy Markdown

Independent test and 60 s smoke report for head 4db9383acea69d0c355ce5d2cb339a9f6ad1d2bb on an AMD Radeon RX 6600 (8 GB VRAM, RDNA2, native wave64).

Tested

  • Hardware: AMD Radeon RX 6600 (8146 MiB VRAM, RDNA2, native wave64, driver 32.0.21045.29003, XCL_ADAPTER=radeon), AMD Ryzen 7 5700X3D, 47.9 GB RAM, Windows 11 (10.0.26200.0), Rust 1.100.0 (stable-x86_64-pc-windows-msvc), DXC 1.8.2502.11.
  • XCL_ADAPTER=radeon cargo test --no-fail-fast -p xcl --lib -- kickoff --test-threads=4: 4 passed, 0 failed, 0 ignored (0 skipped).

Regression run (scripts/smoke.ps1 -Seconds 60, release builds, XCL_ADAPTER=radeon)

main (06c9f55):

xcl-smoke v1
commit: 06c9f5505f63f10c5ec49ef932d75b2c28177324
gpu: AMD Radeon RX 6600
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1469 (PresentX 1469)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 13436 MB

PR #2320 (4db9383):

xcl-smoke v1
commit: 4db9383acea69d0c355ce5d2cb339a9f6ad1d2bb
gpu: AMD Radeon RX 6600
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1537 (PresentX 1537)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16762 MB

Not tested: full workspace test suite on this head, NVIDIA/Intel GPUs, Linux/Wine, or world load past the 60 s smoke window.

AI use: Antigravity (Gemini 4 Neon) ran the builds, tests, and smoke runs and drafted this report; the account owner reviewed and approved posting.

@Decodere
Decodere force-pushed the fix-2163-kickoff-in-flight-spare branch from 4db9383 to 6a3d4a3 Compare November 25, 2026 17:13
@Decodere

Copy link
Copy Markdown
Contributor Author

Rebased onto 50a9fdef (6a3d4a38, resolving the list_x::tests EOF conflict with #1291). Re-verified title_list::tests (4/0), list_x::tests (38/0), and paired 60 s RTX 4060 smoke (1544 -> 1578, 0 device removals/crashes); workspace hit only 50a9fdef's pre-existing #2074 a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier failure (1291 passed, 1 failed).

@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

Thanks!

@Decodere Decodere closed this Nov 25, 2026
@Decodere Decodere reopened this Nov 25, 2026
@Decodere Decodere closed this Nov 25, 2026
@Decodere Decodere reopened this Nov 25, 2026
@Lum7nt

Lum7nt commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

RX 9070 XT verification of exact PR head 6a3d4a38b4b62522fda36a75d5ba3499d6d436eb.

Hardware: AMD Radeon RX 9070 XT, Windows, retail GTA 6 Xbox 1.0.2.1; Rust 1.100.0 MSVC, bundled DXC.

Focused tests: cargo test --locked -p xcl --lib kickoff -- --test-threads=1 — 4 passed, 0 failed, 0 ignored, 0 skipped. This includes both new in-flight KickoffX cases and the spare-list bookkeeping checks.

60-second scripts/smoke.ps1 regression pair:

PR head:

xcl-smoke v1
commit: 6a3d4a38b4b62522fda36a75d5ba3499d6d436eb
gpu: AMD Radeon RX 9070 XT
title: GTA6-1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1048 (PresentX 1048)
presents per 2 s (last 3): 60 61 60
device removals: 0
crashes: 0
peak commit: 14876 MB

Current main:

xcl-smoke v1
commit: 3ceb5507a05355719ff1d7b5c29bc52aff142000
gpu: AMD Radeon RX 9070 XT
title: GTA6-1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1029 (PresentX 1029)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14601 MB

The retail smoke passed but did not specifically trigger back-to-back in-flight KickoffX; the focused gated-queue tests cover that path. The D3D12 debug layer is not installed here, so there is no live ID 553 debug-queue check on this card.

AI use: OpenAI Codex (GPT-6; exact variant not exposed in this session) ran these checks and wrote this report.

@pickles976

Copy link
Copy Markdown

Code-review finding on 6a3d4a38b4b62522fda36a75d5ba3499d6d436eb: the idle-spare invariant is not preserved on allocation/reset failure paths in kickoff_x.

In the candidate/reset_one block in list_x.rs:

  1. When current_target is in flight, pop_spare(w).or_else(|| create_closed_spare(...)) can return None (including native create/initial Close failure). The final else then calls reset_one(current_target) anyway.
  2. If a different candidate exists but reset_one(cand) fails, the code also falls back to (current_target, reset_one(current_target)), without establishing that current_target has retired.

The fallback Reset is not a retirement check: Microsoft explicitly permits ID3D12GraphicsCommandList::Reset while the command list is still executing. If it succeeds before the earlier fence completes, the function resumes recording on the in-flight list that this change is intended to avoid reusing. [INFERENCE] A subsequent Kickoff/Execute before retirement can therefore return to the ID 553 path under spare-allocation pressure, despite passing the success-path gated-queue tests.

Could the error path preserve the same invariant—do not resume/subsequently submit this target until its previous fence retires, or terminate the operation safely—and add coverage for both no-spare/create failure and spare-Reset failure while the old target is gated? Simply checking reset_hr < 0 after falling back does not cover successful Reset of a still-in-flight command list.

Context/limits: our separate Linux/Wine retail integration logged same-recording, same-queue resubmits while approaching a conservative 6000 MiB VRAM cutoff. It does not contain this PR, and that warning alone does not establish that KickoffX caused our run's resubmits. I inspected your source and the API contract here; I did not induce allocation failures or run your PR, and I am not submitting a competing fix. This is general failure-path feedback relevant to limited-memory hosts, not a claim about a specific GPU or the root cause of our earlier host freeze.

AI assistance: OpenAI coding assistant reviewed the linked code/contract and drafted this report.

gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 25, 2026
…1946, xcl-dev#1803, xcl-dev#2297, xcl-dev#2320, xcl-dev#2333

Carries forward still-open high-value upstream PRs onto upstream/main (2898511)
+ our updated Wine PR stack (xcl-dev#867, xcl-dev#1395-successor, xcl-dev#871, xcl-dev#877, xcl-dev#1732).
Preserves UnadoptGuard in xcl-dev#2320 KickoffX reset_one.

Assisted-by: Antigravity (Gemini 4 Neon)
…d list is in flight

Follow-up to xcl-dev#2163 (Part of xcl-dev#1452).

`list_x::kickoff_x()` previously reset and resumed recording on the same
PC command list it had just submitted (or on `primary` after a mid-list
split), even when that list's submission was still executing on the GPU.
A subsequent `KickoffX` or final `Close` + `ExecuteCommandLists` then
resubmitted an in-flight PC command list, triggering D3D12 debug layer
ID 553 (`EXECUTECOMMANDLISTS_COMMANDLIST_STILL_IN_FLIGHT`) and device
removal on strict drivers.

- Add `title_list::primary_of`, `title_list::switch_active_for_kickoff`,
  and `title_list::mark_kickoff_unreset` to switch `F_BACKING` /
  `WRAPPER_OF` / `book.first` / `book.spares` after `Reset` succeeds
  while keeping `F_PRIMARY` out of `book.first` and `book.spares`, and
  suppress `push_segments` (with empty-batch early return in
  `execute_with_waits_on`) if `KickoffX` cannot obtain/reset an idle
  target until the title's next `Reset`.
- Extract shared `list_x::create_closed_spare` (used by both
  `reset_stand_in` and `kickoff_x`) so a spare whose initial `Close`
  fails is released instead of pooled, and `list_x::acquire_kickoff_target`
  so `kickoff_x` never falls back to resetting `current_target` while it
  is still in flight (trying idle `primary`, all idle pooled spares, then
  a fresh spare, and leaving `current_target` closed + unreset on failure).
- Update `list_x::kickoff_x` to preserve `bind` / `ListState` / DRED
  pipeline state onto the new active list, clear retired segment state,
  and guard `init_pso` and predication restore for `COPY` command lists.
- Add unit tests covering `switch_active_for_kickoff` and
  `kickoff_unreset` invariants, back-to-back in-flight `KickoffX` +
  return to `primary` after drain, `KickoffX` after a mid-list
  `Write64 -> Wait64` split, and gated-queue no-spare / spare-`Reset`
  failure paths.

Assisted-by: Google Antigravity (Gemini 4 Neon)
@Decodere
Decodere force-pushed the fix-2163-kickoff-in-flight-spare branch from 6a3d4a3 to 62f6d47 Compare November 25, 2026 20:23
@Decodere

Copy link
Copy Markdown
Contributor Author

Good catch — fixed in 62f6d473 (rebased onto 6d12f58a).

Extracted list_x::acquire_kickoff_target so kickoff_x never falls back to resetting current_target while alloc_pool::in_flight(current_target) is true (on either no-spare/create failure or spare-Reset failure), instead leaving current_target closed and calling title_list::mark_kickoff_unreset(w) (with an empty-batch early return in execute_with_waits_on) so neither a follow-up KickoffX nor Close + ExecuteCommandLists can resubmit the in-flight list until the title's next Reset. Added title_list::tests::kickoff_unreset_suppresses_push_segments_until_reset and gated-queue list_x::tests::kickoff_x_failure_paths_never_reset_in_flight_target (passing on both RTX 4060 & WARP; workspace 1428 passed, 0 failed).

gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 25, 2026
…1946, xcl-dev#1803, xcl-dev#2297, xcl-dev#2320, xcl-dev#2333

Carries forward still-open high-value upstream PRs onto upstream/main (2898511)
+ our updated Wine PR stack (xcl-dev#867, xcl-dev#1395-successor, xcl-dev#871, xcl-dev#877, xcl-dev#1732).
Preserves UnadoptGuard in xcl-dev#2320 KickoffX reset_one.

Assisted-by: Antigravity (Gemini 4 Neon)

@bmjask bmjask 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.

No concrete source-level defect found. In-flight primary protection, spare selection/reset failure behavior, split segment bookkeeping, and state transfer look sound; current CI and broad gated-queue evidence are green. Residual gaps: no live COPY-list back-to-back in-flight reproduction, and current targeted debug-layer coverage would strengthen latest failure-path changes. The deliberate suppression until title Reset after allocation/reset failure should remain documented. I found no blocker.

@oni-swr

oni-swr commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Independent AMD report for 62f6d4737b28a5fc7e9808350724c0c1a4a0f168.

Tested

  • AMD Radeon RX 7800 XT (driver 32.0.31035.1003), Ryzen 7 5700X3D, Windows 11 build 26200, rustc 1.100.0, debug profile, DXC from Windows SDK 10.0.26100.0, XCL_ADAPTER=radeon. Exact PR head (not a local merge onto main); main at the time was 6d12f58a.
  • cargo test --workspace --no-fail-fast -j 4 -- --test-threads=4: 1427 passed, 1 failed, 46 ignored. The one failure is gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1 (seed 722: res[30] = 0x1, CPU 0x7fffffff); it fails identically on main 6d12f58a on this adapter (cargo test -p xcl --lib fuzz_validate_and_gpu_1), so it is not caused by this PR.
  • 7 SKIPPED lines: 6 f16_programs_on_the_gpu / f32_programs_on_the_gpu per-lane cases refused for V_MUL_F16, V_PK_MUL_F16 or V_CVT_F16_F32, and heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).
  • cargo test -p xcl --lib kickoff-area tests ran in the workspace run: the three new list_x::tests::kickoff_x_* GPU scenarios (in-flight switch to idle spare, mid-list Wait split, failure paths) and title_list::tests::kickoff_unreset_suppresses_push_segments_until_reset / switch_active_for_kickoff_keeps_primary_out_of_spares all passed, with no SKIPPED line for them (they ran on the RX 7800 XT, not the WARP fallback).

Not tested

  • scripts/smoke.ps1 / a retail title (no regression run), other adapters, NVIDIA. No game data was used.

AI use

Claude Code (Claude Sonnet 5.5) ran the tests and wrote this report. No game files, dumps or shader names are included.

gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 26, 2026
Integrates split-segment alloc_pool unpin + title_list ABA guard (xcl-dev#1453),
allocator-put-aside memory retention (xcl-dev#1422), and forget-PSO-before-free
(xcl-dev#2422). Preserves UnadoptGuard in list_x reset paths and xcl-dev#2320 kickoff
target switching.

Assisted-by: Antigravity (Gemini 4 Neon)
@DavidM1911

Copy link
Copy Markdown
Contributor

Re-verification on RTX 3060 Ti (Windows 11), new head merged with current main:

Thanks!

— Devin

@upipibi

upipibi commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

NVIDIA report, head 62f6d4737b28a5fc7e9808350724c0c1a4a0f168, merge-base 6d12f58a229bc73889878a448c64dc3af25eeba0. RTX 3070 8 GB, driver 616.56, Win11, rustc 1.100.0, 5950X, 32 GB.

cargo test -p xcl --lib d3d12x:: x3: --test-threads=1 head 258 passed, 0 failed (x3), base 253 passed, 0 failed (x3). Default threads: head runs 1-2 258 passed, 0 failed; run 3 257 passed, 1 failed (sparse::tests::flush_parked_does_not_free_or_reuse_tiles_while_unmap_is_in_flight, one run, not in the PR; open #2775 makes that test wait for every quarantine mark). Base runs 1-2 253 passed, 0 failed; base run 3: sparse::tests::a_tile_decommitted_and_committed_again_keeps_its_video_memory FAILED, then the run hung and was aborted after ~14.5 min (not a pass; one run). Related: #1978 (closed; parallel d3d12x race).

Workspace -- --test-threads=4 --skip hle::xaudio2: head 1415 passed, 0 failed, 46 ignored; base 1410 passed, 0 failed. The e2e title tests were stopped by our runner after ~8 min on both sides; an earlier run here took 381 s, so they are not counted (not a hang). SKIPPED 26 both (21 wave64). No nvlddmkm resets.

AI-assisted (Claude Code, Claude Sonnet 5.5 ran the tests; Claude Opus 5.5 checked and posted).

@thehollowedone

Copy link
Copy Markdown
Contributor

Independent Windows/NVIDIA check of #2320 head 62f6d473. RTX 3080 Ti (driver 621.35), Ryzen 7 9800X3D, Windows 11 build 26300, Rust 1.99.1 MSVC, debug build.

  • Stock head: cargo test --offline --locked -p xcl --lib kickoff_x_ -- --test-threads=1 --nocapture: 4 passed, 0 failed, 0 ignored. cargo test --offline --locked -p xcl --lib hle::d3d12x::title_list::tests -- --test-threads=1: 5 passed, 0 failed, 0 ignored. The stock tests check zero in-flight resubmissions and device health; they do not enable the D3D12 debug layer.
  • Stock head: cargo test --offline --locked --workspace --no-fail-fast -- --test-threads=4: 1,428 passed, 0 failed, 46 ignored across 37 targets. There were 25 printed GPU SKIPPED notices; those are not GPU coverage.
  • Separate scratch test-only instrumentation enabled Graphics Tools' D3D12 debug layer before creating the device and read ID3D12InfoQueue after each gated queue drained. The selected adapter was confirmed as the RTX 3080 Ti. Each of the three new gated kickoff_x_* tests passed in its own process (1 passed, 0 failed each), with zero ID 553 messages. I removed the instrumentation afterward; the worktree is back at the exact PR head.

This adds direct debug-layer evidence for the in-flight KickoffX cases. It does not cover a retail title that invokes the path, AMD/Intel, or the pre-existing title_list::reset fallback on a failed spare allocation.

AI use: Codex (GPT-6.2 Sol) ran the tests, checked the temporary debug instrumentation and drafted this report.

@andrewDoing

Copy link
Copy Markdown
Contributor

COPY queue KickoffX verification on RTX 5070

A synthetic test on PR #2320, head 62f6d4737b28a5fc7e9808350724c0c1a4a0f168, kept a native D3D12 COPY queue in flight behind an unsignalled fence. Two consecutive KickoffX calls switched recording from the primary list to two distinct spare lists. After releasing the fence and draining the queue, recording returned to the primary list.

The probe copied a different 32-bit marker in each of four segments, including the final submission. Readback returned 11111111 22222222 33333333 44444444 in hexadecimal. The three resubmission checks returned zero. The device remained healthy, and the live D3D12 info queue contained no error or corruption messages in the measured interval. One test passed in 0.44 seconds. Run log

A local test-only overlay adapted the PR's gated DIRECT-list fixture. It used the native Windows default adapter, independently identified as the RTX 5070. Retail COPY-list use and world-load performance remain unmeasured. Adapter probe

AI use: OpenAI Codex adapted the fixture, ran it, and wrote this report.

@ClosetPie107

ClosetPie107 commented Nov 27, 2026 •

Copy link
Copy Markdown

Update for head bc3c0423 (adds 7f4c1fc6, 9d9e09fc and bc3c0423 on top of 62f6d473, which the results below are for; the list switch is now behind XCL_KICKOFF_SWAP=1). Same machine and setup as below (RX 9070 16 GB / Mesa 26.3.1 RADV / Proton Experimental experimental-11.0-20261112, vkd3d-proton master ec207194 without the allocator / command-list lpVtbl checks, DXC 1.9.2609.5, Rust 1.96.0, x86_64-pc-windows-gnu debug build). The head itself (base 6d12f58a), with its base the same session as the baseline.

Tests (XCL_REQUIRE_GPU=wave64, --test-threads=1)

  • cargo test -p xcl --lib -- hle::d3d12x::list_x::: 47 passed, 0 failed, 0 ignored (main f9a0cb80: 40 passed, 0 failed).
  • cargo test -p xcl --lib -- hle::d3d12x::title_list::: 5 passed, 0 failed, 0 ignored (main: 3 passed, 0 failed).
  • Lib with --skip compositor_blends_ui_plane_over_scene_plane --skip failed_restore_stops_before_importing_an_unbacked_window --skip grooming_leaves_a_window_under_1_gib_only_its_hole (the first loses the RADV device here, the other two run out of memory under Wine), --test-threads=1: 1298 passed, 8 failed, 26 ignored; base 6d12f58a the same way: 1289 passed, 8 failed, 26 ignored, the same 8.

Device removals with --test-threads=4 (same skips), worth a look:

  • This head: 1 clean run (1298 passed, 8 failed, the base's 8) and 2 runs where the device was lost (0x80004005) and 19 tests failed (texture, sparse and vram tests, and stale_blob_cannot_bypass_the_offline_pipeline_cap, which panics with compute dispatch: D3D12 device removed).
  • The previous head 9d9e09fc: 3 of 3 runs lost the device the same way; with its 8 new KickoffX tests skipped, 1 of 2.
  • The base 6d12f58a: 2 of 5 runs; main f9a0cb80: 1 of 3.
  • So this happens without the PR too, and I don't count it as a failure of this PR; but 5 of 6 four-thread runs on this PR's heads against 2 of 5 on its base is more than I'd expect by chance.

The other binaries fail the same 3 tests as on main here (e2e, pls_quota, predication_e2e). d3d12_resource_and_sync ended the process, as it does on most trees here.

Not tested: a run with XCL_KICKOFF_SWAP=1 (retail or otherwise); native Windows, NVIDIA / Intel.

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


Independent test report under Wine/Proton (not native Windows) for head 62f6d473.

Setup

  • AMD Radeon RX 9070 (RDNA4, RADV GFX1201, Mesa 26.3.1), Ryzen 5 9600X, CachyOS Linux 7.3.5
  • Proton Experimental experimental-11.0-20261112, vkd3d-proton master ec207194 with a local patch dropping the lpVtbl checks in d3d12_command_allocator_from_iface / d3d12_command_list_from_iface, DXC 1.9.2609.5, Rust 1.96.0, x86_64-pc-windows-gnu
  • Head merged onto main 83b00818, test commit 2a7af181

Tests (debug, XCL_REQUIRE_GPU=wave64, --test-threads=1)

  • hle::d3d12x::list_x::: 43 passed, 0 failed (main: 40 passed, 0 failed)
  • hle::d3d12x::title_list::: 5 passed, 0 failed (main: 3 passed, 0 failed)
  • cargo test -p xcl --lib -- --test-threads=4 --skip compositor_blends_ui_plane_over_scene_plane: 1324 passed, 9 failed, 27 ignored (main the same run: 1319 passed, 9 failed, 27 ignored). The failures are main's, except gpu_geometry_wave32_prefix_count_over_a_mask (timing-dependent: it also failed on unrelated trees today) in place of main's xapu_connect_returns_oom_and_cleans_up_on_failure. Without the --skip, the lib binary lost the device in that test (RADV The CS has been rejected); that is the test-order problem main has (list_x:: followed by that test, see my report on D3D12.X: patch assert-checked vtables in place under Wine (#175) #2477).

Retail title, 300 s (release, every run from a copy of the same warm-cache snapshot; XCL_DIRECT_DXIL=1 XCL_PREPARE=1 XCL_PSO_PRELOAD=1 XCL_PSO_WAIT_MS=50 XCL_TEXTURE_LEVEL_PAGES=1 XCL_COHERENT_MB=1024 VKD3D_CONFIG=ignore_shared_fence, A pressed every 10 s)

  • 4 runs: 3 clean (exit 0, 1,956 / 2,088 / 2,054 presents). In 1 the device was removed (0x887a0005) at 294 s, about 24 s after the last present (the 2-second activity lines before it show no presents and no submits), and the title was stopped.
  • main, 4 runs: all clean, 1,892–2,122 presents. One removal in four runs is not enough to call it this PR's.

Not tested

  • Native Windows, NVIDIA/Intel
  • The debug layer (EXECUTECOMMANDLISTS_COMMANDLIST_STILL_IN_FLIGHT): vkd3d-proton has none

AI use

  • Claude Code (Claude Opus 5.5) wrote the test scripts, ran the tests and runs on this machine and wrote this report.

@throny

throny commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

Merge status and pre-merge review (I have been asked to prepare merges of PRs with several independent tests; the bar is: no open critical finding or performance regression, a fresh check of the merge result against today's main, and green required checks. Each merge is still confirmed by a person.)

The PR merges cleanly into main 6089122a, and the three files it touches have not changed on main since your base. I found no defect in the list state transitions: the primary never enters the spares, the list switched away from goes to the spares and pop_spare skips lists still on the GPU, no allocator is reset by this code, no new nested locks, and no recording is handed out twice. The three new tests would fail on main.

What keeps me from proposing it for merging yet:

  • It is on by default and runs on every KickoffX. The list just submitted is always still on the GPU right after its own submit, so acquire_kickoff_target switches lists every time. Each kickoff then also pays inherit_for_split, bind::reset, clear_segment_state, three takes of the LISTS lock, a pop_spare scan, and a CreateCommandList when no spare is idle. The description's own smoke pair shows 1,383 frames against 1,550 on main (-10.8 %): inside the 80 % rule, but a drop, and the description does not say whether that title calls KickoffX at all.
  • Evidence for a default-on change on the submit path: the description has one 60 s smoke run on one NVIDIA card; no world run, nothing on AMD, no debug-layer run. There is no switch for this alone (XCL_ALLOC_SWAP=0 turns off the whole pool).

What would make it mergeable from my side: frames or frame time in a world run with and without the change on a title that does use KickoffX (I can run that on an RTX 4080 if you tell me a setup where it is exercised), or an opt-out switch until that exists.

Smaller notes: when no idle list can be made, mark_kickoff_unreset hides the wrapper's lists from ExecuteCommandLists and later commands are lost with only a rate-limited warning; the PR carries a few drive-by changes (the COPY-list guard, a spare whose Close fails being released, the empty-batch early return, dred::reset); the new GPU tests share global state with the other list_x GPU tests.

Review from reading the code; nothing was built or run for it. AI use: Claude Code (a Claude Opus 5.5 sub-agent reviewed the merge result; Claude Fable 5.2 checked and wrote this).

…ching

Address @throny's pre-merge review on xcl-dev#2320:

- Add `kickoff_swap_enabled_val` / `kickoff_swap_enabled` (`XCL_KICKOFF_SWAP=0`,
  default ON, matching `alloc_pool::enabled()`'s `XCL_ALLOC_SWAP=0` idiom) in
  `crates/xcl/src/hle/d3d12x/list_x.rs`.
- When `XCL_KICKOFF_SWAP=0`, `kickoff_x` skips `title_list::wrapper_of` and
  `acquire_kickoff_target` bypasses `in_flight` / spare-pool scanning /
  `switch_active_for_kickoff` / `mark_kickoff_unreset` (and the `target != this`
  state-inheritance / segment-reset overhead when unsplit), resetting
  `current_target` directly while leaving `XCL_ALLOC_SWAP` unaffected.
- Add unit tests `kickoff_swap_enabled_val_defaults_on_and_disables_on_zero`
  and `kickoff_swap_disabled_keeps_current_target_without_spares`.

Follow-up to xcl-dev#2163
Part of xcl-dev#1452
Assisted-by: Google Antigravity (Gemini 4 Neon)
@Decodere

Copy link
Copy Markdown
Contributor Author

Thanks for the review, @throny! I pushed follow-up commit 7f4c1fc6ea2156317bfcda0a1dfb4cb6ad16f60e (D3D12.X: add XCL_KICKOFF_SWAP=0 opt-out switch for KickoffX list switching) addressing your merge feedback:

  1. Dedicated opt-out switch (XCL_KICKOFF_SWAP=0):
    • Added kickoff_swap_enabled_val / kickoff_swap_enabled in crates/xcl/src/hle/d3d12x/list_x.rs matching alloc_pool::enabled()'s XCL_ALLOC_SWAP=0 idiom (OnceLock<bool>, default ON).
    • When XCL_KICKOFF_SWAP=0, kickoff_x skips title_list::wrapper_of and acquire_kickoff_target bypasses in_flight, spare-pool scanning/creation, switch_active_for_kickoff, mark_kickoff_unreset, and (when unsplit) inherit_for_split / bind::reset / clear_segment_state / extra LISTS lock takes — resetting current_target directly while leaving XCL_ALLOC_SWAP untouched.
    • Added unit tests kickoff_swap_enabled_val_defaults_on_and_disables_on_zero and kickoff_swap_disabled_keeps_current_target_without_spares (proving 0 in_flight calls, 0 spare pops/creates, active backing kept on primary, and no kickoff_unreset even while primary is gated in flight).
  2. Answering the KickoffX & -10.8% smoke question honestly:
    • I ran a temporary local counter probe inside list_x::kickoff_x on a 60 s startup run of title 29640639 (then reverted cleanly): KickoffX was called 0 times in that 60 s startup window.
    • Fresh back-to-back quiet 60 s RTX 4060 runs on 7f4c1fc6 vs exact merge-base 6d12f58a:
      • Merge-base 6d12f58a: 1581 frames (PresentX 1581), 60 60 60, 0 rem/crash, 14018 MB
      • 7f4c1fc6 default (XCL_KICKOFF_SWAP unset): 1557 frames (PresentX 1558, 98.5%), 60 60 60, 0 rem/crash, 14010 MB
      • 7f4c1fc6 opted out (XCL_KICKOFF_SWAP=0): 1573 frames (PresentX 1573, 99.5%), 60 60 60, 0 rem/crash, 13973 MB
    • So the earlier -10.8% (1383 vs 1550) was normal startup run-to-run variance rather than KickoffX cost, AND title 29640639 does not exercise KickoffX in its 60 s startup window — which makes the dedicated XCL_KICKOFF_SWAP=0 escape hatch all the more useful until world-run timings on a KickoffX-using title are collected.
  3. Verification on 7f4c1fc6ea2156317bfcda0a1dfb4cb6ad16f60e (RTX 4060, Windows 11, rustc 1.100.0):
    • cargo clippy --tests -p xcl -- -A clippy::approx_constant -A clippy::while_immutable_condition: exit 0, 0 new warnings in list_x.rs.
    • 3x Debug + 3x Release cargo test -p xcl --lib -- hle::d3d12x::list_x:: hle::d3d12x::title_list:: --test-threads=1 --nocapture: 50 passed; 0 failed; 0 ignored; 0 skipped.
    • Updated the PR description to document XCL_KICKOFF_SWAP=0, the 0-call probe finding, the fresh paired smokes, and the independent community evidence already in this thread (@thehollowedone live D3D12 debug-layer 0 ID 553 PASS on RTX 3080 Ti, @andrewDoing live COPY-queue KickoffX PASS on RTX 5070, @ClosetPie107 RX 9070 PASS, and @oni-swr RX 7800 XT native GPU tests PASS on 62f6d473).

Ready for re-check whenever you have a moment!

(AI use: Google Antigravity (Gemini 4 Neon) implemented XCL_KICKOFF_SWAP=0 and its unit tests, ran clippy/tests/paired smokes and the temporary KickoffX probe, and drafted this reply.)

@throny

throny commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

Re-check of the new head 7f4c1fc6 against main 6089122a (read from the code; nothing built or run for this comment, so it is not a full merge check yet).

Status of the earlier points

  • Opt-out switch: done. XCL_KICKOFF_SWAP=0 is read once and the kickoff path then behaves like main.
  • The swap runs on every KickoffX: unchanged. The list is always in flight right after its own Signal, so the swap path is still taken every time; the cost per kickoff and the −10.8 % frames of the earlier pair are not addressed by a switch that is on by default.
  • Commands lost when no idle list can be made: unchanged, see 1.
  • Unrelated changes in the same PR (COPY guard, Release when Close fails, empty-batch return, the DRED reset): still in.
  • GPU tests sharing global state: partly (the new lock covers only the new tests).

Still open before a default-on merge

  1. acquire_kickoff_target → mark_kickoff_unreset: if no spare can be created while the list is in flight, the title keeps recording into a closed list, Close fails, nothing is submitted and that recording is lost with a rate-limited warning. main would have reset the list and run it. A fallback that waits on the last submit's fence and then resets the current list would keep main's behaviour in that case.
  2. No cap on spares: a title that kicks off several times per frame while the GPU is a frame behind gets one PC list per kickoff; they are never trimmed, pop_spare scans them all under the lock, and idle ones keep their allocator from being reused.
  3. Size: 655 added lines (about 420 are tests). It splits naturally into the create_closed_spare refactor with the unrelated fixes, the title_list helpers with their unit tests, and the swap with its switch and GPU tests.

Sound as far as read: the Release calls through the vtable follow the module's pattern and free each list once; nothing resets an allocator on this path; "idle" is the completed fence value against the Signal issued after each submit; the state carried to the spare matches the existing split path; no lock is held across ExecuteCommandLists, lock order unchanged; two of the tests drive the real kickoff_x and fail on main.

Merge status: not yet. What would change that: the fallback in 1, a cap or trim for 2, and a smoke pair on a title that calls KickoffX showing no frame loss with the default; or the same code with the switch off by default, which could go in on the present evidence once split.

AI use: Claude Code (a Claude Opus 5.5 sub-agent reviewed the head, Claude Fable 5.2 checked and wrote this).

…pares and fence-wait fallback

Addresses pre-merge re-review on xcl-dev#2320:
- Flip XCL_KICKOFF_SWAP to opt-in (XCL_KICKOFF_SWAP=1, default OFF) so default KickoffX behavior matches main until a KickoffX-using title's world-run frame times are measured.
- Add alloc_pool::wait_idle (cloning fence/value and releasing STATE before gpu::fence::wait) and fall back to a bounded 5000 ms fence wait before resetting current_target when no idle spare is available, preserving subsequent commands instead of dropping them via mark_kickoff_unreset (which now triggers only if the bounded wait or Reset itself fails).
- Cap per-wrapper KickoffX spares at MAX_KICKOFF_SPARES = 8 via title_list::spare_count, falling through to the bounded fence wait once the cap is reached.
- Tighten diff scope against merge-base 6d12f58 by restoring reset_stand_in verbatim and dropping unrelated COPY-guard and DRED hunks from kickoff_x (keeping only the empty-batch early return in execute_with_waits_on required by mark_kickoff_unreset).
- Update KickoffX tests for default-OFF / XCL_KICKOFF_SWAP=1 opt-in and add live D3D12 regression coverage for the 8-spare cap and fence-wait fallback.

Assisted-by: Google Antigravity (Gemini 4 Neon)
@Decodere

Copy link
Copy Markdown
Contributor Author

Thanks @throny for the clear re-check and concrete bar — pushed fast-forward commit 9d9e09fc onto 7f4c1fc6 addressing all points:

  1. Opt-in by default (XCL_KICKOFF_SWAP=1, default OFF): Flipped kickoff_swap_enabled_val so the swap path is off unless XCL_KICKOFF_SWAP=1. With the env var unset, kickoff_x skips title_list::wrapper_of, in_flight, spare scanning/creation, fence waiting, switch_active_for_kickoff, and mark_kickoff_unreset, keeping main's default path intact until world-run measurements on a KickoffX-using title are available.
  2. Bounded fence-wait fallback (alloc_pool::wait_idle, 5000 ms): Added alloc_pool::wait_idle(list, dev, timeout_ms), which clones (fence, value) from STATE.last_submit, releases STATE before blocking, and waits via crate::gpu::fence::wait. When no idle spare is available (cap reached or spare creation/reset fails), acquire_kickoff_target waits up to 5000 ms on current_target's last submit fence and resets current_target in place so subsequent commands are not dropped; mark_kickoff_unreset now runs only if that bounded wait or Reset itself fails.
  3. Per-wrapper spare cap (MAX_KICKOFF_SPARES = 8): Added title_list::spare_count (spares + first + extra_active) and capped KickoffX spare creation at 8 non-primary spares per wrapper, falling through to the bounded fence wait once the cap is reached.
  4. Scope cleanup against 6d12f58a: Restored reset_stand_in verbatim (moving create_kickoff_spare private to kickoff_x) and dropped both COPY-list guards and the dred::reset/dred::mark_pipeline hunks from kickoff_x. Kept only the 3-line empty-batch early return in execute_with_waits_on because mark_kickoff_unreset (on wait/reset failure) causes title_list::push_segments to emit 0 segments for that wrapper, preventing real.rs::q_execute_command_lists from passing a 0-list batch to ExecuteCommandLists. Note on size: the branch diff against 6d12f58a (alloc_pool.rs +14, title_list.rs +130, list_x.rs +680/-40) is predominantly tests (~570 lines of unit + live GPU tests vs ~250 lines of production code); happy to split into stacked PRs if you still want smaller review units even with the switch off by default.

Verification on 9d9e09fc (RTX 4060 8 GB, driver 32.0.16.2114, Windows 11, rustc 1.100.0):

  • cargo clippy --tests -p xcl -- -A clippy::approx_constant -A clippy::while_immutable_condition: exit 0, 0 new warnings in touched files.
  • 3x Debug + 3x Release (hle::d3d12x::list_x:: hle::d3d12x::title_list:: hle::d3d12x::alloc_pool:: --test-threads=1 --nocapture): 55 passed; 0 failed; 0 ignored; 0 skipped — including new kickoff_x_spare_cap_and_fence_wait_fallback_recovers_without_dropping_commands (fills all 8 spares, verifies create_calls == 0 at the cap, proves alloc_pool::wait_idle releases STATE via concurrent in_flight check on a helper thread, and verifies both cap and spare-creation-failure paths recover without dropping commands or triggering resubmits).
  • Paired quiet 60 s smokes (title: 29640639, XCL_NETWORK=0, 0 KickoffX calls in startup window):
    • Default OFF (XCL_KICKOFF_SWAP unset): exit 0x0, 1547 frames (60 60 60), 0 removals/crashes, peak commit: 14060 MB.
    • Opt-in (XCL_KICKOFF_SWAP=1): exit 0x0, 1575 frames (60 60 60), 0 removals/crashes, peak commit: 14000 MB.
    • Merge-base 6d12f58a: exit 0x0, 1581 frames (60 60 60), 0 removals/crashes, peak commit: 14018 MB.

AI use: Google Antigravity (Gemini 4 Neon) implemented the opt-in gate, spare cap, fence-wait fallback, scope cleanup, and regression tests, and ran all local tests and smokes on this RTX 4060.

@throny

throny commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

Re-check of 9d9e09fc (code read only: nothing built or run on this head). Thanks for the quick turn; default-off and the bounded wait are the right direction. Not yet, four small things left:

Addressed

  • Swap path is opt-in; the COPY guard and DRED changes are gone.
  • Spares are capped at 8 per wrapper; a failed Close releases the list and unused spares go back to the pool.
  • wait_idle holds no lock while it blocks.

Still open

  1. Default path is not main's when the list was split before. With XCL_KICKOFF_SWAP unset, acquire_kickoff_target resets the list before the state hand-over (inherit_for_split, bind::reset, clear_segment_state, the LISTS update); on main the hand-over came first. A failed Reset now returns before the hand-over. The LISTS entry also newly gets list_type and last_queue, which can change the queue picked for later kickoffs. Either keep main's order when the switch is off, or say why the new order is equivalent.
  2. execute_with_waits_on no longer submits an empty batch, for every caller (a title's own 0-list ExecuteCommandLists included). That is a behaviour change outside the switch: please move it behind the switch or into its own PR.
  3. No test runs the default path through kickoff_x. Every test calls kickoff_x_with(.., true); the default-off test only calls acquire_kickoff_target. One test with false on a split list would cover point 1.
  4. Size: still one PR (about 250 lines of code + 570 of tests). Your offer to split it (wait helper → swap path behind the switch → tests) would make it mergeable sooner.

Minor

  • After the 5000 ms expire the recording is still dropped (mark_kickoff_unreset) and the logged error is E_OUTOFMEMORY; a timeout code would read better. With all lists in flight the title's thread can stall 5 s per KickoffX on the swap path.
  • Idle spares are never trimmed before the wrapper is released.

With the switch off by default I no longer ask for a smoke pair on a title that calls KickoffX; points 1–3 are enough for a "safe to merge" from this account. I will run the suite and a world run on the next head.

AI use: Claude Code; the diff was reviewed by Claude Opus 5.5, the points above were checked against the diff and written by Claude Fable 5.2.

…tch skip, and log wait timeout

Addresses final pre-merge re-check items on xcl-dev#2320:
- Branch cleanly on !swap_enabled in kickoff_x_with so the default-OFF path executes main's exact hand-over-then-reset order without overwriting list_type or last_queue on primary.
- Gate execute_with_waits_on's empty-batch early return behind kickoff_swap_enabled() (via execute_with_waits_on_with) so default-OFF behavior is unchanged for empty batches.
- Return HRESULT_FROM_WIN32(ERROR_WAIT_TIMEOUT) (0x80070102) instead of E_OUTOFMEMORY when the bounded 5000 ms fence wait expires.
- Add live split-list default-OFF test kickoff_x_default_off_split_list_matches_main_handover and verify both opt-in and default-OFF empty-batch handling.

Assisted-by: Google Antigravity (Gemini 4 Neon)
@Decodere

Copy link
Copy Markdown
Contributor Author

Thanks @throny for the fast follow-up — pushed fast-forward commit bc3c0423 onto 9d9e09fc covering points 1–3 and the timeout HRESULT minor:

  1. Exact main default-OFF split path (list_x.rs): Branched cleanly on if !swap_enabled in kickoff_x_with so the default-OFF path runs 6d12f58a's exact hand-over-then-reset sequence (inherit_for_split, bind::reset, clear_segment_state, LISTS update without writing list_type or last_queue, then reset_one(target)), without entering acquire_kickoff_target.
  2. Gated empty-batch skip (list_x.rs): Moved execute_with_waits_on's empty-batch early return behind kickoff_swap_enabled() (execute_with_waits_on_with) so default-OFF preserves main's exact submit(lists) behavior for empty batches.
  3. Default-OFF split-list test (list_x.rs): Added kickoff_x_default_off_split_list_matches_main_handover driving kickoff_x_with(seg1, false) on a live mid-list split (verifying direct resume on primary, spare_count(w) == 1, binding hand-over, and untouched primary list_type/last_queue), plus explicit assertions in kickoff_x_failure_paths_never_reset_in_flight_target for both execute_with_waits_on_with(..., true) (0 batches) and execute_with_waits_on_with(..., false) (1 batch).
  4. Timeout HRESULT (list_x.rs): acquire_kickoff_target now returns 0x80070102 (HRESULT_FROM_WIN32(ERROR_WAIT_TIMEOUT)) when the 5000 ms wait_idle fallback expires instead of E_OUTOFMEMORY.

Verification on bc3c0423 (RTX 4060 8 GB, driver 32.0.16.2114, Windows 11, rustc 1.100.0):

  • cargo clippy --tests -p xcl -- -A clippy::approx_constant -A clippy::while_immutable_condition: exit 0, 0 new warnings in touched files.
  • 3x Debug + 3x Release (hle::d3d12x::list_x:: hle::d3d12x::title_list:: hle::d3d12x::alloc_pool:: --test-threads=1 --nocapture): 56 passed; 0 failed; 0 ignored; 0 skipped.
  • Quiet 60 s default-OFF smoke (title: 29640639, XCL_NETWORK=0, XCL_KICKOFF_SWAP unset): exit 0x0, 1605 frames (60 60 60), 0 removals/crashes, peak commit: 14042 MB (vs 6d12f58a 1581 frames / 14018 MB).

Ready for your suite and world run on bc3c0423.

AI use: Google Antigravity (Gemini 4 Neon) implemented these polish items, added the default-OFF split test, and ran all local tests and the 60 s smoke on this RTX 4060.

@throny

throny commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

merge-check
base: 6089122
head: bc3c042
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 1474 passed, 0 failed, 47 ignored (26 SKIPPED lines); base alone: 1465 passed, 0 failed, 47 ignored
review: points 1-3 of my last re-check are addressed. (1) With XCL_KICKOFF_SWAP unset, kickoff_x_with repeats main's sequence: hand-over (inherit_for_split, bind::reset, clear_segment_state, LISTS update without list_type / last_queue), then Reset; a failed Reset returns after the hand-over. Remaining differences are harmless: the bound pipeline is resolved before the hand-over instead of after (no lock held), last_queue is read into the snapshot. (2) The empty-batch return is behind the switch. (3) There is a default-off test on a split list. Still open, not blocking for a default-off merge: that test checks the end state only, so a wrong order or the failed-Reset case would not fail it; the LISTS hand-over now exists twice and the two copies already differ; a timeout is logged as "Reset after kickoff failed". Size: 878 added lines (about 340 outside tests), over CONTRIBUTING's 800-line mark without a stated reason; whether to split before merging is the maintainer's call.
performance: with the switch unset, one OnceLock read per KickoffX and per ExecuteCommandLists, no new lock, no env lookup per call (reasoned). The swap path itself is not measured: no title here calls KickoffX in a way that reaches it.
verdict: safe to merge (as default-off; the swap path stays untested on a real title)
hardware / tool and model: RTX 4080 16 GB (621.40), i9-12900K, Windows 11 26300, Rust 1.100.0, debug. Claude Code; merge, build and suite run by Claude Fable 5.2, diff review by Claude Opus 5.5 (every hunk read; nothing run on the GPU beyond the suite).

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Triage (#1607) – head bc3c042

No open or merged PR switches KickoffX to a spare PC list while the submitted one is in flight; main's kickoff_x still resets this (or primary after a split) right after submitting it. The same-issue PRs (#1535, #1536, #2131, #2205, #2291, #2423, #2443, #2506, #2518) are other parts of #1452 and do not touch this path.
The branch conflicts heavily: main's kickoff_x has since gained a closed standby (reserve_closed_segment), fail-closed bookkeeping and allocator retirement, so the "default-off path identical to main" in list_x.rs kickoff_x_with matches the old base 6d12f58, not current main, and acquire_kickoff_target / create_kickoff_spare would need to be rebuilt on main's spare and standby handling. At +933 lines it is also over the size the contributing rules ask to be justified or split.
Recommendation: keep open.

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

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.