d3d12_xs: keep the heap-directly-indexed flags on a host that refuses to serialize them #1353

Manually merged
github merged 1 commit from gh-pr/1353/head into gh-pr/1353/base 2026-11-26 09:48:28 +00:00
Owner

@⁠robot00f on GitHub · 2026-11-24 22:16 UTC · original
robot00f:fix/rootsig-heap-flags → main · +363 −21 · 7 files · 1 commits · merged 2026-11-25 02:35 UTC

Claim: #14 (ID D3D12-SET-HEAPS-BLOB; the deterministic d3d12_set_descriptor_heaps failure in #1150)

The test failed at CHECK(!blob.empty()). The empty blob is not the shim dropping anything: it never reaches the shim, and the test was not wrong either.

Cause

The in-box d3d12.dll of Windows 10 (10.0.19041.4355, this machine) refuses D3D12_ROOT_SIGNATURE_FLAG_CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED and ..._SAMPLER_HEAP_DIRECTLY_INDEXED in D3D12SerializeVersionedRootSignature at every descriptor version, with E_INVALIDARG and Unsupported bit-flag set (root signature flags c00). Versions 1.0 and 1.1 both fail; without the bits the same description serializes. That is wider than one test: the 1.0.2.1 shaders set either bit in 18,066 cases (docs/d3d12_vulkan.md), so any title root signature that indexes a heap directly could not be created at all on such a host.

Measured, so the fix is possible: the same host's deserializer, and a WARP device, accept a blob that carries 0xC00 -- a blob serialized without the bits, patched back in and re-hashed deserializes with Flags = 0xc00 and creates a root signature. Only the serializer is the problem.

Fix

serialize_versioned_keeping_heap_flags / serialize_legacy_keeping_heap_flags in runtime/shims/d3d12_xs_rootsig.cpp: call the host as before; if it fails and the description carries either bit, call again with the bits cleared, then put them back into the produced RTS0 flags dword and recompute the DXBC container hash (an all-zero hash stays zeroed). The blob is handed back through a small ID3DBlob. A host that takes the flags itself (Windows 11) still gets one call and its own blob unchanged; the version-1.2 downgrade path uses the same wrapper.

d3d12test::serialize_root_signature does the same retry for tests that serialize directly (zeroing the hash, which the host accepts and the device here does not read), so the failing case now builds a blob everywhere.

Tested

  • d3d12_set_descriptor_heaps: CHECK failed: !blob.empty() 3/3 before, passes 3/3 after.
  • d3d12_xs_root_signature_test, both versions through the real shim: the host refuses (0x80070057), the shim retries, the flags are back through the host deserializer, the shim deserializer and a WARP root signature. Passes 3/3.
  • root_sig_test: new legacy-entry-point case; the flags come back in the RTS0 chunk. All cases pass.
  • No regression: d3d12_bundle_test, d3d12_draw_test, device_proxy_test, xs_proxy_mock_test pass; ctest -R on the three touched tests 3/3.
  • check_no_game_data.py -> exit 0; tests/test_docs_links.py and tests/test_docs_table_rows.py -> OK.

Not tested: a host that natively accepts the flags (no Windows 11 here); the test asserts byte equality with the host blob in that branch. The 1.0.2.1 root signatures themselves were not run (no game files).

GPUs tested: NVIDIA GPU (Pascal class, 4 GB), driver 582.28, Windows 10 19045 (WARP for the root-signature checks).

AI-assisted: yes (OpenCode, DeepSeek V4.1 Flash)

Checklist

  • Based on current main and merges cleanly.
  • One topic.
  • No game data, keys or decryption (CONTRIBUTING.md).
  • A new translator rule is in the contract table of docs/design.md. (No translator change; the measured host behaviour is in docs/d3d12_vulkan.md.)
