d3d12: split memory_wait lists safely, elide satisfied waits, and track cross-submit writes #186

Manually merged
github merged 1 commit from gh-pr/186/head into gh-pr/186/base 2026-11-26 06:37:03 +00:00
Owner

@⁠Vladimir-Human on GitHub · 2026-11-25 18:09 UTC · original
Vladimir-Human:d3d12/fix-memory-wait-stalls → main · +3415 −676 · 26 files · 1 commits · merged 2026-11-25 19:03 UTC

AI-assisted PR. Rebased onto main (4cb6a4a, preserving PR #183 dispatch-wait and split COM/allocator lifetime improvements).

Summary

Eliminates repeated CPU/GPU synchronization stalls and allocator overhead in runtime/d3d12 memory_wait handling (runtime/d3d12/src/ only):

  • Splits memory_wait segments cleanly across COPY, COMPUTE, and DIRECT queues with full bound-state replay (OMSetRenderTargets CPU snapshot, OMSetBlendFactor(NULL) -> [1.0; 4] per Direct3D spec), retaining prefix guest allocator and split tail COM references across submission and marking native_open = false unconditionally before propagating Close() errors.
  • Supports all 8 Comparison predicate ops (1..=8) and safely elides pre-satisfied waits via bounded in-flight cross-submission write tracking (queue_trace::note / retire_fence progress + IN_FLIGHT_WRITES), blocking unsafe elision across both same-queue and cross-queue submissions while delivering 0-fence elision on read-only/retired waits.
  • Uses a persistent per-queue monotonic fence + fast wakeup notifier and RAII PendingWaits / Job::Drop leak guards for placement::held::Waits.
  • All modified Rust files remain <= 1,200 lines with zero inline #[cfg(test)] modules.

Verification (commit 6bae7109, RTX 4070 SUPER 10de:2783)

  • python -m unittest tests.test_repository_hygiene -v: 4/4 PASS (max .rs file 1,166 lines <= 1,200)
  • cargo test --manifest-path runtime/d3d12/Cargo.toml: 125 passed, 0 failed
  • python build.py d3d12 + python build.py lanes: PASS
  • build/lanes/lanes.exe --selftest dispatch-wait --adapter 10de:2783: PASS (wait=list-start & wait=after-dispatch)
  • build/lanes/lanes.exe --selftest all --adapter 10de:2783: 13/13 PASS
  • D3D12 smoke (queues, draw, tables, indirect, copy-resource, buffer-import) + D3D12 Debug Layer probes (F1–F3, in-flight Reset/Release, Fresh split, open query): ALL PASS, 0 unexpected errors
  • BEFORE (7b22d71) vs AFTER (fca35761, rebased 6bae7109): 1,000 pre-satisfied waits 44.54 ms (1,000 fences) -> 1.71 ms (0 fences, 1,000 elided) (26.0x faster); delayed cross-queue wakeup 1,696.4 -> 291.4 µs (5.82x); lanes --benchmark PASS.
  • git merge-tree --write-tree clean vs origin/main (4cb6a4a) and PR #185.
**@⁠Vladimir-Human** on GitHub · 2026-11-25 18:09 UTC · [original](https://github.com/brcly/TuxBox/pull/186) `Vladimir-Human:d3d12/fix-memory-wait-stalls` → `main` · +3415 −676 · 26 files · 1 commits · merged 2026-11-25 19:03 UTC AI-assisted PR. Rebased onto `main` (`4cb6a4a`, preserving PR `#183` `dispatch-wait` and split COM/allocator lifetime improvements). ### Summary Eliminates repeated CPU/GPU synchronization stalls and allocator overhead in `runtime/d3d12` `memory_wait` handling (`runtime/d3d12/src/` only): - Splits `memory_wait` segments cleanly across COPY, COMPUTE, and DIRECT queues with full bound-state replay (`OMSetRenderTargets` CPU snapshot, `OMSetBlendFactor(NULL)` -> `[1.0; 4]` per Direct3D spec), retaining prefix guest allocator and split tail COM references across submission and marking `native_open = false` unconditionally before propagating `Close()` errors. - Supports all 8 `Comparison` predicate ops (`1..=8`) and safely elides pre-satisfied waits via bounded **in-flight cross-submission write tracking** (`queue_trace::note` / `retire_fence` progress + `IN_FLIGHT_WRITES`), blocking unsafe elision across both same-queue and cross-queue submissions while delivering **0-fence elision** on read-only/retired waits. - Uses a persistent per-queue monotonic fence + fast wakeup notifier and RAII `PendingWaits` / `Job::Drop` leak guards for `placement::held::Waits`. - All modified Rust files remain `<= 1,200` lines with zero inline `#[cfg(test)]` modules. ### Verification (commit `6bae7109`, RTX 4070 SUPER `10de:2783`) - `python -m unittest tests.test_repository_hygiene -v`: **4/4 PASS** (max `.rs` file `1,166` lines `<= 1,200`) - `cargo test --manifest-path runtime/d3d12/Cargo.toml`: **125 passed, 0 failed** - `python build.py d3d12` + `python build.py lanes`: **PASS** - `build/lanes/lanes.exe --selftest dispatch-wait --adapter 10de:2783`: **PASS** (`wait=list-start` & `wait=after-dispatch`) - `build/lanes/lanes.exe --selftest all --adapter 10de:2783`: **13/13 PASS** - D3D12 smoke (`queues`, `draw`, `tables`, `indirect`, `copy-resource`, `buffer-import`) + D3D12 Debug Layer probes (F1–F3, in-flight Reset/Release, Fresh split, open query): **ALL PASS, 0 unexpected errors** - BEFORE (`7b22d71`) vs AFTER (`fca35761`, rebased `6bae7109`): 1,000 pre-satisfied waits `44.54 ms (1,000 fences)` -> `1.71 ms (0 fences, 1,000 elided)` (**26.0x faster**); delayed cross-queue wakeup `1,696.4 -> 291.4 µs` (**5.82x**); `lanes --benchmark` PASS. - `git merge-tree --write-tree` clean vs `origin/main` (`4cb6a4a`) and PR `#185`.
Rebased onto origin/main (4cb6a4a, preserving PR #183's dispatch-wait
selftest, split tail ownership in submit.rs, prefix allocator retention,
and raytracing replay error propagation):

- Support all eight D3D12 comparison functions (NEVER..ALWAYS, 1..=8) in
  Wait64BitValueX without poisoning the command list or dropping
  bottom-of-pipe writes, short-circuiting only mathematical tautologies
  (ALWAYS, >= 0, <= u64::MAX).
- Extend mid-list segment splitting and bound-state replay across COPY
  (including compact DMA lists), COMPUTE, and DIRECT command lists
  (replaying heaps, compute/graphics root signatures and arguments,
  PSO/state object, IA/SO/RS/OM state with CPU-snapshotted RTV/DSV
  descriptors, OMSetBlendFactor(NULL) -> [1.0; 4], and predication),
  retaining barrier fallback only for open non-timestamp queries,
  post-ExecuteBundle lists before ClearState, unsnapshotted RTV/DSV
  handles, or BUNDLE lists.
- Guard failed split_active() native Close() by setting native_open =
  false unconditionally and preserving existing recording errors in Close().
- Replace per-wait CreateFence allocations with one persistent monotonic
  ID3D12Fence and persistent wait event per queue, plus RAII PendingWaits
  and Job::Drop guards so placement held waits never leak or double-release.
- Add safe submission-time wait elision for prefix-free monotone waits
  backed by conservative intra-list, intra-batch, and device-wide
  cross-submission in-flight write tracking (reusing the queue progress
  fence from queue_trace::note with retire_fence fallback).
- Replace unconditional 1 ms sleep polling with a shared wakeup notifier
  bridged to a process-lifetime event armed on queue progress fences.
- Add unit and D3D12 GPU integration/regression tests in
  runtime/d3d12/src/tests/commands/{memory_wait.rs,memory_wait_regressions.rs}.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:37:02 +00:00
github manually merged commit 6bae71091f into gh-pr/186/base 2026-11-26 06:37:03 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.