startup: return E_OUTOFMEMORY when a D3D12 wrapper cannot be allocated #2648
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2656"
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 Not-Saii on 2026-11-26T00:48:24Z.
Change
Fixes #2653.
wrap()insrc/startup_stubs/d3d12_xs_device.cppused the_aligned_mallocresult without a check. Under the job commit limit, a failed wrapper allocation became a write through a null pointer insided3d12_xs.dll, so the title never saw an error. This was seen at the slot 55 derived-pipeline placeholder in a startup run, reported on #2653 and #1199.wrap()returnsnullptrwhen the allocation fails, logging the first four failures. It also catchesstd::bad_allocfrom the registry insert and frees the block.E_OUTOFMEMORYwith a null output. The descriptor heap also frees backing memory the stand-in allocated for it, and the placed buffer drops its linear-buffer entry.x2w_startup::attach_devicekeeps its documented ownership: on failure it releases the device reference and leaves*wrappednull.D3D12XboxCreateDevicethen returnsE_OUTOFMEMORY. The device used for removal reporting is recorded only after the wrapper exists.x2w_d3d12_fail_wraps(count): the nextcountwrapper allocations fail. It is used only by the new test.Not changed: memory that the committed-resource path takes from the title's own allocator stays allocated on this failure, because the stand-in has no free hook for it (commented at the call site). The memory growth behind the original stop belongs to #1199.
Verification
Branch head
6864ec86on8972929c; it merges cleanly with the currentmain. Windows 11 Pro 26300.9974, MSVC 19.44 (14.44.35207), Windows SDK 10.0.26100.0,devpreset. Backend: WARP. D3D12 debug layer off (X2W_D3D12_DEBUG=0).startup_wrap_allocation_warp: passed. Device creation and slots 8, 9, 14, 16, 55, 73 and 127 each returnedE_OUTOFMEMORYwith a null output when armed, thenS_OK.startup_wrap_allocation_control_warp: passed. The control never arms the failure, so all eight checks fail and the fixture printsFAIL:.startup_wrap_allocation_warpfailed onDevice::slot55 derived pipeline ... returned 0x00000000 and a null output. With the slot 73 null check removed, it crashed (segfault) at slot 73, the original failure.Related stand-in tests after a full
devbuild:84 of 84 passed, with no capability skips.
tests/docs_links_check.pyandtests/bidi_controls_check.pyalso pass. Hardware variants were not run.Evidence and follow-up
The fixture is source-built: it creates the device through
D3D12XboxCreateDeviceon WARP and calls the device slots with synthetic descriptors (an empty serialized root signature, a direct queue, a four-entry view heap). It covers 8 of the 16 call sites: device creation, slot 9 (the sharedcreate_slotpath), queue slot 8, descriptor heap, root signature, command list, committed resource and the slot 55 placeholder. The other 8 (queue slot 48, two command-signature placeholders, placed buffer, placed texture and three pipeline paths) follow the same pattern and were checked by reading. The placed-buffer, placed-texture and stream-pipeline paths need title memory or translated shaders to reach; the others could be added cheaply. Whether a title handlesE_OUTOFMEMORYfrom these slots is not established.Docs: new "Wrapper allocation failure" section in
docs/startup-runtime.mdwith the test command.Checklist
AI-assisted (Claude Code).
🤖 Generated with Claude Code
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T00:51:17Z.
Review: COMMENTED
Review of head
a526db0e(comment only, no Win2025 run by me).What I read:
wrap()null/bad_alloc handling and all new caller paths insrc/startup_stubs/d3d12_xs_device.cpp, theattach_deviceownership change, the new test and its CMake entries, and the docs change.E_OUTOFMEMORYwith a null output. I found no leaked reference. The budget tickets andbacking_budget->begin_use()are taken only afterwrap()succeeds, so nothing is left unbalanced on failure. The packed-format tag is private data on the released resource, so no stale entry is left behind.attach_devicesetsremoval_deviceonly on success, andx2w_d3d12_permissive_create_devicenow returnsE_OUTOFMEMORY. That is consistent with the header comment.E_OUTOFMEMORYwith a null output, thenS_OKonce disarmed. Thecontrolrun never arms it and must print FAIL, which gives a negative control. The test does not cover the other callers (command list, placed buffer, committed, stream pipeline). Optional: extend it if cheap.Commands run (Linux, exact head):
python3 tests/docs_links_check.py(ok, 19 files, 507 links),python3 tests/bidi_controls_check.py(ok),git diff --check origin/main...HEAD(clean). The C++ fixture builds only on Windows, so I ran no mutation here.Not merged by me, for two reasons:
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by Not-Saii on 2026-11-26T01:03:57Z.
Thanks for the review. Extended in
6864ec86: the fixture now also arms the failure for slot 9 (CreateCommandAllocator, which covers the sharedcreate_slotpath), slot 73 (command list) and slot 127 (committed resource). Each returnsE_OUTOFMEMORYwith a null output, then succeeds; the control reports all eight. With the slot 73 null check removed locally, the test crashed at slot 73.I left out the placed-buffer, placed-texture and stream-pipeline paths: they need title memory or translated shaders to reach. The PR description lists which call sites are covered.
ctest --preset dev --no-tests=error -R "^startup_wrap_allocation" -V: 2/2 passed on WARP (Windows 11 26300.9974). The 84 related WARP stand-in tests still pass after a fulldevbuild.AI-assisted (Claude Code).
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-26T01:06:49Z.
I kept the additional allocator, command-list and committed-resource checks from
6864ec86and pushed a small follow-up in36081125. In a source-built test, creating a second device with the wrapper allocation forced to fail left the first device's live queue crashing onGetDevice. The follow-up publishes the new device and its debug state only after wrapping succeeds. The test now checksE_OUTOFMEMORY, a null second output, and the identity of the first device returned by the live queue.Windows Release:
ctest --preset release --no-tests=error -j 1 -R '^startup_wrap_allocation' -Vpassed both WARP tests, including the slot 55 negative control. After this merges, a repeat of the same 12 GiB case would tell us how the caller handles the returned HRESULT. The separate allocation pressure and placement failures remain tracked in #1199.Imported from R0Y00/Xbox2Windows. Originally posted by Not-Saii on 2026-11-26T01:19:47Z.
Repeat of the 12 GiB case after #2656 merged. In this run no wrapper allocation failed, so it does not show how the caller handles the new
E_OUTOFMEMORYfromwrap(). The first failures were D3D12 placement and page mapping instead.Setup. Release build of
mainatf4c6998a(includes the #2656 merge341215a9);ctest --preset release --no-tests=error -R "^startup_wrap_allocation"passed 2/2 on WARP. Windows 11 Pro 26300.9974, RTX 4090 (driver 32.0.16.1088, debug layer off), 32 GB RAM. Same switches as the earlier 12 GiB run, without lazy commit:The cache is the same revision-17 cache as before, translated offline with
--pendingon this revision first. Input was scripted this time (A every 4 s from the first poll), where the earlier 12 GiB run was driven by hand. The title read 11 presses.Process commit (DirectStorage heartbeat, MiB): 6,790 at 10 s, 12,005 at 40 s, 12,160 at 50 s, 12,223 at 80 s (last sample).
Failures, in log order:
Device::slot133(CreatePlacedResourceX?)texture, 4096×4096, 11 mips →0x8007000e, 8 times. The title went on.x2w-xmem GPU view mirror failed stage=map-view ... error=1455for a 250-page range (count=0xfa ... -> 0 (err 1455)), once.XMemMapPhysicalPagesScatter failed stage=map-view ... error=1455, 4 times.+0x4da6341) to an address inside one of the scatter ranges that failed to map. Immediately before it, two first-chance read faults ind3d12_xs.dlltouched the GPU-view range whose mirror failed; the stand-in handled them.No
x2w-d3d12 wrap(...): wrapper allocation failedline appeared, so the path #2656 changed was not reached. The run stopped before anyExecuteIndirect(0 calls), with 10 graphics pipelines translated and 1,357 textures uploaded.Compared with the earlier 12 GiB run on
d371ce46(before #2656, controller input): that run stopped at 221.3 s insided3d12_xs.dllon the unchecked wrapper allocation, at about 12.2 GiB. Here the cap was reached at the same point in loading, but the first failures were placement and page mapping, and the stop was the title writing to an unmapped page. So at this cap, which stage fails first varies between runs. One run; I have not repeated it.AI-assisted (Claude Code).