Skip to content

startup: track UAV/RTV/DSV descriptor slots in the retire class (slice 3a) - #2719

Merged
MasterDomino merged 5 commits into
R0Y00:mainfrom
triggered02:startup/retire-slice3
Nov 26, 2026
Merged

MasterDomino merged 5 commits into
R0Y00:mainfrom
triggered02:startup/retire-slice3

Conversation

@triggered02

Copy link
Copy Markdown
Contributor

Slice 3a of #2379: UAV (slot 19), RTV (slot 20) and DSV (slot 21) descriptor slots now hold a retire reference exactly like slot-18 SRV slots, instead of taking the resource out of the retire class for good.

What changed

  • src/startup_stubs/d3d12_capture.inl: view_slot_names_resource() (slots 18-21; 17 CBV and 22 sampler name none) and three helpers — view_refs_add, view_refs_release, view_refs_leave_class. Slot 19 (UAV) counts both the view resource and its counter resource; 20/21 count the resource. note_view adds on a materialized view in a tracked shadow_slot() and releases the previous record's refs when a different view takes the slot (the same view written again keeps its id and changes no count). note_copy adds a ref for every materialized copied-in record and releases the ones the destination slots named before, so a self-copy is idempotent. retire_drop_heap_views releases the refs of every materialized record still in that heap's shadow entries.
  • src/startup_stubs/d3d12_xs_device.cpp: view_slot<19..21> keeps the old retire_leave_class only when the destination descriptor slot is not tracked (or there is no desktop destination handle); when it is tracked, note_view owns the reference and the resource stays in the class. retire_drop_heap_views covers 18-21. The fixture probe x2w_d3d12_retire_probe gains view_refs (the resource's retire_view_refs), read under the same switch.
  • Fixtures: cases 8 and 9 in tests/startup_resource_retire_title.cpp; tests/startup_resource_retire.cpp gets the matching probe field.
  • Docs: docs/startup-runtime.md (budget section) and a new docs/experiments.md section that also closes the code fence the Slice 2 record left open.

Semantics

The ref is taken at view creation and dropped when the slot is overwritten, copied over, or its heap is destroyed — so a resource survives exactly as long as some tracked descriptor still names it, and the drain's existing retire_view_refs == 0 gate frees it afterwards. Untracked heaps keep the old conservative retire_leave_class fallback; nothing is freed under a descriptor the shim cannot follow.

One design fact worth stating up front

retire_classify excludes textures created with ALLOW_RENDER_TARGET, ALLOW_DEPTH_STENCIL or ALLOW_UNORDERED_ACCESS, and desktop only materializes a UAV/RTV/DSV on a resource carrying the matching flag. So a class texture's 19-21 view call is always the console-only/refused path — it records nothing and adds no ref. This slice is therefore a correctness and regression guard (a refused 19-21 view must not permanently exclude a class texture), not the fix for the remaining retained memory; that is slice 3b (descriptor-held textures whose slots are never overwritten). The fixture proves the ref contract through the probe counter and through the tracked-vs-untracked branch with the real budget oracle, and the docs say so rather than claiming a budget drop this cannot produce.

Verified (14d1c534 on origin/main e46d336c)

cmake --build --preset dev --target startup_resource_retire_title startup_resource_retire startup_resource_retire_views   # exit 0
ctest --preset dev --no-tests=error -R '^startup_resource_retire(_title|_views)?_'
  → 100% tests passed, 0 tests failed out of 26   (20 passed, 6 skipped: all _debug1, debug layer absent here)

WARP (Microsoft Basic Render Driver) and NVIDIA GeForce GTX 1660 SUPER. docs_links_check.py (526 links), bidi_controls_check.py (1971 files), git diff --check: pass. Adjacent ^startup_(resource_budget|view_census) → 14 selected, 10 passed, 4 _debug1 skipped, 0 failed.

Fail-first mutants (temporary edits, reverted; each fails on WARP, (c) on hardware too):

mutation first assertion
no ref added for 19-21 FAIL: RTV created in a tracked slot: 0 tracked slot refs, expected 1
no ref released on overwrite FAIL: RTV overwrote the slot: previous resource: 1 tracked slot refs, expected 0
keep the old unconditional retire_leave_class for 19-21 FAIL: a refused view in a tracked slot kept the texture out of the retire class (retained=65536/1 expected=0/0)
no ref released on heap destruction FAIL: copy heap destroyed: 1 tracked slot refs, expected 0

Running the new fixture against the pre-change sources fails as expected (retained=65536/1 expected=0/0), so it is fail-first rather than a fixture written to the new behavior.

Not established

  • The budget-column retention case cannot be shown for 19-21 views through class textures (see the design fact above); it is asserted through the probe and the tracked/untracked branch instead.
  • A slot-19 texture+counter pair is invalid on desktop (CreateUnorderedAccessView with a counter on a texture removes the device), so the counter half is driven with a structured buffer UAV; the shim still records the invalid console-style call as unmaterialized.
  • Not exercised: copying a tracked view into an untracked destination heap; a descriptor write racing a drain (pre-existing caveat); X2W_D3D12_RELEASE_RETIRED_VIEWS=1 still rewrites slot 18 only, so a 19-21 ref is never nulled and such a resource is kept — unreachable for class textures today, documented in the docs.

Refs #2379. CC @JB2WIN @MasterDomino for the slice-3 split discussed on the issue — this is part 1; the never-overwritten-descriptor half (3b) is next and is the one that changes the memory outcome.

AI-assisted.

…3a, Refs R0Y00#2379)

view_slot<19>, <20> and <21> took their resource out of the retire class
unconditionally (slot 19 twice, for its resource and its counter), so a class
texture named by a UAV/RTV/DSV descriptor could never be freed.

- d3d12_capture.inl: view_refs_add/release/leave_class handle slots 18-21 as one
  reference per tracked descriptor slot (slot 19: one for the resource and one
  for the counter). note_view adds a materialized view's refs when the
  destination slot is tracked, releases the previous record's refs on overwrite,
  and keeps the retire_leave_class fallback for a descriptor no shadow slot
  tracks. note_copy moves refs with the copied views, releases the overwritten
  destination's refs, and leaves the class only when the copy goes into an
  untracked heap.
- d3d12_xs_device.cpp: view_slot<19..21> looks the destination up with
  shadow_slot() under note_lock (note_view's existing lock): a tracked slot lets
  note_view own the accounting and keeps the resource in the class; an untracked
  slot or a destination with no desktop handle keeps retire_leave_class. A
  destroyed descriptor heap drops the refs of every tracked slot.
- x2w_d3d12_retire_probe: reports retire_view_refs as view_refs (fixture-only).
- startup_resource_retire_title: case 8 drives RTV/DSV/UAV references through
  create, the same view again, overwrite, descriptor copy and heap destruction
  (plus a slot-19 counter); case 9 covers the tracked and untracked fallback of a
  refused view on a class texture in both switch modes.

No freeing rule change: the drain still frees only at retire_view_refs == 0.
…, Refs R0Y00#2379)

- startup-runtime.md#d3d12-resource-budget: the tracked descriptor slots now
  cover 18-21, one reference per materialized view (slot 19 also for its counter
  resource), released by overwrite, descriptor copy and heap destruction; the
  untracked-heap retire_leave_class fallback stays. Notes that the class still
  excludes RT/DS/UAV textures, so a class texture's 19-21 view is the refused
  console-only case today, and that RELEASE_RETIRED_VIEWS keeps rewriting only
  slot 18 SRVs.
- experiments.md: new Slice 3a section with the WARP/GTX 1660 SUPER fixture
  results and the four failing mutants; closes the code fence the Slice 2
  section left open.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-26T03:36:05.045412Z 14d1c53 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@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 14d1c53 (code + fixture tests only; the update with main did not change this PR's own diff).

Checked:

  • view_refs_add / view_refs_release / view_refs_leave_class keep add and release symmetric for slots 18-21, with the slot-19 counter handled on both sides. note_view, note_copy (both the tracked and the untracked source branches) and retire_drop_heap_views all go through the same helpers, so a slot-18 record behaves as before.
  • view_slot<19..21> only keeps the old retire_leave_class when the destination is untracked, so nothing is freed under a descriptor the shim cannot follow.
  • The PR states that a class texture's 19-21 view is always the refused path (so this is a regression guard, not a memory fix), and the docs say the same. Good.
  • Fixtures: cases 8 and 9 assert the ref counts via the probe and the retained budget. The mutation table in the PR body covers add, release-on-overwrite, release-on-heap-destroy and the old unconditional leave-class.
  • No other open or merged PR covers this slice. No game or startup claim.

Nit (not blocking): git diff --check reports a blank line at EOF in tests/startup_resource_retire_title.cpp:1294.

Commands run (Linux): git diff --check origin/main...HEAD, python3 tests/docs_links_check.py, python3 tests/bidi_controls_check.py. The fixtures need the Windows build, so they are covered by the Win2025 run that follows.

AI-assisted; commands listed were executed locally.

@R0Y00

R0Y00 commented Nov 26, 2026

Copy link
Copy Markdown
Owner

On a local integration of the 3a slice with main, the full resource-retirement group passed 26/26 on WARP and RTX, including the existing same-slot rebind and no-retire controls. When integrating the docs, please keep the main row that makes X2W_D3D12_RELEASE_RETIRED_VIEWS diagnostic-only. The 3a branch also adds an older duplicate option row and a paragraph that still describes automatically replacing slot-18 views with null. Both need to be removed so the accepted #2679 compatibility behavior stays clear.

@triggered02

Copy link
Copy Markdown
Contributor Author

Thanks for the review and for merging main in (73ff782) � I adopted your merge commit as-is.

Nit fixed in �630b20d ( ests: drop the trailing blank line at end of the title retire fixture): the file now ends at the closing brace with a single line terminator, so git diff --check reports nothing (verified after the commit: git diff --check exit 0).

Re-ran the affected fixtures on that head rather than assuming a whitespace-only change is inert:
cmake --build --preset dev --target startup_resource_retire_title startup_resource_retire startup_resource_retire_views # exit 0 ctest --preset dev --no-tests=error -R '^startup_resource_retire(_title|_views)?_' ? 100% tests passed, 0 tests failed out of 26 (6 _debug1 skips, no debug layer on this host)
Nothing else changed: no code, no fixture assertions, no docs. The slice split you noted (3a = regression guard, 3b = the never-overwritten descriptor lifetime that actually changes retained memory) is unchanged, and 3b is the next thing I will bring.

@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 0630b20d (comment only).

What I read: d3d12_capture.inl (view_slot_names_resource, view_refs_add/release/leave_class, note_view, note_copy), d3d12_xs_device.cpp (view_slot<19..21>, retire_drop_heap_views, x2w_d3d12_retire_probe), docs. The ref accounting reads consistent: one ref per tracked slot, slot 19 also counts the counter resource, same-view rewrite changes nothing, copy adds before it releases, untracked destinations fall back to retire_leave_class.

Blocking: Windows Server 2025 WARP fails on this head. Debug and release build fine, but the retire suite (--regex startup_resource_retire, 26 tests) has 4 failures, reproduced on a second run:

  • startup_resource_retire_views_warp_debug0
  • startup_resource_retire_views_keep_warp
  • startup_resource_retire_views_hardware_debug0
  • startup_resource_retire_views_keep_hardware (not the PR's fault if it is only the missing adapter, but it fails with the same stage)

First error line of the WARP run:
FAIL: T1 kept although only a descriptor names it / stage 'T1 freed with its descriptor never overwritten' live=0/0 expected=0/0 retained=65536/1 expected=0/0

So a resource named only by a slot-18 SRV (created by a slot 18 view into a tracked heap, never overwritten) stays retained after the title frees it. The views_noretire and title/reasons suites pass. I did not check whether the same stage also fails on current main, so please confirm whether this comes from the new tracked pre-check in view_slot or from the probe change (as_wrapper(...)->own().real is no longer required to report view_refs).

Linux checks: tests/docs_links_check.py ok, tests/bidi_controls_check.py ok, git diff --check origin/main...HEAD clean.

Not merged: Win2025 does not pass, so this stays open. Startup-path claims are not verified on the title; that stays with the maintainers.

Commands run: x2w_pipe.py win2025 2719 --wait 7200 --keep-release (build only, pass) and ... --regex startup_resource_retire (4 failed of 26).

AI-assisted; commands listed were executed locally.

@triggered02

Copy link
Copy Markdown
Contributor Author

Thanks � this is exactly the report I wanted, and I can explain the four failures: the tree your Win2025 run exercised is older than #2679, not head �630b20d.

Evidence:

  1. The failing stage you quoted � 'T1 freed with its descriptor never overwritten' / FAIL: T1 kept although only a descriptor names it � was introduced by d3d12: opt-in release of retired textures held only by never-overwritten descriptor slots #2579 ( c97ade7) and removed by d3d12: keep live SRVs intact during resource retirement #2679 (293e77f, Keep live SRVs intact during resource retirement, merged 2026-11-26T03:21:47Z, co-authored by you). git log --all -S'T1 freed with its descriptor never overwritten' shows exactly three commits: c97ade7 (added), d1d9261, 293e77f (removed).
  2. ests/startup_resource_retire_views.cpp at head �630b20d is byte-identical to current origin/main � both are blob 263dd96dcdb5d0df86946cce40fb21840d0de77c. So that stage string cannot be emitted by head �630b20d.
  3. The behavior behind those stages no longer exists on main by design: src/startup_stubs/d3d12_xs_device.cpp:832-833 now logs "X2W_D3D12_RELEASE_RETIRED_VIEWS no longer clears live descriptors; budget statistics only". A tree from before d3d12: keep live SRVs intact during resource retirement #2679 would assert the opposite (descriptor-only resource freed) and fail exactly the four tests you listed.
  4. Local run on �630b20d (Windows 11 26200, in-box WARP 10.0.26100.9818, GTX 1660 SUPER, clean dev build): ctest --preset dev --no-tests=error -R '^startup_resource_retire' ? 100% passed, 0 failed of 26 (6 _debug1 skipped, no debug layer). The four named ones pass individually: �iews_warp_debug0, �iews_keep_warp, �iews_hardware_debug0, �iews_keep_hardware (8/8 in the views group).

Could you re-run x2w_pipe.py win2025 2719 --wait 7200 --keep-release with a clean build directory / fresh checkout at �630b20d and paste the checked-out base sha? If it still fails on that exact tree, the failing stage will be one that exists in blob 263dd96d and I will fix it � but with a stale pre-#2679 tree the four failures are expected and not caused by this PR.

One design note for the record: #2719 does not reinstate descriptor clearing. It tracks 19-21 slots symmetric with 18 and is documented as a regression guard, not a memory fix. The reverted #2579 behavior is the subject of the next slice (#2379 3b), which has to solve the live-SRV safety that #2679 re-established, and I will not bring it without the �iews_keep cases agreeing.

@triggered02

Copy link
Copy Markdown
Contributor Author

Doc correction pushed as �527cabe on this branch (no code, no fixture change).

While checking this against #2679 I found my slice-3a docs commit had kept a row and a paragraph from the withdrawn descriptor-clearing behavior: docs/startup-runtime.md listed X2W_D3D12_RELEASE_RETIRED_VIEWS twice � once correctly as a legacy diagnostic, once claiming a released class texture whose only references are never-overwritten slot-18 descriptors "is freed once those slots are replaced by null descriptors". That has not been true since #2679 (293e77f), which removed the clearing and stated the rule that now holds: a tracked descriptor reference is an owner until the slot is overwritten, copied over, or its heap is destroyed.

�527cabe deletes the duplicate row and rewrites the paragraph to the current rule, citing #2679. docs_links_check (527 links) and �idi_controls_check pass; git diff --check clean. The 19-21 accounting itself is unchanged � that part was accurate.

Separately: I confirmed the four Win2025 �iews_* failures come from a pre-#2679 tree (that stage string was removed by #2679 and ests/startup_resource_retire_views.cpp is byte-identical to main at this head), so nothing in the code halves of this PR is failing. Head is now �527cabe.

Copy link
Copy Markdown
Contributor

Independent Windows Release rerun from a clean checkout of 0630b20d609b6565a1a26c34922cc8e197055fcf: 26/26 passed, no skips, on in-box WARP 10.0.26100.10068 and RTX 4070 (32.0.16.2124), Windows 11 build 26300.10075. All six _debug1 cases ran and passed. I verified that the tested commit contains 293e77f6 (#2679). The current head a527cabe adds a docs-only change relative to the tested commit.

cmake --build --preset release --target startup_resource_retire_title startup_resource_retire startup_resource_retire_views startup_resource_retire_reasons
ctest --preset release --no-tests=error -j 1 -R '^startup_resource_retire(_title|_views)?_' --output-on-failure

@triggered02

Copy link
Copy Markdown
Contributor Author

@R0Y00 @RonLogic Thank you both!

  • Both doc fixes @R0Y00 requested (X2W_D3D12_RELEASE_RETIRED_VIEWS kept diagnostic-only; duplicate row and withdrawn slot-18 null-replacement paragraph removed) are in the current head a527cabe (docs: drop the withdrawn descriptor-clearing claim from the retire section), verified with docs_links_check.py (527 links) and bidi_controls_check.py.
  • Thank you @RonLogic for the independent clean-checkout Windows Release rerun on 0630b20d (26/26 passed, 0 skips on in-box WARP 10.0.26100.10068 and RTX 4070 32.0.16.2124, Windows 11 build 26300.10075, verifying d3d12: keep live SRVs intact during resource retirement #2679 is present). a527cabe adds only the docs fix above on top of 0630b20d.

Per @R0Y00's decision on #2379 to keep design B, this PR (#2719) concludes slice 3 with the 19-21 regression guard and #2679 compatibility preserved.

@MasterDomino MasterDomino 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.

Approving a527cabe, checked merged with current main (e3cf6a91).

Runs (WARP 10.0.26100.9818 and AMD Radeon RX 9070 XT, driver 32.0.32029.2010; Windows 11 build 26300):

  • ctest --preset dev --no-tests=error -j 4 -R '^startup_(resource_retire|resource_budget|view_census|compute_dispatch_texture|pixel_uav)': 44/44 passed, no skips, including the debug-layer variants.
  • Case 8 runs on hardware with the switch on, and case 9 runs on WARP with it off.
  • #2710's refused-UAV record composes correctly: it stays unmaterialized, no ref is added, and a live slot is kept.

No path frees a resource that a live UAV, RTV or DSV slot still names:

  • The retire class excludes buffers, and textures with render-target, depth-stencil or unordered-access flags.
  • view_slot refuses a 19–21 view without the matching flag, so a class texture never has a materialized 19–21 view, and a UAV counter is always a buffer.
  • The drain nulls own().real before Release.

The X2W_D3D12_RELEASE_RETIRED default stays off, and _VIEWS stays diagnostic-only. That meets @R0Y00's 3a criteria: slots 19–21 hold their resource until overwritten, copied over, or their heap is destroyed, and the #2468 same-slot rebind fixtures are unchanged and pass.

Negative controls, with the shim rebuilt for each:

  • DSV dropped from view_slot_names_resource: 4 of 26 fail, "DSV created in a tracked slot: 0 tracked slot refs, expected 1".
  • Counter ref not added: 4 of 26 fail, "UAV with counter created: counter …".
  • The old unconditional retire_leave_class: 4 of 26 fail, "a refused view in a tracked slot kept the texture out of the retire class".

Non-blocking follow-ups:

  • Untested guard: dropping view_refs_leave_class for a tracked view copied into an untracked heap (d3d12_capture.inl:462) still passes all 26, for slot 18 as well. A case for that copy would cover the one safety branch this PR rewrote.
  • Stale docs: docs/startup-runtime.md says a refused class-texture 19–21 view "records no view", but since #2710 a refused UAV records an unmaterialized one.
  • Wording: "prerequisite for a later slice that admits those textures" reads against the decision to end slice 3 here.

AI-assisted; commands listed were executed locally.

@MasterDomino
MasterDomino merged commit 33004fa into R0Y00:main Nov 26, 2026
5 checks passed
@MasterDomino

Copy link
Copy Markdown
Collaborator

@tedin7 @R0Y00: the Release segfault in startup_resource_retire_title from #2768 is fixed in #2774.

  • Cause: a pre-existing shim heuristic. small_result took a live wrapper left in rdx as the hidden-pointer form and overwrote the descriptor heap's vtable. startup: track UAV/RTV/DSV descriptor slots in the retire class (slice 3a) #2719's case 9 exposed it at /O2.
  • Result: all six variants pass in Release and dev, and the new case 10 fails without the shim change.
  • Merge: it's our code, so it needs one of you to review and merge.

AI-assisted; commands listed were executed locally.

tedin7 pushed a commit that referenced this pull request Nov 26, 2026
…holds a wrapper (#2774)

small_result chose the (return buffer, object) form whenever its second
argument was a live wrapper. A title-ABI call to descriptor heap slot 9
(GetCPUDescriptorHandleForHeapStart) passes only `this`, so the second
register holds whatever the caller left there. When that was another live
wrapper, the shim wrote the handle over the heap object's vtable and
returned the heap's address as the handle.

Case 9 of startup_resource_retire_title (#2719) nests the slot 9 call in a
slot 20 call; at /O2 rdx still held the resource wrapper, so the RTV went to
an untracked slot and the heap's next Release jumped into data. All six
variants segfaulted in Release since #2719.

small_result now takes its object from receiver(), the rule the larger
struct-returning slots already use: a wrapper first is the object, and only
when both look like wrappers does the one on this thread's stack become the
result buffer. Case 10 calls slot 9 with a live wrapper in the second
argument and through a return buffer; it fails in Debug and Release without
the shim change.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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.

5 participants