startup: keep closed lists submittable across their allocator's Reset #1350
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1357"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by Jess-Doit on 2026-11-24T09:10:06Z.
Change
Fixes #1352.
In
X2W_D3D12_RENDER=1mode, the D3D12 stand-in (src/startup_stubs/d3d12_xs_device.cpp) had two problems:queue_executeclearedlist_readyon a list's first submit, so later submits of the same closed list did nothing. Desktop D3D12 allows a closed list to be executed again until it is reset.Now, in render mode only:
retire_draw_sampler_heapsgives each submit its own references to the list's sampler heaps. Before, it moved them into the first submit's batch, which a second submit would have outlived. The list keeps its own references untildiscard_draw_sampler_heapsat its next Reset.ExecuteCommandListshas already run when the tracking fence is created and signalled. If either step fails, each submitted list's allocator is marked untracked and is never reset or reused again. Its GPU work keeps its memory, at the cost of one allocator.releaseonly counts), so a later object cannot reuse an entry.Outside render mode nothing changes: allocator Reset is forwarded, and lists record on the allocator they were reset with.
Fixture
tests/startup_list_resubmit.cppgoes throughD3D12XboxCreateDevicewithX2W_D3D12_PERMISSIVE=1 X2W_D3D12_LIST_NOOP=1 X2W_D3D12_RENDER=1 X2W_D3D12_DEBUG=1.ff0000ffffff0000x2w_d3d12_allocator_pool_size(a)= 2, because the earlier allocator the GPU has passed is reused; bluestartup_list_resubmit_untracked_*runs the same probe withX2W_TEST_SUBMIT_FENCE_FAIL=1, which makes every submit fence fail. Steps 1–5 must read the same. Nothing may be reset or reused, so step 6 must find 4 desktop allocators behind a.At the end,
GetDeviceRemovedReasonmust beS_OK, and the debug layer must have stored no error or corruption messages (ID3D12InfoQueue). In step 3 the stand-in logsallocator … Reset -> 0x00000000, 2 desktop allocators.Negative controls:
With
src/startup_stubsfrommain(before #1348), the probe fails at step 2 on both adapters (exit 23):With the per-queue fence check removed from
allocator_idle, step 5 fails on both adapters (exit 56). The readback returns00000000instead of the pending blue clear.With the
untrackedcheck removed fromallocator_idle,startup_list_resubmit_untracked_*fails at step 5 on both adapters in the same way. The allocator holding the pending submit is reset, because its failed fence left no submit to wait for.Verification
Tested
a14064ec(on a merge ofmainatb9c9f624) on Windows 10 22H219045.6456with a GTX 1060 6 GB (10de:1c03, driver32.0.15.6094) and in-box WARP (10.0.19041.5794), with the D3D12 debug layer enabled.startup_list_resubmit_{,untracked_}{warp,hardware}, the selection coversstartup_queue_wait_*and the existing render-mode tests that submit throughqueue_execute: stream request and draw, MRT, BC7 draw, address SRV, address BC view, BC chain, dump fence, plane refresh and NV12 draw.tests/docs_links_check.py: passed.Probe output, the same on both adapters:
The
untrackedruns print the same lines, except6 desktop allocators behind a: 4 (expected 4).CI runs
startup_list_resubmit_warpin the Debug and Release Windows jobs.Not covered
X2W_DRAW_DUMP_FRAMEreadback tracker was not checked with resubmitted lists.AI-assisted (Claude Code).
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T09:16:10Z.
Review: COMMENTED
Technical peer-review at commit
fc6d25db6a6d4bc1a68067d8ee8aafdbd6f7467a.Verification
git diff --check origin/main...HEAD: clean.tests/docs_links_check.py: passed (16 Markdown files, 301 links).tests/bidi_controls_check.py: passed (1130 tracked files).--preset dev): 11/11 passed (startup_list_resubmit_{warp,hardware},startup_stream_{request,draw}_*,startup_mrt_{fxc,dxc}_*,startup_xg_bc7_draw_*) in6.90s(build 25.24s)./O2(--preset release): 11/11 passed in8.28s(build 42.04s).Code Review Notes
draw_lock->allocator_lockinnote_submits;list_resetreleasesallocator_lockbeforediscard_draw_sampler_heaps), andretire_draw_sampler_heapsnow copiesComPtrs per submit so resubmissions retain sampler heap references untillist_reset.device_create_command_list_x(src/startup_stubs/d3d12_xs_device.cpp:2210): Passesunwrap(allocator)(the initialID3D12CommandAllocator*) rather thantitle_allocator(a).current->real. If a new list is created afterallocator_resethas swappedcurrent,CreateCommandListwill touch the older/busy desktop allocator (though it immediatelyClose()s the list).allocator_reset(src/startup_stubs/d3d12_xs_device.cpp:1060-1061):next->submits.clear()runs beforenext->real->Reset(); moving it insideif (SUCCEEDED(hr))would avoid mutating state on a failedReset.tests/startup_list_resubmit.cppexercises theallocator->lists != 0swap path and resubmission acrossallocator_reset, though as noted in the PR description,Probe::submitwaits on the fence after each submit so the in-flight GPU fence branch (GetCompletedValue() < submit.second) is not exercised by the test.Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T09:26:17Z.
Review: CHANGES_REQUESTED
The resubmission control covers the recorded-but-idle case. The critical untested case is a submit already queued behind an unsignaled fence and a later list Reset releasing its recording. Please add a two-queue or explicit fence-gated fixture for that case, with readback and a prior-allocator reuse control. Also ensure that a failed internal retire-fence creation or Signal cannot mark that allocation reusable: ExecuteCommandLists has already happened. Keep the native GPU work lifetime even when retirement bookkeeping fails, and resync the two queue changes on main.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T09:53:06Z.
Review: COMMENTED
Technical retest & peer-review at commit
a14064ec28d773ab4582cf11abb762d5b7d39107:Verification
git diff --check origin/main...HEAD: clean.tests/docs_links_check.py: passed (16 Markdown files, 303 links).tests/bidi_controls_check.py: passed (1,150 tracked files).--preset dev): 9/9 passed in2.15s(build25.66s):startup_list_resubmit_{warp,hardware},startup_list_resubmit_untracked_{warp,hardware},startup_queue_wait_{warp,hardware},startup_stream_request_warp,startup_stream_draw_{warp,hardware}./O2(--preset release): 9/9 passed in1.91s(build37.75s): 9/9 passed.Retest of Earlier Findings
device_create_command_list_x(src/startup_stubs/d3d12_xs_device.cpp): Resolved — now resolvestitle_allocator(a).current->realunderallocator_lockinstead of passing the initialunwrap(allocator).allocator_reset(src/startup_stubs/d3d12_xs_device.cpp): Resolved —next->submits.clear(),allocator_swaps, andtitle.current = nextnow run only insideif (SUCCEEDED(hr))afternext->real->Reset().tests/startup_list_resubmit.cppstep 5 queues a submit behind an unsignalled fence (queue_waitslot 17), resets the list onto another allocator, resets the first allocator, and verifies the pending submit still renders blue after the CPU signals the fence with zeroID3D12InfoQueueerrors. Step 6 verifies prior-allocator reuse (pool size 2), andX2W_TEST_SUBMIT_FENCE_FAIL=1(startup_list_resubmit_untracked_*) verifies untracked allocators are never reset or reused (pool size 4).Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T09:58:27Z.
Review: APPROVED
Re-reviewed
a14064ec. A submit without a usable retirement fence now marks each affected allocator as unavailable for reuse. Windows Release passed all six cases fromctest --preset release --no-tests=error -R "^startup_(list_resubmit|queue_wait)_"on WARP and RTX 4060 Laptop. This covers the queued submit behind a gate, resetting its list and allocator, and the injected unavailable retirement fence. There were no skips.Imported from R0Y00/Xbox2Windows. Originally posted by Jess-Doit on 2026-11-24T09:28:34Z.
Thanks for the review. All three points are addressed in
8e2162de, which also mergesmain(after #1348):device_create_command_list_x: now creates the list ontitle_allocator(a).current->real, the desktop allocator the title's allocator currently stands for.allocator_reset:next->submits.clear()and the swap counter now run only after the desktopResetsucceeds.ID3D12InfoQueue.allocator_idle, step 5 fails on both adapters (exit 56; the readback returns00000000).Debug and Release each passed 24/24 on the GTX 1060 and WARP: the probe,
startup_queue_wait_*and the existing render-mode tests.Imported from R0Y00/Xbox2Windows. Originally posted by Jess-Doit on 2026-11-24T09:37:45Z.
@R0Y00 thanks. These are addressed in
8e2162deanda14064ec, which also mergemainatb9c9f624(both queue changes from #1348 included):ID3D12InfoQueue). With the fence check removed, step 5 reads00000000on both adapters (exit 56).x2w_d3d12_allocator_pool_size(a)(a new fixture export) stays at 2. A then records and draws on it.ExecuteCommandLists, each submitted list's allocator is marked untracked and is never reset or reused.startup_list_resubmit_untracked_*forces that withX2W_TEST_SUBMIT_FENCE_FAIL=1. Steps 1–5 must read the same, including the pending blue, and step 6 must find 4 allocators: nothing is reused.untrackedcheck removed, that test fails at step 5 on both adapters.Debug and Release each passed 26/26 on the GTX 1060 and WARP: both probe variants,
startup_queue_wait_*and the existing render-mode tests.