Skip to content

startup: keep the heap-indexing root flags for shader translation on Windows 10 - #1277

Merged
R0Y00 merged 11 commits into
R0Y00:mainfrom
rasptum:startup/win10-root-flags
Nov 25, 2026
Merged

R0Y00 merged 11 commits into
R0Y00:mainfrom
rasptum:startup/win10-root-flags

Conversation

@rasptum

@rasptum rasptum commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Fixes #1160 (the Windows 10 cause; see the note there on the Windows 11 report).

Problem

The executable's root signatures set CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED | SAMPLER_HEAP_DIRECTLY_INDEXED (0xC00). The in-box Windows 10 D3D12 runtime predates shader model 6.6, so D3D12SerializeVersionedRootSignature (reached through d3d12_xs.dll) returns E_INVALIDARG. The executable doesn't check it, so its pipeline object stays null and a startup run stops at about 75 s on a read through it (#1160).

Change (opt-in, X2W_D3D12_PERMISSIVE=1)

  1. Serializer. d3d12_xs_SerializeVersionedRootSignature repeats a refused serialization without the two bits, then records, by blob content, which bits it removed. The record is exported as x2w_stripped_root_flags. Content keying keeps working when a caller copies the blob before CreateRootSignature.
  2. Translation copy. The recording device restores those bits in the copy of the blob it keeps for shader translation. The title's shaders take the heap pointers in the user SGPRs that the flags add. Without them, gfx2hlsl lays the registers out one short (s_load through s10 holding None), and the UI glyph pipelines never translate.

The desktop root signature itself still lacks the bits, so a shader that really indexes the heaps still needs shader model 6.6. Without the switch, nothing changes.

Test

New scenario d3d12_xs_shim_heap_indexing in tests/d3d12_xs_shim_check.cpp:

case expected
switch off, 0xC00 (negative control) E_INVALIDARG, no blob, same as desktop
switch on, 0xC00 blob byte-identical to the desktop serialization without the bits; caller's descriptor unchanged; x2w_stripped_root_flags = 0xC00
switch on, 0xC00 | 0x03000000 same blob (console bits stripped as before), same record
blob with other content, null blob record 0
switch on, 0xC00 | 0x04000000 still E_INVALIDARG (the retry doesn't hide other faults)
runtime that accepts 0xC00 pass-through checked, exit 77 (skip): retry unreachable

Mutants (local, not committed): removing the retry fails the scenario (hr=0x80070057), and so does retrying without recording (recorded=0x0).

ctest --preset dev --no-tests=error -R '^(d3d12_xs_shim_|startup_stubs$)' -V
ctest --preset release --no-tests=error -R '^(d3d12_xs_shim_|startup_stubs$)' -V

Result: 7/7 passed on both presets, and again after rebasing onto 943a9ccd.

Environment: Windows 10 Pro 19045, in-box D3D12 runtime (no Agility SDK), NVIDIA RTX 3060 (driver 32.0.15.9636), MSVC (VS 2022) x64, debug layer off. On this machine the scenario runs, not skips.

Startup measurement, same machine: with this change the run continues past the 75 s stop. Once 0x800 is restored for translation, the four glyph pipelines translate. Together with the colour-blend decode (#1216) and 16ac9a22's wide-descriptor fix, that is what made the setup-page text readable on Windows 10 (#1150).

Docs: docs/startup-runtime.md, the X2W_D3D12_PERMISSIVE row.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

…tion 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 (R0Y00#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 R0Y00#1160 (the Windows 10 cause).

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

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

Peer review at commit 31719cc56f9d0d7755ba161b697bdafec002d2d5:

Findings

  • src/d3d12_xs_shim.cpp & src/d3d12_xs_shim.def: serialize_for_runtime retries E_INVALIDARG only when X2W_D3D12_PERMISSIVE=1 and heap_indexing_flags (0xC00) are set, leaves the caller's descriptor unmodified, restores original failure/error_blob if the retry fails, and records stripped bits by FNV-1a content hash (x2w_stripped_root_flags, bounded to 4096 entries under SRWLOCK).
    • Minor edge case: if two root signatures differed only in 0x400 vs 0x800 and were both stripped, their serialized blobs would hash identically and the second entry would win in x2w_stripped_root_flags; practically benign since callers typically set both (0xC00) or a single consistent mask.
  • src/startup_stubs/d3d12_capture.inl: note_root_blob bounds-checks the DXBC/RTS0 header offsets before restoring stripped into the RTS0 flags word of the translation copy.
  • tests/d3d12_xs_shim_check.cpp: heap_indexing_checks covers the SM 6.6 pass-through (exit 77 when desktop accepts 0xC00), negative control (X2W_D3D12_PERMISSIVE unset), retry with/without console bits, unretried blob isolation, and non-masking of unrelated invalid bits (0x04000000).

Verification

  • Linux:
    • git diff --check origin/main...HEAD: clean
    • /root/.local/share/x2w-rev-venv/bin/python -B tests/docs_links_check.py: passed (Checked 16 Markdown files and 284 links)
    • /root/.local/share/x2w-rev-venv/bin/python -B tests/bidi_controls_check.py: passed (Checked 1069 tracked source, script and build/CI files: no bidirectional controls)
  • Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP):
    • Debug (--preset dev):
      • cmake --build --preset dev --target d3d12_xs_shim_check -- -j 6 (22.62s)
      • ctest --preset dev -R '^d3d12_xs_shim_' --parallel 4 --no-tests=error --output-on-failure: 5/6 passed (0.13s), d3d12_xs_shim_heap_indexing Skipped (77) — desktop runtime on Build 26100 accepts 0xC00 (pass-through verified; Win10 retry path not reachable on this OS build)
    • Release /O2 (--preset release):
      • cmake --build --preset release --target d3d12_xs_shim_check -- -j 6 (35.35s)
      • ctest --preset release -R '^d3d12_xs_shim_' --parallel 4 --no-tests=error --output-on-failure: 5/6 passed (0.18s), d3d12_xs_shim_heap_indexing Skipped (77)

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

The contents of a stripped blob do not identify which input produced it. The same legal baseline, an input with only the view-heap flag, and an input with only the sampler-heap flag will all serialize to the same bytes after stripping. The lookup consequently gives a valid baseline blob the flags from a different call and can conflate the two flagged inputs. The existing control changes an unrelated flag, so it misses this collision.

Please preserve provenance through an explicitly identifiable representation, or keep the fallback scoped to a path that can pass the original flags directly to translation. Add a control for the identical unflagged baseline and the two individual flag combinations in both orders. Also validate the translation-side root-signature consumer, so success checks which flags it uses and not just which value the lookup returns.

@lukaslw-lab

Copy link
Copy Markdown
Contributor

AI-assisted (Claude Code).

Independent Windows 10 confirmation, measured in a startup run.

Without #1277 With #1277 (31719cc5)
Host Windows 10 22H2 (19045), RTX 3080 Ti 32.0.16.1047, release same
Programs dropped after a failed root signature ~25,000 of ~26,000 (E_INVALIDARG from D3D12SerializeVersionedRootSignature) 0
Run null read at ~31 s in renderer setup (the first consumer of a dropped program) 420 s, no crash, first-run setup pages drawn
  • Traced statically and with hit counters: the title converts its compact root signatures, serializes them through d3d12_xs.dll, and only drops the program on failure; CreateRootSignature itself was never reached for those programs.
  • ctest --preset release -R '^(d3d12_xs_shim_|startup_stubs$)' passes on this host; d3d12_xs_shim_heap_indexing takes the retry path (not the exit-77 skip).
  • Rebase note: on current main, offscreen_check compiles src/startup_stubs/d3d12_xs_device.cpp without linking d3d12_xs.dll, so the extern "C" x2w_stripped_root_flags declaration in d3d12_capture.inl fails to link (LNK2019). Resolving it at run time (GetProcAddress on d3d12_xs.dll, 0 when absent) fixed the build locally.

@ChazY11

ChazY11 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Verified on Windows 11: the fallback is inert and nothing in the shim suite regressed

Independent reviewer, not the author; I did not touch the branch. Reviewed 31719cc5 (mergeable against current main).

I am on Windows 11 build 26300.9974, so I cannot exercise the Windows 10 refusal you are fixing. What I can check is the
other half — that on a runtime which accepts 0xC00 this change does nothing and breaks nothing.

cmake --preset dev
cmake --build --preset dev                                   # no FAILED target
ctest --preset dev --no-tests=error -R '^(d3d12_xs_shim_|desktop_root_signature)' -V
test without X2W_D3D12_PERMISSIVE with X2W_D3D12_PERMISSIVE=1
desktop_root_signature pass pass
d3d12_xs_shim_exports pass pass
d3d12_xs_shim_serialize pass pass
d3d12_xs_shim_deserialize pass pass
d3d12_xs_shim_iids pass (30/30 exports) pass
d3d12_xs_shim_warp_root pass pass
d3d12_xs_shim_heap_indexing skip skip

7 of 7 pass or skip in both modes, so the permissive path is genuinely opt-in: with the variable unset the serializer
never retries, and with it set there is nothing to retry because this runtime accepts the flags.

The skip is self-explaining, which is the right behaviour:

desktop accepts heap-indexing flags (hr=0x00000000); pass-through identical; retry not reachable: skip

That also confirms your premise from the other side: on this build the desktop serializer returns S_OK for 0xC00, so
the Windows 10 result cannot be reproduced here, and the test says so instead of pretending to pass.

The parts of your new test that can run on Windows 11 do run and pass here: the negative controls for unobserved
invalid flag bits and for a null blob still return E_INVALIDARG through both the desktop and the shim path
(d3d12_xs_shim_serialize prints embedded_params=3 stripped_hr=0x80070057 null_hr=0x80070057), so the retry logic
did not turn a genuine rejection into an acceptance.

Two things worth adding before merge

  1. One positive execution of the retry path. From here it is only ever a skip, so the new code has no machine that
    ran it in this PR. If you have the Windows 10 build, please paste that run (build, adapter or WARP driver, debug-layer
    status, and the x2w_stripped_root_flags value it recorded) into the description — that is the one claim a reviewer
    cannot otherwise check.
  2. Say which OS skipped. The line above is good, but a reader cannot tell from it whether the skip means "this
    runtime supports the flags" or "a capability is missing". Including the OS build in that printf would make the
    record self-describing, and it costs nothing.

Verdict

No objection from me for the inertness half: build clean, seven of seven pass or skip with and without the variable, the
negative controls still reject, and the skip is reported rather than hidden. The Windows 10 positive path remains
unverified on my side, so I would like your own Windows 10 run in the description before this merges.

Happy to re-run on this machine after a rebase.

rasptum and others added 3 commits November 24, 2026 10:34
…returned

Review of R0Y00#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>
@rasptum

rasptum commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

@R0Y00 thanks for the review. Addressed in f92d39c0 (plus a merge of main, c31afac4).

Provenance. The content-keyed record is gone. After a retry, the serializer now returns its own ID3DBlob around the desktop blob. That object registers its buffer with the bits it removed and unregisters it in its destructor, before the desktop blob is released, so the address cannot be reused while a record exists. x2w_stripped_root_flags answers only for that exact buffer and size. A blob from any other call, or a copy of the same bytes elsewhere, reports 0, and the translation copy then keeps the desktop flags instead of guessing. I took this option because the recording device only sees (pointer, size) at CreateRootSignature and cannot be handed the original descriptor.

Controls. d3d12_xs_shim_heap_indexing now serializes the baseline, 0x400 only, 0x800 only and 0xC00, holds all four alive together, in both call orders. The four blobs are byte-identical. Each goes through the recording device's CreateRootSignature on WARP, and the test parses the RTS0 flags of the translation copy itself: they must be the base flags plus exactly that call's bits. A copy of the 0xC00 blob in test memory must give the base flags only. The previous content-keyed shim fails this control. Existing controls are unchanged.

Results. Windows 10 19045, MSVC, RTX 3060 + WARP: the six d3d12_xs_shim_* scenarios pass in dev and release (heap_indexing runs here, it does not skip). On a merge with main at c864f138 the same six pass again. Main has moved since; the branch still merges cleanly, and I did not rerun the full suite on the newest main.

ctest --preset release --no-tests=error -R '^d3d12_xs_shim_(exports|serialize|deserialize|iids|warp_root|heap_indexing)$' -V

Still open, as before: the desktop root signature itself lacks the bits, so a shader that really indexes the heaps needs shader model 6.6.

AI-assisted (Claude Code).

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

Re-review of head c31afac (comment only, not an approval). My earlier review was at 31719cc.

Verdict: 0 P1 / 0 P2, three nits.

Earlier points

  • Fixed (f92d39c): the blob-bytes-versus-input question. The content hash is gone; RetriedBlob wraps the desktop blob, records the removed bits against that exact (pointer, size) and unregisters in its destructor before releasing the buffer. The test serializes baseline, 0x400, 0x800 and 0xC00 together in both orders, passes each through the recording device's CreateRootSignature, parses the RTS0 flags of the translation copy, and checks that a byte copy gets 0 and keeps the desktop flags. The 0x400/0x800 hash-collision nit disappears with the hash.
  • LNK2019 for offscreen_check: addressed by /alternatename:x2w_stripped_root_flags=x2w_no_stripped_root_flags in d3d12_xs_device.cpp (the shim DLL links the strong definition). I could not link either build, so this is a read.
  • Win11 stays inert: with X2W_D3D12_PERMISSIVE unset nothing retries.

Semantics: the shim retries only on E_INVALIDARG, only when 0xC00 is set, and only with X2W_D3D12_PERMISSIVE=1; the caller's descriptor is untouched, and a failed retry returns the first error and its blob. Console flags (0x03000000) are stripped first. note_root_blob restores the removed bits into the translation copy only; the desktop root signature never carries 0x400/0x800. The PR touches only the top of d3d12_xs_device.cpp and adds x2w_d3d12_root_translation_blob after device_create_root_signature; it does not touch SetGraphicsRootSignature or sampler-heap code, so it does not collide with my open PR #1685, which does.
The test diff only adds lines (no loosened assertion) and checks serialized bytes, not source text. No title-specific content.

Run

  • git diff --check origin/main...HEAD, docs_links_check (16 files, 348 links) and bidi_controls_check: pass. x86_64-w64-mingw32-g++ -std=c++17 -fsyntax-only -Isrc src/d3d12_xs_shim.cpp: 0 errors; on d3d12_xs_device.cpp only the two __try/__except errors from the host compiler.
  • Mutations on StrippedBlob, RetriedBlob and x2w_stripped_root_flags, extracted from the real source into a g++/ASan harness with Win32 stubs (file restored with git checkout -- each time): destructor never unregisters, lookup ignoring size and recording 0xC00 for every blob are all caught; skipping inner_->Release() is caught only by LeakSanitizer. NOT testable on Linux: a mutation of note_root_blob's RTS0 offset and of the retry gating; only the Windows-only d3d12_xs_shim_heap_indexing test covers them.

Nits

  1. x2w_d3d12_root_translation_blob is a dllexport in the production d3d12_xs.dll that exists only for the test; consider guarding it or exposing it another way.
  2. If the title copies the blob bytes and releases the blob before CreateRootSignature, the translation copy silently loses the 0xC00 bits. A one-time log line would help diagnose that.
  3. RetriedBlob's constructor does push_back under the lock; if that throws, the object leaks. Unlikely in practice.

Not run: d3d12_xs_shim_heap_indexing (needs the Windows desktop D3D12 runtime and WARP; it skips with 77 on Windows 11 and Server 2025, so only Windows 10 exercises the retry) and the MSVC-only /alternatename pragma.

Linux limits: no Windows, WARP or GPU here; LLVM 19 only (CI pins LLVM 15). Anything that needs them was not run.

AI-assisted; commands listed were executed locally.

rasptum and others added 3 commits November 24, 2026 13:24
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>
…ew-e5d8c8

# Conflicts:
#	docs/startup-runtime.md
…ew-e5d8c8

# Conflicts:
#	src/startup_stubs/d3d12_xs_device.cpp
…ew-e5d8c8

# Conflicts:
#	docs/startup-runtime.md
#	src/startup_stubs/d3d12_xs_device.cpp
@rasptum

rasptum commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Thanks. Head c1afe2a: f799a9e plus merges of main up to a651490. Only prose in docs/startup-runtime.md and the block next to our fixture export in d3d12_xs_device.cpp needed a hand resolution, and both sides were kept. The shim, note_root_blob and the test are unchanged from f799a9e.

Interaction with the heap-indexed root changes on main. Device slot 16 reads the heap-indexing flags from the desktop blob passed to CreateRootSignature; only the separate translation copy gets the restored bits. After a Windows 10 retry the desktop flags are 0. Slot 34 then sets the root directly, the compute-root path does the same, and root_without_bindings is computed from those same desktop flags. That is consistent with the desktop object, which has no indexed heaps. The .root request and its translation key keep the restored bits. The provenance control checks both sides (translation flags and the flags slot 34 acts on) for the baseline, 0x400 only, 0x800 only and 0xC00, in both orders, plus a byte copy. A mutant that adds the restored bits to slot 34's flags still fails 6 of the 8 flagged cases.

Nits on c31afac.

  1. Test-only export: kept. It follows the existing fixture-export pattern (x2w_d3d12_allocator_pool_size), and guarding it would need a separate test build of the DLL. It now also reports slot 34's flags, so no second export was added.
  2. Lost bits when the title copies the blob: a one-time log line now fires when a blob has the bytes of a live retried blob at another address (a copy, or a call that never had the bits; the answer stays 0). A copy made after the blob is released can't be detected without content keys.
  3. Leak if registration throws: fixed. The wrapper is allocated without throwing and registered inside try/catch. On failure the caller gets the desktop blob unwrapped, with no bits recorded and nothing leaked.

Tests at c1afe2a. Windows 10 19045, WARP. ctest --preset <dev|release> --no-tests=error -R '^(d3d12_xs_shim_|desktop_root_signature$|startup_list_resubmit_warp|startup_heap_indexed_root)' -V: 11/11 passed in dev and 11/11 in release, with no skips. The heap-indexing test takes the retry path, and all 10 provenance cases pass.

AI-assisted (Claude Code).

@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 head c1afe2a3ae71b2be70ad735f5bb8062743a5b1e0

Independent reviewer, not the author; I did not touch the branch.

Result: no P1, no P2. Two nits.

Commands run locally (Linux, in a worktree of this head)

  • git diff --stat origin/main...HEAD: 7 files, +384/-7 (shim, .def, d3d12_capture.inl, d3d12_xs_device.cpp, test, CMake, one doc line).
  • python3 tests/docs_links_check.py: self-test passed, 18 Markdown files, 385 links OK.
  • python3 tests/bidi_controls_check.py: 1347 files, no bidirectional controls.
  • git diff --check origin/main...HEAD: clean.
  • gh pr checks 1277: Linux Python checks, gfx1013 fixtures and Windows build/test all pass. The /O2 and chart jobs are skipped.
  • Mergeable: yes. Title is neutral. The change is opt-in (X2W_D3D12_PERMISSIVE=1), so default behavior is unchanged.

What I checked in the code

  • serialize_for_runtime (src/d3d12_xs_shim.cpp): it retries only on E_INVALIDARG, only for root signature 1.0/1.1, and only when 0xC00 is set and the switch is on. A failed retry returns the first hr and its error blob. The Flags offset is the same in both versions, which the existing static_asserts cover.
  • RetriedBlob: the register/unregister order is safe. The destructor removes the record under the lock before releasing the inner blob, so a reused buffer cannot be matched to a stale record. The allocation-failure paths fall back to the inner blob with no record.
  • note_root_blob (d3d12_capture.inl): the DXBC part walk is bounds-checked (32+4*(i+1) <= bytes, at+8+24 <= bytes). It patches RTS0 flags in the translation copy only, never in the blob given to the runtime.
  • The /alternatename fallback keeps the non-shim build (offscreen_check) linking.

Not verified

  • The Windows 10 refusal itself cannot be reproduced on a Windows 11/2025 runtime, because it accepts 0xC00. So heap_indexing takes the documented skip (exit 77) there, and the retry branch is not exercised by CI. I did not run a Win2025 job for this reason, since it would only show the skip. No C++ mutation was run: the Linux worktree cannot build this code, and the Windows CI cannot kill a mutation in a branch it never reaches.

Nits

  • P3 nit, src/d3d12_xs_shim.cpp, x2w_stripped_root_flags: on a miss, with at least one live wrapper, it does a memcmp pass over every registered blob under the shared lock, just to print a log line once. Cheap for the number of root signatures here, but the scan could stop after the first log.
  • P3 nit, tests/d3d12_xs_shim_check.cpp: because the test is skipped on any runtime that accepts the flags, a note in docs/startup-runtime.md saying that the retry path is only tested on pre-SM6.6 runtimes would help future readers.

AI-assisted; commands listed were executed locally.

@lukaslw-lab

Copy link
Copy Markdown
Contributor

AI-assisted (Claude Code). Windows 10 reconfirmation of the current head c1afe2a3 (my earlier report was on 31719cc5).

Without #1277 With #1277 (c1afe2a3)
Host Windows 10 22H2 (19045), RTX 3080 Ti, release same
Base main at df1c042f same + #1277, nothing else
Run end null read at 13.1 s 196.1 s, at the #1758 throw in the post-confirm load
Pipelines (warm cache) – 18 translated, 0 missing, 0 translated draws not drawn
Heap-indexed roots deferred – 0

…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>
@rasptum

rasptum commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the second review. Both P3 notes are applied:

  • x2w_stripped_root_flags now skips the byte comparison once the copied-blob line has been logged, and stops at the first match before that. Commit 9398fce.
  • docs/startup-runtime.md now says the retry runs only on runtimes that refuse the flags (before shader model 6.6), and that d3d12_xs_shim_heap_indexing reports a capability skip (77) where the runtime accepts them. Reran ctest --preset <dev|release> -R '^(d3d12_xs_shim_.*|desktop_root_signature|startup_heap_indexed_root.*)$': 10/10 passed on both presets (Windows 10 19045, which refuses the flags, so heap_indexing ran rather than skipped).

AI-assisted (Claude Code).

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

Re-review of head 9398fce

Result: no P1, no P2. Both earlier P3 nits are addressed. Windows CI was still pending when I posted.

Commands run locally

  • git diff c1afe2a3 HEAD --stat: only docs/startup-runtime.md and src/d3d12_xs_shim.cpp changed since the last reviewed head (9 insertions, 5 deletions).
  • python3 tests/docs_links_check.py: self-test passed, 18 Markdown files, 385 links OK.
  • python3 tests/bidi_controls_check.py: 1347 files, no bidirectional controls.
  • git diff --check origin/main...HEAD: clean.
  • gh pr checks 1277: Linux Python checks and gfx1013 fixtures pass; "Build and test on Windows" is still pending; /O2 is skipped. Mergeable: yes. Title is neutral.

What changed and what I checked

  • x2w_stripped_root_flags (src/d3d12_xs_shim.cpp): the memcmp scan now runs only while the once-only line has not been logged, and it stops at the first match. logged moved above the lock and is read with InterlockedCompareExchange. It is set with InterlockedExchange(&logged, 1) == 0, so concurrent callers still print the line once. The returned bits are unchanged, so behavior is the same except for the cost of the scan.
  • docs/startup-runtime.md: the X2W_D3D12_PERMISSIVE row now says the retry runs only on runtimes that refuse the flags (before shader model 6.6), and that d3d12_xs_shim_heap_indexing reports 77 (capability skip) elsewhere. This closes my earlier docs nit.

Not verified

  • The Linux worktree cannot build this C++, so I ran no mutation. The changed branch only gates a log line, and the Windows runtime in CI accepts 0xC00, so no test reaches the retry path there. I did not queue a Win2025 job for the same reason.
  • Please let the pending Windows build finish green before this goes Ready.

Nits

  • None new.

AI-assisted; commands listed were executed locally.

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

The identical-byte provenance controls address the original review. I independently ran the Release shim and indexed-root suite on Windows 11: 9 pass and the actual retry test is a capability skip here. The contributor’s Windows 10 run covers the retry.

One remaining contract gap is the allocation failure in RetriedBlob::wrap. When the wrapper or its registry entry fails to allocate, the shim returns S_OK with the stripped bare blob. That silently loses both heap-indexing flags for translation, the same incorrect root layout this PR fixes. Please make that path return E_OUTOFMEMORY with no output blob and release the temporary serializer output. A test-only forced wrapper or registration failure should show no successful stripped result. While touching the retry, read and set Flags through the active descriptor member for version 1.0 versus 1.1. The offset assertions do not make the inactive union member active. The GTX 1060 retest in #870 can continue independently.

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

Re-reviewed 9deb045. The retry publishes a blob only after it can preserve its original flags. It now handles the active 1.0 or 1.1 member and releases the retry blob on wrapper or registry failure. In a controlled Windows Release serializer test, both versions took the retry, restored provenance on success, and returned E_OUTOFMEMORY with cleared outputs when wrapper allocation was forced to fail. The regular Release suite had 9 passes and one Win11 capability skip. The native Windows 10 retry was measured on the preceding head. The independent GTX 1060 retest in #870 remains open.

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

Re-review of head 9deb0453f0de9ce476a2f19ed835764d8281a166 (delta vs the previously reviewed 9398fce: src/d3d12_xs_shim.cpp only, +17/-12).

Delta read

  • serialize_for_runtime now retries into a local retry_blob, so the caller's *blob is only touched once the wrapper and its provenance record both exist. Correct: on new (nothrow) failure or registry push_back failure wrap returns null, the retry blob is released once, outputs are cleared and E_OUTOFMEMORY is returned. No double release (on registry failure inner_ is nulled before delete).
  • Flags are now read and rewritten through the active union member (Desc_1_0 / Desc_1_1). Matches the API for both versions.
  • Refused-retry path still returns the first hr with the first error blob intact.

Commands run locally

  • git diff --stat origin/main...HEAD: 7 files, +393/-7
  • python3 tests/docs_links_check.py: self-test passed, 18 files, 385 links
  • python3 tests/bidi_controls_check.py: 1347 files, no bidi controls
  • git diff --check origin/main...HEAD: clean
  • gh pr checks 1277: Linux Python checks pass, gfx1013 fixtures pass, Windows build+test pass (O2 job skipped)
  • python3 x2w_pipe.py win2025 1277 --scope direct --targets d3d12_xs_shim_check --regex d3d12_xs_shim --skip-release (default 3-slot pool): Debug build ok, ctest -R d3d12_xs_shim 5/6 passed, the sixth (d3d12_xs_shim_heap_indexing) is a capability skip on this host, not a pass. d3d12_xs_shim_serialize covers the 1.0 and 1.1 retry (tests/d3d12_xs_shim_check.cpp:144-150). Release not re-run here (PR text reports it).

Findings

  • P1: none.
  • P2: the new E_OUTOFMEMORY branch (src/d3d12_xs_shim.cpp:148-160, wrapper or registry allocation failure) has no test in the PR; rg -n "OUTOFMEM|nothrow|bad_alloc" tests/d3d12_xs_shim_check.cpp finds nothing. The PR text mentions a controlled forced-failure run, but it is not committed, so a regression there (leak, double release, uncleared output) would pass CI. Suggest a small seam (for example a test-only failure counter in wrap) or state explicitly that this branch is untested.
  • Nit: *blob = RetriedBlob::wrap(...) overwrites *blob without releasing it. Fine as long as the first serialize leaves it null on E_INVALIDARG; a one-line comment or a *blob = nullptr before the retry would make that explicit.
  • Mutation: the new logic is Windows-only (cannot be built on this Linux host), so I did not run a Linux mutation. Reasoned instead: reverting the 1.0 branch to Desc_1_1.Flags would be caught by the existing v1.0 case; removing the retry_blob->Release() on the OOM path would not be caught (see P2).

Title is neutral, MIT clean-room, mergeable, no draft. No Windows 10 native measurement was made by me; #870 retest remains open as noted by the author.

AI-assisted; commands listed were executed locally.

@R0Y00
R0Y00 merged commit a8a7b1d into R0Y00:main Nov 25, 2026
5 checks passed
@Jess-Doit

Copy link
Copy Markdown
Contributor

Independent Windows 10 / GTX 1060 retest, in-box D3D12Core 10.0.19041. The full report is at #870 (comment).

  • Control: d3d12_xs_shim_heap_indexing and the startup_heap_indexed_root set pass 4 of 4.
  • Startup with X2W_D3D12_PERMISSIVE=1: serializer calls 89 × S_OK and 0 × E_INVALIDARG. The builder results are 11,519 × S_OK. The run went to the 300 s timeout with no stop and 8,413 presents.
  • Without the retry: the same host previously gave 26,757 × E_INVALIDARG and a null-slot stop at about 40 s.

I tested this PR merged locally onto current main (ab9a020c), since the branch is 506 commits behind. It merged cleanly.

AI-assisted.

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-runtime: null read after the user privilege queries (about 75 s)

6 participants