startup: give the placed page aliases and the draw dumps the teardown boundary #2623

Merged
thepatrickworld merged 4 commits from upstream-pr/2631 into main 2026-11-26 01:48:48 +00:00
thepatrickworld commented 2026-11-25 23:39:21 +00:00 (Migrated from github.com)

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:

  • the placed page aliases of the translated indirect address route (d3d12_xs_device.cpp);
  • the draw-dump readbacks (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 FreeLibrary they release them normally, driven by the flag in startup_stubs/d3d12_teardown.h.

  • PlacedPageAliases wraps the std::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.
  • DrawReadbacks walks entries_ in its destructor and detaches each recorded buffer and its fence.
  • The boundary comment in d3d12_teardown.h now names both.

What is measured, and what is not

Neither site faults on this machine. With the detach disabled, the alias run still exits 0 while 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_probe grew 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) — and startup_teardown_unload covers four caches:

  • on 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;
  • on process termination, the child reports detached=<owned> released=0 per cache through X2W_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 a ComPtr (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 the Disabled tag and owns nothing.

Test

Built at 8ecaa8ec with this patch applied, Windows 11 25H2, MSVC 19.44.35230, AMD Radeon RX 9070 XT (1002:7550, driver 32.0.32029.2010):

cmake --preset dev -DINTAKE_PYTHON=…\out\pe-env\Scripts\python.exe
cmake --build --preset dev --target d3d12_xs_shim startup_teardown_unload startup_indirect_draw_indexed
.\out\build\dev\startup_teardown_unload.exe <abs path>\d3d12_xs.dll hardware
unload indexed-validation: 3 objects released, references 4 -> 1, module unloaded
unload rect-converter: 2 objects released, references 3 -> 1, module unloaded
warm placed-pages: backing heap handed over with 1 reference
unload placed-pages: heap alive after the unload, 1 reference, placed buffer released first
unload placed-pages: heap released last, 1 -> 0
unload placed-pages: 1 objects released, module unloaded
unload draw-readbacks: 2 objects released, module unloaded
x2w-teardown readbacks detached=2 released=0
x2w-teardown pages detached=1 released=0
termination: both caches detached every owned reference, released none
negative control X2W_TEARDOWN_NO_GUARD=pages: the check failed as it must
negative control X2W_TEARDOWN_NO_GUARD=readbacks: the check failed as it must
startup_teardown_unload hardware: PASS

The debug layer is not installed on this machine (d3d12SDKLayers.dll is absent), so these runs carry no validation-layer output.

  • hardware: exit 0, PASS; warp (Microsoft Basic Render Driver): exit 0, PASS.
  • X2W_TEARDOWN_NO_GUARD=pages: exit 11, pages detached=0 released=1 (want detached=1 released=0).
  • X2W_TEARDOWN_NO_GUARD=readbacks: exit 11, readbacks detached=0 released=2 (want detached=2 released=0).
  • translated-indexed, -upload, -rect, -alias, rect on the card, and alias-off on the card plus translated-indexed on WARP: child exit 0 each, unchanged.

Two defects surfaced while building the check, both fixed in the second commit: the probe answered 0 because a fixture created without a parameter block gets a bare D3D12CreateDevice device back, which is not in the shim registry, so as_wrapper() finds nothing — that device is already the desktop one and is now used as such; and widen() kept the terminating null MultiByteToWideChar writes with -1, so CreateProcessW truncated 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 an ALLOW_CROSS_ADAPTER one 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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6616037065 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2631). Originally posted by [thepatrickworld](https://github.com/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: - the placed page aliases of the translated indirect address route (`d3d12_xs_device.cpp`); - the draw-dump readbacks (`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 `FreeLibrary` they release them normally, driven by the flag in `startup_stubs/d3d12_teardown.h`. - `PlacedPageAliases` wraps the `std::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. - `DrawReadbacks` walks `entries_` in its destructor and detaches each recorded buffer and its fence. - The boundary comment in `d3d12_teardown.h` now names both. ## What is measured, and what is not Neither site faults on this machine. With the detach disabled, the alias run still exits `0` while 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_probe` grew 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) — and `startup_teardown_unload` covers four caches: - on `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; - on process termination, the child reports `detached=<owned> released=0` per cache through `X2W_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 a `ComPtr` (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 the `Disabled` tag and owns nothing. ## Test Built at `8ecaa8ec` with this patch applied, Windows 11 25H2, MSVC 19.44.35230, AMD Radeon RX 9070 XT (`1002:7550`, driver `32.0.32029.2010`): ```powershell cmake --preset dev -DINTAKE_PYTHON=…\out\pe-env\Scripts\python.exe cmake --build --preset dev --target d3d12_xs_shim startup_teardown_unload startup_indirect_draw_indexed .\out\build\dev\startup_teardown_unload.exe <abs path>\d3d12_xs.dll hardware ``` ```text unload indexed-validation: 3 objects released, references 4 -> 1, module unloaded unload rect-converter: 2 objects released, references 3 -> 1, module unloaded warm placed-pages: backing heap handed over with 1 reference unload placed-pages: heap alive after the unload, 1 reference, placed buffer released first unload placed-pages: heap released last, 1 -> 0 unload placed-pages: 1 objects released, module unloaded unload draw-readbacks: 2 objects released, module unloaded x2w-teardown readbacks detached=2 released=0 x2w-teardown pages detached=1 released=0 termination: both caches detached every owned reference, released none negative control X2W_TEARDOWN_NO_GUARD=pages: the check failed as it must negative control X2W_TEARDOWN_NO_GUARD=readbacks: the check failed as it must startup_teardown_unload hardware: PASS ``` The debug layer is not installed on this machine (`d3d12SDKLayers.dll` is absent), so these runs carry no validation-layer output. - `hardware`: exit `0`, `PASS`; `warp` (`Microsoft Basic Render Driver`): exit `0`, `PASS`. - `X2W_TEARDOWN_NO_GUARD=pages`: exit `11`, `pages detached=0 released=1 (want detached=1 released=0)`. - `X2W_TEARDOWN_NO_GUARD=readbacks`: exit `11`, `readbacks detached=0 released=2 (want detached=2 released=0)`. - `translated-indexed`, `-upload`, `-rect`, `-alias`, `rect` on the card, and `alias-off` on the card plus `translated-indexed` on WARP: child exit `0` each, unchanged. Two defects surfaced while building the check, both fixed in the second commit: the probe answered `0` because a fixture created without a parameter block gets a bare `D3D12CreateDevice` device back, which is not in the shim registry, so `as_wrapper()` finds nothing — that device is already the desktop one and is now used as such; and `widen()` kept the terminating null `MultiByteToWideChar` writes with `-1`, so `CreateProcessW` truncated 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 an `ALLOW_CROSS_ADAPTER` one 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._
tedin7 commented 2026-11-26 00:01:06 +00:00 (Migrated from github.com)

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).

  • PlacedPageAliases keeps lookup, free-slot scan and insertion identical through begin()/end(); the call site changes only by using Page and the static type. The 64-entry array is value-initialized, so the detach loop is safe on never-used slots.
  • DrawReadbacks::~DrawReadbacks detaches each recorded buffer and fence only when d3d12_process_terminating is set. FreeLibrary still releases normally. Same contract as #2590.
  • d3d12_teardown.h is already included by d3d12_xs_device.cpp; the new include in draw_dump_tracking.h resolves x2w_startup::d3d12_process_terminating inside the same namespace.
  • No other open or merged PR covers these two statics (searched #2572 / #2590 follow-ups).

Commands run locally: git diff --stat origin/main...HEAD, git diff --check origin/main...HEAD (clean), rg over the teardown header and includes.

Not verified / why not merged by us:

  • Required CI was still pending on this head when I looked, and there is no Windows run on it.
  • The PR body says the page-cache detach is not a reproduced fault and the draw-dump cache is not exercised by any test, so no test fails if the detach is removed (no negative control). That is stated honestly in the body, but it means the behavior is guarded by review only.
  • It belongs to the startup-teardown work (#2572). We do not have the game, so we cannot confirm the exit behavior there. The merge stays with MasterDomino or @R0Y00, who can verify it on the real startup path.

Code looks sound to me.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6066537780 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2631#pullrequestreview-6066537780). Originally posted by [tedin7](https://github.com/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). - `PlacedPageAliases` keeps lookup, free-slot scan and insertion identical through `begin()`/`end()`; the call site changes only by `using Page` and the static type. The 64-entry array is value-initialized, so the detach loop is safe on never-used slots. - `DrawReadbacks::~DrawReadbacks` detaches each recorded buffer and fence only when `d3d12_process_terminating` is set. FreeLibrary still releases normally. Same contract as #2590. - `d3d12_teardown.h` is already included by `d3d12_xs_device.cpp`; the new include in `draw_dump_tracking.h` resolves `x2w_startup::d3d12_process_terminating` inside the same namespace. - No other open or merged PR covers these two statics (searched #2572 / #2590 follow-ups). Commands run locally: `git diff --stat origin/main...HEAD`, `git diff --check origin/main...HEAD` (clean), `rg` over the teardown header and includes. Not verified / why not merged by us: - Required CI was still pending on this head when I looked, and there is no Windows run on it. - The PR body says the page-cache detach is not a reproduced fault and the draw-dump cache is not exercised by any test, so no test fails if the detach is removed (no negative control). That is stated honestly in the body, but it means the behavior is guarded by review only. - It belongs to the startup-teardown work (#2572). We do not have the game, so we cannot confirm the exit behavior there. The merge stays with MasterDomino or @R0Y00, who can verify it on the real startup path. Code looks sound to me. AI-assisted; commands listed were executed locally.
R0Y00 commented 2026-11-26 00:01:06 +00:00 (Migrated from github.com)

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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6066633533 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2631#pullrequestreview-6066633533). Originally posted by [R0Y00](https://github.com/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.
thepatrickworld commented 2026-11-26 00:01:14 +00:00 (Migrated from github.com)

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:

  • PlacedPageAliases wraps the std::array<Page, 64> of the translated indirect address route; begin()/end() keep the lookup and free-slot scan identical.
  • DrawReadbacks detaches each recorded buffer and its fence in its destructor.
  • d3d12_teardown.h names 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-alias holds 2 placed pages at exit, so the cache is populated and the detach runs; but with the detach removed, the same mode still exits 0 while 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 66026a39 with the patch applied (same tree as the pushed 15c7dbbe), RX 9070 XT (1002:7550, driver 32.0.32029.2010), child exit 0 for translated-indexed, -upload, -rect, -alias, rect, plus alias-off on the card and translated-indexed on WARP, and startup_teardown_unload hardware: PASS. CI on 15c7dbbe: Windows, Python on Linux and the gfx1013 fixtures all green; the two skipped checks (/O2 build, 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 which RedProducers (red_producer_diagnostic.inl) is safe by construction — heap-allocated live instance never destroyed, static fallback built through the Disabled tag and owning nothing.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7178105429 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2631#issuecomment-7178105429). Originally posted by [thepatrickworld](https://github.com/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: - `PlacedPageAliases` wraps the `std::array<Page, 64>` of the translated indirect address route; `begin()`/`end()` keep the lookup and free-slot scan identical. - `DrawReadbacks` detaches each recorded buffer and its fence in its destructor. - `d3d12_teardown.h` names 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-alias` holds **2 placed pages** at exit, so the cache is populated and the detach runs; but with the detach removed, the same mode still exits `0` while 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 `66026a39` with the patch applied (same tree as the pushed `15c7dbbe`), RX 9070 XT (`1002:7550`, driver `32.0.32029.2010`), child exit `0` for `translated-indexed`, `-upload`, `-rect`, `-alias`, `rect`, plus `alias-off` on the card and `translated-indexed` on WARP, and `startup_teardown_unload hardware: PASS`. CI on `15c7dbbe`: Windows, Python on Linux and the gfx1013 fixtures all green; the two skipped checks (`/O2` build, 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 which `RedProducers` (`red_producer_diagnostic.inl`) is safe by construction — heap-allocated live instance never destroyed, static fallback built through the `Disabled` tag and owning nothing. _AI-assisted._
R0Y00 commented 2026-11-26 01:01:56 +00:00 (Migrated from github.com)

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, and x2w_d3d12_cached_object_probe returns the placed buffer, so the normal FreeLibrary fixture 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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6067098879 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2631#pullrequestreview-6067098879). Originally posted by [R0Y00](https://github.com/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, and `x2w_d3d12_cached_object_probe` returns the placed buffer, so the normal `FreeLibrary` fixture 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.
thepatrickworld commented 2026-11-26 01:02:13 +00:00 (Migrated from github.com)

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, driver 32.0.32029.2010) and on WARP.

Populated entries. x2w_d3d12_cached_objects_probe grew 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 answers 1; bit 8 creates the readback buffer and the fence a recorded dump holds and answers 2. 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_unload now 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:

unload indexed-validation: 3 objects released, references 4 -> 1, module unloaded
unload rect-converter: 2 objects released, references 3 -> 1, module unloaded
unload placed-pages: slot 0 reference 2 -> 1
unload placed-pages: 1 objects released, module unloaded
unload draw-readbacks: slot 0 reference 2 -> 1
unload draw-readbacks: slot 1 reference 2 -> 1
unload draw-readbacks: 2 objects released, module unloaded

Process termination detaches. The child process reports per cache, and the parent requires detached=<owned> released=0:

x2w-teardown readbacks detached=2 released=0
x2w-teardown pages detached=1 released=0
termination: 8 objects left to the process exit path
termination: both caches detached every owned reference, released none

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:

negative control X2W_TEARDOWN_NO_GUARD=pages: the check failed as it must
  (x2w-teardown pages detached=0 released=1 (want detached=1 released=0))
negative control X2W_TEARDOWN_NO_GUARD=readbacks: the check failed as it must
  (x2w-teardown readbacks detached=0 released=2 (want detached=2 released=0))

Exit codes: hardware 0, warp 0, and with either no-guard variable set 11.

Two defects surfaced while building the check, both fixed: the probe answered 0 because a fixture creates its device without a parameter block, so D3D12XboxCreateDevice returns a plain D3D12CreateDevice result 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_device is no help: attach_device() is its only writer, so there it is null or names another device); and widen() kept the terminating null MultiByteToWideChar writes with -1, so CreateProcessW truncated 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 a ALLOW_CROSS_ADAPTER one 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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7179114631 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2631#issuecomment-7179114631). Originally posted by [thepatrickworld](https://github.com/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`, driver `32.0.32029.2010`) and on WARP. **Populated entries.** `x2w_d3d12_cached_objects_probe` grew 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 answers `1`; bit 8 creates the readback buffer and the fence a recorded dump holds and answers `2`. 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_unload` now 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: ```text unload indexed-validation: 3 objects released, references 4 -> 1, module unloaded unload rect-converter: 2 objects released, references 3 -> 1, module unloaded unload placed-pages: slot 0 reference 2 -> 1 unload placed-pages: 1 objects released, module unloaded unload draw-readbacks: slot 0 reference 2 -> 1 unload draw-readbacks: slot 1 reference 2 -> 1 unload draw-readbacks: 2 objects released, module unloaded ``` **Process termination detaches.** The child process reports per cache, and the parent requires `detached=<owned> released=0`: ```text x2w-teardown readbacks detached=2 released=0 x2w-teardown pages detached=1 released=0 termination: 8 objects left to the process exit path termination: both caches detached every owned reference, released none ``` **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: ```text negative control X2W_TEARDOWN_NO_GUARD=pages: the check failed as it must (x2w-teardown pages detached=0 released=1 (want detached=1 released=0)) negative control X2W_TEARDOWN_NO_GUARD=readbacks: the check failed as it must (x2w-teardown readbacks detached=0 released=2 (want detached=2 released=0)) ``` Exit codes: `hardware` `0`, `warp` `0`, and with either no-guard variable set `11`. Two defects surfaced while building the check, both fixed: the probe answered `0` because a fixture creates its device without a parameter block, so `D3D12XboxCreateDevice` returns a plain `D3D12CreateDevice` result 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_device` is no help: `attach_device()` is its only writer, so there it is null or names another device); and `widen()` kept the terminating null `MultiByteToWideChar` writes with `-1`, so `CreateProcessW` truncated 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 a `ALLOW_CROSS_ADAPTER` one 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._
upstream-sync closed this pull request 2026-11-26 02:04:50 +00:00
R0Y00 commented 2026-11-26 02:04:51 +00:00 (Migrated from github.com)

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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6067446356 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2631#pullrequestreview-6067446356). Originally posted by [R0Y00](https://github.com/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.
thepatrickworld commented 2026-11-26 02:05:12 +00:00 (Migrated from github.com)

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 once FreeLibrary had released the placed buffer. Fixed in ace926c0.

The probe now hands the heap over with a reference the fixture owns, and startup_teardown_unload holds it across the unload and releases it last:

warm placed-pages: backing heap handed over with 1 reference
unload placed-pages: slot 0 reference 2 -> 1
unload placed-pages: heap alive after the unload, 1 reference, placed buffer released first
unload placed-pages: heap released last, 1 -> 0
unload placed-pages: 1 objects released, module unloaded

Releasing it after FreeLibrary is 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 bare D3D12CreateDevice object, so its vtable lives in d3d12.dll and not in d3d12_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 XT 1002:7550, driver 32.0.32029.2010):

