gpu: rotate desktop allocator after failed list Close before recovery #1881

Merged
R0D4X merged 2 commits from upstream-pr/1888 into main 2026-11-24 20:36:23 +00:00
R0D4X commented 2026-11-24 20:17:08 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0D4X on 2026-11-24T20:17:08Z.


Fixes #1876

Root Cause

When list_close() fails on a command list (Close() returns E_FAIL), the desktop ID3D12CommandAllocator (title.current->real) still has that failed recording attached to it. In list_reset(), the state.list_close_failed recovery branch called CreateCommandList(..., title.current->real, ...) directly on the same desktop allocator while previous was still alive and before the allocator was Reset().

  • With the D3D12 debug layer enabled, d3d12SDKLayers.dll intercepts the invalid RSSetViewports on the compute list before the UMD records it, masking the UMD fault.
  • Without the D3D12 debug layer (as on the reporter's machine where d3d12SDKLayers.dll was not installed), nvwgf2umx.dll accepts CreateCommandList on the tainted allocator and then crashes with 0xC0000005 (null read at +0x150, nvwgf2umx.dll+0x89014e) on the subsequent replacement->Close() in list_close().

Summary

  • src/startup_stubs/d3d12_xs_device.cpp:
    • Track bool close_failed on DesktopAllocator (set in list_close() when Close() fails; cleared in allocator_reset() / spare reuse after ID3D12CommandAllocator::Reset() succeeds).
    • In list_reset(), when title.current->close_failed is true and title.type == type, rotate to an idle spare desktop allocator (after Reset()) or allocate a fresh one before opening the replacement/reset command list, leaving the tainted allocator untouched until previous is released and the allocator is reset. Wrong-type allocator calls (e.g., DIRECT allocator for a COMPUTE list) still fail CreateCommandList with E_INVALIDARG without touching the pool.
  • tests/startup_list_resubmit.cpp:
    • Assert in step 7 that x2w_d3d12_allocator_pool_size(compute_b) == 2 after recovery (catches reusing the tainted allocator even on WARP or with the debug layer active).
    • Reset compute_b after the step 7 submissions complete and verify the pool size stays 2 (the retired desktop allocator is cleanly Reset() and reused) and a follow-up Reset/Close/submit on compute_b succeeds cleanly.
  • CMakeLists.txt:
    • Add startup_list_resubmit_nodebug_warp and startup_list_resubmit_nodebug_hardware (without X2W_D3D12_DEBUG=1) so hosts with the debug layer installed also exercise the direct UMD path.

Verification

  • Base commit: 59c9e234 (upstream/main)
  • Host environment: Windows 11 x64 (10.0.26300.9974), MSVC 19.44.35230, Windows SDK 10.0.26100.0
  • WARP: Microsoft Basic Render Driver (1414:008c), driver 10.0.26100.9818
  • Hardware GPU: NVIDIA GeForce RTX 5080 (10de:2c02), driver 32.0.16.2124

Before / After A/B on RTX 5080 (no D3D12 debug layer)

Running out/build/dev/startup_list_resubmit.exe hardware and hardware untracked with X2W_D3D12_PERMISSIVE=1 X2W_D3D12_LIST_NOOP=1 X2W_D3D12_RENDER=1 and X2W_D3D12_DEBUG unset:

  • Before fix (59c9e234): both crashed with 0xC0000005 at nvwgf2umx.dll+0x89014e (read of 0x150) inside list_close() -> replacement->Close().
  • After fix: both exit 0 (7 recovered Reset: 0x00000000, Close: 0x00000000, desktop allocators behind compute_b: 2, device removed reason: 0x00000000).

Commands and Observed Results

ctest --preset dev --no-tests=error -j 1 -R '^startup_list_resubmit' -V
  • Observed: 6 passed, 0 skipped, 0 failed (startup_list_resubmit_{warp,nodebug_warp,untracked_warp,hardware,nodebug_hardware,untracked_hardware}), debug layer enabled on the non-nodebug runs with 0 unexpected errors.
ctest --preset release --no-tests=error -j 1 -R '^startup_list_resubmit' -V
  • Observed: 6 passed, 0 skipped, 0 failed (2.64 s).
ctest --preset pr --no-tests=error -j 1 --output-on-failure
.\out\pe-env\Scripts\python.exe -B tests/docs_links_check.py
.\out\pe-env\Scripts\python.exe -B tests/bidi_controls_check.py
  • Observed: pr 23 passed, 4 skipped (spirv_minlod*_warp, local pinned SPIR-V tools not installed), 0 failed (17.51 s); docs_links_check.py: 18 files / 376 links ok; bidi_controls_check.py: 1330 files ok.

  • Scope note: these source-built fixtures verify command-list recovery after a failed Close() on WARP and RTX 5080; they do not establish full-game startup.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6590580202 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1888). Originally posted by [R0D4X](https://github.com/R0D4X) on 2026-11-24T20:17:08Z. --- Fixes #1876 ## Root Cause When `list_close()` fails on a command list (`Close()` returns `E_FAIL`), the desktop `ID3D12CommandAllocator` (`title.current->real`) still has that failed recording attached to it. In `list_reset()`, the `state.list_close_failed` recovery branch called `CreateCommandList(..., title.current->real, ...)` directly on the same desktop allocator while `previous` was still alive and before the allocator was `Reset()`. - With the D3D12 debug layer enabled, `d3d12SDKLayers.dll` intercepts the invalid `RSSetViewports` on the compute list before the UMD records it, masking the UMD fault. - Without the D3D12 debug layer (as on the reporter's machine where `d3d12SDKLayers.dll` was not installed), `nvwgf2umx.dll` accepts `CreateCommandList` on the tainted allocator and then crashes with `0xC0000005` (null read at `+0x150`, `nvwgf2umx.dll+0x89014e`) on the subsequent `replacement->Close()` in `list_close()`. ## Summary - **`src/startup_stubs/d3d12_xs_device.cpp`**: - Track `bool close_failed` on `DesktopAllocator` (set in `list_close()` when `Close()` fails; cleared in `allocator_reset()` / spare reuse after `ID3D12CommandAllocator::Reset()` succeeds). - In `list_reset()`, when `title.current->close_failed` is true and `title.type == type`, rotate to an idle spare desktop allocator (after `Reset()`) or allocate a fresh one before opening the replacement/reset command list, leaving the tainted allocator untouched until `previous` is released and the allocator is reset. Wrong-type allocator calls (e.g., DIRECT allocator for a COMPUTE list) still fail `CreateCommandList` with `E_INVALIDARG` without touching the pool. - **`tests/startup_list_resubmit.cpp`**: - Assert in step 7 that `x2w_d3d12_allocator_pool_size(compute_b) == 2` after recovery (catches reusing the tainted allocator even on WARP or with the debug layer active). - Reset `compute_b` after the step 7 submissions complete and verify the pool size stays `2` (the retired desktop allocator is cleanly `Reset()` and reused) and a follow-up `Reset`/`Close`/submit on `compute_b` succeeds cleanly. - **`CMakeLists.txt`**: - Add `startup_list_resubmit_nodebug_warp` and `startup_list_resubmit_nodebug_hardware` (without `X2W_D3D12_DEBUG=1`) so hosts with the debug layer installed also exercise the direct UMD path. ## Verification - **Base commit:** `59c9e234` (`upstream/main`) - **Host environment:** Windows 11 x64 (`10.0.26300.9974`), MSVC `19.44.35230`, Windows SDK `10.0.26100.0` - **WARP:** `Microsoft Basic Render Driver` (`1414:008c`), driver `10.0.26100.9818` - **Hardware GPU:** `NVIDIA GeForce RTX 5080` (`10de:2c02`), driver `32.0.16.2124` ### Before / After A/B on RTX 5080 (no D3D12 debug layer) Running `out/build/dev/startup_list_resubmit.exe hardware` and `hardware untracked` with `X2W_D3D12_PERMISSIVE=1 X2W_D3D12_LIST_NOOP=1 X2W_D3D12_RENDER=1` and `X2W_D3D12_DEBUG` unset: - **Before fix (`59c9e234`):** both crashed with `0xC0000005` at `nvwgf2umx.dll+0x89014e` (read of `0x150`) inside `list_close()` -> `replacement->Close()`. - **After fix:** both exit `0` (`7 recovered Reset: 0x00000000, Close: 0x00000000`, `desktop allocators behind compute_b: 2`, `device removed reason: 0x00000000`). ### Commands and Observed Results ```powershell ctest --preset dev --no-tests=error -j 1 -R '^startup_list_resubmit' -V ``` - Observed: **6 passed, 0 skipped, 0 failed** (`startup_list_resubmit_{warp,nodebug_warp,untracked_warp,hardware,nodebug_hardware,untracked_hardware}`), debug layer enabled on the non-`nodebug` runs with `0` unexpected errors. ```powershell ctest --preset release --no-tests=error -j 1 -R '^startup_list_resubmit' -V ``` - Observed: **6 passed, 0 skipped, 0 failed** (2.64 s). ```powershell ctest --preset pr --no-tests=error -j 1 --output-on-failure .\out\pe-env\Scripts\python.exe -B tests/docs_links_check.py .\out\pe-env\Scripts\python.exe -B tests/bidi_controls_check.py ``` - Observed: `pr` **23 passed, 4 skipped** (`spirv_minlod*_warp`, local pinned SPIR-V tools not installed), **0 failed** (17.51 s); `docs_links_check.py`: 18 files / 376 links ok; `bidi_controls_check.py`: 1330 files ok. - Scope note: these source-built fixtures verify command-list recovery after a failed `Close()` on WARP and RTX 5080; they do not establish full-game startup.
upstream-sync closed this pull request 2026-11-24 21:01:08 +00:00
ChazY11 commented 2026-11-24 21:01:22 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-24T20:23:07Z.


Built it, ran it, broke one of the three mechanisms

At the PR head, Windows 11 build 26300.9974, WARP 10.0.26100.9818 and the three GPU-less variants:

cmake --preset dev
cmake --build --preset dev --target startup_list_resubmit
ctest --preset dev -R '^startup_list_resubmit'
100% tests passed, 0 tests failed out of 6

Three mutations to src/startup_stubs/d3d12_xs_device.cpp, each rebuilt into d3d12_xs.dll (timestamp verified) and reverted:

mutation result
if (target->close_failed && title.type == type) → if (false) (keep using the tainted allocator) caught
the rotation's SUCCEEDED(spare->real->Reset()) dropped not caught
a freshly created allocator constructed with close_failed = true not caught

So the decision to stop using a tainted allocator is pinned — which is the root cause in the description — while the two
details around it are not distinguishable with this fixture. Neither looks equivalent on inspection, so I would rather say
what each would need than call them gaps:

  • The Reset() on the spare matters when the spare has been used and is idle. A case where title.pool already holds a
    spent allocator that needs resetting before reuse would separate it; if the fixture only ever rotates to a never-used spare,
    Reset() is a no-op there.
  • close_failed = true on a new allocator only changes behaviour on the next list_reset on that allocator. One extra
    reset-then-close cycle after the rotation would make it fail.

Both are cheap additions to tests/startup_list_resubmit.cpp if you want the rotation pinned in the same depth as the
decision.

What the change gets right

The recovery no longer calls CreateCommandList on an allocator whose failed recording is still attached, and it looks for an
idle spare before creating one — which is the right order for a driver that faults on a second recording. The
list_close_failed flag on the wrapper stays for the "replacement needed" case, so the two states (this list failed, this
allocator is tainted) are now separate, which is what the root-cause paragraph describes.

One question

allocator_idle(spare) presumably consults spare->submits against the fence. If a spare has an untracked submit (the
existing untracked flag), is it excluded from rotation? Reading the loop I could not tell whether allocator_idle returns
false for an untracked allocator or whether that case cannot reach here.

Verdict

Reviewed. The fix addresses the reported crash path and its central decision is pinned by a mutation; the two surrounding
details are not yet distinguishable.

Notes

  • AI-assisted review.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7143464152 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1888#issuecomment-7143464152). Originally posted by [ChazY11](https://github.com/ChazY11) on 2026-11-24T20:23:07Z. --- ## Built it, ran it, broke one of the three mechanisms At the PR head, Windows 11 build 26300.9974, WARP 10.0.26100.9818 and the three GPU-less variants: ```powershell cmake --preset dev cmake --build --preset dev --target startup_list_resubmit ctest --preset dev -R '^startup_list_resubmit' 100% tests passed, 0 tests failed out of 6 ``` Three mutations to `src/startup_stubs/d3d12_xs_device.cpp`, each rebuilt into `d3d12_xs.dll` (timestamp verified) and reverted: | mutation | result | |---|---| | `if (target->close_failed && title.type == type)` → `if (false)` (keep using the tainted allocator) | **caught** | | the rotation's `SUCCEEDED(spare->real->Reset())` dropped | not caught | | a freshly created allocator constructed with `close_failed = true` | not caught | So the *decision* to stop using a tainted allocator is pinned — which is the root cause in the description — while the two details around it are not distinguishable with this fixture. Neither looks equivalent on inspection, so I would rather say what each would need than call them gaps: - **The `Reset()` on the spare** matters when the spare has been used and is idle. A case where `title.pool` already holds a spent allocator that needs resetting before reuse would separate it; if the fixture only ever rotates to a never-used spare, `Reset()` is a no-op there. - **`close_failed = true` on a new allocator** only changes behaviour on the *next* `list_reset` on that allocator. One extra reset-then-close cycle after the rotation would make it fail. Both are cheap additions to `tests/startup_list_resubmit.cpp` if you want the rotation pinned in the same depth as the decision. ## What the change gets right The recovery no longer calls `CreateCommandList` on an allocator whose failed recording is still attached, and it looks for an idle spare **before** creating one — which is the right order for a driver that faults on a second recording. The `list_close_failed` flag on the wrapper stays for the "replacement needed" case, so the two states (this list failed, this allocator is tainted) are now separate, which is what the root-cause paragraph describes. ## One question `allocator_idle(spare)` presumably consults `spare->submits` against the fence. If a spare has an untracked submit (the existing `untracked` flag), is it excluded from rotation? Reading the loop I could not tell whether `allocator_idle` returns false for an untracked allocator or whether that case cannot reach here. ## Verdict Reviewed. The fix addresses the reported crash path and its central decision is pinned by a mutation; the two surrounding details are not yet distinguishable. ## Notes - AI-assisted review.
R0Y00 commented 2026-11-24 21:01:22 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T20:32:31Z.


Reproduced the recovery Close crash on main in both hardware submission modes with SDKLayers disabled, then verified the allocator rotation on RTX 4060 Laptop (616.56), Windows 11 26200.9974 and WARP. I added the untracked/no-debug-layer combination to CTest and made the debug-off setting explicit, alongside the recovery note. Debug ctest --preset dev --no-tests=error -R '^startup_list_resubmit_' passed all eight cases, no skips. The production code is unchanged in this follow-up. An independent local diagnostic that held the original list alive also passed, so the measured conclusion is that rotating the allocator fixes the tested failure, without needing to assign a unique internal driver cause.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7143704290 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1888#issuecomment-7143704290). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T20:32:31Z. --- Reproduced the recovery Close crash on main in both hardware submission modes with SDKLayers disabled, then verified the allocator rotation on RTX 4060 Laptop (616.56), Windows 11 26200.9974 and WARP. I added the untracked/no-debug-layer combination to CTest and made the debug-off setting explicit, alongside the recovery note. Debug ctest --preset dev --no-tests=error -R '^startup_list_resubmit_' passed all eight cases, no skips. The production code is unchanged in this follow-up. An independent local diagnostic that held the original list alive also passed, so the measured conclusion is that rotating the allocator fixes the tested failure, without needing to assign a unique internal driver cause.
ChazY11 commented 2026-11-24 21:01:25 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-24T21:01:06Z.


Follow-up on the two mutants I reported as not caught before the merge. I re-ran them against the merged fixture (69 commits,
f8f9bd7f), rebuilding d3d12_xs.dll and checking its timestamp each time, then running the three WARP variants:

cmake --build --preset dev --target d3d12_xs_shim
ctest --preset dev -R '^startup_list_resubmit_.*_warp$'
100% tests passed, 0 tests failed out of 3        # baseline, and again after each revert
mutation result
if (spare != title.current && allocator_idle(spare) && SUCCEEDED(spare->real->Reset())) → drop the Reset() still not caught
target = new DesktopAllocator{created, 0, {}, false, true}; (a new allocator born close_failed) still not caught

Step 6 and step 7 in the merged test do cover rotation and the failed-Close recovery, so this is not missing coverage of the
situation — it is two details inside it that the assertions cannot separate:

  • The Reset() on the spare. It only matters when the spare has been recorded on before. Step 6's reused allocator is idle
    but, as far as I can tell, has never carried a recording, so Reset() and "no Reset()" behave the same there. A step where
    the spare carried a list that was submitted and completed, then is reused, would make the call load-bearing (and the debug
    layer would flag a recording on an unreset allocator).
  • close_failed = true on a fresh allocator. It only changes the next list_reset on that allocator. Step 7 creates an
    allocator through the rotation path and then finishes, so nothing exercises a second reset on it. One extra
    Reset/Close cycle after the recovery would pin it.

Both are extensions of the existing steps rather than new scenarios, which is why I am reporting them here instead of opening a
change on top of a fresh merge. If you would rather have them as a patch, say so and I will send the two steps.

Measurement note for anyone repeating this: this test loads d3d12_xs.dll, so mutating the source and rebuilding
startup_list_resubmit shows "not rebuilt" and proves nothing.

  • AI-assisted.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7144364610 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1888#issuecomment-7144364610). Originally posted by [ChazY11](https://github.com/ChazY11) on 2026-11-24T21:01:06Z. --- Follow-up on the two mutants I reported as not caught before the merge. I re-ran them against the merged fixture (69 commits, `f8f9bd7f`), rebuilding **`d3d12_xs.dll`** and checking its timestamp each time, then running the three WARP variants: ```powershell cmake --build --preset dev --target d3d12_xs_shim ctest --preset dev -R '^startup_list_resubmit_.*_warp$' 100% tests passed, 0 tests failed out of 3 # baseline, and again after each revert ``` | mutation | result | |---|---| | `if (spare != title.current && allocator_idle(spare) && SUCCEEDED(spare->real->Reset()))` → drop the `Reset()` | still not caught | | `target = new DesktopAllocator{created, 0, {}, false, true};` (a new allocator born `close_failed`) | still not caught | Step 6 and step 7 in the merged test do cover rotation and the failed-`Close` recovery, so this is not missing coverage of the *situation* — it is two details inside it that the assertions cannot separate: - **The `Reset()` on the spare.** It only matters when the spare has been recorded on before. Step 6's reused allocator is idle but, as far as I can tell, has never carried a recording, so `Reset()` and "no `Reset()`" behave the same there. A step where the spare carried a list that was submitted and completed, then is reused, would make the call load-bearing (and the debug layer would flag a recording on an unreset allocator). - **`close_failed = true` on a fresh allocator.** It only changes the *next* `list_reset` on that allocator. Step 7 creates an allocator through the rotation path and then finishes, so nothing exercises a second reset on it. One extra `Reset`/`Close` cycle after the recovery would pin it. Both are extensions of the existing steps rather than new scenarios, which is why I am reporting them here instead of opening a change on top of a fresh merge. If you would rather have them as a patch, say so and I will send the two steps. Measurement note for anyone repeating this: this test loads `d3d12_xs.dll`, so mutating the source and rebuilding `startup_list_resubmit` shows "not rebuilt" and proves nothing. - AI-assisted.
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
R0Y00/Xbox2Windows!1881
No description provided.