Skip to content

d3d12: opt-in release of retired textures held only by never-overwritten descriptor slots - #2579

Merged
tedin7 merged 4 commits into
R0Y00:mainfrom
JB2WIN:startup/retire-held-reasons
Nov 25, 2026
Merged

tedin7 merged 4 commits into
R0Y00:mainfrom
JB2WIN:startup/retire-held-reasons

Conversation

@JB2WIN

@JB2WIN JB2WIN commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Change

Follow-up to the opt-in X2W_D3D12_RELEASE_RETIRED=1 path (#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=1 is a diagnostic only. Together with X2W_D3D12_RELEASE_RETIRED=1 and X2W_D3D12_BUDGET=1 it adds one x2w-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=1 is opt-in and works on top of X2W_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 existing retire_hold and flight bookkeeping. A slot that cannot be rewritten keeps its ref, so its texture stays retained. Nothing waits on the GPU.
  • The slot clearing takes draw_lock (try-acquire, never blocking) before note_lock, in the same order as the translated draw path. A draw holds draw_lock from 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) at HEAD rebased onto 2f7fd286: exit 0, 0 warning C.

ctest --preset release --no-tests=error -R '<55 related tests>' gives: 100% tests passed, 0 tests failed out of 55. The set:

  • the new startup_resource_retire_reasons* and startup_resource_retire_views* cases;
  • the existing startup_resource_retire* (incl. _title), startup_resource_budget*, startup_resource_address_index*, startup_list_copy*, startup_resource_desc_* and startup_address_srv_* cases;
  • startup_stubs and docs_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_views creates textures with SRVs in shader-visible heaps, including copied slots. It releases the textures and reads the desktop descriptors back with a compute probe.
    • The keep and noretire modes are the negative controls: the texture must stay retained, and the slots must stay intact.
    • Four local mutants fail the fixture: null rewrite omitted, release-time fence ignored, token not cleared, and copies skipped.
  • startup_resource_retire_reasons creates one resource per main reason and compares the whole heartbeat line. The off and no-retire modes are its negative controls.
  • Not covered by a fixture:
    • the draw/drain interleaving fixed in the third commit, because the window is not deterministically reachable from a single-threaded fixture;
    • the "slot cannot be rewritten" (stuck) path.

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.
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted (Claude Code). An independent read-only review found the draw/drain race fixed in the third commit.

🤖 Generated with Claude Code

JB2WIN and others added 3 commits November 25, 2026 22:37
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 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 723d13d (comment only).

What I checked:

  • Both new switches are opt-in. Without X2W_D3D12_RELEASE_RETIRED_VIEWS the drain returns before retire_null_ready_views, so default behavior is unchanged.
  • Lock order in retire_null_ready_views (draw_lock, then note_lock, both try-acquire, no blocking) matches the order described for draw_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_views has keep and noretire negative controls; startup_resource_retire_reasons has off/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: pass
  • git 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.

@ChazY11

ChazY11 commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

#2579 builds and its new suites are wired correctly; the four startup_resource_retire_title_* cases in this PR fail identically on main, so that is not this PR's regression

What I ran

cmake --preset dev                                     → OK
cmake --build --preset dev --target startup_resource_retire        → exit 0
cmake --build --preset dev --target startup_resource_retire_reasons → exit 0
ctest --preset dev -R 'resource_retire'                → 26 cases registered

Both new executables build. The reasons family (7 cases: warp/hardware × on/off/no-retire) and the views
family (registered, needs its own target) are structured the right way — every positive case has an off and a
no-retire negative control, so "the line appears" and "the line appears because the switch is on" are separate
assertions.

The failure I want to place accurately

startup_resource_retire_title_{warp,hardware}_debug{0,1}
    FAIL: slot 133 texture sampled by a translated draw: pixel (0,0) got ffff00ff want fff8f1ea

0xffff00ff is 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 the
cleared target.

