Repository navigation
runtime: keep the view tables consistent when an allocation fails - #2799
Conversation
note_view added a new record to view_records, view_materialized and view_ids one after the other, with no handler for a failed allocation. Everything that can allocate now runs first, so a record goes into all three containers or into none. On failure the process keeps running, a log line names the container, the destination descriptor is left untracked, and the resources of a created view leave the retire class. startup_view_alloc injects the failure at each of the three sites, for slot 18 and a slot 19 view with a counter resource. This does not reduce the memory the records use. Refs R0Y00#1199 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
New test registrations go in tests/cmake/<family>.cmake, so move the startup_view_alloc block out of CMakeLists.txt. The block is unchanged. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
tedin7
left a comment
There was a problem hiding this comment.
Review of head 51c1e1c1 (main merged into the branch; the PR's own diff is unchanged from bed557de).
Code (d3d12_capture.inl, d3d12_xs_device.cpp): no problem found. store_view does every allocation first (two reserve, then try_emplace), so the two push_back calls cannot fail and a record goes into all three containers or none. The view_ids lookup runs before this path, so try_emplace instead of operator[]= does not change the result for an existing hash. drop_unrecorded_view clears the shadow slot and title token, releases the replaced view, and logs only through first_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.- Failing lines:
FAIL: an earlier view changed its idandFAIL: an earlier view added a record, fromtests/startup_view_alloc.cpp:223and:226. - Same result on a second run, so it is not flaky.
- Likely cause (not confirmed by a patched run):
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. - This only affects the test. The fix code itself was not shown wrong.
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.py and tests/bidi_controls_check.py pass; git diff --check origin/main...HEAD clean. 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.
The stand-in identifies a view by every byte of its description. The fixture rebuilt the constant buffer view description with brace initialization, which need not clear its padding, so the same view could get a new id. A review reported this as six failures in a Release build. Zero the three view descriptions with memset before setting their fields. Only the fixture changes. Refs R0Y00#1199 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
@tedin7 Thanks for the review, and for finding this. I had only run the Debug build. Fixed in 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 I did not rerun the broader regression filter, the DirectStorage checks or the Could you retest on your Win2025 setup when you have time? AI-assisted (Claude Code). |
|
Win2025 WARP receipt for head 23bc1a1 after 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
AI-assisted; commands listed were executed locally. |
tedin7
left a comment
There was a problem hiding this comment.
Review of head 23bc1a1 (main merged in; the PR's own diff is unchanged since fab361e).
- Fixture fix from the earlier review is in: the three view descriptions are zeroed with
memsetbefore their fields are set, so padding no longer differs between Debug and Release. - Each of the three allocation sites (records, materialized, ids) has an armed test and a
controltest that never arms the failure and must print FAIL, so every site has a negative control. - No sibling table or callsite was left out in the touched view-publication path; docs section is linked and the link check passes.
Commands run:
git diff --check origin/main...HEAD: cleanpython3 tests/docs_links_check.py: 28 files, 543 links OKpython3 tests/bidi_controls_check.py: OK- Win2025 WARP, dev and release,
startup_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.
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 startup: count new view records by slot behind an opt-in census #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 runtime: fail a DirectStorage request on allocation failure #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