**@⁠robot00f** on GitHub · 2026-11-24 22:16 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1353) `robot00f:fix/rootsig-heap-flags` → `main` · +363 −21 · 7 files · 1 commits · merged 2026-11-25 02:35 UTC Claim: https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14 (ID `D3D12-SET-HEAPS-BLOB`; the deterministic `d3d12_set_descriptor_heaps` failure in #1150) The test failed at `CHECK(!blob.empty())`. The empty blob is not the shim dropping anything: it never reaches the shim, and the test was not wrong either. ### Cause The in-box `d3d12.dll` of Windows 10 (10.0.19041.4355, this machine) refuses `D3D12_ROOT_SIGNATURE_FLAG_CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED` and `..._SAMPLER_HEAP_DIRECTLY_INDEXED` in `D3D12SerializeVersionedRootSignature` at every descriptor version, with `E_INVALIDARG` and `Unsupported bit-flag set (root signature flags c00)`. Versions 1.0 and 1.1 both fail; without the bits the same description serializes. That is wider than one test: the 1.0.2.1 shaders set either bit in 18,066 cases (docs/d3d12_vulkan.md), so any title root signature that indexes a heap directly could not be created at all on such a host. Measured, so the fix is possible: the same host's *deserializer*, and a WARP device, accept a blob that carries `0xC00` -- a blob serialized without the bits, patched back in and re-hashed deserializes with `Flags = 0xc00` and creates a root signature. Only the serializer is the problem. ### Fix `serialize_versioned_keeping_heap_flags` / `serialize_legacy_keeping_heap_flags` in `runtime/shims/d3d12_xs_rootsig.cpp`: call the host as before; if it fails and the description carries either bit, call again with the bits cleared, then put them back into the produced `RTS0` flags dword and recompute the DXBC container hash (an all-zero hash stays zeroed). The blob is handed back through a small `ID3DBlob`. A host that takes the flags itself (Windows 11) still gets one call and its own blob unchanged; the version-1.2 downgrade path uses the same wrapper. `d3d12test::serialize_root_signature` does the same retry for tests that serialize directly (zeroing the hash, which the host accepts and the device here does not read), so the failing case now builds a blob everywhere. ### Tested - `d3d12_set_descriptor_heaps`: `CHECK failed: !blob.empty()` 3/3 before, passes 3/3 after. - `d3d12_xs_root_signature_test`, both versions through the real shim: the host refuses (0x80070057), the shim retries, the flags are back through the host deserializer, the shim deserializer and a WARP root signature. Passes 3/3. - `root_sig_test`: new legacy-entry-point case; the flags come back in the RTS0 chunk. All cases pass. - No regression: `d3d12_bundle_test`, `d3d12_draw_test`, `device_proxy_test`, `xs_proxy_mock_test` pass; `ctest -R` on the three touched tests 3/3. - `check_no_game_data.py` -> exit 0; `tests/test_docs_links.py` and `tests/test_docs_table_rows.py` -> OK. Not tested: a host that natively accepts the flags (no Windows 11 here); the test asserts byte equality with the host blob in that branch. The 1.0.2.1 root signatures themselves were not run (no game files). GPUs tested: NVIDIA GPU (Pascal class, 4 GB), driver 582.28, Windows 10 19045 (WARP for the root-signature checks). AI-assisted: yes (OpenCode, DeepSeek V4.1 Flash) ### Checklist - [x] Based on current main and merges cleanly. - [x] One topic. - [x] No game data, keys or decryption (CONTRIBUTING.md). - [ ] A new translator rule is in the contract table of docs/design.md. (No translator change; the measured host behaviour is in docs/d3d12_vulkan.md.)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:48:27 +00:00
github manually merged commit a330747f23 into gh-pr/1353/base 2026-11-26 09:48:28 +00:00
Author
Owner

@⁠Snooozs on GitHub · 2026-11-25 01:00 UTC · original

Retail confirmation on Windows 10, counts only. Windows 10 Pro 22H2 (19045), Ryzen 7 7700, 32 GB RAM, RTX 5060 Ti 16 GB (NVIDIA 621.01), VS 2022 RelWithDebInfo, own 1.0.2.1 copy. Base: #984 273b3bdf9 + #968 f2268abea + the CPU-alias change from the #968 comments; shaders translated with that tree; scripts/windows-boot/boot.ps1 defaults.

without this PR with this PR's runtime/shims change
ended by itself at 31 s, 0xc0000005 at exe+0xb5a5f8 (read of 0x68), two threads ran its full 301 s limit
PresentX ok / failed 62 / 0 16,654 / 0
captures non-black 2 of 2 40 of 40
states game=2 session=0 game=3 session=3 at 55 s, session=d at 95 s
device loss none none

One run each, same overlay and pipeline cache folder, so the second run also had the cache the first one left. The only code difference is this PR applied to d3d12_xs.cpp and d3d12_xs_rootsig.* (it applies cleanly to #984). So on Windows 10 that stop is the refused 0xC00 flags, as suspected in #14.

While reading it: RewrittenBlob counts references with a plain ULONG; std::atomic or InterlockedIncrement would match the thread-safety a host blob has. I have not seen it matter. I did not run the PR's own tests.

AI-assisted (Claude Code, Claude Opus 5.5).

**@⁠Snooozs** on GitHub · 2026-11-25 01:00 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1353#issuecomment-7149116487) Retail confirmation on Windows 10, counts only. Windows 10 Pro 22H2 (19045), Ryzen 7 7700, 32 GB RAM, RTX 5060 Ti 16 GB (NVIDIA 621.01), VS 2022 RelWithDebInfo, own 1.0.2.1 copy. Base: #984 `273b3bdf9` + #968 `f2268abea` + the CPU-alias change from the #968 comments; shaders translated with that tree; `scripts/windows-boot/boot.ps1` defaults. | | without this PR | with this PR's `runtime/shims` change | |---|---|---| | ended | by itself at 31 s, `0xc0000005` at `exe+0xb5a5f8` (read of `0x68`), two threads | ran its full 301 s limit | | `PresentX` ok / failed | 62 / 0 | 16,654 / 0 | | captures non-black | 2 of 2 | 40 of 40 | | states | game=2 session=0 | game=3 session=3 at 55 s, session=d at 95 s | | device loss | none | none | One run each, same overlay and pipeline cache folder, so the second run also had the cache the first one left. The only code difference is this PR applied to `d3d12_xs.cpp` and `d3d12_xs_rootsig.*` (it applies cleanly to #984). So on Windows 10 that stop is the refused `0xC00` flags, as suspected in #14. While reading it: `RewrittenBlob` counts references with a plain `ULONG`; `std::atomic` or `InterlockedIncrement` would match the thread-safety a host blob has. I have not seen it matter. I did not run the PR's own tests. AI-assisted (Claude Code, Claude Opus 5.5).
Author
Owner

@⁠QemmHD on GitHub · 2026-11-25 02:35 UTC · original · edited 2026-11-25 04:27 UTC

Merging.

Why merged: on Windows 10, the in-box d3d12.dll refuses root-signature flags 0xC00 (heap directly indexed) in its serializer, so the title is left with a null program and stops about 15 s in (a read of 0x68); testers on Windows 10 hit this every boot. This retries only after the host has refused, and only when 0xC00 is in the description. It covers both the versioned and the legacy D3D12SerializeRootSignature, patches the flags back into RTS0 after checking the container hash (failing closed), and it's claimed as D3D12-SET-HEAPS-BLOB. It's the better of the two PRs for this. #683 does the same for the versioned path only, by probing each bit through a static that captures the first serializer pointer.

Why it's good: on this Windows 11 host the real serializer accepts the flags, so I also checked the refusal path independently with a harness: a fake serializer that refuses 0xC00 and forwards everything else to the real Windows 11 serializer, on the RTX 4070 SUPER's hardware D3D12 device. #1353's wrappers (versioned 1.0 and 1.1, legacy 1.0) return S_OK after exactly one refusal; the flags read back as 0xc01 through the host deserializer; hardware CreateRootSignature succeeds; an unrelated failure is passed through; and a host that accepts the flags gets a byte-identical blob, 16/16. root_sig, root_signature, root_signature_oracle, d3d12_set_descriptor_heaps, d3d12_xs_root_signature, d3d12_draw, bundle, device_proxy and xs_proxy_mock* pass 14/14, both plain and with LEONIDA_VK_VALIDATION=1. The repository-consistency set gives 578/5/0. It merges cleanly onto main after #984 (neither #984 nor DadaCap's prototype carries this fix). Minor note: it returns S_FALSE ("flags lost") if a blob can't be patched, which is fine.

AI-assisted (Claude Code, Claude Opus 5.5).

**@⁠QemmHD** on GitHub · 2026-11-25 02:35 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1353#issuecomment-7150911701) · edited 2026-11-25 04:27 UTC Merging. **Why merged:** on Windows 10, the in-box `d3d12.dll` refuses root-signature flags `0xC00` (heap directly indexed) in its serializer, so the title is left with a null program and stops about 15 s in (a read of `0x68`); testers on Windows 10 hit this every boot. This retries only after the host has refused, and only when `0xC00` is in the description. It covers both the versioned and the legacy `D3D12SerializeRootSignature`, patches the flags back into `RTS0` after checking the container hash (failing closed), and it's claimed as D3D12-SET-HEAPS-BLOB. It's the better of the two PRs for this. #683 does the same for the versioned path only, by probing each bit through a static that captures the first serializer pointer. **Why it's good:** on this Windows 11 host the real serializer accepts the flags, so I also checked the refusal path independently with a harness: a fake serializer that refuses `0xC00` and forwards everything else to the real Windows 11 serializer, on the RTX 4070 SUPER's hardware D3D12 device. #1353's wrappers (versioned 1.0 and 1.1, legacy 1.0) return S_OK after exactly one refusal; the flags read back as `0xc01` through the host deserializer; hardware `CreateRootSignature` succeeds; an unrelated failure is passed through; and a host that accepts the flags gets a byte-identical blob, 16/16. root_sig, root_signature, root_signature_oracle, d3d12_set_descriptor_heaps, d3d12_xs_root_signature, d3d12_draw, bundle, device_proxy and xs_proxy_mock* pass 14/14, both plain and with `LEONIDA_VK_VALIDATION=1`. The repository-consistency set gives 578/5/0. It merges cleanly onto main after #984 (neither #984 nor DadaCap's prototype carries this fix). Minor note: it returns S_FALSE ("flags lost") if a blob can't be patched, which is fine. AI-assisted (Claude Code, Claude Opus 5.5).
This discussion has been locked. Commenting is limited to contributors.
No description provided.