startup: match descriptor shadow slots on a descriptor boundary #3563

Merged
Jess-Doit merged 2 commits from upstream-pr/3563 into main 2026-11-30 15:53:51 +00:00
Jess-Doit commented 2026-11-30 07:23:36 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Jess-Doit on 2026-11-30T07:23:36Z.


Refs #2468. Refs #3558.

Change

shadow_slot in src/startup_stubs/d3d12_capture.inl found a descriptor's tracking slot by checking whether the desktop CPU handle lay inside a heap's span. Desktop CPU handles need not be addresses. On a GTX 1060, CPU-only view heaps get small tagged handles whose spans interleave, for example three two-descriptor heaps at 0x3, 0x4 and 0x5 with a 0x20 increment. A handle in one heap therefore fell inside an earlier heap's span and was tracked in the wrong slot.

The lookup now prefers the heap where the handle sits on a descriptor boundary, and searches the heaps newest first. A released heap keeps its entry, so when a new heap is handed the same tag or address, the new heap is the one the handle names. Handles that are real addresses (WARP and the other adapters measured so far) resolve as before, apart from that reuse case.

The choice lives in src/startup_stubs/descriptor_heap_match.h so it can be tested without a device. The handle alone cannot settle two cases: several heaps with the handle on a boundary (starts that differ by a multiple of the increment), or no heap with it on a boundary. The header documents both, and two counters report them in the periodic x2w-d3d12 log, printed only when nonzero.

Verification

Windows 10 19045, NVIDIA GTX 1060 6GB driver 32.0.15.6094, in-box WARP 10.0.19041. Dev build of this branch (b359ac71) on main 44a3ad5a.

Check Before After
Budget and retire families, GTX 1060 and WARP 31 passed, 7 failed 34 passed, 4 failed
startup_descriptor_heap_match and its two controls — 3 passed (both controls fail as required)
ctest --preset pr — 72 passed, 0 failed, 14 capability skips

startup_descriptor_heap_match checks the three interleaved heaps from the GTX 1060, a fourth heap at 0x23 that shares a boundary, address handles, and a reused tag and address. The first-contains control is the lookup on main and fails 8 cases; the oldest-first control fails the 4 shared-boundary and reuse cases.

Now passing on the GTX 1060:

  • startup_resource_retire_reasons_hardware: it held one view reference too few.
  • startup_resource_retire_title_hardware_debug0 and _debug1: Tv2 was kept after heap2 was released, as reported on #2468.

All three already passed on WARP and still do.

The four remaining failures are the startup_resource_retire_views_*_hardware crashes. They are a separate problem: a descriptor copy from a shader-visible heap, tracked in #3558.

$env:XBOX2WINDOWS_ADAPTER = '1060'
ctest --preset dev --no-tests=error -j 1 -R '^startup_resource_(budget|retire)'
ctest --preset dev --no-tests=error -R '^startup_descriptor_heap_match'
ctest --preset pr --no-tests=error -j 2

