Skip to content

runtime: keep the view tables consistent when an allocation fails - #2799

Merged
tedin7 merged 5 commits into
R0Y00:mainfrom
JVProg:startup/view-note-alloc-failure
Nov 26, 2026
Merged

tedin7 merged 5 commits into
R0Y00:mainfrom
JVProg:startup/view-note-alloc-failure

Conversation

@JVProg

@JVProg JVProg commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Change

When note_view cannot allocate room for a new view record, the process now keeps running instead of stopping.

Before, the record went into view_records, view_materialized and view_ids one after the other, with no handler for a failed allocation. A handler alone would not be enough: if only view_materialized failed, the record vector would be longer than the flag vector, and code that checks only the record count would read past the flags.

  • Everything that can allocate now runs first: a reserve on each full vector (1.5x growth), then try_emplace on view_ids. The two push_back calls then have room. A record goes into all three containers or into none.
  • The device's view slots return 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.
  • The destination's shadow entry and title-memory token are cleared, and the replaced view drops its references. A draw then sees a descriptor without a view, not the earlier one.
  • If the desktop view was created, its resources leave the retire class of X2W_D3D12_RELEASE_RETIRED, because no record names that use. They stay in memory rather than risk an early release.
  • The failure path does not allocate in the view containers.

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_view in d3d12_capture.inl. The two new exports, x2w_d3d12_fail_view_allocations and x2w_d3d12_view_probe, are for the fixture only.

Overlap with open PRs: #2773 (92db6d4e) and #2782 (9f275268) also edit d3d12_capture.inl. In a trial merge with this branch, #2782 is clean. #2773 merges the code automatically and conflicts in docs/startup-runtime.md; its docs/experiments.md conflict also appears against main. 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_view identifies a view by every byte of the description, padding included. The three view descriptions are now zeroed with memset. The fix code is unchanged. The branch also includes the main merge 51c1e1c1.

  • On this PC the unchanged fixture passed 18 of 18 in Release at 51c1e1c1, so I did not reproduce the failure as it was.
  • Forced reproduction, in a Debug copy of bed557de: filling the padding with a different byte on each call made all six injection cases fail with FAIL: an earlier view changed its id and FAIL: an earlier view added a record.
  • On the tree committed as fab361e4, after cmake --build --preset <preset> --target startup_view_alloc startup_view_census: ctest --preset <preset> -R "startup_view_(alloc|census)" --repeat until-fail:3 --no-tests=error passed 18 of 18 in each of three repetitions, with <preset> as dev and as release.
  • Release negative controls, in a copy of bed557de with the updated fixture: without the counter release, the six injection cases fail with FAIL: the replaced slot 19 view kept its counter reference; with the three old insertions restored, the six injection cases exit with 0xc0000409 and the other 12 tests pass.
  • Not rerun after this update: the broader regression filter, the DirectStorage checks, the pr preset 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 six startup_view_census* cases from startup: count new view records by slot behind an opt-in census #2613.
  • Negative control without the fix (the three old insertions restored, injection points kept): all six 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 dialog abort() has been called, which waits until it is dismissed (I pressed Abort). The six control and six census cases pass.
  • Slot 19 check: with the counter release deliberately removed from the failure path, the six injection cases fail with 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 six startup_resource_retire*_debug1 cases.
  • 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_failure is 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, after cmake --build --preset pr: 40 selected, 26 passed, 0 failed. Capability skips: the 14 spirv_*_warp cases (SPIR-V tools not set up locally).
  • python -B tests/docs_links_check.py and python -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 named view_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.cpp is 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:

  • In the committed fixture the failure is injected; it does not exhaust memory.
  • Stack exhaustion (0xc00000fd) and a failure path free of any allocation are not tested.
  • No draw is run after a failed publication; what a draw sees is based on the cleared shadow entry and token.
  • For view_ids it is raised before the insertion, so the fixture relies on the standard guarantee that a failed single insertion leaves an unordered_map unchanged.
  • For slot 19 only reference counts are checked, because resources that allow unordered access are never in the retire class. Slots 20 to 22 are not exercised with a failure.
  • note_view_target can also allocate (a new RTV or DSV handle). That path is unchanged.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed. (docs/startup-runtime.md)
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

JVProg and others added 3 commits November 26, 2026 11:21
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 tedin7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

  • ctest release, 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 six startup_view_census* cases pass.
  • Failing lines: FAIL: an earlier view changed its id and FAIL: an earlier view added a record, from tests/startup_view_alloc.cpp:223 and :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:170 builds D3D12_CONSTANT_BUFFER_VIEW_DESC desc{...}. Brace-initialization does not clear the 4 bytes of tail padding after SizeInBytes. note_view copies and hashes all desc_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>
@JVProg

JVProg commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

@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 with memset before 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 both dev and release (Windows 11, WARP and RX 9070 XT).

I did not rerun the broader regression filter, the DirectStorage checks or the pr preset after this change. The PR description has the details.

Could you retest on your Win2025 setup when you have time?

AI-assisted (Claude Code).

@tedin7

tedin7 commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

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 23bc1a16f41ee4cf3c00c80194592ddbb4d8cd5b:

  • Debug (--preset dev):
    • Build (cmake --build --preset dev --target startup_view_alloc d3d12_xs_shim -- -j 2): 4.49s (configure 0.00s)
    • Test (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_warp 0.20s, startup_view_alloc_records_control_warp 0.22s, startup_view_alloc_materialized_warp 0.05s, startup_view_alloc_materialized_control_warp 0.06s, startup_view_alloc_ids_warp 0.05s, startup_view_alloc_ids_control_warp 0.05s)
  • Release /O2 (--preset release):
    • Build (cmake --build --preset release --target startup_view_alloc d3d12_xs_shim -- -j 2): 50.08s (configure 0.00s)
    • Test (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_warp 0.15s, startup_view_alloc_records_warp 0.16s, startup_view_alloc_materialized_warp 0.07s, startup_view_alloc_materialized_control_warp 0.07s, startup_view_alloc_ids_warp 0.04s, startup_view_alloc_ids_control_warp 0.04s)
  • sccache: 25/40 hits; wall 60.4s
    tested: 23bc1a1 via fetch (pull/2799/head, no patch)

AI-assisted; commands listed were executed locally.

@tedin7 tedin7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 memset before 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 control test 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: clean
  • python3 tests/docs_links_check.py: 28 files, 543 links OK
  • python3 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)
  • _hardware tests 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.

@tedin7
tedin7 merged commit 6a09405 into R0Y00:main Nov 26, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants