Skip to content

startup: defer heap-indexed root signatures and refuse real draws under them - #1732

Merged
R0Y00 merged 1 commit into
R0Y00:mainfrom
MasterDomino:startup/root-heap-indexed
Nov 24, 2026
Merged

R0Y00 merged 1 commit into
R0Y00:mainfrom
MasterDomino:startup/root-heap-indexed

Conversation

@MasterDomino

Copy link
Copy Markdown
Collaborator

What and why

Refs #870. Follows R0Y00's direction on #870 (17:12Z and 17:21Z): defer the native root bind until a real draw has the indexed heaps it needs, keep the translated path on its own root signature, refuse a real draw that lacks a heap or cannot restore the signature's state, and keep the unflagged path and the existing root-CBV controls. Supersedes the approach of the closed draft #1685 (a one-entry default sampler heap bound before the root signature); the debug-layer message callback with a plain-list control comes from that draft, hence the co-author trailer.

Command-list slot 34 forwarded every title root signature to the desktop list. Title root signatures carry D3D12_ROOT_SIGNATURE_FLAG_CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED and/or SAMPLER_HEAP_DIRECTLY_INDEXED (0x400, 0x800), but slot 32 only tracks the title's heaps and never forwards them, so the debug layer reports message ID 1419 for each flag. In a local startup run (RX 9070 XT, driver 32.0.31044.16, X2W_D3D12_DEBUG=1, 75 s) unmodified main gave 394 ID-1419 messages out of 400 debug messages; a prototype of this change gave 0 of 6, with translated draws unchanged (14,419 vs 14,080, 0 not drawn). Translated draws bind their own root signature (create_translated_root, no flags) and are not a source of the message.

Change

  • Device slot 16 records the two heap-indexing flags of each title root signature (the CreateRootSignature log line now prints them).
  • Slot 34 keeps tracking the title's parameters, root addresses and constants for every root signature. An unflagged root signature is still set on the desktop list immediately. A flagged one is deferred: not set on the desktop list, logged (first three), counted. Root SRVs (slot 44) are not forwarded under a deferred root; their title address is still kept.
  • New header-only helper src/startup_stubs/heap_indexed_root.h: decide_real_root takes the flags, the mirrored view and sampler heaps on the list (bound, entries, whole), the highest index the draw reads (or unknown), and whether every root constant, descriptor table and root descriptor can be set again. It returns bind or a specific refusal: view heap missing, sampler heap missing, both heaps missing, root state not restorable. A heap covers a draw only at indices it holds, so a one-entry sampler heap covers index 0 only and never stands in for the view heap.
  • Real draw (slot 12) under a deferred root: the stand-in has no mirrored heap and keeps root constants and descriptor tables only as title values, so it asks the helper with those facts and the draw is refused, counted per reason, and logged (real draw refused: root signature heap flags 0x..., <reason>, first three per reason, then every 1000th). The x2w-render totals line adds heap-indexed roots deferred N (real draws refused: view heap, sampler heap, both heaps, state). The deferred bind after a bind decision is one line and is not reachable with the stand-in's facts.
  • Docs: docs/startup-runtime.md (Heap-indexed root signatures) and docs/experiments.md.

Tests

Branch startup/root-heap-indexed at 0ceece32, based on e4ac2c78. Windows 11 build 26300, MSVC 19.44.35221, Debug (--preset dev). WARP: Microsoft Basic Render Driver 10.0.26100.9818. Hardware: AMD Radeon RX 9070 XT, driver 32.0.31044.16. The draw fixtures enable the D3D12 debug layer in-process (X2W_TEST_DEBUG_LAYER=1); GPU-based validation off.

. .\tools\dev.ps1
cmake --preset dev
cmake --build --preset dev
ctest --preset dev --no-tests=error -R '^startup_(heap_indexed_root.*|root_heap_(warp|hardware)|root_cbv_(warp|hardware))$' -V
ctest --preset dev --no-tests=error -R '^startup_' -j 4

Real-draw decision coverage (device-free)