🤖 Generated with Claude Code

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5560891861 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3563). Originally posted by [Jess-Doit](https://github.com/Jess-Doit) on 2026-11-30T07:23:36Z. --- Refs #2468. Refs #3558. ## Change `shadow_slot` in `src/startup_stubs/d3d12_capture.inl` found a descriptor's tracking slot by checking whether the desktop CPU handle lay inside a heap's span. Desktop CPU handles need not be addresses. On a GTX 1060, CPU-only view heaps get small tagged handles whose spans interleave, for example three two-descriptor heaps at 0x3, 0x4 and 0x5 with a 0x20 increment. A handle in one heap therefore fell inside an earlier heap's span and was tracked in the wrong slot. The lookup now prefers the heap where the handle sits on a descriptor boundary, and searches the heaps newest first. A released heap keeps its entry, so when a new heap is handed the same tag or address, the new heap is the one the handle names. Handles that are real addresses (WARP and the other adapters measured so far) resolve as before, apart from that reuse case. The choice lives in `src/startup_stubs/descriptor_heap_match.h` so it can be tested without a device. The handle alone cannot settle two cases: several heaps with the handle on a boundary (starts that differ by a multiple of the increment), or no heap with it on a boundary. The header documents both, and two counters report them in the periodic `x2w-d3d12` log, printed only when nonzero. ## Verification Windows 10 19045, NVIDIA GTX 1060 6GB driver 32.0.15.6094, in-box WARP 10.0.19041. Dev build of this branch (`b359ac71`) on `main` `44a3ad5a`. | Check | Before | After | |---|---|---| | Budget and retire families, GTX 1060 and WARP | 31 passed, 7 failed | 34 passed, 4 failed | | `startup_descriptor_heap_match` and its two controls | — | 3 passed (both controls fail as required) | | `ctest --preset pr` | — | 72 passed, 0 failed, 14 capability skips | `startup_descriptor_heap_match` checks the three interleaved heaps from the GTX 1060, a fourth heap at 0x23 that shares a boundary, address handles, and a reused tag and address. The first-contains control is the lookup on `main` and fails 8 cases; the oldest-first control fails the 4 shared-boundary and reuse cases. Now passing on the GTX 1060: - `startup_resource_retire_reasons_hardware`: it held one view reference too few. - `startup_resource_retire_title_hardware_debug0` and `_debug1`: Tv2 was kept after heap2 was released, as reported on #2468. All three already passed on WARP and still do. The four remaining failures are the `startup_resource_retire_views_*_hardware` crashes. They are a separate problem: a descriptor copy from a shader-visible heap, tracked in #3558. ```powershell $env:XBOX2WINDOWS_ADAPTER = '1060' ctest --preset dev --no-tests=error -j 1 -R '^startup_resource_(budget|retire)' ctest --preset dev --no-tests=error -R '^startup_descriptor_heap_match' ctest --preset pr --no-tests=error -j 2 ``` 🤖 Generated with [Claude Code](https://claude.com/claude-code)
lukaslw-lab commented 2026-11-30 10:10:49 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-11-30T10:10:49Z.

Review: APPROVED


Reviewed ac6d858d by reading the diff; not built or run.

Verdict: approve. On adapters whose CPU handles are real addresses, the lookup gives the same result as before. On interleaved tagged handles it picks the right heap whenever only one heap has the handle on a descriptor boundary. No MUST.

  • Unchanged for address handles (d3d12_capture.inl:258-269). Real heap spans don't overlap, so at most one heap contains a handle. That heap is returned whether or not the handle is on a boundary, with the same floor index and room as before.- SHOULD: the boundary test still has blind spots, and they are silent. Two heaps whose start handles differ by a multiple of the increment (0x3 and 0x23 with 0x20) both match on a boundary, and whichever registered first wins. Released heaps also never leave heap_infos(): retire_drop_heap_views (d3d12_xs_device.cpp:6344) only clears their shadow. So if the driver reuses a tag, the stale entry comes first and takes the new heap's descriptors. The stale-entry problem predates this PR, but tagged handles make reuse of small values likelier. With tagged handles the fallback to the first containing heap is also wrong by construction. A counter for multi-heap matches and fallbacks would show whether either happens in a run, and the comment could name the limit.
  • SHOULD: no test on CI reaches the new branch. WARP hands out address handles, so no CI case has overlapping spans. The fixed cases (startup_resource_retire_reasons_hardware, ..._title_hardware_debug0/1) need the GTX 1060. A small check of the lookup with the body's three heaps (0x3/0x4/0x5, increment 0x20, two descriptors each) would pin the boundary preference, and a fourth heap at 0x23 would pin the limit above.

CI: Windows passed. The red Linux job is tests/startup_triage_run_check.py, which fails on main 44a3ad5a too (the output UAV element-limit reason #3546 adds). It is not caused by this PR.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6110234979 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3563#pullrequestreview-6110234979). Originally posted by [lukaslw-lab](https://github.com/lukaslw-lab) on 2026-11-30T10:10:49Z. **Review:** APPROVED --- Reviewed `ac6d858d` by reading the diff; not built or run. **Verdict: approve.** On adapters whose CPU handles are real addresses, the lookup gives the same result as before. On interleaved tagged handles it picks the right heap whenever only one heap has the handle on a descriptor boundary. No MUST. - **Unchanged for address handles** (`d3d12_capture.inl:258-269`). Real heap spans don't overlap, so at most one heap contains a handle. That heap is returned whether or not the handle is on a boundary, with the same floor index and `room` as before.- **SHOULD: the boundary test still has blind spots, and they are silent.** Two heaps whose start handles differ by a multiple of the increment (0x3 and 0x23 with 0x20) both match on a boundary, and whichever registered first wins. Released heaps also never leave `heap_infos()`: `retire_drop_heap_views` (`d3d12_xs_device.cpp:6344`) only clears their shadow. So if the driver reuses a tag, the stale entry comes first and takes the new heap's descriptors. The stale-entry problem predates this PR, but tagged handles make reuse of small values likelier. With tagged handles the fallback to the first containing heap is also wrong by construction. A counter for multi-heap matches and fallbacks would show whether either happens in a run, and the comment could name the limit. - **SHOULD: no test on CI reaches the new branch.** WARP hands out address handles, so no CI case has overlapping spans. The fixed cases (`startup_resource_retire_reasons_hardware`, `..._title_hardware_debug0/1`) need the GTX 1060. A small check of the lookup with the body's three heaps (0x3/0x4/0x5, increment 0x20, two descriptors each) would pin the boundary preference, and a fourth heap at 0x23 would pin the limit above. CI: Windows passed. The red Linux job is `tests/startup_triage_run_check.py`, which fails on `main` `44a3ad5a` too (the output UAV element-limit reason #3546 adds). It is not caused by this PR.
Jess-Doit commented 2026-11-30 15:16:20 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Jess-Doit on 2026-11-30T15:16:20Z.


Thanks for the review. Both SHOULDs are addressed in b359ac71:

  • Stale heaps and shared boundaries. The lookup now searches the heaps newest first, so a heap handed a released heap's tag or address wins over the stale entry. That reuse case could already happen with address handles on main. The two cases the handle cannot settle (several heaps on a boundary, or none) are documented in the new src/startup_stubs/descriptor_heap_match.h. Each has a counter in the periodic x2w-d3d12 log, printed only when nonzero.
  • A test CI can reach. The heap choice moved into that header. startup_descriptor_heap_match checks it without a device, covering the 0x3/0x4/0x5 heaps, a fourth heap at 0x23, address handles, and a reused tag and address. Two controls must fail: first-contains is the lookup on main and fails 8 cases, and oldest-first fails the 4 shared-boundary and reuse cases.

Rerun on the same host (GTX 1060, driver 32.0.15.6094, Windows 10 19045):

  • Budget and retire families: still 34 passed, 4 failed. The 4 failures are the #3558 views crashes.
  • ctest --preset pr: 72 passed, 0 failed, 14 capability skips.

Ready for more review

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7282719811 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3563#issuecomment-7282719811). Originally posted by [Jess-Doit](https://github.com/Jess-Doit) on 2026-11-30T15:16:20Z. --- Thanks for the review. Both SHOULDs are addressed in `b359ac71`: - **Stale heaps and shared boundaries.** The lookup now searches the heaps newest first, so a heap handed a released heap's tag or address wins over the stale entry. That reuse case could already happen with address handles on `main`. The two cases the handle cannot settle (several heaps on a boundary, or none) are documented in the new `src/startup_stubs/descriptor_heap_match.h`. Each has a counter in the periodic `x2w-d3d12` log, printed only when nonzero. - **A test CI can reach.** The heap choice moved into that header. `startup_descriptor_heap_match` checks it without a device, covering the 0x3/0x4/0x5 heaps, a fourth heap at 0x23, address handles, and a reused tag and address. Two controls must fail: first-contains is the lookup on `main` and fails 8 cases, and oldest-first fails the 4 shared-boundary and reuse cases. Rerun on the same host (GTX 1060, driver 32.0.15.6094, Windows 10 19045): - Budget and retire families: still 34 passed, 4 failed. The 4 failures are the #3558 views crashes. - `ctest --preset pr`: 72 passed, 0 failed, 14 capability skips. Ready for more review
R0Y00 commented 2026-11-30 15:53:44 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-30T15:53:44Z.

Review: APPROVED


Independent re-review of b359ac71. The revised lookup prefers a boundary match and then the newest registration, and reports ambiguous boundaries and off-boundary fallbacks. ctest --preset release --no-tests=error -R '^startup_descriptor_heap_match' passed 3/3, including both expected-failure controls for first-contains and oldest-first. These are source-built span tests, with no GPU dependency. The earlier review's two follow-ups are addressed.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6115524735 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3563#pullrequestreview-6115524735). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-30T15:53:44Z. **Review:** APPROVED --- Independent re-review of `b359ac71`. The revised lookup prefers a boundary match and then the newest registration, and reports ambiguous boundaries and off-boundary fallbacks. `ctest --preset release --no-tests=error -R '^startup_descriptor_heap_match'` passed 3/3, including both expected-failure controls for first-contains and oldest-first. These are source-built span tests, with no GPU dependency. The earlier review's two follow-ups are addressed.
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!3563
No description provided.