I checked main before writing this. On 8f045aee, after checking the branch out and rebuilding the same target, the
same four cases fail with the same message and the same value. git diff <merge-base> HEAD -- CMakeLists.txt shows
this PR adds only startup_resource_retire_reasons and startup_resource_retire_views — the title executable and its
twelve 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 title cases set only X2W_D3D12_BUDGET/PERMISSIVE/LIST_NOOP/RENDER/RESOURCE_INDEX_CHECK/DEBUG — nothing that points
at a fixture file — and they are registered with SKIP_RETURN_CODE 77. On this machine they fail rather than skip, which
means 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 exact
transcript.

What I did not do

I did not run the reasons or views suites to completion: views reports Not Run because its executable
(startup_resource_retire_views from tests/startup_resource_retire_views.cpp) is a separate target I did not build,
and reasons I built but did not run in this pass. Both are cheap to do next round; I would rather state that than
imply 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.

@tedin7

tedin7 commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

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 2981290da425f5705407dcb6098e8620f8a65e43:

  • Debug (--preset dev):
    • Build (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 (configure 0.00s)
    • Test (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_warp 0.02s, startup_present_signature_unheld_source_control_warp 0.02s, startup_upload_arena_warp 0.17s, startup_upload_arena_hardware 0.05s, startup_present_signature_warp 0.42s, startup_upload_lifetime_warp 0.28s, startup_upload_lifetime_hardware 0.32s, startup_resource_budget_warp_debug0 0.37s, startup_resource_budget_warp_debug1 0.03s, startup_resource_budget_warp_debug1_inline_control 0.03s, startup_resource_budget_warp_debug0_inline_control 0.38s, startup_resource_budget_hardware_debug0 0.06s, startup_resource_budget_hardware_debug0_inline_control 0.07s, startup_resource_budget_hardware_debug1 0.03s, startup_resource_budget_hardware_debug1_inline_control 0.09s, startup_resource_retire_warp_debug1 0.03s, startup_resource_retire_warp_debug0 0.26s, startup_resource_retire_off_warp 0.24s, startup_resource_retire_hardware_debug1 0.03s, startup_resource_retire_hardware_debug0 0.13s, startup_resource_retire_off_hardware 0.14s, startup_resource_retire_reasons_off_warp 0.16s, startup_resource_retire_reasons_warp 0.25s, startup_resource_retire_reasons_no_retire_warp 0.06s, startup_resource_retire_reasons_hardware 0.07s, startup_resource_retire_reasons_off_hardware 0.06s, startup_resource_retire_reasons_no_retire_hardware 0.11s, startup_resource_retire_title_warp_debug1 0.03s, startup_resource_retire_title_off_warp 0.19s, startup_resource_retire_title_warp_debug0 0.27s, startup_resource_retire_title_hardware_debug1 0.03s, startup_resource_retire_title_hardware_debug0 0.12s, startup_resource_retire_title_off_hardware 0.14s, startup_resource_retire_views_warp_debug1 0.03s, startup_resource_retire_views_keep_warp 0.11s, startup_resource_retire_views_warp_debug0 0.17s, startup_resource_retire_views_noretire_warp 0.07s, startup_resource_retire_views_hardware_debug0 0.08s, startup_resource_retire_views_hardware_debug1 0.03s, startup_resource_retire_views_keep_hardware 0.08s, startup_resource_retire_views_noretire_hardware 0.12s, d3d12_xs_shim_exports 0.05s, d3d12_xs_shim_serialize 0.03s, d3d12_xs_shim_deserialize 0.02s, d3d12_xs_shim_iids 0.02s, d3d12_xs_shim_heap_indexing 0.02s, d3d12_xs_range 0.04s, d3d12_xs_range_full_last_window_control 0.01s, d3d12_xs_shim_warp_root 0.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
  • Release /O2 (--preset release):
    • Build (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 (configure 0.00s)
    • Test (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_warp 0.02s, startup_present_signature_unheld_source_control_warp 0.02s, startup_upload_arena_warp 0.16s, startup_present_signature_warp 0.27s, startup_upload_arena_hardware 0.07s, startup_upload_lifetime_warp 0.27s, startup_upload_lifetime_hardware 0.33s, startup_resource_budget_warp_debug0_inline_control 0.13s, startup_resource_budget_warp_debug1 0.03s, startup_resource_budget_warp_debug0 0.24s, startup_resource_budget_warp_debug1_inline_control 0.03s, startup_resource_budget_hardware_debug0 0.06s, startup_resource_budget_hardware_debug0_inline_control 0.07s, startup_resource_budget_hardware_debug1 0.04s, startup_resource_budget_hardware_debug1_inline_control 0.07s, startup_resource_retire_warp_debug1 0.03s, startup_resource_retire_warp_debug0 0.25s, startup_resource_retire_off_warp 0.19s, startup_resource_retire_hardware_debug1 0.03s, startup_resource_retire_hardware_debug0 0.09s, startup_resource_retire_off_hardware 0.13s, startup_resource_retire_reasons_off_warp 0.13s, startup_resource_retire_reasons_warp 0.20s, startup_resource_retire_reasons_no_retire_warp 0.06s, startup_resource_retire_reasons_hardware 0.06s, startup_resource_retire_reasons_off_hardware 0.05s, startup_resource_retire_reasons_no_retire_hardware 0.09s, startup_resource_retire_title_warp_debug1 0.03s, startup_resource_retire_title_off_warp 0.20s, startup_resource_retire_title_warp_debug0 0.31s, startup_resource_retire_title_hardware_debug1 0.03s, startup_resource_retire_title_hardware_debug0 0.08s, startup_resource_retire_title_off_hardware 0.09s, startup_resource_retire_views_warp_debug1 0.03s, startup_resource_retire_views_warp_debug0 0.18s, startup_resource_retire_views_keep_warp 0.09s, startup_resource_retire_views_noretire_warp 0.07s, startup_resource_retire_views_hardware_debug0 0.08s, startup_resource_retire_views_hardware_debug1 0.03s, startup_resource_retire_views_keep_hardware 0.07s, startup_resource_retire_views_noretire_hardware 0.11s, d3d12_xs_shim_exports 0.05s, d3d12_xs_shim_serialize 0.02s, d3d12_xs_shim_deserialize 0.02s, d3d12_xs_shim_iids 0.02s, d3d12_xs_shim_heap_indexing 0.02s, d3d12_xs_range 0.05s, d3d12_xs_range_full_last_window_control 0.01s, d3d12_xs_shim_warp_root 0.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
  • sccache: 20/28 hits; wall 14.3s

AI-assisted; commands listed were executed locally.

@tedin7
tedin7 merged commit fc97ade into R0Y00:main Nov 25, 2026
5 checks passed
@ChazY11

ChazY11 commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

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 built views at all, here is that gap
closed.

cmake --build --preset dev --target startup_resource_retire_views   → exit 0
ctest --preset dev -R 'resource_retire_(reasons|views)'
    startup_resource_retire_reasons_{warp,hardware} ...............  Passed
    startup_resource_retire_reasons_off_{warp,hardware} ...........  Passed
    startup_resource_retire_reasons_no_retire_{warp,hardware} .....  Passed
    startup_resource_retire_views_{warp,hardware}_debug{0,1} ......  Passed
    startup_resource_retire_views_keep_{warp,hardware} ............  Passed
    startup_resource_retire_views_noretire_{warp,hardware} ........  Passed
    100% tests passed, 0 tests failed out of 14

14/14 on WARP and the physical GPU, with the off / no-retire / keep controls each passing, which means each control
is genuinely reaching its "switch off ⇒ line absent" branch rather than passing vacuously.

Five mutations of retire_classify and the two switches

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.

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.

3 participants