d3d12: opt-in release of retired textures held only by never-overwritten descriptor slots #2571
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2579"
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 JB2WIN on 2026-11-25T21:39:13Z.
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
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T21:41:48Z.
Review: COMMENTED
Review of head
723d13db(comment only).What I checked:
X2W_D3D12_RELEASE_RETIRED_VIEWSthe drain returns beforeretire_null_ready_views, so default behavior is unchanged.retire_null_ready_views(draw_lock, thennote_lock, both try-acquire, no blocking) matches the order described fordraw_translated. Contention just defers the work.retire_views_stuck).retire_classify/retire_set_class, and slots 29/30 are marked aliased/reserved. The docs section was extended.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: cleanNot 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.
Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-25T21:48:17Z.
#2579 builds and its new suites are wired correctly; the four
startup_resource_retire_title_*cases in this PR fail identically onmain, so that is not this PR's regressionWhat I ran
Both new executables build. The
reasonsfamily (7 cases:warp/hardware×on/off/no-retire) and theviewsfamily (registered, needs its own target) are structured the right way — every positive case has an
offand ano-retirenegative control, so "the line appears" and "the line appears because the switch is on" are separateassertions.
The failure I want to place accurately
0xffff00ffis magenta, i.e.ClearRenderTargetView({1,0,1,1})— the test's own clear colour, not a sampled texel(
tests/startup_resource_retire_title.cpp:373). So the draw never wrote the pixel the case expects; it is reading thecleared target.
I checked
mainbefore writing this. On8f045aee, after checking the branch out and rebuilding the same target, thesame four cases fail with the same message and the same value.
git diff <merge-base> HEAD -- CMakeLists.txtshowsthis PR adds only
startup_resource_retire_reasonsandstartup_resource_retire_views— thetitleexecutable and itstwelve cases are already on
main.So: not a #2579 regression, and I am not reporting it as one.
What it is, and why it is worth a line of code
The
titlecases set onlyX2W_D3D12_BUDGET/PERMISSIVE/LIST_NOOP/RENDER/RESOURCE_INDEX_CHECK/DEBUG— nothing that pointsat a fixture file — and they are registered with
SKIP_RETURN_CODE 77. On this machine they fail rather than skip, whichmeans the pixel comparison runs and gets the clear colour. Either the translated-draw path is genuinely not producing
output here, or the case needs a condition it is not checking for. A magenta result is the signature of "nothing was
drawn", and a case whose whole point is "the sampled texture survived retirement" should distinguish "the draw did not
happen" from "the draw happened and sampled the wrong texel" — right now both read as a pixel mismatch.
Concretely I would (a) fail the draw itself with its own message before comparing pixels, or (b) return 77 when the
pipeline cannot be created, the way the dispatch cases do. Either way the message a future contributor sees would say
which of the two happened.
This is on
main, so it belongs in an issue rather than this PR — say the word and I will open it with this exacttranscript.
What I did not do
I did not run the
reasonsorviewssuites to completion:viewsreportsNot Runbecause its executable(
startup_resource_retire_viewsfromtests/startup_resource_retire_views.cpp) is a separate target I did not build,and
reasonsI built but did not run in this pass. Both are cheap to do next round; I would rather state that thanimply a green matrix I did not see.
AI-assisted; Windows 11 build 26300, WARP and the installed physical GPU, MSVC x64 via the Build Tools dev shell.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T21:53:31Z.
Win2025 WARP receipt for head
2981290dafter 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
2981290da425f5705407dcb6098e8620f8a65e43:--preset dev):cmake --build --preset dev --target d3d12_xs_device_obj d3d12_xs_shim startup_present_signature startup_resource_budget startup_resource_retire startup_resource_retire_reasons startup_resource_retire_title startup_resource_retire_views startup_upload_arena startup_upload_lifetime -- -j 2):2.08s(configure0.00s)ctest --preset dev -R 'startup_resource_retire|startup_resource_budget|startup_upload|startup_present_signature|d3d12_xs' --parallel 2 --no-tests=error --output-on-failure): 36/49 passed (3.24s:startup_present_signature_held_source_warp0.02s,startup_present_signature_unheld_source_control_warp0.02s,startup_upload_arena_warp0.17s,startup_upload_arena_hardware0.05s,startup_present_signature_warp0.42s,startup_upload_lifetime_warp0.28s,startup_upload_lifetime_hardware0.32s,startup_resource_budget_warp_debug00.37s,startup_resource_budget_warp_debug10.03s,startup_resource_budget_warp_debug1_inline_control0.03s,startup_resource_budget_warp_debug0_inline_control0.38s,startup_resource_budget_hardware_debug00.06s,startup_resource_budget_hardware_debug0_inline_control0.07s,startup_resource_budget_hardware_debug10.03s,startup_resource_budget_hardware_debug1_inline_control0.09s,startup_resource_retire_warp_debug10.03s,startup_resource_retire_warp_debug00.26s,startup_resource_retire_off_warp0.24s,startup_resource_retire_hardware_debug10.03s,startup_resource_retire_hardware_debug00.13s,startup_resource_retire_off_hardware0.14s,startup_resource_retire_reasons_off_warp0.16s,startup_resource_retire_reasons_warp0.25s,startup_resource_retire_reasons_no_retire_warp0.06s,startup_resource_retire_reasons_hardware0.07s,startup_resource_retire_reasons_off_hardware0.06s,startup_resource_retire_reasons_no_retire_hardware0.11s,startup_resource_retire_title_warp_debug10.03s,startup_resource_retire_title_off_warp0.19s,startup_resource_retire_title_warp_debug00.27s,startup_resource_retire_title_hardware_debug10.03s,startup_resource_retire_title_hardware_debug00.12s,startup_resource_retire_title_off_hardware0.14s,startup_resource_retire_views_warp_debug10.03s,startup_resource_retire_views_keep_warp0.11s,startup_resource_retire_views_warp_debug00.17s,startup_resource_retire_views_noretire_warp0.07s,startup_resource_retire_views_hardware_debug00.08s,startup_resource_retire_views_hardware_debug10.03s,startup_resource_retire_views_keep_hardware0.08s,startup_resource_retire_views_noretire_hardware0.12s,d3d12_xs_shim_exports0.05s,d3d12_xs_shim_serialize0.03s,d3d12_xs_shim_deserialize0.02s,d3d12_xs_shim_iids0.02s,d3d12_xs_shim_heap_indexing0.02s,d3d12_xs_range0.04s,d3d12_xs_range_full_last_window_control0.01s,d3d12_xs_shim_warp_root0.12s); skipped (capability, not a pass):startup_present_signature_held_source_warp,startup_present_signature_unheld_source_control_warp,startup_resource_budget_warp_debug1,startup_resource_budget_warp_debug1_inline_control,startup_resource_budget_hardware_debug1,startup_resource_budget_hardware_debug1_inline_control,startup_resource_retire_warp_debug1,startup_resource_retire_hardware_debug1,startup_resource_retire_title_warp_debug1,startup_resource_retire_title_hardware_debug1,startup_resource_retire_views_warp_debug1,startup_resource_retire_views_hardware_debug1,d3d12_xs_shim_heap_indexing/O2(--preset release):cmake --build --preset release --target d3d12_xs_device_obj d3d12_xs_shim startup_present_signature startup_resource_budget startup_resource_retire startup_resource_retire_reasons startup_resource_retire_title startup_resource_retire_views startup_upload_arena startup_upload_lifetime -- -j 2):3.25s(configure0.00s)ctest --preset release -R 'startup_resource_retire|startup_resource_budget|startup_upload|startup_present_signature|d3d12_xs' --parallel 2 --no-tests=error --output-on-failure): 36/49 passed (2.76s:startup_present_signature_held_source_warp0.02s,startup_present_signature_unheld_source_control_warp0.02s,startup_upload_arena_warp0.16s,startup_present_signature_warp0.27s,startup_upload_arena_hardware0.07s,startup_upload_lifetime_warp0.27s,startup_upload_lifetime_hardware0.33s,startup_resource_budget_warp_debug0_inline_control0.13s,startup_resource_budget_warp_debug10.03s,startup_resource_budget_warp_debug00.24s,startup_resource_budget_warp_debug1_inline_control0.03s,startup_resource_budget_hardware_debug00.06s,startup_resource_budget_hardware_debug0_inline_control0.07s,startup_resource_budget_hardware_debug10.04s,startup_resource_budget_hardware_debug1_inline_control0.07s,startup_resource_retire_warp_debug10.03s,startup_resource_retire_warp_debug00.25s,startup_resource_retire_off_warp0.19s,startup_resource_retire_hardware_debug10.03s,startup_resource_retire_hardware_debug00.09s,startup_resource_retire_off_hardware0.13s,startup_resource_retire_reasons_off_warp0.13s,startup_resource_retire_reasons_warp0.20s,startup_resource_retire_reasons_no_retire_warp0.06s,startup_resource_retire_reasons_hardware0.06s,startup_resource_retire_reasons_off_hardware0.05s,startup_resource_retire_reasons_no_retire_hardware0.09s,startup_resource_retire_title_warp_debug10.03s,startup_resource_retire_title_off_warp0.20s,startup_resource_retire_title_warp_debug00.31s,startup_resource_retire_title_hardware_debug10.03s,startup_resource_retire_title_hardware_debug00.08s,startup_resource_retire_title_off_hardware0.09s,startup_resource_retire_views_warp_debug10.03s,startup_resource_retire_views_warp_debug00.18s,startup_resource_retire_views_keep_warp0.09s,startup_resource_retire_views_noretire_warp0.07s,startup_resource_retire_views_hardware_debug00.08s,startup_resource_retire_views_hardware_debug10.03s,startup_resource_retire_views_keep_hardware0.07s,startup_resource_retire_views_noretire_hardware0.11s,d3d12_xs_shim_exports0.05s,d3d12_xs_shim_serialize0.02s,d3d12_xs_shim_deserialize0.02s,d3d12_xs_shim_iids0.02s,d3d12_xs_shim_heap_indexing0.02s,d3d12_xs_range0.05s,d3d12_xs_range_full_last_window_control0.01s,d3d12_xs_shim_warp_root0.12s); skipped (capability, not a pass):startup_present_signature_held_source_warp,startup_present_signature_unheld_source_control_warp,startup_resource_budget_warp_debug1,startup_resource_budget_warp_debug1_inline_control,startup_resource_budget_hardware_debug1,startup_resource_budget_hardware_debug1_inline_control,startup_resource_retire_warp_debug1,startup_resource_retire_hardware_debug1,startup_resource_retire_title_warp_debug1,startup_resource_retire_title_hardware_debug1,startup_resource_retire_views_warp_debug1,startup_resource_retire_views_hardware_debug1,d3d12_xs_shim_heap_indexingsccache: 20/28 hits; wall14.3sAI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-25T22:12:14Z.
Follow-up: the two suites I said I had not run, plus five mutations of the retire classification
Since my last comment said plainly that I had built but not run
reasons, and not builtviewsat all, here is that gapclosed.
14/14 on WARP and the physical GPU, with the
off/no-retire/keepcontrols each passing, which means each controlis genuinely reaching its "switch off ⇒ line absent" branch rather than passing vacuously.
Five mutations of
retire_classifyand the two switchesFlagsexclusion removedHeapType == DEFAULTrequirement removedrelease_retired_views_enabled()no longer requires the master switchThe three caught ones are the exclusions that decide "this resource is not in the retire class", and the
reasonssuite 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 anUPLOADorREADBACKheap 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_viewswithout the master switch. TheENVIRONMENTforviews_*always sets bothX2W_D3D12_RELEASE_RETIRED=1andX2W_D3D12_RELEASE_RETIRED_VIEWS=1, and thekeepcontrol sets only the first — soRETIRED_VIEWS=1alone (withoutRELEASE_RETIRED) is never tried. That combination is the one the&&guards, and it iscurrently unconstrained. One case with
X2W_D3D12_RELEASE_RETIRED_VIEWS=1and noX2W_D3D12_RELEASE_RETIREDwould pinit, 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
titlefailure stands as reportedNothing above changes my previous finding:
startup_resource_retire_title_*fails identically onmain(8f045aee) andon 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.