Skip to content

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

Merged
R0Y00 merged 1 commit into
R0Y00:mainfrom
Jess-Doit:startup/visible-heap-copy-mirror
Nov 30, 2026
Merged

R0Y00 merged 1 commit into
R0Y00:mainfrom
Jess-Doit:startup/visible-heap-copy-mirror

Conversation

@Jess-Doit

Copy link
Copy Markdown
Contributor

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 startup: match descriptor shadow slots on a descriptor boundary #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

…U-only mirror

Desktop D3D12 reads CopyDescriptors sources and ClearUnorderedAccessView CPU
handles only from CPU-only heaps. A console title may copy out of a
shader-visible heap, and the stand-in forwarded that copy unchanged: the debug
layer reports message 654 on every adapter, and a GTX 1060 driver faults in
CopyDescriptorsSimple (R0Y00#3558).

Each title view or sampler heap created shader-visible now gets a CPU-only
mirror of its visible prefix, retained by the desktop heap like the CPU tail.
Views, samplers and copy destinations in a visible range are written to the
mirror and copied from there; copy sources and UAV clears read the mirror.
Shadow tracking stays keyed on the visible handle.

The retire-views debug-layer tests now fail on message 654 in the shim's log,
which the shim drains from the info queue before the test can count it. Case 6
copies into and out of the visible heap. The control turns the mirror off with
X2W_D3D12_NO_VISIBLE_HEAP_MIRROR=1 and requires the message.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Makto94

Makto94 commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

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.

@R0Y00 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

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 66bc211.

@R0Y00
R0Y00 merged commit bee9c64 into R0Y00:main Nov 30, 2026
5 checks passed
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.

startup: descriptor copies from a shader-visible heap crash the NVIDIA driver

3 participants