Skip to content

startup: release retired slot-133 title-memory textures and track slot-18 SRV reuse (slice 2) - #2468

Merged
R0Y00 merged 7 commits into
R0Y00:mainfrom
triggered02:startup/retire-slot133-textures
Nov 25, 2026
Merged

R0Y00 merged 7 commits into
R0Y00:mainfrom
triggered02:startup/retire-slot133-textures

Conversation

@triggered02

@triggered02 triggered02 commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Extends the merged Slice 1 (#2443, merge commit c887a65a) to device slot 133 (CreatePlacedResourceX) committed 2D textures with title_memory (Refs #2379, Slice 2).

Rebased onto origin/main 851a1400 as a clean linear chain of five commits (the earlier merge commit was linearized; its "keep both experiment records" resolution is preserved byte-for-byte — see the verification note). The slice-1 commits are not in this branch, and the diff against main is this slice plus the review follow-ups below (10 files, 1439 insertions, 61 deletions).

What changed (Slice 2)

  • Slot 133 class inclusion (src/startup_stubs/d3d12_xs_device.cpp): device_place_resource_x (slot 133) sets retire_when_idle = retire_class(..., address, allow_title_memory=true) for non-buffer committed 2D textures (1 sample, DEFAULT heap, no RT/DS/UAV flags); slot 127 resources with __XMemAllocationHooks__ title_memory stay excluded.
  • resource_address_index / existing_memory_texture: drain_retired_resources() erases (title_memory, wrapper) under note_lock after claiming refs (0 -> retired_refs) and before real->Release(), keeping resource_infos() intact.
  • texture_uploads / list_copy_texture / draw_lock: the upload gate is kind == subresource && (!own().retire_when_idle || own().title_memory), so with the switch off nothing changes for ordinary textures while retiring slot 133 textures still upload on CopyTextureRegion; sync_title_source() and the copy path guard texture_uploads() with draw_lock, and the drain erases real under draw_lock before real->Release(). dropped_flights is pre-reserved before retire_lock so flight collection cannot allocate under it.
  • written_textures: retire_note_title_release() snapshots written_textures()[addr].generation at final guest Release() (or clears immediately when no live sibling/tiled SRV or descriptor ref shares the address), and the drain clears stale entries only while the generation is unchanged and no live resource or tiled SRV uses the address.
  • Descriptor & view reuse (view_slot<18> SRVs + draw_translated): note_view/note_copy/retire_drop_heap_views track materialized slot-18 SRV descriptor slots through HeapInfo::shadow (retire_view_refs), falling back to retire_leave_class outside tracked heaps or for slots 19-21; draw_translated holds bound textures with retire_hold.
  • Review follow-ups (JB2WIN's read of 911375fa):
    • S3: the switch-off upload gate above (it was title_memory alone, which changed the off path for ordinary textures).
    • S5: desktop view creation returns void, so a removed device is the only failure it reports; record_view now materializes a view only when SUCCEEDED(GetDeviceRemovedReason()), releases the slot's previous view reference otherwise, and skips note_view_target.
    • S1/S2: retire_hold reads the wrapper's desktop pointer and takes its AddRef under retire_lock (a leaf, taken after draw_lock/allocator_lock; the drain releases it before taking the other locks), and a use it cannot record sets retire_hold_missed, which the drain re-checks and answers by keeping that desktop object for the process.
    • S6: the "newer generation preserved" case is now case 6.
    • B1: case 7 is a real draw path — a host-built translated pixel shader samples a slot-133 title-memory texture through a descriptor table written by slot 18, the readback must hold the exact texels plus a clear sentinel row/column, and the texture must stay in the budget until the closed draw recording is dropped.
    • B2: fail-first mutants for the drain view-ref gate, resource_address_index().erase, texture_uploads().erase, note_copy ref counting, retire_drop_heap_views, the release-time written_textures cleanup, and the drain generation match (all caught).
  • Fixture & docs: tests/startup_resource_retire_title.cpp (8 cases; startup_resource_retire_title_{warp,hardware}_debug{0,1} and _off_ with X2W_RESOURCE_INDEX_CHECK=1), fixture-only read-only probes x2w_d3d12_resource_index_probe, x2w_d3d12_texture_upload_probe, x2w_d3d12_written_probe, tests/startup_resource_retire.cpp classes() so slot 133 T retires while a live-SRV V stays retained, plus docs/startup-runtime.md and docs/experiments.md.

Verification (1ef07a64 on origin/main 851a1400)

  • ctest --preset dev --no-tests=error -R '^startup_resource_retire(_title)?_': 12 tests, 100% passed, 0 failed — 8 runnable pass on WARP (Microsoft Basic Render Driver) and on NVIDIA GeForce GTX 1660 SUPER with debug_errors_or_warnings=0, 4 _debug1 variants skip with 77 (Graphics Tools absent). Repeated 3×, green each time.
  • Broader suite ctest --preset dev -R '^(startup_resource_|startup_list_copy|startup_address_srv_)' -j 4: 34 tests, 100% passed, 0 failed.
  • Mutants (each temporary, reverted): the seven B2 mutants above, plus the S3 gate revert, plus B1's retire_hold removal (retained=0/0 expected=65536/1) and skipped token resolve (pixel (0,0) got 00000000 want fff8f1ea) — all caught on WARP and hardware.
  • git diff --check clean; tests/docs_links_check.py (19 files, 472 links), bidi_controls_check.py, startup_translator_check.py, startup_tools_lint_check.py, and main's new startup_gfx2hlsl_sop2_complement_check.py / startup_gfx2hlsl_getpc_refusal_check.py: PASS.
  • Linearization is lossless: for all 12 non-docs files the delta 4cd1cffc → 1ef07a64 is patch-identical to main's own 1405d945 → 851a1400 delta; docs/experiments.md at 1ef07a64 is exactly current main's text with the Slice 2 record appended, and that record is byte-identical to the merge resolution (the only lines not carried over are four that main itself rewrote in gfx2hlsl: lower s_nand_b32, s_nor_b32 and s_xnor_b32 on lane masks #2459).
  • End-to-end from JB2WIN (911375fa, RTX 3080, release build, X2W_D3D12_RELEASE_RETIRED=1 X2W_D3D12_BUDGET=1): process exited normally at 605 s, 17000 desktop references dropped, retained textures 4.36 GB / 2315 (Slice 1: access violation after 8x E_OUTOFMEMORY, 13.7 GB / 6733), no OOM and no device removal. Different game path from the Slice 1 run, so directional only.

Not established

  • The _debug1 variants have not run here (no debug layer); the new draw path is exercised with X2W_D3D12_DEBUG=0 only.
  • The remaining ~4.6 GB over budget and 2315 retained textures in the end-to-end run are consistent with textures still named by descriptor slots that are never overwritten; nothing here releases those.
  • Release-build and full-title start-up runs are JB2WIN's measurements, not reproduced on this host.

AI-assisted.

@JB2WIN

JB2WIN commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

A start-up measurement of 911375fa, plus review notes from reading the code.

Host: RTX 3080 10 GB, driver 32.0.16.2124, Windows 11 26200, release build, X2W_D3D12_RELEASE_RETIRED=1 X2W_D3D12_BUDGET=1, 40 GiB job cap, warm shader cache, manual input. Values are from the last heartbeat.

build end released local / budget texture retained OOM / device removed
#2443 (slice 1) access violation at 435 s after 8× E_OUTOFMEMORY (slot 133 placement) 0 22.4 / 9.4 GB 13.7 GB / 6733 8 / 0
#2468 (slice 2) process exited normally at 605 s 17000 desktop references dropped 14.1 / 9.5 GB 4.36 GB / 2315 0 / 0
unreviewed v2 prototype (no list or descriptor proof, for reference only) process exited normally at 753 s 21000 resources, 16.3 GB 8.7 / 9.5 GB 0 0 / 0

So slice 2 releases most of what slice 1 cannot. Local memory still ended about 4.6 GB over budget, with 2315 textures retained, presumably the ones still referenced from descriptor slots that were never overwritten (see S7 below). Not verified per resource. The run had no crash, no stop and no retire error. The two runs did not cover the same game path, so this is not a like-for-like comparison.

Notes from an independent read of the diff (not executed: no mutants and no extra tests were run here):

  • B1: tests/startup_resource_retire_title.cpp has no draw path (descriptor table bind, draw, readback after the guest release). This leaves retire_hold in d3d12_draw.inl:2017 and the token resolution at :1966-1984 untested: removing that hold would not fail the fixture.
  • B2: The new release conditions have no fail-first mutant: the retire_view_refs check in drain (d3d12_xs_device.cpp:4486), resource_address_index().erase (:4525), texture_uploads().erase (:4536), the note_copy ref counting (d3d12_capture.inl:347-361), retire_drop_heap_views (:4288) and written_textures generation keeping (:4323-4338, :4527-4533).
  • S3 (switch off): list_copy_texture.inl:150-160 now gates upload_texture on title_memory instead of !retire_when_idle. Without the switch, subresource copies of non-title-memory textures would no longer call it. Please check that this is intended, because "unset, nothing changes" is the contract from startup: opt-in release of retired committed 2D textures after list and fence lifetimes (slice 1) #2443.
  • S5: d3d12_xs_device.cpp:3857 calls record_view(true) even when the desktop view creation returned a failure HRESULT. That keeps the resource retained forever: a leak, not a safety issue.
  • S1/S2: retire_hold reads own().real without the lock (:4347), and its fallback only clears retire_when_idle (:4367), which drain does not re-check. This is only reachable with use after release, but it is worth one lock or atomic.
  • S6: the test header promises a "newer generation preserved" case that case 3 does not exercise.

AI-assisted (Claude Code)

@triggered02

Copy link
Copy Markdown
Contributor Author

Thanks — the end-to-end numbers are the part I could not produce here, and they match the intent of the slice: #2468 exits normally at 605 s, 17000 desktop references dropped, retained textures down to 4.36 GB / 2315 from 13.7 GB / 6733, with no E_OUTOFMEMORY and no device removal. I read the comparison as directional only, for the reason you give (different game path), and the remaining 4.6 GB over budget with 2315 retained textures is consistent with S7: a texture stays retained while a descriptor slot still references it, and nothing here overwrites those slots.

S3 is a real bug in this diff, not an intended change. You are right that the contract from #2443 is "switch off, nothing changes". The intended predicate is:

if (side_src.kind == x2w_list_copy_texture::Kind::subresource
    && (!src_wrapper->own().retire_when_idle || src_wrapper->own().title_memory)) {

With the switch off, retire_when_idle is false for every resource (the retire class is never assigned), so every subresource copy uploads exactly as before; with it on, retire-class resources that have no title memory still skip the upload, and the slot-133 title-memory textures upload, which is what makes releasing them safe. Gating on title_memory alone changed the switch-off path for ordinary textures and slipped past the fixture because case 1 only covers the switch-on slot-133 copy. I will add the switch-off ordinary-texture case, and title_memory-alone must fail it.

On the other notes — all accepted, and each gets a fail-first check rather than only a fix:

  • B1 (no draw path): add a case that places the slot-133 texture, binds it through a descriptor table, draws, reads the render target back, then releases the guest resource and drains, asserting the readback is still correct and the resource leaves the budget only after the drain. It must fail when retire_hold is removed and when the token resolution at d3d12_draw.inl:1966-1984 is broken; that is the only way the hold is actually pinned.
  • B2 (no mutants for the release conditions): one mutant per condition, each required to make startup_resource_retire_title fail — retire_view_refs gate in drain (d3d12_xs_device.cpp:4486), resource_address_index().erase (:4525), texture_uploads().erase (:4536), the note_copy per-slot ref counting (d3d12_capture.inl:347-361), retire_drop_heap_views (:4288), and the written_textures generation keeping (:4323-4338, :4527-4533).
  • S5 (record_view on a failed view creation): record the view only on a success HRESULT; on failure release the socket and do not retain, so a failed desktop view cannot pin the resource forever.
  • S1/S2 (retire_hold racing with release): take the retire lock while reading own().real, and make the fallback visible to drain — the class is cleared under the lock and drain re-checks it, so the fallback cannot leave a hold that nothing re-reads.
  • S6 (header promises a case the fixture does not run): add the "newer generation preserved" case, or delete the claim from the header comment. I will add the case.

#2443 is still open, so this stays stacked. I will push the S3 fix and the draw-path case first (they are independent of the slice-1 review), post the sha and the mutation results here, then rebase onto main and mark this Ready once #2443 lands.

If you disagree with the S3 predicate — in particular whether a non-title-memory resource should ever reach list_copy_texture at all when the switch is on — say so before I push it.

@JB2WIN

JB2WIN commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

A longer run of 911375fa on the same host and settings: 1005 s with manual input, stopped by me, no crash, no E_OUTOFMEMORY, no device removal, 26.3 fps.

  • The drain dropped 86000 desktop references.
  • texture retained still grows in steps at scene changes and does not come back down:
time local / budget texture retained
~300 s 10.3 / 9.5 GB 1.0 GB / 539
~400–600 s 13.3 / 9.5 GB 3.8 GB / ~2100 (flat)
~700 s 15.5 / 9.5 GB 7.5 GB / 3771
~800 s to end 17.4 / 9.5 GB 8.7 GB / 4375 (flat)

For comparison, the v2 prototype (no list or descriptor proof) ended a 753 s run with 0 retained and 8.7 GB local. So in this workload a large set of slot 133 textures stays alive after the guest Release, which matches S7 above. A guess, not verified per resource: they are still counted by retire_view_refs because their descriptor slots are never overwritten, or they left the class through a path that retire_leave_class takes. If it helps, I can rerun with an extra log line, for example a periodic count of the retired-but-held resources split by reason (view refs, list hold, flight, left class), if you add one behind an env switch.

AI-assisted (Claude Code)

@triggered02

Copy link
Copy Markdown
Contributor Author

Pushed 1a0ab9f8 (d52f267a source, 2ef78901 fixture, 1a0ab9f8 docs) on top of 911375fa. S3, S5, S1/S2, S6 and the B2 mutants are in; B1 (draw path) is not in this push — details at the bottom.

S3 — fixed, and the mutant now fails. Both gates are
kind == subresource && (!own().retire_when_idle || own().title_memory), so with the switch off every subresource copy uploads as before, and with it on only retire-class resources without title memory skip. Case 5 (off mode) copies between two slot-127 committed textures with no title memory. Observable: the per-desktop-object texture_uploads() entry that the no-title-memory path records — the existing x2w_d3d12_retire_probe is switch-gated and the sibling fixture asserts it must stay unavailable off, so the fixture gets a read-only x2w_d3d12_texture_upload_probe(desktop_ptr) plus the existing x2w_d3d12_list_copy_texture_stats forwarded counter. Reverting the predicate to title_memory alone fails _off_warp and _off_hardware with FAIL: ordinary texture copy recorded no upload (source=0 destination=0).

S5 — the premise does not hold, so the fix is different. The desktop view creation the shim binds for slots 19-21 returns void, not HRESULT; I checked with a typed vtable call and the return register holds a non-HRESULT value (e.g. 0x2dd3f490300), so "view creation returned a failure HRESULT" cannot happen. The only failure it reports is a removed device, so record_view() now records a materialized view only when SUCCEEDED(GetDeviceRemovedReason()); on failure the slot is recorded unmaterialized, which releases its previous view reference and adds none, and note_view_target is skipped. That closes the "view keeps the resource retained forever" case without inventing an HRESULT that does not exist. My first attempt trusted the call result and made hardware title runs flaky, which is how the void return surfaced; that attempt is gone.

S1/S2 — fixed. retire_hold reads own().real and does the AddRef under retire_lock; the leaf-lock rule is kept (retire_lock is taken after draw_lock/allocator_lock and nothing is taken under it, per the comment at d3d12_xs_device.cpp:4239; the draw and copy call sites are all draw_lock-then-retire_lock, and drain_retired_resources releases retire_lock before taking the other three, so no new ordering edge). The fallback now clears retire_when_idle and sets retire_hold_missed, which the drain re-checks under retire_lock: it counts retire_kept and drops only the retire bookkeeping, keeping the desktop object for the process, like a submission that cannot be fenced. Not fixture-covered: reaching it needs fault injection in the hold path (not in your B2 list).

S6 — fixed by adding the case. Case 6 (on mode): a live slot-18 SRV keeps the older resource pending; the entry survives Release with the generation snapshotted, a newer generation of the same address arrives, the view is dropped, and after the older resource retires the entry must still read generation 2. Case 3's comment no longer claims it.

B2 — seven mutants, all caught (each a temporary edit, reverted; on-mode mutants fail only _debug0, the off variants correctly unaffected, _debug1 skips with 77):

mutation failing CTest first assertion
drain retire_view_refs check disabled startup_resource_retire_title_warp_debug0 (+hardware) FAIL: T_addr2 freed while SRV slots live
resource_address_index().erase skipped same FAIL: resource_address_index entry for retired T_addr1 is still present
texture_uploads().erase skipped same FAIL: texture_uploads entry for retired T1 is still present
note_copy source add-ref loop removed same FAIL: Tv1 freed while copied SRV in heap2 holds it
retire_drop_heap_views made a no-op same FAIL: T_addr2 kept after heap released
release-time cleanup erases a live view's entry same FAIL: a live view did not keep written_textures entry
drain generation-match check removed same FAIL: retiring the older generation released the newer written generation

Two of those needed fixture probes as well: the index check only detects missing live entries, and written_textures is otherwise unobservable from the fixture, so x2w_d3d12_resource_index_probe and x2w_d3d12_written_probe exist next to the upload probe. All three are read-only, take the same locks the shim takes, change nothing, and answer in both switch modes.

Verification on 1a0ab9f8: ctest --preset dev --no-tests=error -R '^startup_resource_retire(_title)?_' → 12 tests, 8 passed, 4 skipped (_debug1, no debug layer), 0 failed; the suite was run repeatedly green, including 20 repeats on hardware. git diff --check clean, tests/docs_links_check.py passes (19 files, 467 links), docs/startup-runtime.md and docs/experiments.md describe the gate, the view recording and the hold fallback.

B1 (draw path) is the next push. It is a new fixture case rather than a fix: place the slot-133 texture, bind it through a descriptor table, draw, read the target back, then release the guest resource and drain, asserting the readback stays correct and the budget only lets go after the drain — with retire_hold removal and a broken token resolution as the two required mutants. I will post the sha here.

One unrelated observation, not caused by this change and not fixed here: startup_resource_retire_hardware_debug0 (the sibling non-title fixture) occasionally fails FAIL: the resolved destination is not the clear colour. It passed 10/10 on the pre-fix tree, did not reproduce in 8 later full-suite runs or 20 repeats on the final tree, and every required run was green.

@triggered02

Copy link
Copy Markdown
Contributor Author

B1 is in: d72f1e29 adds case7_draw_samples_slot133_texture to tests/startup_resource_retire_title.cpp (+302) plus the CMake link (d3dcompiler, for the host D3DCompile of the fixture shader) and the two docs paragraphs. No src/ change in this commit; the mutants below were temporary and reverted.

What the case does

  1. Builds a shader the shim can resolve itself, so nothing is hand-registered: device slot 16 root signature, slot 57 PSO with two synthetic code blobs and the root blob, published as <key>.txt + .vs.cso + .ps.cso into a per-pid X2W_SHADER_CACHE directory under %TEMP% (ud 1 / udsrc 0 rect / srv 0 tex2d table 0 0). The pixel shader does a Texture2D.Load of the slot-133 texture.
  2. Places a slot-133 title-memory 64x64 RGBA8 texture at a synthetic VirtualAlloc guest address filled with a generated pattern, creates the SRV through slot 18 (which writes the X2WV view token), binds it with SetDescriptorHeaps + SetGraphicsRootDescriptorTable, and draws a full-screen triangle through slot 12 into a 4x4 target (3x3 scissor, magenta clear).
  3. Reads the target back through the fixture's own queue/readback and asserts all 16 pixels: the 9 covered pixels are the exact sampled texel words, the 7 pixels of the untouched row/column are the clear sentinel, so a partial write cannot pass.
  4. x2w_d3d12_retire_probe must report list_holds > 0 for the closed list — that is the draw's retire_hold.
  5. Releases the guest resource, overwrites the descriptor with the target's SRV (dropping the slot-18 view reference), drains repeatedly: the budget must still count the texture retained (65536/1).
  6. The readback is still exact, then the recording is dropped; settle must show the texture leave the budget, and a third readback is still exact.

Mutants, both required ones fail the case (temporary edits to d3d12_draw.inl, reverted; verified on WARP and on the GTX 1660 SUPER, exit 5, not a build error):

mutant failure
M1: remove retire_hold(self, resource) at d3d12_draw.inl:2017 FAIL: slot 133 texture left the budget before its draw recording was dropped — stage 'slot 133 texture held by the closed draw list' live=262144/4 expected=262144/4 retained=0/0 expected=65536/1
M2: skip the token resolve at d3d12_draw.inl:1971-1975 (known = words[1] < view_records().size() → false) FAIL: slot 133 texture sampled by a translated draw: pixel (0,0) got 00000000 want fff8f1ea (with srv 0 texture: … -> view UNKNOWN, resource 0)

Verification on d72f1e29: cmake --build --preset dev --target startup_resource_retire_title clean; ctest --preset dev --no-tests=error -R '^startup_resource_retire(_title)?_' → 12/12, 100% passed, 0 failed, of which 8 runnable pass and the 4 _debug1 variants skip with 77 (no debug layer on this host). Case 7 passed on WARP (Microsoft Basic Render Driver) and on the NVIDIA GeForce GTX 1660 SUPER, both with debug_errors_or_warnings=0. git diff --check clean; tests/docs_links_check.py passes (19 files, 467 links).

Still not pinned, stated plainly: the new draw path has only run with X2W_D3D12_DEBUG=0, because the debug layer is absent here; M2 is the "skip the resolve" form (binds a null view) rather than picking a different live decoy token, which would need a second sampled texture; and the per-pid shader-cache directory under %TEMP% is left behind after a pass, same as startup_indirect_draw_indexed.

I am marking this Ready for review now. It is still stacked on #2443 (1ecd4cfc): when that merges I will rebase onto main, re-run these 12 tests plus startup_resource_retire and startup_translator_check, and post the rebased sha here before asking for merge.

@triggered02
triggered02 marked this pull request as ready for review November 25, 2026 18:41
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 25, 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-25T18:48:27.035984Z d72f1e2 Draft marked ready
ℹ️ 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.

@triggered02
triggered02 force-pushed the startup/retire-slot133-textures branch from d72f1e2 to d03296d Compare November 25, 2026 18:42
@triggered02 triggered02 changed the title startup: opt-in release of retired slot-133 title-memory textures (slice 2, stacked on #2443) startup: release retired slot-133 title-memory textures and track slot-18 SRV reuse (slice 2) Nov 25, 2026
@triggered02

Copy link
Copy Markdown
Contributor Author

Rebased onto main now that #2443 merged as c887a65: head is d03296d on origin/main d2cc0a7. The slice-1 commits are gone from this branch; the diff against main is the slice-2 change plus the S3/S5/S1/S2/S6 and B1/B2 follow-ups (10 files, +1440/-61). Rebuilt and re-ran after the rebase: ctest --preset dev --no-tests=error -R '^startup_resource_retire(title)?' gives 12/12, 100% passed, 0 failed (8 runnable on WARP and GTX 1660 SUPER, 4 _debug1 skipped 77), and docs_links_check.py passes with 470 links.

This is no longer stacked and is Ready for review. The review notes from your 911375f read are all answered in the two comments above (S3 fixed as the switch-off gate, S5 re-done because view creation returns �oid, S1/S2 under the retire lock with a drain re-check, S6 and B1 added as cases 6 and 7, seven B2 mutants caught). The description now matches this head.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d72f1e2957

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/startup_stubs/d3d12_xs_device.cpp Resolved

R0Y00 commented Nov 25, 2026

Copy link
Copy Markdown
Owner

I resolved the docs-only conflict with main and kept both experiment entries. The final pushed head is 4cd1cffc. Independent Windows Release build of startup_resource_retire, startup_resource_retire_title and startup_resource_budget, then ctest --preset release --no-tests=error -j 1 -R '^startup_resource_(retire|budget)' -V: 20/20 on WARP and RTX 4060 Laptop, with both debug modes and switch-off controls, zero skips. This verifies the source-built retention and draw fixtures. The actual executable comparison from #2379 uses a separate prototype. Fresh CI is pending.

@MasterDomino

Copy link
Copy Markdown
Collaborator

AMD data for this PR's own runtime code, @R0Y00: an executable run of #2468 itself, not the v2 prototype. I built and ran head d03296d3. The new head 4cd1cffc only merges main, and git diff d03296d3 4cd1cffc -- src/startup_stubs/ is empty, so the runtime code is identical. I'm reporting fixture results and executable results separately.

Fixture results (source-built)

  • Environment: Windows 11 build 26300, --preset release. AMD Radeon RX 9070 XT (1002:7550, driver 32.0.32029.2010) and WARP 10.0.26100.9818. The D3D12 debug layer is available on this host, so the _debug1 variants run here.
  • Command:
    ctest --preset release --no-tests=error -R '^startup_(resource|list_copy|address_srv)'
  • Result: 37/37 passed, 0 failed, 0 skipped. That covers retire, retire_title, budget, list_copy and address_srv on both adapters, including debug1.

Executable results (local title run, aggregates only)

build end released peak local / budget texture retained, end 0x8007000e / device removed
switch off (main) access violation at 493.9 s 0 21.0 / 16.2 GB 11.40 GB / 5171 14 / 0
#2468 d03296d3, switch on access violation at 573.8 s 54000 desktop references 20.3 / 16.2 GB 9.91 GB / 5083 8 / 0
v2 prototype, switch on (reference only) still running at the 600 s timeout 23000 resources, 18.8 GB 10.3 / 16.2 GB 0.01 GB / 8 0 / 0

Retention over time (budget heartbeats about 5 s apart):

arm ~290 s ~370 s ~460 s end
#2468 0.13 GB / 25 4.30 GB / 2069 7.15 GB / 3396 9.91 GB / 5083 at 574 s
off 0.08 GB / 14 5.85 GB / 2665 (~350 s) 8.77 GB / 4043 (~390 s) 11.40 GB / 5171 at 494 s

So on this card and cap, slice 2 slows the growth and moves the out-of-memory crash about 80 s later. Retention still climbs in steps and doesn't come back down, which is the same shape @JB2WIN saw on the RTX 3080. The last verified point is the run reaching 573.8 s. The first remaining failure is an access violation after 8× 0x8007000e in placement, the same failure mode as the off arm, just later.

This fits the S7 hypothesis: most retained textures stay counted through descriptor slots that are never overwritten. v2, which lacks that proof, keeps retention at zero. I haven't verified it per resource.

Merge status: the Codex P2 inline thread at d3d12_xs_device.cpp:4325 (an SRV-held sibling's written_textures entry erased on a sibling's release) is unresolved. I'm not merging while it's open. The fixture results above are fine.

Limits: one run, a local executable run rather than a source-built fixture, aggregate counters only.

AI-assisted; commands listed were executed locally.

@triggered02

Copy link
Copy Markdown
Contributor Author

Thanks for the merge commit 4cd1cff � I have kept it and did not force-push over it. My local rebase of the same five commits was discarded in favour of your merge, so the remote branch and this PR head stay as you left them.

Verified on 4cd1cff:

  • No conflict markers anywhere in docs/, and both experiment records are present (## Opt-in release of retired slot-133 title-memory textures (Slice 2) at 14791, the short-operand-list section at 14806).
  • ctest --preset dev --no-tests=error -R '^startup_resource_retire(title)?' ? 12 tests, 100% passed, 0 failed (8 runnable pass on WARP and the GTX 1660 SUPER, 4 _debug1 variants skip with 77 because the debug layer is absent here).
  • ests/docs_links_check.py ? 19 Markdown files, 470 links, pass.

CI is running on 4cd1cff now. The review follow-ups and the draw-path case from my earlier comments are all in this head; the only open limits are the ones stated in the description (no _debug1 coverage on this host, no AMD hardware, and the retained-texture remainder in the end-to-end run that this slice does not release).

triggered02 and others added 5 commits November 26, 2026 00:41
… retire fixture (B1)

startup_resource_retire_title had no draw path, so draw_translated's retire_hold and the slot-133 view-token resolution were untested. Case 7 samples a slot 133 title-memory texture through a descriptor table with a host-built translated pipeline and asserts the exact readback (including a clear sentinel row and column). The closed recording must keep the released texture retained until it is dropped, which is the hold; a skipped token resolve binds no view and fails the readback.
@triggered02
triggered02 force-pushed the startup/retire-slot133-textures branch from 4cd1cff to 1ef07a6 Compare November 25, 2026 19:16
@triggered02

Copy link
Copy Markdown
Contributor Author

Fixed and re-pushed: head is now 1ef07a64, a clean linear chain of the five slice-2 commits on current origin/main 851a1400 — the merge commit is gone, so the branch follows the same single-chain shape as the other PRs here.

1ef07a64 tests: cover the translated draw hold and SRV token resolution in the retire fixture (B1)
61b20893 docs: record the retire upload gate, view recording and hold fallback (review follow-up)
05bd5dc5 tests: cover the retire-class upload gate, newer written generations and retire bookkeeping
0b80b4d5 startup: guard the retire-class upload gate, hold lock and view recording (review follow-up)
141f6857 startup: release retired slot-133 title-memory textures and track slot-18 SRV reuse (slice 2)

The "keep both experiment records" resolution from 4cd1cffc is preserved, and I checked that claim rather than assuming it:

  • For all 12 non-docs files, the delta 4cd1cffc → 1ef07a64 is patch-identical (git patch-id) to main's own 1405d945 → 851a1400 delta — the rebase changed nothing in the code, tests, CMake or CI lists beyond what main itself changed.
  • docs/experiments.md at 1ef07a64 is exactly current main's text with the Slice 2 record appended at the end, and that record is byte-identical to the one in 4cd1cffc. The only lines from 4cd1cffc not present are four lines of the sop2-complement paragraph that main itself rewrote in gfx2hlsl: lower s_nand_b32, s_nor_b32 and s_xnor_b32 on lane masks #2459 — following main there is correct, not a loss. No conflict markers anywhere.

Verified on 1ef07a64:

  • Full cmake --build --preset dev (620 targets) → exit 0.
  • ctest --preset dev --no-tests=error -R '^startup_resource_retire(_title)?_' → 12/12 passed, repeated 3× green (8 runnable on WARP + GTX 1660 SUPER, 4 _debug1 skip 77, no debug layer here).
  • ctest --preset dev -R '^(startup_resource_|startup_list_copy|startup_address_srv_)' -j 4 → 34/34 passed.
  • docs_links_check.py (472 links), bidi_controls_check.py, startup_translator_check.py, startup_tools_lint_check.py, and main's new sop2_complement / getpc_refusal checks → all pass; git diff --check clean.

The description now matches this head. CI is running on 1ef07a64; the PR is MERGEABLE, and the only remaining gate is an approving review. The earlier mutant evidence (seven B2 mutants, the S3 gate revert, and B1's hold-removal / skipped-resolve mutants, all caught on WARP and hardware) applies unchanged because the code is byte-identical.

@ChazY11

ChazY11 commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Built and run here: 12/12 pass, two of three mutations caught, and the survivor is the UAV/RTV/DSV leave-class path that no test drives

ctest --preset dev -R 'resource_retire'
    startup_resource_retire_warp_debug0/1 ......  Passed
    startup_resource_retire_off_warp ...........  Passed
    startup_resource_retire_hardware_debug0/1 ..  Passed
    startup_resource_retire_off_hardware .......  Passed
    startup_resource_retire_title_warp_debug0/1   Passed
    startup_resource_retire_title_off_warp ....   Passed
    startup_resource_retire_title_hardware_debug0/1  Passed
    startup_resource_retire_title_off_hardware .  Passed
    100% tests passed, 0 tests failed out of 12

Six cases per backend with the debug layer on and off, on WARP and on the physical GPU — that is a good matrix for a
lifetime change, because a use-after-free usually shows up only with the debug layer's residency tracking on.

Reproduction note for anyone else: the six older startup_resource_retire_* cases come back Not Run unless
startup_resource_retire is built as well as startup_resource_retire_title. That is a missing executable, not a
failure; I hit it before building both.

Three mutations of the new retire logic

mutation of src/startup_stubs/d3d12_xs_device.cpp result
retire_drop_heap_views(self) skipped when the object is a descriptor heap caught
retire_note_title_release(self) skipped when retire_when_idle caught
leave-class range for UAV/RTV/DSV shifted: N >= 19 && N <= 21 → N >= 20 && N <= 22 survived

The two caught ones are the load-bearing halves: a heap released while views still reference its descriptors, and a
title release not recorded, both change the retire decision and both are asserted.

The survivor is a slot range the fixture never enters

The title fixture exercises the slot 18 SRV path throughout — T2 held by slot 70 → slot 18 SRV in heap[0],
descriptor/view reuse with CopyDescriptorsSimple, and dropping the descriptor that holds the SRV reference. The
if constexpr (N >= 19 && N <= 21) branch (UAV, RTV and DSV keep the resource's old lifetime) is a different class,
and nothing in the file drives it:

grep -n 'slot 1[89]|slot 2[0-2]' tests/startup_resource_retire_title.cpp
    644: T2 (held by slot 70 -> slot 18 SRV in heap[0]) …
    721: 4: descriptor & view reuse (slot 18 SRV + CopyDescriptorsSimple + heap release + …)
    929: … then drop the descriptor that holds its slot 18 SRV reference by …

A repo-wide search for a slot 19/20/21 case turns up unrelated tests (api_trace_check.cpp, startup_clear_uav.cpp,
the gamesave readers), none of which reaches this branch.

So shifting the range by one is invisible here: not a defect, and the branch may well be correct — but it is a class of
view whose retire behaviour this PR does not constrain. If a UAV or RTV view over a retired resource is something the
title does, one case that creates a slot-19 UAV and releases the resource underneath it would close it.

Environment

Windows 11 build 26300.9974; startup_resource_retire_title and startup_resource_retire built with
cmake --build --preset dev --target …; debug layer on and off in the matrix above. Each mutation was built, run,
reverted and rebuilt; final state 12/12 green.

AI-assisted.

@R0Y00

R0Y00 commented Nov 25, 2026

Copy link
Copy Markdown
Owner

Fixed the same-address SRV case in e29b1a7b. Releasing a second texture at the same address now preserves write/format metadata while an older slot-18 SRV still holds the first texture. The shared check protects cleanup at both release and drain. In the new control, removing the sibling-view check fails on WARP as soon as the newer wrapper is released. The exact fixed commit passed all 12 ^startup_resource_retire Release CTests on WARP and RTX 4060 Laptop, including debug-layer runs and switch-off controls. This verifies the source-built lifetime case. The matched executable retest remains tracked in #2379.

@triggered02

Copy link
Copy Markdown
Contributor Author

Your merge 35b4361 is the head and I kept it � I had a linearized rebase ready locally, but your merge commit was already on the remote, so I did not force-push over it.

Verified on 35b4361:

  • No conflict markers anywhere; both experiment records present in docs/experiments.md (## Startup translator: v_sad_u8, v_sad_u16 and v_sad_u32 at 14979, ## Opt-in release of retired slot-133 title-memory textures (Slice 2) at 14994).
  • Your same-address SRV fix is intact:
    etire_address_has_live_user present at the release and drain call sites, and both of your controls are in the fixture (FAIL: releasing the newer wrapper erased metadata � at :838, FAIL: draining the newer wrapper erased metadata � at :844).
  • The slice-2 draw-path case is intact (case7_draw_samples_slot133_texture at :864, called at :1065).
  • cmake --build --preset dev --target startup_resource_retire_title startup_resource_retire ? exit 0; ctest --preset dev --no-tests=error -R '^startup_resource_retire(title)?' ? 12/12 passed (4 _debug1 skip 77, no debug layer here); ests/docs_links_check.py ? 19 files/476 links.

CI on 35b4361 is green (Windows build, fixtures, Linux Python; /O2 and coverage skip by design). The branch is 4 commits behind current main, which GitHub re-checks on merge; I left that alone rather than adding another merge or rebasing over your commit. If you would rather have a single linear chain for the final merge, say the word and I will linearize it � otherwise this head is ready for approval.

@R0Y00
R0Y00 merged commit 6b9fb9d into R0Y00:main Nov 25, 2026
5 checks passed
@JB2WIN JB2WIN mentioned this pull request Nov 25, 2026
@JB2WIN

JB2WIN commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Follow-up for descriptor slots that are never overwritten: #2579 (opt-in, on top of X2W_D3D12_RELEASE_RETIRED=1). AI-assisted (Claude Code).

@Jess-Doit

Jess-Doit commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

@triggered02, a hardware result for the merged fixture: startup_resource_retire_title_hardware_debug0 and _debug1 fail on a GTX 1060 6GB. The failure is on a clean dev build of main 0104f763.

Host: Windows 10 19045, NVIDIA driver 32.0.15.6094, --preset dev.

Test Result
startup_resource_retire_title_warp_debug0 / _debug1 pass
startup_resource_retire_title_off_warp / _off_hardware pass
startup_resource_retire_title_hardware_debug0 (layer off) fail
startup_resource_retire_title_hardware_debug1 (layer on) fail

Both hardware arms stop at the same point, the last stage of case4_descriptor_and_view_reuse:

FAIL: Tv2 kept after heap2 released
  stage 'Tv2 retired after heap2 released' live=262144/4 expected=262144/4 retained=65536/1 expected=0/0
  • The earlier stages of case 4 pass on hardware: Tv1 held by both heaps, then by the heap2 copy, then retired after the descriptor overwrite, and Tv2 held by the overwritten heap2[0].
  • Only the retire on heap2.Reset() stays at 1 retained texture (64 KiB) after settle(). The WARP arms free it.
  • Live bytes and objects match, so the stray object is the released Tv2 and not a new allocation.

It failed in all 4 runs here: one on clean main, and three on a branch whose only change to this fixture is the draw_revision pin. I haven't looked into the cause. It may be in the heap-release path on hardware, or settle_limit may not cover a slower fence on this adapter. I can run a variant with a larger settle limit or extra drains here if that would help.

AI-assisted (Claude Code).

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.

6 participants