Repository navigation
d3d12: opt-in release of retired textures held only by never-overwritten descriptor slots - #2579
Conversation
X2W_D3D12_RETIRE_REASONS=1 (with X2W_D3D12_RELEASE_RETIRED=1 and X2W_D3D12_BUDGET=1) adds one "x2w-retire held:" line to the heartbeat. It counts final-released resources whose desktop object is still alive, by reason (view-refs, list-hold, flight, queued-waiting-fence, left-class:*, never-class:*) with bytes from the budget ticket and the age in frames. The retire class decision now records why a resource is not a member, and the first use that took it out of the class. No behavior change; without the switches nothing is recorded and no line is built. Fixture startup_resource_retire_reasons creates one resource per main reason and compares the whole line; the off and no-retire modes are the negative controls. AI-assisted (Claude Code) Refs R0Y00#2379 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… held only by descriptor slots With X2W_D3D12_RELEASE_RETIRED=1 a released class texture stayed retained for as long as any tracked slot-18 descriptor slot named it, which is forever when the title never overwrites the slot. With the new switch the drain replaces those slots by null SRVs once the release-time fences have passed: shadow entries and refs are dropped in every heap (copies included), the desktop descriptor is rewritten with CreateShaderResourceView(nullptr), the view records naming the resource are cleared and the view token in title descriptor memory is cleared. Lists and submissions keep the desktop object through the existing retire_hold/flight mechanism. Without the switch nothing changes. The fixture reads the desktop descriptors back with a compute probe and has keep/noretire negative controls. Four local mutants (null rewrite omitted, release-time fence ignored, token not cleared, copies skipped) fail it. AI-assisted (Claude Code). Refs R0Y00#2379 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A translated draw holds draw_lock from reading a view record until it records its hold on the sampled texture. Clearing the records without that lock let the drain drop a texture between those two steps, so the draw recorded a texture it no longer held. Take draw_lock (try, never blocking) before note_lock, in the draw path's order. AI-assisted (Claude Code). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
tedin7
left a comment
There was a problem hiding this comment.
Review of head 723d13d (comment only).
What I checked:
- Both new switches are opt-in. Without
X2W_D3D12_RELEASE_RETIRED_VIEWSthe drain returns beforeretire_null_ready_views, so default behavior is unchanged. - Lock order in
retire_null_ready_views(draw_lock, thennote_lock, both try-acquire, no blocking) matches the order described fordraw_translated. Contention just defers the work. - A slot that cannot be rewritten keeps its ref, so the texture stays retained (
retire_views_stuck). - Siblings: the class decision moved into
retire_classify/retire_set_class, and slots 29/30 are marked aliased/reserved. The docs section was extended. - Tests:
startup_resource_retire_viewshaskeepandnoretirenegative controls;startup_resource_retire_reasonshasoff/no-retire controls. The PR body lists the two paths not covered (draw/drain interleaving, stuck path). I agree these are hard to reach in a single-threaded fixture.
Commands executed locally (Linux, worktree at this head):
python3 tests/docs_links_check.py: pass (19 files, 494 links)python3 tests/bidi_controls_check.py: passgit diff --check origin/main...HEAD: clean
Not done in this review: the C++ fixtures need MSVC, so I did not mutate them on Linux. I will run them on the Windows pool before any merge decision.
Remaining risk: the claim that no recorded list or submission reads a title heap descriptor is a design argument, not something a fixture proves. It is opt-in, so I consider it acceptable.
AI-assisted; commands listed were executed locally.
#2579 builds and its new suites are wired correctly; the four
|
|
Win2025 WARP receipt for head 2981290 after updating with main (first run hit an sccache server crash, second run built only, third run executed the tests below). Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit
AI-assisted; commands listed were executed locally. |
Follow-up: the two suites I said I had not run, plus five mutations of the retire classificationSince my last comment said plainly that I had built but not run 14/14 on WARP and the physical GPU, with the Five mutations of
|
| mutation | result |
|---|---|
| the buffer-dimension exclusion removed | caught |
| the MSAA exclusion removed | caught |
the render-target / depth-stencil / UAV Flags exclusion removed |
caught |
the HeapType == DEFAULT requirement removed |
survived |
release_retired_views_enabled() no longer requires the master switch |
survived |
The three caught ones are the exclusions that decide "this resource is not in the retire class", and the reasons
suite names them — that is exactly what it is for, and each exclusion has a case.
The two survivors
HeapType == DEFAULT. No case creates a resource in an UPLOAD or READBACK heap and asserts that it is excluded.
The exclusion is one line and looks right; it simply has no fixture. Worth noting because a bug here would free a
readback resource the title still maps — the failure would be a crash on Unmap, not a wrong pixel.
release_retired_views without the master switch. The ENVIRONMENT for views_* always sets both
X2W_D3D12_RELEASE_RETIRED=1 and X2W_D3D12_RELEASE_RETIRED_VIEWS=1, and the keep control sets only the first — so
RETIRED_VIEWS=1 alone (without RELEASE_RETIRED) is never tried. That combination is the one the && guards, and it is
currently unconstrained. One case with X2W_D3D12_RELEASE_RETIRED_VIEWS=1 and no X2W_D3D12_RELEASE_RETIRED would pin
it, and it should behave as if views were off.
Neither is a defect I can demonstrate; both are places where the code is stricter than any fixture.
The title failure stands as reported
Nothing above changes my previous finding: startup_resource_retire_title_* fails identically on main (8f045aee) and
on this branch, with the magenta clear colour as the sampled value. It is pre-existing and it belongs in an issue, not
here.
AI-assisted; Windows 11 build 26300, WARP plus the installed physical GPU (Intel Arc 140T, driver 32.0.101.8132). Each
mutation rebuilt all three targets and re-ran the suites, then reverted and rebuilt; final state 14/14 green.
Change
Follow-up to the opt-in
X2W_D3D12_RELEASE_RETIRED=1path (#2443, #2468). That path keeps a released texture alive while any tracked slot-18 descriptor slot still names it. If the title never overwrites such a slot in a shader-visible heap, the texture stays alive for the rest of the process.This PR has three commits:
X2W_D3D12_RETIRE_REASONS=1is a diagnostic only. Together withX2W_D3D12_RELEASE_RETIRED=1andX2W_D3D12_BUDGET=1it adds onex2w-retire held:line to the heartbeat. The line counts final-released resources whose desktop object is still alive. It groups them by reason (view-refs,list-hold,flight,queued-waiting-fence,left-class:*,never-class:*) and gives the bytes and the oldest age in frames. It does not change behavior.X2W_D3D12_RELEASE_RETIRED_VIEWS=1is opt-in and works on top ofX2W_D3D12_RELEASE_RETIRED=1. Once the release-time fences have passed, the drain replaces descriptor slots that only name a released texture with null SRVs of the same dimension. It does this in every heap that has a shadow, copies included. It drops the shadow refs, clears the view records that name the resource, and clears the view token in title descriptor memory. Lists and submissions keep their desktop reference through the existingretire_holdand flight bookkeeping. A slot that cannot be rewritten keeps its ref, so its texture stays retained. Nothing waits on the GPU.draw_lock(try-acquire, never blocking) beforenote_lock, in the same order as the translated draw path. A draw holdsdraw_lockfrom the moment it reads a view record until it records its hold on the sampled texture. Without the lock, a texture could be dropped between those two steps.Without the new switches nothing changes. Documented in
docs/startup-runtime.md.Refs #2379
Verification
Build:
cmake --build --preset release(MSVC, VS 2026 BuildTools,X2W_WITH_OPUS=ON) atHEADrebased onto2f7fd286: exit 0, 0warning C.ctest --preset release --no-tests=error -R '<55 related tests>'gives:100% tests passed, 0 tests failed out of 55. The set:startup_resource_retire_reasons*andstartup_resource_retire_views*cases;startup_resource_retire*(incl._title),startup_resource_budget*,startup_resource_address_index*,startup_list_copy*,startup_resource_desc_*andstartup_address_srv_*cases;startup_stubsanddocs_links.Adapter: NVIDIA GeForce RTX 3080 (hardware cases) and WARP.
Evidence and follow-up
Both fixtures are source-built and need no external data.
startup_resource_retire_viewscreates textures with SRVs in shader-visible heaps, including copied slots. It releases the textures and reads the desktop descriptors back with a compute probe.keepandnoretiremodes are the negative controls: the texture must stay retained, and the slots must stay intact.startup_resource_retire_reasonscreates one resource per main reason and compares the whole heartbeat line. Theoffand no-retire modes are its negative controls.Checklist
AI-assisted (Claude Code). An independent read-only review found the draw/drain race fixed in the third commit.
🤖 Generated with Claude Code