Skip to content

d3d12_xs: pin that the root-signature flag mask keeps every public flag (#7140) - #7234

Closed
aslan2142 wants to merge 2 commits into
ProjectLeonida:mainfrom
aslan2142:root-sig-flag-mask
Closed

aslan2142 wants to merge 2 commits into
ProjectLeonida:mainfrom
aslan2142:root-sig-flag-mask

Conversation

@aslan2142

@aslan2142 aslan2142 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue: #7049 (comment). Answers #7140.

What #7140 asks

  • The retail executable's root signatures carry no 0x03000000: one direct 1.1 description with Flags = 0x80, and a decoder whose Flags is a 16-bit read.
  • It proposes making the mask depend on where the blob came from, since applied to those descriptors it "clears a public flag".

What the mask really does

  • runtime/shims/d3d12_xs_rootsig.h:14: kXboxRootSignatureFlagHighByte = 0xFF000000u, so it clears bits 24-31.
  • runtime/shims/d3d12_xs_rootsig.cpp:9 (clear_high_byte) applies it in the three helpers that the d3d12_xs shims use: versioned descriptors, the legacy descriptor and an RTS0 blob.
  • Every public D3D12_ROOT_SIGNATURE_FLAGS value is in bits 0-11. The highest is SAMPLER_HEAP_DIRECTLY_INDEXED (0x800).
  • So the mask can't remove a public flag, and 0x80 (LOCAL_ROOT_SIGNATURE in d3d12.h) passes through unchanged.
  • Nothing else rewrites the executable's flags:
    • the 1.2 → 1.1 rewrite copies Flags as it is, and only runs for 1.2;
    • an unknown version is forwarded unchanged;
    • the Vulkan device's CreateRootSignature (parse_rts0) keeps the flags and masks nothing.

tedin7 reached the same conclusion on #7140. No behaviour change is needed, so this PR pins the current behaviour with a test, so that a later change to the mask can't start clearing public flags unnoticed.

Changes

  • New runtime/test/root_sig_public_flags_test.cpp, registered in CMake as root_sig_public_flags (built when d3d12.lib is found, like root_sig_test).
    • The helpers keep all 65536 flag values in [0, 0xFFFF], for 1.0, 1.1, 1.2 and the legacy descriptor, and they never rewrite an RTS0 blob that carries such a value.
    • For each public flag, 0x80 alone and all twelve together, the registered serializer shims return the host's blob byte for byte (1.0, 1.1 and the legacy entry point). A 1.2 blob from the shim deserializes with the same flags.
    • The registered deserializer shim returns the same flags the host returns.
    • A blob with 0x03000080 comes back as 0x80, with a valid container hash and every other byte unchanged.
    • Two static_asserts: the public flags are exactly 0xFFF, and none of them is in kXboxRootSignatureFlagHighByte.
  • docs/d3d12_vulkan.md: the open question "does the executable carry the bits" is answered from Q19: the retail executable's own root signatures carry no 0x03000000 flag — mask should be conditional #7140, with a note that the mask stays unconditional and why.

Tested

  • No GPU needed (CPU side and the host's D3D12 serializer only).
  • Local cross-build: clang 23 for x86_64-w64-mingw32 against DirectX-Headers 1.721, run under Wine 11.22 (vkd3d's d3d12.dll). This is not the MSVC build that CI runs.
  • root_sig_public_flags_test: 28 PASS, 0 FAIL. Wine's serializer stops at 1.1, so the 1.2 cases go through the shim's 1.1 rewrite.
  • Mutation checks in a scratch copy:
    • a mask of 0xFF000080 fails to compile on the static_assert;
    • clearing 0x80 in clear_high_byte gives 17 failures.
  • root_sig_test (unchanged): 50 PASS, 0 FAIL.
  • Linux CMake configure is fine.
  • tests/test_docs_*.py: 9 of 11 pass. test_docs_cli_flags and test_docs_links fail on docs/dev-tools.md, which this PR doesn't touch.

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

…ag (ProjectLeonida#7140)

The shims clear bits 24-31 of a root signature's flags on every descriptor and RTS0 blob. ProjectLeonida#7140 asks to make that
conditional on the blob's origin, since the retail executable's root signatures carry no 0x03000000 (one 1.1
description with Flags 0x80, and a decoder whose Flags is a 16-bit read). Every public D3D12_ROOT_SIGNATURE_FLAGS
value is in bits 0-11, so the mask can't change those descriptors and no behaviour change is needed.

root_sig_public_flags_test pins it:
- the descriptor helpers (1.0, 1.1, 1.2, legacy) keep all 65536 flag values in [0, 0xFFFF], and an RTS0 blob with
  such flags is not rewritten;
- the registered serializer shims give the host's blob byte for byte for each public flag, 0x80 and all twelve, and
  the deserializer shim returns the host's flags;
- a blob with 0x03000080 comes back as 0x80 with a valid container hash and no other byte changed;
- static_asserts that no public flag is in kXboxRootSignatureFlagHighByte.

docs/d3d12_vulkan.md: the executable's answer to the open question, and why the mask stays unconditional.

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

Copy link
Copy Markdown
Contributor

Review: #7234, d3d12_xs: pin that the root-signature flag mask keeps every public flag (#7140)

Verdict: approve. This PR changes no behaviour. It adds a test and a short doc note. The reasoning holds: the mask cannot reach any public flag, so making it conditional (what #7140 asked for) would change nothing. A few nits follow, and none of them blocks the merge.

What changed

  1. docs/d3d12_vulkan.md closes the open question "do the game executable's root signatures carry 0x03000000?". They don't. The executable's direct call passes a 1.1 description with Flags = 0x80 (LOCAL_ROOT_SIGNATURE), and its decoder reads Flags as a zero-extended 16-bit value. The doc also explains why the mask stays unconditional.
  2. runtime/test/root_sig_public_flags_test.cpp is a new test with no game data. Every descriptor and blob in it is built by hand or by the host d3d12.dll.
  3. runtime/CMakeLists.txt adds the target and its add_test. It uses the same sources, link line and guard (WIN32 AND LEONIDA_BUILD_WINDOWS_RUNTIME, D3D12_LIBRARY) as root_sig_test, so it builds wherever root_sig_test builds.

Why the change is sound

I checked the code under test (runtime/shims/d3d12_xs_rootsig.cpp, runtime/shims/d3d12_xs.cpp):

  • clear_high_byte is flags & ~0xFF000000, and kXboxRootSignatureFlagHighByte in d3d12_xs_rootsig.h is that same constant. So for any flags below 0x01000000 the mask does nothing. The two static_asserts make this a compile-time fact: the twelve listed flags OR to 0xFFF, and none of them overlaps the high byte. The 65 536-value loops then confirm the copy itself, i.e. no other descriptor field changes and the version is kept. They cost little.
  • copy_rts0_blob_clear_xbox_flags returns false when cleared == flags. That is why the "never rewritten" loop holds without re-hashing the blob: the helper never checks the input hash. The loop also can't pass by default, because check(at != 0, …) first confirms the host blob has an RTS0 part.
  • The flags offset. The test reads flags at off + 8 + 20. That is the chunk header (FourCC + size) followed by the fixed RTS0 header: Version, NumParameters, ParamOffset, NumStaticSamplers, StaticSamplerOffset, then Flags. It matches the helper.
  • The serializer comparison handles the 1.2 fallback correctly. If the host refuses 1.2, the shim may still succeed through downgrade_root_signature_1_2_to_1_1, so the byte comparison is skipped for that case. The round-trip through GetUnconvertedRootSignatureDesc still checks the flags, and flags_of reads the 1.1 arm correctly. For 1.0 and 1.1, the shim has to refuse exactly what the host refuses. Some flags may be invalid under 1.0 on some runtimes, for example the *_HEAP_DIRECTLY_INDEXED ones, and that rule covers them.
  • The 0x03000080 case. The test checks four things: only bits 24-25 change, every byte outside the flags dword and the hash range (bytes 4-19) is unchanged, the rewritten container hash is valid, and the deserializer shim returns 0x80. The 0xFCFF0080 → 0x00FF0080 case pins that the whole top byte is cleared, not only 0x03000000. That matches what the header documents.
  • Ownership. COM objects are released through Blobs and explicit Release() calls, and nothing leaks on the failure paths.

Nits (non-blocking)

  1. Where the claim about the executable comes from. The doc sentence about the retail executable's call site and its 16-bit decoder cites only Q19: the retail executable's own root signatures carry no 0x03000000 flag — mask should be conditional #7140. Per the "quote file and offset" rule, please add the RVA of the call site and of the decoder's Flags load (to the doc or to Q19: the retail executable's own root signatures carry no 0x03000000 flag — mask should be conditional #7140). Then the next reader can recheck it against their own copy.
  2. The test asserts more about the call site than the doc says. The test says "1.1, no parameters, no samplers, Flags 0x80", while the doc only says "a 1.1 description with Flags = 0x80". If the real call has parameters, either reword the test comment or add that detail to the doc.
  3. "Every public flag" means every flag in kPublicFlags. The list is pinned to SDK 10.0.26100 / DirectX-Headers 1.721. A future SDK flag such as 0x1000 would not be caught automatically. That's fine, because it would still be far below bit 24. Consider saying in the comment that the list has to be extended by hand when the headers grow.
  4. The new target repeats root_sig_test's setup. It repeats the same four sources and the same option block. Merging the cases into root_sig_test, or using a small CMake helper, would save one build and one link. This is a matter of taste.
  5. Observation, pre-existing and out of scope. d3d12_xs.cpp registers D3D12CreateRootSignatureDeserializer, but not D3D12CreateVersionedRootSignatureDeserializer. The test only calls the host's versioned deserializer on blobs the shim produced, so it is unaffected. Still, if any package DLL imports the versioned entry point, a blob carrying 0x03000000 would reach the host without the mask. If that import exists, it's worth a finding: in the coordination issue.

Test results (Windows 11, CPython 3.13)

The harness ran these, and all passed:

  • git diff --check
  • python -m compileall -q make_game.py tools tests
  • python -I scripts/check_no_game_data.py on the changed files
  • python -I make_game.py --help

No targeted tests were run. The harness found no matching test file, and I did not build runtime/ or run ctest here. So this review does not confirm that root_sig_public_flags_test passes. Please paste the ctest -R root_sig_public_flags output from the author's machine or from CI, with the Windows build (10 22H2, 11 23H2 or 24H2) and whether the Agility SDK is present. That decides which 1.2 branch runs. The test only uses the serializer and deserializer and creates no device, so the GPU doesn't matter.

Adherence

  • No game data. The test inputs are hand-built descriptors and blobs from the host serializer. No carved files, shader bytes or game dumps are added. The doc reports the executable's behaviour as prose (a flag value and a read width) and quotes no code or bytes from it.
  • No keys, decryption or protection workarounds. This is ordinary DXBC container hashing (MD5 variant), which already exists in the tree.
  • Nothing online.
  • Fix, don't disable. Nothing is skipped or gated. The mask stays on every path, and the PR adds proof that this is safe instead of narrowing it.

AI-assisted.

@pulria

pulria commented Nov 23, 2026

Copy link
Copy Markdown

Tested dc91f75b6 on Windows 11 Pro 10.0.26300 (in-box d3d12.dll, no Agility SDK), MSVC 19.44 (VS 2022 Build Tools, 14.44.35207), Windows SDK 10.0.26100, x64 RelWithDebInfo, no GPU used: pass

  • The head trial-merged onto main 1924c8f91 with no conflicts. No commit on main since the PR's base fd335571a touches the sources the new target links: registry.cpp, d3d12_xs.cpp, d3d12_xs_device.cpp, d3d12_xs_rootsig.*.
  • Fresh configure and full build of the merged tree (CPU configuration, no Vulkan headers): no errors, and no warnings from root_sig_public_flags_test.cpp at /W4 /permissive-. The build's six other warnings are in other test files and also appear on main.
  • ctest: 112/112 passed, including root_sig_public_flags (0.16 s), root_sig, root_signature and root_signature_oracle.
  • Run directly: 29 PASS, 0 failures. This host's serializer handles 1.2 itself. For each of 1.0, 1.1 and 1.2 the run reports 13 byte-identical, 1 refused by the host too, 0 different.

Mutation check. I changed clear_high_byte in runtime/shims/d3d12_xs_rootsig.cpp to also clear 0x80 (~(kXboxRootSignatureFlagHighByte | 0x80u)) and rebuilt only the test. It failed 18 checks: the four helper sweeps (32768 changed each), the blob sweep, the serializer and deserializer comparisons, the executable's 1.1 + 0x80 call, and both blob-rewrite checks. So the test catches a mask that reaches a public flag. I restored the file afterwards.

One non-blocking nit from that run. Under the mutation, versioned 1.2 reports 1 different, while 1.0 and 1.1 report 2 different. In test_serializer_shim_matches_host, a case where the host refuses and the shim succeeds isn't counted for 1.2. That allowance is right for runtimes that serialize only up to 1.1, but on a host that serializes 1.2 itself it hides the all-flags case: the host refuses 0xFFF, and the shim accepts 0xF7F. The other checks still fail, so nothing slips through here. If you want, the allowance could apply only when the host refused the empty 1.2 descriptor as well, i.e. when the runtime has no 1.2.

The review's reasoning matches what I read: every public flag is in bits 0-11, the mask clears 24-31, and the 1.2 → 1.1 rewrite copies Flags unchanged.

AI-assisted (Claude Code).

…nly on a host without 1.2

The allowance is for runtimes that serialize only up to 1.1, where the shim rewrites 1.2 as 1.1. On a host that
serializes 1.2 itself it hid a real difference: under a mask that also clears 0x80, the host refuses all twelve
flags and the shim accepts 0xF7F. The host is now probed once with an empty 1.2 description, and the allowance
applies only when it refuses that too (review of ProjectLeonida#7234).

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

Copy link
Copy Markdown
Contributor Author

Thanks @pulria for the native Windows run and the mutation check. You're right about the 1.2 allowance. It's fixed in 715bde0:

  • test_serializer_shim_matches_host now asks the host once whether it serializes an empty 1.2 description. It prints the answer: host serializer takes/refuses root signature 1.2.
  • "Host refuses, shim succeeds" for 1.2 is accepted only when the host refuses that empty 1.2 description too. Otherwise 1.2 is held to the same rule as 1.0 and 1.1: the shim must refuse what the host refuses.

What this changes:

  • Under Wine's vkd3d (no 1.2), the allowance still applies. The run is unchanged: root_sig_public_flags_test passes all 28 checks, root_sig_test passes 50, and the mutation that also clears 0x80 still fails 17.
  • On a host that serializes 1.2 itself, the all-flags case under that mutation now counts as different, so 1.2 should report 2 different like 1.0 and 1.1. I couldn't run that here; a native rerun would confirm it.
  • One correction to the PR text: the new test has 28 checks, not 30. I miscounted the PASS lines.

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

@myokex

myokex commented Nov 23, 2026

Copy link
Copy Markdown

Tested dc91f75b6 merged onto main 042c5f378 on Windows 11, Visual Studio 2022 (MSVC, RelWithDebInfo), CMake 4.4.4, Vulkan SDK 1.4.363.0, AMD Radeon RX 7800 XT (driver 32.0.32029.2010); synthetic tests only, no game files, against the host d3d12.dll: pass.

AI-assisted (Claude Code).

@Jadiac5

Jadiac5 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 715bde0 on Windows 11, AMD Radeon RX 9070 XT (RDNA4), driver 32.0.32029.2010: pass

  • Built root_sig_public_flags_test and root_sig_test (MSVC, Ninja, RelWithDebInfo). Both exit 0. The new test prints 28 PASS lines and "OK (0 failures)". The earlier Windows runs were on the head before this one.
  • On this host the new probe prints "host serializer takes root signature 1.2". The 1.2 serializer case: 13 flag sets byte-identical to the host, 1 refused by the host too, 0 different. So the "host refuses, shim succeeds" branch is not taken here.
  • Negative control: I changed clear_high_byte in runtime/shims/d3d12_xs_rootsig.cpp (line 9) so that it also clears flag bit 0x80, which is public. The new test then fails: 18 FAIL lines, for example "all 65536 flag values in [0, 0xFFFF] come out unchanged (32768 changed)" for the 1.0, 1.1 and 1.2 helpers. Restored afterwards.
  • The test only uses the serializer and the deserializer. No GPU work is involved.
  • Not done: a host that serializes only up to 1.1 (the other branch of the new probe). Not run against the retail executable.

AI-assisted (Claude Code).

@karearl

karearl commented Nov 23, 2026

Copy link
Copy Markdown

Baseline on main here: d3d12_vulkan_device, d3d12_present and xbox_present fail on this machine without the PR too; no Vulkan SDK installed, so the glslang/llvm-mc shader tests were not built.

AI-assisted (Claude Code).

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.

7 participants