runtime: keep the view tables consistent when an allocation fails #2791
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2799"
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 JVProg on 2026-11-26T10:48:37Z.
Change
When
note_viewcannot allocate room for a new view record, the process now keeps running instead of stopping.Before, the record went into
view_records,view_materializedandview_idsone after the other, with no handler for a failed allocation. A handler alone would not be enough: if onlyview_materializedfailed, the record vector would be longer than the flag vector, and code that checks only the record count would read past the flags.reserveon each full vector (1.5x growth), thentry_emplaceonview_ids. The twopush_backcalls then have room. A record goes into all three containers or into none.void, so the report is a log line naming the container (first eight failures):x2w-d3d12 note_view: out of memory in <container> -> view of slot <n> not recorded, destination descriptor untracked.X2W_D3D12_RELEASE_RETIRED, because no record names that use. They stay in memory rather than risk an early release.Record identity and the ids of recorded views do not change. This handles the failure; it does not reduce the memory the records use. The matched commit-budget replay is separate and not part of this PR.
Shared interface:
note_viewind3d12_capture.inl. The two new exports,x2w_d3d12_fail_view_allocationsandx2w_d3d12_view_probe, are for the fixture only.Overlap with open PRs: #2773 (
92db6d4e) and #2782 (9f275268) also editd3d12_capture.inl. In a trial merge with this branch, #2782 is clean. #2773 merges the code automatically and conflicts indocs/startup-runtime.md; itsdocs/experiments.mdconflict also appears againstmain. I did not build or test those merged trees, and I don't see a required merge order.Refs #1199.
Verification
Base
700522ef, Windows 11 build 26300, WARP and AMD Radeon RX 9070 XT (driver 32.0.32029.2010), D3D12 debug layer off for the view tests. I don't have an RTX 3070.Update after review (
fab361e4, fixture only)The review reported six Release failures. The cause is in the fixture: it rebuilt the constant buffer view description with brace initialization, and
note_viewidentifies a view by every byte of the description, padding included. The three view descriptions are now zeroed withmemset. The fix code is unchanged. The branch also includes themainmerge51c1e1c1.51c1e1c1, so I did not reproduce the failure as it was.bed557de: filling the padding with a different byte on each call made all six injection cases fail withFAIL: an earlier view changed its idandFAIL: an earlier view added a record.fab361e4, aftercmake --build --preset <preset> --target startup_view_alloc startup_view_census:ctest --preset <preset> -R "startup_view_(alloc|census)" --repeat until-fail:3 --no-tests=errorpassed 18 of 18 in each of three repetitions, with<preset>asdevand asrelease.bed557dewith the updated fixture: without the counter release, the six injection cases fail withFAIL: the replaced slot 19 view kept its counter reference; with the three old insertions restored, the six injection cases exit with0xc0000409and the other 12 tests pass.prpreset and the local commit-limit probe (Debug only).Earlier results (
bed557de)ctest --preset dev -R "startup_view_(alloc|census)" --repeat until-fail:3 --no-tests=error: 18 of 18 passed in each of three repetitions, no skips. This includes the sixstartup_view_census*cases from #2613.startup_view_alloc_<site>_<backend>cases fail; run directly, each ends with exit code 3 after the failure is armed. This Debug build can first stop at the CRT dialogabort() has been called, which waits until it is dismissed (I pressed Abort). The sixcontroland six census cases pass.FAIL: the replaced slot 19 view kept its counter reference.ctest --preset dev -R "dstorage|storage_worker|startup_stubs|startup_wrap_allocation|startup_address_srv|startup_resource_retire|descriptor" -j 1 --no-tests=error: 78 selected, 72 passed, 0 failed. Includes the DirectStorage destination and worker-start checks. Capability skips: the sixstartup_resource_retire*_debug1cases.ctest --preset dev -R "^startup_storage_(alloc_failure|worker_start)$|^startup_dstorage_destination$" --no-tests=error: 3 of 3 passed, no skips.startup_storage_alloc_failureis the allocation-failure check from #1410; the filter above does not select it.ctest --preset pr --no-tests=error, aftercmake --build --preset pr: 40 selected, 26 passed, 0 failed. Capability skips: the 14spirv_*_warpcases (SPIR-V tools not set up locally).python -B tests/docs_links_check.pyandpython -B tests/bidi_controls_check.py: passed.Additional local check (probe not included in this PR; Debug build of
bed557de): with a Windows job limiting process commit, and no fault injection, on WARP and an RX 9070 XT, 3 runs each of two setups (about 1M records with 32 MiB headroom; no headroom from a small table). With the fix, 12 of 12 runs passed: no partial record, the destination was untracked, and after lifting the limit the first published id was intact and a new view was recorded. Without the fix, 12 of 12 exited with code 3. With the fix, the log namedview_records; real exhaustion did not exercise the other two containers. Stack exhaustion and allocation-free handling remain unverified.Not run: the full CTest suite and a run of a title.
Evidence and follow-up
tests/startup_view_alloc.cppis original code for this repository (MIT) and uses only synthetic descriptors and resources. It makes the allocation at each of the three sites fail on slot 18 and on a slot 19 view with a counter resource, then checks that nothing partial is left, earlier views keep their ids, and later views are recorded.Reproduction:
docs/startup-runtime.md, D3D12 view allocation failure.Limits:
0xc00000fd) and a failure path free of any allocation are not tested.view_idsit is raised before the insertion, so the fixture relies on the standard guarantee that a failed single insertion leaves anunordered_mapunchanged.note_view_targetcan also allocate (a new RTV or DSV handle). That path is unchanged.Checklist
docs/startup-runtime.md)AI-assisted (Claude Code).
🤖 Generated with Claude Code
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T10:54:04Z.
Review: COMMENTED
Review of head
51c1e1c1(main merged into the branch; the PR's own diff is unchanged frombed557de).Code (
d3d12_capture.inl,d3d12_xs_device.cpp): no problem found.store_viewdoes every allocation first (tworeserve, thentry_emplace), so the twopush_backcalls cannot fail and a record goes into all three containers or none. Theview_idslookup runs before this path, sotry_emplaceinstead ofoperator[]=does not change the result for an existing hash.drop_unrecorded_viewclears the shadow slot and title token, releases the replaced view, and logs only throughfirst_calls(failed, 8).Release build of the new test fails (blocking). The Debug (
dev) run passes, the Release run does not.ctestrelease,startup_view_(alloc|census): 12 of 18 passed. All six injection cases fail:startup_view_alloc_{records,materialized,ids}_{warp,hardware}. The six*_control_*and sixstartup_view_census*cases pass.FAIL: an earlier view changed its idandFAIL: an earlier view added a record, fromtests/startup_view_alloc.cpp:223and:226.tests/startup_view_alloc.cpp:170buildsD3D12_CONSTANT_BUFFER_VIEW_DESC desc{...}. Brace-initialization does not clear the 4 bytes of tail padding afterSizeInBytes.note_viewcopies and hashes alldesc_bytes, so in Release the same view created twice can hash differently and get a new id and record. Debug fills the stack the same way each time, which hides it. Zeroing the descriptor first (D3D12_CONSTANT_BUFFER_VIEW_DESC desc{}; desc.BufferLocation = ...; desc.SizeInBytes = 256;) should fix it. The same check applies to the texture view descriptors in the test.Win2025 (WARP, VM has no hardware GPU): dev 18/18 passed; release 12/18 (above). A first attempt ran with the wrong build targets and is not counted. Real-GPU run not available (RunPod stopped).
Also checked:
tests/docs_links_check.pyandtests/bidi_controls_check.pypass;git diff --check origin/main...HEADclean. No other open or merged PR covers this slice. I did not run mutations of the fix: the test only builds on Windows.Not merged. Please fix the descriptor initialization and push; I can retest.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by JVProg on 2026-11-26T11:05:02Z.
@tedin7 Thanks for the review, and for finding this. I had only run the Debug build.
Fixed in
fab361e4(fixture only): the three view descriptions are now zeroed withmemsetbefore their fields are set.On my PC the old fixture passed in Release, so I forced the case by filling the padding of the constant buffer view description with a different byte on each call (Debug copy of
bed557de). All six injection cases then failed with your two messages. With the fix,startup_view_(alloc|census)passed 18 of 18 three times in bothdevandrelease(Windows 11, WARP and RX 9070 XT).I did not rerun the broader regression filter, the DirectStorage checks or the
prpreset after this change. The PR description has the details.Could you retest on your Win2025 setup when you have time?
AI-assisted (Claude Code).
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T14:00:07Z.
Review: COMMENTED
Review of head
23bc1a16(main merged in; the PR's own diff is unchanged sincefab361e4).memsetbefore their fields are set, so padding no longer differs between Debug and Release.controltest that never arms the failure and must print FAIL, so every site has a negative control.Commands run:
git diff --check origin/main...HEAD: cleanpython3 tests/docs_links_check.py: 28 files, 543 links OKpython3 tests/bidi_controls_check.py: OKstartup_view_alloc_.*warp: 6/6 and 6/6 (receipt posted on the PR)_hardwaretests not run: the VM has WARP only, and the real-GPU run is not available.No findings. This is not a startup-path claim, so no game run is needed.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T13:59:07Z.
Win2025 WARP receipt for head
23bc1a16after updating with main (31 commits). Review of this head: only the fixture memset fix since the last review; the control tests (3) fail the fixture as intended, so each site has a negative control. The 6 _hardware tests were not run (VM has WARP only; real-GPU run not available, RunPod stopped).Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit
23bc1a16f41ee4cf3c00c80194592ddbb4d8cd5b:--preset dev):cmake --build --preset dev --target startup_view_alloc d3d12_xs_shim -- -j 2):4.49s(configure0.00s)ctest --preset dev -R 'startup_view_alloc_.*warp' --parallel 2 --no-tests=error --output-on-failure): 6/6 passed (0.50s:startup_view_alloc_records_warp0.20s,startup_view_alloc_records_control_warp0.22s,startup_view_alloc_materialized_warp0.05s,startup_view_alloc_materialized_control_warp0.06s,startup_view_alloc_ids_warp0.05s,startup_view_alloc_ids_control_warp0.05s)/O2(--preset release):cmake --build --preset release --target startup_view_alloc d3d12_xs_shim -- -j 2):50.08s(configure0.00s)ctest --preset release -R 'startup_view_alloc_.*warp' --parallel 2 --no-tests=error --output-on-failure): 6/6 passed (0.44s:startup_view_alloc_records_control_warp0.15s,startup_view_alloc_records_warp0.16s,startup_view_alloc_materialized_warp0.07s,startup_view_alloc_materialized_control_warp0.07s,startup_view_alloc_ids_warp0.04s,startup_view_alloc_ids_control_warp0.04s)sccache: 25/40 hits; wall60.4stested:
23bc1a16via fetch (pull/2799/head, no patch)AI-assisted; commands listed were executed locally.