startup: read descriptor copies out of shader-visible heaps from a CPU-only mirror #3627

Merged
Jess-Doit merged 1 commit from upstream-pr/3627 into main 2026-11-30 17:28:26 +00:00
Jess-Doit commented 2026-11-30 16:26:51 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Jess-Doit on 2026-11-30T16:26:51Z.


Fixes #3558.

Change

Desktop D3D12 reads CopyDescriptors/CopyDescriptorsSimple sources, and the CPU handle of ClearUnorderedAccessView*, only from CPU-only heaps. A console title may copy out of a shader-visible heap. copy_descriptor_run forwarded such a copy unchanged, so the source was in the shader-visible desktop heap.

This is option 2 from the fix options comment, a CPU-only mirror:

  • Mirror heap. Each title view or sampler heap created shader-visible gets a CPU-only desktop heap the size of its visible prefix. The desktop heap retains it through SetPrivateDataInterface, like the existing CPU tail. DescriptorRange gains a mirror field, and desktop_cpu_handle can return the mirror handle of a visible descriptor.
  • Writes. A view (view_slot, including the refused-SRV null), a console sampler (slot 61) or a copy into a visible range is written to the mirror first, then copied from the mirror to the visible heap. Both copies read a CPU-only heap.
  • Reads. A copy out of a visible range, and a UAV clear's CPU handle, read the mirror.
  • Shadow tracking stays keyed on the visible handle, so note_view, note_copy and shadow_slot are unchanged.

Cost: one extra descriptor copy per write into a visible range, plus a CPU-only heap the size of each visible title heap.

X2W_D3D12_NO_VISIBLE_HEAP_MIRROR=1 turns the mirror off. It is a negative control only, documented in docs/startup-runtime.md.

Tests

As mumba17 noted on #3558, the debug layer reports the copy as message 654 on every adapter. The retire-views tests didn't catch it because the shim drains the info queue into its log in check_device, so the test's own count is always 0. tests/cmake/startup_visible_heap_mirror.cmake adds:

  • Message check: FAIL_REGULAR_EXPRESSION on message 654 for startup_resource_retire_views_{warp,hardware}_debug1, so the contract is checked on WARP in CI.
  • Control: startup_resource_retire_views_no_mirror_control_warp runs with the mirror off and passes only if message 654 appears.
  • Case 6 in tests/startup_resource_retire_views.cpp covers copies into and out of the visible heap. It copies a view between two visible slots and overwrites the source. It then copies both slots out to the CPU-only staging heap, and each must read what was last written there.

Verification

Windows 10 19045, NVIDIA GTX 1060 6GB (driver 32.0.15.6094) and in-box WARP 10.0.19041. Dev build of this branch (5ee979df) on main cf43986d.

Retire-views family

Test main (cf43986d; GTX 1060 crash measured on 44a3ad5a) This branch
retire_views_hardware_debug0, _debug1, keep_hardware, noretire_hardware access violation in CopyDescriptorsSimple passed
retire_views_warp_debug1 passed, with message 654 in the log passed, no debug-layer messages
retire_views_no_mirror_control_warp — passed (message 654 logged 4 times)
retire_views_warp_debug1 with X2W_D3D12_NO_VISIBLE_HEAP_MIRROR=1 — failed on the message, as required

Wider checks

  • Budget and retire families (^startup_resource_(budget|retire)): 39 passed, 0 failed on GTX 1060 and WARP. This is the first full pass of these families on the GTX 1060, together with #3563.
  • ctest --preset pr: 65 passed, 0 failed, 24 capability skips.
  • Descriptor, sampler, clear and view-token tests (168): 163 passed or skipped. Five failed:
    • startup_compute_descriptor_scc_hardware, native_graphics_sampler_heap_{warp,hardware} and startup_compute_dispatch_sampler_heap_{warp,hardware}.
    • They need shader model 6.6, which this host doesn't have ("shader model below 6.6", "Create sampler heap PSO failed").
    • They fail the same way with the mirror off.
$env:XBOX2WINDOWS_ADAPTER = '1060'
ctest --preset dev --no-tests=error -j 1 -R '^startup_resource_retire_views_'
ctest --preset dev --no-tests=error -j 1 -R '^startup_resource_(budget|retire)'
ctest --preset pr --no-tests=error -j 2