startup_heap_indexed_root: passed, 3222 of 3222 decisions as expected. 22 named cases (each flag alone, both, none; one-entry sampler heap at index 0, index 1 and unknown; sampler heap alone under both flags, with one entry and whole; view heap alone; neither; state lost with heaps present; other root flags; the stand-in's own request for each flag set) plus a 3200-case matrix: flags {0, 0x400, 0x800, 0xC00} x view heap {absent, one entry, four entries, whole} x highest view index {0, 1, 3, 4, unknown} x the same for samplers x restorable {no, yes}, compared with expectations written separately in the test.

startup_heap_indexed_root_sampler-alone_control and startup_heap_indexed_root_bind-unrestorable_control (WILL_FAIL): passed, i.e. the check failed with 2192/3200 and 2759/3200 matching under the mutated expectations.

This covers the decision only. No source-built fixture reaches the stand-in's real-draw branch (see Not covered).

Translated GPU readback and debug layer (source-built)

startup_root_heap_{warp,hardware}: the root CBV fixture (a translated pixel shader reading four floats through root parameter 0) with the title root signature created with each flag alone, both, and neither. For every flagged case the same root signature blob is first set on a plain desktop list with no heaps (fail-first control); it must report exactly one ID 1419 per flag, otherwise the run exits 77. Through the stand-in, every case must report 0 messages with ID 1419, draw the exact 32 pixels, and log one deferral line per slot-34 call (none for the unflagged case).

Case WARP RX 9070 XT
bound, flags 0x0 (unflagged, immediate bind) 32 px exact, stand-in 0 x 1419, 0 other errors same
bound, 0x400 control 1 x 1419; 32 px exact (yellow); stand-in 0 x 1419, 0 other errors same
bound, 0x800 control 1 x 1419; 32 px exact; stand-in 0, 0 other same
bound, 0xC00 control 2 x 1419; 32 px exact; stand-in 0, 0 other same
null, 0xC00 control 2 x 1419; 32 px exact (zeros); stand-in 0, 0 other same
switch_root, 0xC00 control 2 x 1419; 32 px exact (zeros, address cleared); stand-in 0, 0 other same

Result: startup_root_heap_warp passed (3.5 s), startup_root_heap_hardware passed (4.7 s). The hardware draw runs on the RX 9070 XT; the pipeline-preparation step of each case uses WARP as in the other stream fixtures.

The existing startup_root_cbv_{warp,hardware} (bound, unbound, null, same_root, switch_root, wrong_type; no debug layer, unflagged root signatures serialized as version 1.0 exactly as before) passed unchanged on both backends.

All startup tests

ctest --preset dev --no-tests=error -R '^startup_' -j 4: 198 tests, 194 passed, 0 failed, 4 skipped. The skips are capability skips unrelated to this change: startup_view_heap_{warp,hardware} and startup_logical_view_{warp,hardware} ("adapter accepts 1245184 descriptors directly"). Docs checks: tests/docs_links_check.py (17 files, 365 links) and tests/bidi_controls_check.py passed.

Negative controls

  • Slot 34 restored to forward every root signature (if (true) in place of if (!pass.root_heap_flags)): startup_root_heap_warp and startup_root_heap_hardware failed with AssertionError: bound 0x400: stand-in list: 1 messages with a control id or id 1419, 0 other errors. Run case by case under the same mutant, the stand-in reported 0 (0x0), 1 (0x400), 1 (0x800), 2 (0xC00), 2 (null 0xC00) and 6 (switch_root 0xC00) ID-1419 messages on both WARP and the RX 9070 XT, so each flag fails independently. startup_root_cbv_{warp,hardware} still passed under that mutant (no debug layer, no flags). Reverted.
  • Helper mutants, each failing startup_heap_indexed_root (exit 1), then reverted (3222/3222 again):
    • a bound sampler heap satisfies the view heap: FAIL both flags, one-entry sampler heap alone: ... -> bind, expected view heap missing (2559/3222);
    • refusal turned into bind when the state cannot be restored: FAIL both flags, both heaps, state lost: ... -> bind, expected root state not restorable (2778/3222);
    • a bound heap covers any index: FAIL sampler flag, one-entry heap, index 1: ... -> bind, expected sampler heap missing (2332/3222).

Not covered

  • The real-draw path end to end. On current main pipeline_real is set only by build_stream_pipeline, which needs compile_translation; that has returned no shader since e658fe2, so no source-built test can reach the real branch of list_draw. The refusal and its counters are checked only through the device-free decision matrix, not through a draw. As asked on P0: main executable startup progress #870, no alternate pipeline-build path was added for this slice. Because the stand-in cannot restore root constants and descriptor tables under a deferred root, the real path for flagged roots stays explicitly refused until a real end-to-end fixture exists.
  • Compute root signatures and other command-list slots are unchanged.
  • No claim about full-game startup or frame rate. The in-title message counts above come from a prototype of this change, not from this exact commit.

🤖 Generated with Claude Code

…er them

Device slot 16 records whether a title root signature indexes the
CBV/SRV/UAV heap (0x400) or the sampler heap (0x800) directly. Command-list
slot 34 keeps tracking the title's parameters for every root signature but
no longer sets a flagged one on the desktop list, where the title's heaps
are never bound (debug layer message ID 1419). Unflagged roots keep the
immediate bind. Root SRVs (slot 44) are not forwarded under a deferred root.

A real draw under a deferred root is decided by heap_indexed_root.h: it
binds only when the list mirrors every indexed heap at the indices the draw
reads and all root state can be restored. The stand-in has neither, so the
draw is refused with a specific reason, counted and logged.

Tests: startup_heap_indexed_root (device-free decision matrix, two mutated
controls) and startup_root_heap_{warp,hardware} (root CBV draw with the
debug layer on, each flag alone, both and none, with a plain-list
fail-first control that must report 1419).

Refs R0Y00#870

Co-authored-by: tedin7 <110300616+tedin7@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@MasterDomino

Copy link
Copy Markdown
Collaborator Author

@tedin7 this is the single implementation from #870 that replaces #1685; your message-callback counter and plain-list control are in tests/startup_root_heap.cpp (co-author trailer on the commit). A Windows Debug + Release /O2 run from you would be welcome, since I've only run Debug here.

AI-assisted.

@tedin7 tedin7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Review of PR #1732 (0ceece32c0db5aa961bcdb1727ad39b470a0376c).

Findings

No blocking issues found.

  • Note (environment / coverage): On the Windows Server 2025 WARP VM, startup_root_heap_warp capability-skipped (exit 77, debug layer unavailable), so the live debug-layer ID-1419 suppression check in startup_root_heap_{warp,hardware} was not exercised on that node. All other targeted tests—including startup_heap_indexed_root, both WILL_FAIL negative controls, startup_root_cbv_warp, startup_stream_*, and startup_stubs—passed in both Debug and Release /O2.

What looks good

  • Heap-indexed root deferral (src/startup_stubs/d3d12_xs_device.cpp):
    • Device slot 16 (device_create_root_signature) extracts D3D12_ROOT_SIGNATURE_FLAG_CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED (0x400) and SAMPLER_HEAP_DIRECTLY_INDEXED (0x800) into root_heap_flag_map().
    • Command-list slot 34 (list_graphics_root) keeps tracking pass.root and pass.root_address for all root signatures, binds unflagged ones immediately on the desktop list, and defers flagged ones (pass.root_heap_flags, pass.deferred_root, logged first 3, counted in heap_roots_deferred), clearing pass.root_heap_flags / pass.deferred_root when a null or non-root-signature is passed.
    • Slot 44 (list_root_srv) avoids forwarding root SRVs to the desktop list under a deferred root while still recording pass.root_address.
  • Safe refusal of real draws (src/startup_stubs/heap_indexed_root.h, list_draw):
    • Translated draws (!pass.pipeline_real) run before the deferred-root check and continue using their own unflagged root signature. list_draw_indexed in src/startup_stubs/d3d12_draw.inl only dispatches draw_translated and has no real-draw branch.
    • Real draws in list_draw under pass.root_heap_flags consult x2w_startup::decide_real_root with absent mirrored heaps and state_restorable = false, returning safely without drawing or touching uninitialized handles, while updating heap_root_refusals[decision], render_draws_skipped, and x2w-render totals.
    • heap_covers and decide_real_root check heap.bound and (heap.whole || (highest != unknown_heap_index && highest < heap.entries)), keep view and sampler heap requirements independent, and check state_restorable after heap coverage.
  • Coverage separation & title-neutrality:
    • Real-draw decision coverage (startup_heap_indexed_root + two WILL_FAIL controls) and translated GPU readback (startup_root_heap_{warp,hardware}) are reported separately, with the unreached list_draw real-draw branch explicitly noted under "Not covered".
    • Diff and docs are 100% title-neutral.

Checks & verification

  • python3 /root/.local/state/xbox2windows/pipeline/x2w_pipe.py prep-verify 1732 --dir /tmp/rev-x2w-83/1732 --json: git_diff_check, docs_links_check, bidi_controls_check, py_compile (1 file) all passed.
  • Win2025 (x2w_pipe.py win2025 1732 --targets cpu_shim_startup,cpu_shim_startup_guest,cpu_shim_startup_lifted,d3d12_xs_shim,startup_heap_indexed_root_check,startup_stream_consumer,startup_stream_depth,startup_stub_consumer --regex '^(startup_heap_indexed_root|startup_heap_indexed_root_bind-unrestorable_control|startup_heap_indexed_root_sampler-alone_control|startup_root_heap_warp|startup_root_cbv_warp|startup_stream_draw_warp|startup_stream_depth_warp|startup_stream_request_warp|startup_stream_viewport_warp|startup_stubs)$'):
    • Debug (--preset dev): build 21.77s, 9/10 passed (4.72s), startup_root_heap_warp skipped (exit 77).
    • Release /O2 (--preset release): build 38.85s, 9/10 passed (4.88s), startup_root_heap_warp skipped (exit 77).
  • Win2025 --patch mutation (heap_covers in src/startup_stubs/heap_indexed_root.h mutated to return heap.bound;):
    • x2w_pipe.py win2025 1732 --patch ... --skip-release --targets startup_heap_indexed_root_check --regex '^(startup_heap_indexed_root|startup_heap_indexed_root_bind-unrestorable_control|startup_heap_indexed_root_sampler-alone_control)$': startup_heap_indexed_root failed as expected (2332 of 3222 heap-indexed root decisions as expected, exit code 1).

AI-assisted; commands listed were executed locally.

@R0Y00
R0Y00 merged commit 48d9571 into R0Y00:main Nov 24, 2026
5 checks passed
rasptum added a commit to rasptum/Xbox2Windows that referenced this pull request Nov 24, 2026
After merging main with R0Y00#1732, device slot 16 records each root
signature's heap-indexing flags for command-list slot 34, which defers a
flagged root instead of setting it on the desktop list. It reads those
flags from the blob passed to CreateRootSignature through the desktop
deserializer. note_root_blob restores the bits only in its separate
translation copy. So after a Windows 10 retry, slot 34 sees 0 and sets
the root directly, while translation (the .root request, its key, and
the manifest that create_translated_root consumes) keeps the restored
bits. That is the right split on a runtime that refuses 0xC00: the
desktop root signature really has no indexed heaps, so the debug-layer
rejection R0Y00#1732 avoids cannot happen, and real draws under it are not
heap-indexed. No code change was needed to reconcile the two.

Test: d3d12_xs_shim_heap_indexing's provenance control now also checks,
for baseline, 0x400-only, 0x800-only and 0xC00 in both orders and for a
byte copy, that the flags slot 34 acts on are 0. The fixture export
x2w_d3d12_root_translation_blob reports them alongside the translation
copy. Mutant: OR-ing the restored bits into slot 34's flags fails 6 of
the 8 provenance cases (all flagged inputs).

Review nits (tedin7, c31afac):
- RetriedBlob::wrap allocates with nothrow and registers inside
  try/catch; if either fails the caller gets the desktop blob unwrapped
  (no bits), so nothing leaks and no exception crosses the export.
- x2w_stripped_root_flags logs once when a blob misses the pointer
  lookup but has the bytes of a live retried blob: either a copy (bits
  not restored) or a call without the bits; the bytes cannot say which,
  so the answer stays 0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
R0Y00 added a commit that referenced this pull request Nov 25, 2026
…Windows 10 (#1277)

* startup: keep the title's heap-indexing root flags for shader translation on Windows 10

The executable's root signatures set CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED and
SAMPLER_HEAP_DIRECTLY_INDEXED (0xC00). The in-box Windows 10 D3D12 runtime
predates shader model 6.6 and answers E_INVALIDARG. The executable does not
check the result, so its pipeline object stays null and a startup run stops
at about 75 s on a read through it (#1160).

With X2W_D3D12_PERMISSIVE=1, d3d12_xs_SerializeVersionedRootSignature now
repeats a refused serialization without those two bits and remembers, by blob
content, which bits it removed (exported as x2w_stripped_root_flags). The
recording device restores them in the copy of the blob it keeps for shader
translation. The title's shaders take the heap pointers in the user SGPRs
those flags add; without them gfx2hlsl lays the registers out one short
("s_load through s10 holding None") and the UI glyph pipelines are never
translated. The desktop root signature itself still lacks the bits, so a
shader that really indexes the heaps still needs shader model 6.6.

Test: d3d12_xs_shim_heap_indexing.
- Switch off: the shim answers E_INVALIDARG like the desktop runtime
  (negative control).
- Switch on: the retried blob is byte-identical to the desktop serialization
  without the bits, alone and with the console bits 0x03000000, and the
  caller's descriptor is unchanged.
- x2w_stripped_root_flags reports 0xC00 for that blob and 0 for a blob with
  other content and for null.
- Unobserved invalid bits next to 0xC00 stay refused.
- A runtime that accepts the flags makes the retry unreachable: the test then
  checks pass-through and returns 77 (skip).
Mutants: no retry, and retry without recording, each fail it.

Measured on Windows 10 19045, RTX 3060: the startup run continues past the
75 s stop, and the four glyph pipelines translate once 0x800 is restored.

Fixes #1160 (the Windows 10 cause).

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

* startup: tie stripped heap-indexing root flags to the blob the retry returned

Review of #1277: the bytes of a blob serialized without the heap-indexing
bits do not identify the input. The legal baseline without them, an input
with only 0x400, one with only 0x800 and one with both serialize to the same
bytes, so the content-keyed lookup gave a baseline blob the bits of another
call and could not tell the two single-flag inputs apart.

Design: of the two options in the review, this keeps an explicitly
identifiable representation, because the recording device only ever sees
(pointer, size) at CreateRootSignature and cannot be handed the original
descriptor. After a retry, d3d12_xs_SerializeVersionedRootSignature returns
its own ID3DBlob around the desktop blob. That object registers its buffer
with the removed bits while it lives and unregisters it in its destructor,
before releasing the desktop blob, so the address cannot be reused while a
record for it exists. x2w_stripped_root_flags answers only for that exact
buffer and size. A blob from any other call, or a copy of the bytes in
other memory, reports 0: the translation copy then keeps the desktop flags
instead of guessing. Nothing changes with X2W_D3D12_PERMISSIVE unset or on
a runtime that accepts the flags (no retry, no wrapper).

The recording device declares x2w_stripped_root_flags with a linker
fallback that returns 0, so offscreen_check, which compiles
d3d12_xs_device.cpp without the shim, links again on current main.
A fixture export, x2w_d3d12_root_translation_blob, returns the copy the
recording device keeps for translation (the .root request and the
translation key).

Test: d3d12_xs_shim_heap_indexing gains a provenance control. With the
switch on, the baseline, 0x400-only, 0x800-only and 0xC00 inputs are
serialized and held alive together, in both call orders (baseline first,
both first). Each blob is byte-identical to the others, goes through the
recording device's CreateRootSignature (slot 16) on WARP, and the RTS0
flags of the translation copy, parsed by the test, must be the base flags
plus exactly that call's bits; the lookup must agree. A copy of the 0xC00
blob in test memory must give the base flags only. Existing controls are
unchanged: switch off refuses, retried bytes equal the desktop
serialization, unrelated blob and null record nothing, unobserved invalid
bits stay refused, and a runtime with shader model 6.6 skips (77).
Mutant: the previous content-keyed shim fails the provenance control.

Merged origin/main (d90dd76) first; it merged without conflicts.

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

* startup: pin stripped root flags against the deferred heap-indexed roots

After merging main with #1732, device slot 16 records each root
signature's heap-indexing flags for command-list slot 34, which defers a
flagged root instead of setting it on the desktop list. It reads those
flags from the blob passed to CreateRootSignature through the desktop
deserializer. note_root_blob restores the bits only in its separate
translation copy. So after a Windows 10 retry, slot 34 sees 0 and sets
the root directly, while translation (the .root request, its key, and
the manifest that create_translated_root consumes) keeps the restored
bits. That is the right split on a runtime that refuses 0xC00: the
desktop root signature really has no indexed heaps, so the debug-layer
rejection #1732 avoids cannot happen, and real draws under it are not
heap-indexed. No code change was needed to reconcile the two.

Test: d3d12_xs_shim_heap_indexing's provenance control now also checks,
for baseline, 0x400-only, 0x800-only and 0xC00 in both orders and for a
byte copy, that the flags slot 34 acts on are 0. The fixture export
x2w_d3d12_root_translation_blob reports them alongside the translation
copy. Mutant: OR-ing the restored bits into slot 34's flags fails 6 of
the 8 provenance cases (all flagged inputs).

Review nits (tedin7, c31afac):
- RetriedBlob::wrap allocates with nothrow and registers inside
  try/catch; if either fails the caller gets the desktop blob unwrapped
  (no bits), so nothing leaks and no exception crosses the export.
- x2w_stripped_root_flags logs once when a blob misses the pointer
  lookup but has the bytes of a live retried blob: either a copy (bits
  not restored) or a call without the bits; the bytes cannot say which,
  so the answer stays 0.

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

* startup: stop the copied-blob scan once its line is logged; say when the retry runs

x2w_stripped_root_flags compared every registered blob's bytes on a miss
only to print a once-only line; the comparison now stops after a match
and is skipped once the line has been logged. docs/startup-runtime.md
says the retry runs only on runtimes that refuse the heap-indexing flags
and that d3d12_xs_shim_heap_indexing reports 77 elsewhere.

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

* startup: fail the root signature retry if provenance cannot be kept

---------

Co-authored-by: rasptum <348594691+rasptum@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Royoo <3230853833@qq.com>
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.

3 participants