x2w-teardown readbacks detached=2 released=0
x2w-teardown pages detached=1 released=0
termination: both caches detached every owned reference, released none
negative control X2W_TEARDOWN_NO_GUARD=pages: the check failed as it must
  (x2w-teardown pages detached=0 released=1 (want detached=1 released=0))
negative control X2W_TEARDOWN_NO_GUARD=readbacks: the check failed as it must
  (x2w-teardown readbacks detached=0 released=2 (want detached=2 released=0))
startup_teardown_unload hardware: PASS

Exit codes: hardware 0, warp 0, and 11 with either no-guard variable set. The debug layer is not installed on this machine (d3d12SDKLayers.dll is absent), so these runs carry no validation-layer output.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7179906784 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2631#issuecomment-7179906784). Originally posted by [thepatrickworld](https://github.com/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 once `FreeLibrary` had released the placed buffer. Fixed in `ace926c0`. The probe now hands the heap over with a reference the fixture owns, and `startup_teardown_unload` holds it across the unload and releases it last: ```text warm placed-pages: backing heap handed over with 1 reference unload placed-pages: slot 0 reference 2 -> 1 unload placed-pages: heap alive after the unload, 1 reference, placed buffer released first unload placed-pages: heap released last, 1 -> 0 unload placed-pages: 1 objects released, module unloaded ``` Releasing it after `FreeLibrary` is 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 bare `D3D12CreateDevice` object, so its vtable lives in `d3d12.dll` and not in `d3d12_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 XT `1002:7550`, driver `32.0.32029.2010`): ```text x2w-teardown readbacks detached=2 released=0 x2w-teardown pages detached=1 released=0 termination: both caches detached every owned reference, released none negative control X2W_TEARDOWN_NO_GUARD=pages: the check failed as it must (x2w-teardown pages detached=0 released=1 (want detached=1 released=0)) negative control X2W_TEARDOWN_NO_GUARD=readbacks: the check failed as it must (x2w-teardown readbacks detached=0 released=2 (want detached=2 released=0)) startup_teardown_unload hardware: PASS ``` Exit codes: `hardware` `0`, `warp` `0`, and `11` with either no-guard variable set. The debug layer is not installed on this machine (`d3d12SDKLayers.dll` is absent), so these runs carry no validation-layer output. _AI-assisted._
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!2623
No description provided.