🤖 Generated with Claude Code

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5569315547 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3627). Originally posted by [Jess-Doit](https://github.com/Jess-Doit) on 2026-11-30T16:26:51Z. --- Fixes #3558. ## Change Desktop D3D12 reads `CopyDescriptors`/`CopyDescriptorsSimple` sources, and the CPU handle of `ClearUnorderedAccessView*`, only from CPU-only heaps. A console title may copy out of a shader-visible heap. `copy_descriptor_run` forwarded such a copy unchanged, so the source was in the shader-visible desktop heap. This is option 2 from the [fix options comment](https://github.com/R0Y00/Xbox2Windows/issues/3558#issuecomment-7270689242), a CPU-only mirror: - **Mirror heap.** Each title view or sampler heap created shader-visible gets a CPU-only desktop heap the size of its visible prefix. The desktop heap retains it through `SetPrivateDataInterface`, like the existing CPU tail. `DescriptorRange` gains a `mirror` field, and `desktop_cpu_handle` can return the mirror handle of a visible descriptor. - **Writes.** A view (`view_slot`, including the refused-SRV null), a console sampler (slot 61) or a copy into a visible range is written to the mirror first, then copied from the mirror to the visible heap. Both copies read a CPU-only heap. - **Reads.** A copy out of a visible range, and a UAV clear's CPU handle, read the mirror. - **Shadow tracking** stays keyed on the visible handle, so `note_view`, `note_copy` and `shadow_slot` are unchanged. Cost: one extra descriptor copy per write into a visible range, plus a CPU-only heap the size of each visible title heap. `X2W_D3D12_NO_VISIBLE_HEAP_MIRROR=1` turns the mirror off. It is a negative control only, documented in `docs/startup-runtime.md`. ## Tests As mumba17 noted on #3558, the debug layer reports the copy as message 654 on every adapter. The retire-views tests didn't catch it because the shim drains the info queue into its log in `check_device`, so the test's own count is always 0. `tests/cmake/startup_visible_heap_mirror.cmake` adds: - **Message check:** `FAIL_REGULAR_EXPRESSION` on message 654 for `startup_resource_retire_views_{warp,hardware}_debug1`, so the contract is checked on WARP in CI. - **Control:** `startup_resource_retire_views_no_mirror_control_warp` runs with the mirror off and passes only if message 654 appears. - **Case 6** in `tests/startup_resource_retire_views.cpp` covers copies into and out of the visible heap. It copies a view between two visible slots and overwrites the source. It then copies both slots out to the CPU-only staging heap, and each must read what was last written there. ## Verification Windows 10 19045, NVIDIA GTX 1060 6GB (driver 32.0.15.6094) and in-box WARP 10.0.19041. Dev build of this branch (`5ee979df`) on `main` `cf43986d`. **Retire-views family** | Test | `main` (`cf43986d`; GTX 1060 crash measured on `44a3ad5a`) | This branch | |---|---|---| | `retire_views_hardware_debug0`, `_debug1`, `keep_hardware`, `noretire_hardware` | access violation in `CopyDescriptorsSimple` | passed | | `retire_views_warp_debug1` | passed, with message 654 in the log | passed, no debug-layer messages | | `retire_views_no_mirror_control_warp` | — | passed (message 654 logged 4 times) | | `retire_views_warp_debug1` with `X2W_D3D12_NO_VISIBLE_HEAP_MIRROR=1` | — | failed on the message, as required | **Wider checks** - Budget and retire families (`^startup_resource_(budget|retire)`): 39 passed, 0 failed on GTX 1060 and WARP. This is the first full pass of these families on the GTX 1060, together with #3563. - `ctest --preset pr`: 65 passed, 0 failed, 24 capability skips. - Descriptor, sampler, clear and view-token tests (168): 163 passed or skipped. Five failed: - `startup_compute_descriptor_scc_hardware`, `native_graphics_sampler_heap_{warp,hardware}` and `startup_compute_dispatch_sampler_heap_{warp,hardware}`. - They need shader model 6.6, which this host doesn't have ("shader model below 6.6", "Create sampler heap PSO failed"). - They fail the same way with the mirror off. ```powershell $env:XBOX2WINDOWS_ADAPTER = '1060' ctest --preset dev --no-tests=error -j 1 -R '^startup_resource_retire_views_' ctest --preset dev --no-tests=error -j 1 -R '^startup_resource_(budget|retire)' ctest --preset pr --no-tests=error -j 2 ``` 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Makto94 commented 2026-11-30 16:35:52 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Makto94 on 2026-11-30T16:35:52Z.


Hardware run of this PR on a second NVIDIA GPU, one where the copy did not crash on main.

Environment

  • Adapter: NVIDIA GeForce RTX 3070 Ti, driver 32.0.16.2101, Windows 11 build 26300
  • main: cf43986d; this PR: 5ee979df
  • Debug layer per test as in the table. debug1 tests enable it, debug0, keep and noretire do not.
  • main was a full build. The PR was an incremental build in the same worktree.

Command

ctest --preset dev --no-tests=error -j 1 -R "^startup_resource_retire_views" -V --output-on-failure

Result

Test debug layer main cf43986d PR 5ee979df
startup_resource_retire_views_warp_debug0 off passed, 654 absent passed, 654 absent
startup_resource_retire_views_warp_debug1 on passed, 654 present (1) passed, 654 absent
startup_resource_retire_views_keep_warp off passed, 654 absent passed, 654 absent
startup_resource_retire_views_noretire_warp off passed, 654 absent passed, 654 absent
startup_resource_retire_views_hardware_debug0 off passed, 654 absent passed, 654 absent
startup_resource_retire_views_hardware_debug1 on passed, 654 present (1) passed, 654 absent
startup_resource_retire_views_keep_hardware off passed, 654 absent passed, 654 absent
startup_resource_retire_views_noretire_hardware off passed, 654 absent passed, 654 absent
startup_resource_retire_views_no_mirror_control_warp (negative control) on not in main passed, 654 present (4), as the test requires

main: 8/8 passed. PR: 9/9 passed. No capability skips (77) in either run. No crash on main on this card.

Both debug1 runs also log message 1328 (CreateCommittedResource ignoring InitialState) on main and on the PR; unrelated to this change.

The mirror removes message 654 in the two debug1 tests (WARP and RTX 3070 Ti). Nothing regressed in the tests run here. This run does not cover the GTX 1060 crash.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7284924095 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3627#issuecomment-7284924095). Originally posted by [Makto94](https://github.com/Makto94) on 2026-11-30T16:35:52Z. --- Hardware run of this PR on a second NVIDIA GPU, one where the copy did not crash on `main`. **Environment** - Adapter: NVIDIA GeForce RTX 3070 Ti, driver 32.0.16.2101, Windows 11 build 26300 - `main`: `cf43986d`; this PR: `5ee979df` - Debug layer per test as in the table. `debug1` tests enable it, `debug0`, `keep` and `noretire` do not. - `main` was a full build. The PR was an incremental build in the same worktree. **Command** ```powershell ctest --preset dev --no-tests=error -j 1 -R "^startup_resource_retire_views" -V --output-on-failure ``` **Result** | Test | debug layer | `main` `cf43986d` | PR `5ee979df` | |---|---|---|---| | `startup_resource_retire_views_warp_debug0` | off | passed, 654 absent | passed, 654 absent | | `startup_resource_retire_views_warp_debug1` | on | passed, 654 present (1) | passed, 654 absent | | `startup_resource_retire_views_keep_warp` | off | passed, 654 absent | passed, 654 absent | | `startup_resource_retire_views_noretire_warp` | off | passed, 654 absent | passed, 654 absent | | `startup_resource_retire_views_hardware_debug0` | off | passed, 654 absent | passed, 654 absent | | `startup_resource_retire_views_hardware_debug1` | on | passed, 654 present (1) | passed, 654 absent | | `startup_resource_retire_views_keep_hardware` | off | passed, 654 absent | passed, 654 absent | | `startup_resource_retire_views_noretire_hardware` | off | passed, 654 absent | passed, 654 absent | | `startup_resource_retire_views_no_mirror_control_warp` (negative control) | on | not in `main` | passed, 654 present (4), as the test requires | `main`: 8/8 passed. PR: 9/9 passed. No capability skips (77) in either run. No crash on `main` on this card. Both `debug1` runs also log message 1328 (`CreateCommittedResource` ignoring `InitialState`) on `main` and on the PR; unrelated to this change. The mirror removes message 654 in the two `debug1` tests (WARP and RTX 3070 Ti). Nothing regressed in the tests run here. This run does not cover the GTX 1060 crash.
R0Y00 commented 2026-11-30 17:28:16 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-30T17:28:16Z.

Review: APPROVED


Reviewed the mirror creation/lifetime, writes and copy-out/Clear CPU handle routes. Exact revision, Windows 11 build 26300.9974 Debug, WARP driver 10.0.26100.9818 and RTX 4060 Laptop GPU driver 32.0.16.1656: ctest --preset dev --no-tests=error --output-on-failure -j 1 -R '^startup_resource_retire_views_' passed 9/9. Neither debug-enabled mirror run reported message 654. Turning the mirror off in the WARP negative control reported it four times. Also verified that this head integrates without conflict with current main at 66bc2115.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6117134997 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3627#pullrequestreview-6117134997). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-30T17:28:16Z. **Review:** APPROVED --- Reviewed the mirror creation/lifetime, writes and copy-out/Clear CPU handle routes. Exact revision, Windows 11 build 26300.9974 Debug, WARP driver 10.0.26100.9818 and RTX 4060 Laptop GPU driver 32.0.16.1656: `ctest --preset dev --no-tests=error --output-on-failure -j 1 -R '^startup_resource_retire_views_'` passed 9/9. Neither debug-enabled mirror run reported message 654. Turning the mirror off in the WARP negative control reported it four times. Also verified that this head integrates without conflict with current main at 66bc2115.
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!3627
No description provided.