startup: give the placed page aliases and the draw dumps the teardown boundary #2623
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2631"
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 thepatrickworld on 2026-11-25T23:39:21Z.
What / Why
Refs #2572, follow-up to #2590. That patch gave the indexed-validation pipeline and the rectangle-list converter an explicit lifetime boundary. Two more function-local statics in the shim own desktop D3D12 objects and are destroyed during the module's CRT teardown — the moment #2590 showed reaches a display driver Windows has already detached:
d3d12_xs_device.cpp);draw_dump_tracking.h), which hold a recorded copy and its fence.Change
Both get the contract #2590 introduced: on the terminating path they detach their references, and on
FreeLibrarythey release them normally, driven by the flag instartup_stubs/d3d12_teardown.h.PlacedPageAliaseswraps thestd::array<Page, 64>;begin()/end()keep the lookup, the free-slot scan and the insertion identical, so no call site changed. The heap and page words stay plain addresses, not owned.DrawReadbackswalksentries_in its destructor and detaches each recorded buffer and its fence.d3d12_teardown.hnow names both.What is measured, and what is not
Neither site faults on this machine. With the detach disabled, the alias run still exits
0while releasing its two pages at teardown — unlike #2590, where removing either destructor put the fault back with its own child exit code. The boundary is made uniform with #2590's; it is not a repair of an observed failure.What the ownership is worth is now checked from the sources instead of assumed.
x2w_d3d12_cached_objects_probegrew two bits that populate the two caches on the desktop device — a heap and a placed buffer for the alias route (bit 4), the readback buffer and the fence a recorded dump holds (bit 8) — andstartup_teardown_unloadcovers four caches:FreeLibrary, each cache must give back what it took — the device reference count for the two original caches, the entry's own object count for the two new ones, which hold no reference on the device — and the fixture owns the heap behind the placed buffer, checking that the buffer was released first and releasing the heap last;detached=<owned> released=0per cache throughX2W_TEARDOWN_REPORT, and the parent requires it;X2W_TEARDOWN_NO_GUARD=<cache>turns that cache's detach into a normal release, and the check must then fail. Without that control the guard would be untested.The other statics of this shape
A scan of
src/for function-local statics whose type holds aComPtr(qualified names included) finds five:d3d12_draw.inl—IndexedValidationPipeline, fixed in #2590.rect_indirect_args.h—RectIndirectArguments, fixed in #2590.d3d12_xs_device.cpp— the page cache, this patch.draw_dump_tracking.h—DrawReadbacks, this patch.red_producer_diagnostic.inl—RedProducers, safe by construction: the live instance is heap-allocated and never destroyed, and the static fallback is built through theDisabledtag and owns nothing.Test
Built at
8ecaa8ecwith this patch applied, Windows 11 25H2, MSVC 19.44.35230, AMD Radeon RX 9070 XT (1002:7550, driver32.0.32029.2010):The debug layer is not installed on this machine (
d3d12SDKLayers.dllis absent), so these runs carry no validation-layer output.hardware: exit0,PASS;warp(Microsoft Basic Render Driver): exit0,PASS.X2W_TEARDOWN_NO_GUARD=pages: exit11,pages detached=0 released=1 (want detached=1 released=0).X2W_TEARDOWN_NO_GUARD=readbacks: exit11,readbacks detached=0 released=2 (want detached=2 released=0).translated-indexed,-upload,-rect,-alias,recton the card, andalias-offon the card plustranslated-indexedon WARP: child exit0each, unchanged.Two defects surfaced while building the check, both fixed in the second commit: the probe answered
0because a fixture created without a parameter block gets a bareD3D12CreateDevicedevice back, which is not in the shim registry, soas_wrapper()finds nothing — that device is already the desktop one and is now used as such; andwiden()kept the terminating nullMultiByteToWideCharwrites with-1, soCreateProcessWtruncated the child command line.Not covered
The crash class itself for these two caches: no fault appears here with or without the guard, and #2590 stays the reproduction. The negative control therefore proves that a release is detected where a detach was required, not that such a release faults on this driver — both no-guard children exit cleanly.
The fixture loads no title, so both entries are placed by test hooks (
insert_for_test,record_for_test) rather than by the real route and dump paths, and the entered alias is an ordinary placed buffer, not anALLOW_CROSS_ADAPTERone over a title address: cross-adapter sharing is still not exercised. On WARP, one negative-control run lost the pages report line (the assertion still failed as required), so the child's report path has that intermittency.AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T23:41:17Z.
Review: COMMENTED
Review of head
15c7dbbe(comment only).Read the full diff against origin/main (3 files, +48/-5).
PlacedPageAliaseskeeps lookup, free-slot scan and insertion identical throughbegin()/end(); the call site changes only byusing Pageand the static type. The 64-entry array is value-initialized, so the detach loop is safe on never-used slots.DrawReadbacks::~DrawReadbacksdetaches each recorded buffer and fence only whend3d12_process_terminatingis set. FreeLibrary still releases normally. Same contract as #2590.d3d12_teardown.his already included byd3d12_xs_device.cpp; the new include indraw_dump_tracking.hresolvesx2w_startup::d3d12_process_terminatinginside the same namespace.Commands run locally:
git diff --stat origin/main...HEAD,git diff --check origin/main...HEAD(clean),rgover the teardown header and includes.Not verified / why not merged by us:
Code looks sound to me.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-25T23:51:20Z.
Review: CHANGES_REQUESTED
Please add a source-built check for the ownership change before we land it. The reported alias run establishes that the cache is populated, but exits successfully with or without the new guard. The draw-dump path has no populated test at this head. Please exercise a populated alias entry and a recorded draw readback and verify that normal unload releases the owned resources and fence, while process termination detaches those references. A release counter or test hook is enough if disabling either new guard makes its corresponding check fail. The #2590 crash reproduction can stay separate.
Imported from R0Y00/Xbox2Windows. Originally posted by thepatrickworld on 2026-11-25T23:49:34Z.
Quick recap so this one is cheap to read.
In one line: two more function-local statics that own desktop D3D12 objects now get the teardown boundary #2590 introduced, so no function-local static cache of that shape in
src/is left without one. Refs #2572.What changed — 3 files, +48/−5, no call-site edits:
PlacedPageAliaseswraps thestd::array<Page, 64>of the translated indirect address route;begin()/end()keep the lookup and free-slot scan identical.DrawReadbacksdetaches each recorded buffer and its fence in its destructor.d3d12_teardown.hnames both in its boundary comment.The one thing worth your attention before reading the diff: no crash was reproduced here — the page cache is the only one of the two sites these runs exercise. A probe in the destructor shows
translated-indexed-aliasholds 2 placed pages at exit, so the cache is populated and the detach runs; but with the detach removed, the same mode still exits0while releasing both pages at teardown. This is #2590's boundary, not a fix for an observed fault. Default is to keep it: it is self-contained, 48 lines, no call-site edits, nothing stacks on it. If you'd rather not carry a defensive change with no failure behind it, say so and I'll close it; #2590 is where removing the destructor puts the fault back with its own child exit code.Everything else verified: built at
66026a39with the patch applied (same tree as the pushed15c7dbbe), RX 9070 XT (1002:7550, driver32.0.32029.2010), child exit0fortranslated-indexed,-upload,-rect,-alias,rect, plusalias-offon the card andtranslated-indexedon WARP, andstartup_teardown_unload hardware: PASS. CI on15c7dbbe: Windows, Python on Linux and the gfx1013 fixtures all green; the two skipped checks (/O2build, coverage chart) are gated to non-PR runs, not path-filtered.Left alone on purpose: the draw-dump cache runs only when a dump frame is requested, so it is untested here; and a scan of
src/for statics of this shape finds five, of whichRedProducers(red_producer_diagnostic.inl) is safe by construction — heap-allocated live instance never destroyed, static fallback built through theDisabledtag and owning nothing.AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-26T00:54:56Z.
Review: CHANGES_REQUESTED
The revised probe now covers both populated caches. One ownership hole remains in that probe:
heap.Detach()abandons the creator’s backing-heap reference. The cache keeps only a non-owning heap pointer, andx2w_d3d12_cached_object_probereturns the placed buffer, so the normalFreeLibraryfixture has no owner that can release the heap after the placed resource. Please have the test own the backing heap through the unload and placed-resource release, then release it. Keep the reference-count and process-exit controls for the alias, readback and fence.Imported from R0Y00/Xbox2Windows. Originally posted by thepatrickworld on 2026-11-26T00:47:22Z.
All four points are in
e23f26f5(the head; its commit message was re-worded after this reply, the tree is the one described below), built and run on the RX 9070 XT (1002:7550, driver32.0.32029.2010) and on WARP.Populated entries.
x2w_d3d12_cached_objects_probegrew two bits. Bit 4 creates a heap and a placed buffer on the desktop device, enters it where the translated indirect address route keeps its aliases, and answers1; bit 8 creates the readback buffer and the fence a recorded dump holds and answers2. Trace at this head:heap hr=0x00000000,placed hr=0x00000000,insert=1 used=1/64,readback hr=0x00000000,fence hr=0x00000000,record=1.Normal unload releases.
startup_teardown_unloadnow covers four caches and requires each one to give back what it took -- the device reference count for the two original caches, the entry's own object count for the two new ones:Process termination detaches. The child process reports per cache, and the parent requires
detached=<owned> released=0:Negative control. After the passing run the test re-runs the child once per cache with
X2W_TEARDOWN_NO_GUARD=<cache>, which turns that cache's detach into a normal release, and requires the check to fail:Exit codes:
hardware0,warp0, and with either no-guard variable set11.Two defects surfaced while building the check, both fixed: the probe answered
0because a fixture creates its device without a parameter block, soD3D12XboxCreateDevicereturns a plainD3D12CreateDeviceresult that is not in the shim registry,as_wrapper()returned null and the probe stopped there -- the desktop device is the handle itself on that path (removal_deviceis no help:attach_device()is its only writer, so there it is null or names another device); andwiden()kept the terminating nullMultiByteToWideCharwrites with-1, soCreateProcessWtruncated the child command line.Limits of this check, so it is not read as more than it is: the fixture loads no title, and both new entries come from hooks on the caches themselves (
insert_for_test,record_for_test) rather than from a real translated-indirect-address call or a real draw dump; the entered entry is an ordinary placed buffer, not aALLOW_CROSS_ADAPTERone over a title address, so cross-adapter sharing is still not exercised; the negative control shows that the check notices a release at exit, not that the release faults (both no-guard children exited cleanly on this driver); and on WARP the readbacks negative-control run printed no line for the pages cache (the assertion still failed correctly, so the run stays green, but that line did not appear that time).AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-26T01:45:42Z.
Review: APPROVED
Windows Release passed both teardown CTests at
224e286a, on WARP and RTX 4060 Laptop. Normal unload relinquishes the placed buffer and the fixture releases the backing heap last to reference zero. The new error-path ordering also preserves that heap until the cache unloads. The two per-cache process-exit controls still detect releasing instead of detaching. This resolves the backing-heap ownership finding.Imported from R0Y00/Xbox2Windows. Originally posted by thepatrickworld on 2026-11-26T01:34:23Z.
You are right about the abandoned heap: the cache holds only a non-owning heap pointer, so
heap.Detach()left the backing heap with no owner onceFreeLibraryhad released the placed buffer. Fixed inace926c0.The probe now hands the heap over with a reference the fixture owns, and
startup_teardown_unloadholds it across the unload and releases it last:Releasing it after
FreeLibraryis safe in this fixture for a reason the code states: the heap is created on the desktop device, which for a fixture built without a parameter block is the bareD3D12CreateDeviceobject, so its vtable lives ind3d12.dlland not ind3d12_xs.dll; and the fixture still holds that device at that point, so the runtime cannot be unloaded under the heap.The other controls are unchanged, and re-run at this head (
ace926c0, RX 9070 XT1002:7550, driver32.0.32029.2010):Exit codes:
hardware0,warp0, and11with either no-guard variable set. The debug layer is not installed on this machine (d3d12SDKLayers.dllis absent), so these runs carry no validation-layer output.AI-assisted.