d3d12_xs: only take the console slot-14 layout when the descriptor size agrees #4

Manually merged
github merged 1 commit from gh-pr/4/head into gh-pr/4/base 2026-11-26 08:39:45 +00:00
Owner

@⁠yyc160 on GitHub · 2026-11-24 01:16 UTC · original
yyc160:slot14-range-guard → main · +16 −3 · 1 files · 1 commits · merged 2026-11-24 01:26 UTC

Fixes the false positive in #3.

proxy_create_descriptor_heap treated a readable, non-zero word after the PC description as a console address. A normal 16-byte D3D12_DESCRIPTOR_HEAP_DESC is almost always followed by readable, non-zero memory, so every ordinary heap created through the proxy entered the console path and reported that word as its CPU handle; the first Create*View then wrote through it.

The console layout carries a size as well as an address, and that size is 32 bytes per descriptor. A PC desc's trailing words are whatever the caller holds next and do not encode NumDescriptors * 32, so requiring the agreement separates the two layouts without guessing anything about the address.

I also tried requiring the range to be a committed, writable VirtualQuery region. That is a true property of the console layout, but it rejects d3d12_console_descriptor_heap_test's synthetic address, and a console heap whose VA is not backed by title memory would fail it too, so I left it out. Size alone is enough for the corpus here.

Measurements

Windows 11, MSVC 14.44.35207, Windows SDK 10.0.26100.0, Ninja, RTX 5070 Ti with driver 32.0.16.1742. Base is main@2e4715746; the only difference between the two rows is this commit.

tree ctest failed
main@2e4715746 278/300 22
main@2e4715746 + this commit 296/300 4

d3d12_descriptor goes from exit 139 to exit 0. The 18 tests that stop failing are the ones that create a heap through the proxy and then write through the handle:

d3d12_vulkan_device  d3d12_f16_halves   d3d12_m2_formats   d3d12_msaa_draw
d3d12_depth24_draw   d3d12_subgroup     d3d12_translated_draw
d3d12_m2_textured    d3d12_m3_frame     d3d12_m3_first_pass
d3d12_m4_compute     d3d12_buffer_uav   d3d12_compute      d3d12_draw
d3d12_set0_compute   d3d12_bindless_churn  d3d12_bindless_churn_validated
d3d12_present

The four that still fail fail identically with and without this change, and are unrelated to descriptor heaps:

  • root_sig: FAIL blob helper rewrites an all-zero-checksum Xbox blob and keeps its zero checksum, FAIL shim deserializer accepts an all-zero-checksum Xbox blob with the high byte cleared
  • d3d12_com, d3d12_vulkan_device: ExecuteCommandLists failed: a list is not closed; nothing was submitted and invalid copy or resolve; nothing was submitted
  • d3d12_depth_resolve

Nothing here quotes the executable: test names, a file:line and pass/fail only.

**@⁠yyc160** on GitHub · 2026-11-24 01:16 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/4) `yyc160:slot14-range-guard` → `main` · +16 −3 · 1 files · 1 commits · merged 2026-11-24 01:26 UTC Fixes the false positive in #3. `proxy_create_descriptor_heap` treated a readable, non-zero word after the PC description as a console address. A normal 16-byte `D3D12_DESCRIPTOR_HEAP_DESC` is almost always followed by readable, non-zero memory, so every ordinary heap created through the proxy entered the console path and reported that word as its CPU handle; the first `Create*View` then wrote through it. The console layout carries a size as well as an address, and that size is 32 bytes per descriptor. A PC desc's trailing words are whatever the caller holds next and do not encode `NumDescriptors * 32`, so requiring the agreement separates the two layouts without guessing anything about the address. I also tried requiring the range to be a committed, writable `VirtualQuery` region. That is a true property of the console layout, but it rejects `d3d12_console_descriptor_heap_test`'s synthetic address, and a console heap whose VA is not backed by title memory would fail it too, so I left it out. Size alone is enough for the corpus here. ## Measurements Windows 11, MSVC 14.44.35207, Windows SDK 10.0.26100.0, Ninja, RTX 5070 Ti with driver 32.0.16.1742. Base is `main@2e4715746`; the only difference between the two rows is this commit. | tree | ctest | failed | |---|---|---| | `main@2e4715746` | 278/300 | 22 | | `main@2e4715746` + this commit | 296/300 | 4 | `d3d12_descriptor` goes from exit 139 to exit 0. The 18 tests that stop failing are the ones that create a heap through the proxy and then write through the handle: ``` d3d12_vulkan_device d3d12_f16_halves d3d12_m2_formats d3d12_msaa_draw d3d12_depth24_draw d3d12_subgroup d3d12_translated_draw d3d12_m2_textured d3d12_m3_frame d3d12_m3_first_pass d3d12_m4_compute d3d12_buffer_uav d3d12_compute d3d12_draw d3d12_set0_compute d3d12_bindless_churn d3d12_bindless_churn_validated d3d12_present ``` The four that still fail fail identically with and without this change, and are unrelated to descriptor heaps: - `root_sig`: `FAIL blob helper rewrites an all-zero-checksum Xbox blob and keeps its zero checksum`, `FAIL shim deserializer accepts an all-zero-checksum Xbox blob with the high byte cleared` - `d3d12_com`, `d3d12_vulkan_device`: `ExecuteCommandLists failed: a list is not closed; nothing was submitted` and `invalid copy or resolve; nothing was submitted` - `d3d12_depth_resolve` Nothing here quotes the executable: test names, a file:line and pass/fail only.
proxy_create_descriptor_heap treated a readable, non-zero word after the PC
description as a console address. A normal 16-byte D3D12_DESCRIPTOR_HEAP_DESC
is almost always followed by readable, non-zero memory, so every ordinary heap
from a proxy device entered the console path and reported garbage as its CPU
handle; the first Create*View then wrote through it.

The console layout also carries a size, and that size is 32 bytes per
descriptor. Requiring it makes the two layouts distinguishable without guessing
at the address: a PC desc's trailing word is whatever the caller happens to
hold next, and it does not encode NumDescriptors * 32.

Measured on Windows 11, MSVC 14.44.35207, RTX 5070 Ti: ctest 278/300 -> 296/300,
22 failed -> 4 failed. d3d12_descriptor exits 139 before and 0 after; the four
remaining failures (root_sig, d3d12_com, d3d12_vulkan_device, d3d12_depth_resolve)
are unrelated shim behaviour and fail either way.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 08:39:43 +00:00
github manually merged commit 37246f11d1 into gh-pr/4/base 2026-11-26 08:39:45 +00:00
Author
Owner

@⁠wavehs on GitHub · 2026-11-24 01:27 UTC · original

macOS arm64 review (Apple M3 Pro) — the fix is right and it was merged as I was checking it; two things to pin now that the equality decides the dispatch

Read at head 37246f11d, which is what ubi/main 30daa6958 contains (the merged file is byte-identical to the PR head: git diff 37246f11d ubi/main -- runtime/shims/d3d12_xs_device.cpp is empty). Host: macOS 27.2.1, Apple M3 Pro (arm64), CPython 3.15.2.

Check Result
git diff 2e4715746 37246f11d (branch point → head) 1 file, +16/−3 — runtime/shims/d3d12_xs_device.cpp; the README hunk in the PR diff is the branch being behind main, not part of the change
git merge-tree --write-tree 30daa6958 37246f11d clean
python3 -I scripts/run_semantic_tests.py tests/semantic at the head 459 files, 6,046 tests, 2 failed (test_exec_computed, test_image_atomics_guard) — identical to unmodified main, as expected: tools/ and tests/semantic/ are byte-identical between ubi/main and this head
GPU fixtures on MoltenVK/KosmicKrisp none run and none applicable: d3d12_xs_device.cpp is a WIN32-only shim, the Vulkan backend is untouched by the change, and the file does not compile on this host at all

So the only thing I can contribute is the arithmetic and what the new predicate now depends on.

The bug is real and the fix is right. address != 0 was not evidence: the two words after a 16-byte D3D12_DESCRIPTOR_HEAP_DESC are whatever the caller holds next, and reading them as a console VA is exactly the kind of check that passes for the wrong reason. Requiring size == NumDescriptors * 32 is a much better discriminator, and the helper is sound at its boundaries: address == 0, size == 0, NumDescriptors == 0, and NumDescriptors > 0xFFFFFFFF/32 all reject, so the multiplication cannot wrap. One behaviour change worth knowing: a NumDescriptors == 0 heap with a console address now goes to the PC call, which returns E_INVALIDARG for a zero-descriptor heap anyway — same outcome, different route.

1. The equality is now load-bearing, and the number it encodes is listed as unmeasured in this repository. docs/d3d12_vulkan.md says, twice, that the console's heap increments are open:

  • :3916 — "Are Xbox descriptor bytes GFX10 T#/S#, and what are the heap increments? … the increment values still need measuring."
  • :3858-3859 — "descriptor bytes and heap increments are still Open. Slot 15 is forwarded unchanged, but the actual increment values were not measured."

kConsoleDescriptorSize = 32 is the PC increment (runtime/shims/d3d12_com.h:418), and the predicate now requires the console's own size word to agree with it exactly. If a retail descriptor heap reports a page-rounded size, or an increment other than 32, the console path silently stops being taken and the boot's GetCPUDescriptorHandleForHeapStart() == address check fails with the same symptom as the false positive — one layer further from the cause. Nothing else in the tree contradicts that today, but nothing confirms it either: console_size_ is parsed, stored and never read (runtime/shims/d3d12_vulkan_device.cpp:1710, 1773), so the only witness to the equality is runtime/test/d3d12_console_descriptor_heap_test.cpp:35-36, which was written to the same assumption (size = 8ull * 32ull).

The cheap closure is one log_once at the decision point, in the style already used for slot 62's extra words and for the console heap itself:

[rt] d3d12_xs slot 14: address 0x… size 0x… (32*NumDescriptors 0x…)

and, separately, one log_once on the rejection path when address != 0 but the size disagrees. A single retail boot would then turn open question 4 from "Open" into measured for the heap sizes, and a false negative would show up as a line in the trace instead of as a wrong CPU handle in a Create*View.

2. Two 32s that must agree live in two files. kConsoleDescriptorSize here vs rt::d3d12::descriptor_size (d3d12_com.h:418, used as kDescriptorSize at d3d12_vulkan_device.cpp:60-65 for the heap's own stride). If the descriptor stride ever changes for one heap type, the predicate and the heap disagree with no compiler complaint. Using the existing constant, or a comment naming it, removes that.

3. The accept branch has no test. d3d12_console_descriptor_heap_test calls create_console_descriptor_heap directly, so it never passes through proxy_create_descriptor_heap; the new predicate's true branch is pinned by nothing. set_console_descriptor_heap_handler (d3d12_xs_device.h:118) exists for exactly this: install a fake handler, pass a 32-byte desc with size = 8*32, and assert the handler received the address — otherwise a future tightening can disable the console path with every test still green, which is the mirror image of the bug you just fixed.

The remaining false positive needs both trailing words to hold N*32, which is a drastically weaker coincidence than one non-zero word; a caller that keeps a computed N*32 byte count next to the desc is the shape to imagine, and it would have to land in both slots. Your comment says "size alone is enough for the corpus here", which is an honest way to state it.

The Windows numbers (278 → 296 of 300) are yours on MSVC/RTX 5070 Ti; I could not reproduce them and did not try.

No game files. AI-assisted.

**@⁠wavehs** on GitHub · 2026-11-24 01:27 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/4#issuecomment-7119120485) **macOS arm64 review (Apple M3 Pro) — the fix is right and it was merged as I was checking it; two things to pin now that the equality decides the dispatch** Read at head `37246f11d`, which is what `ubi/main` `30daa6958` contains (the merged file is byte-identical to the PR head: `git diff 37246f11d ubi/main -- runtime/shims/d3d12_xs_device.cpp` is empty). Host: macOS 27.2.1, Apple M3 Pro (arm64), CPython 3.15.2. | Check | Result | |---|---| | `git diff 2e4715746 37246f11d` (branch point → head) | **1 file, +16/−3** — `runtime/shims/d3d12_xs_device.cpp`; the README hunk in the PR diff is the branch being behind `main`, not part of the change | | `git merge-tree --write-tree 30daa6958 37246f11d` | clean | | `python3 -I scripts/run_semantic_tests.py tests/semantic` at the head | **459 files, 6,046 tests, 2 failed** (`test_exec_computed`, `test_image_atomics_guard`) — identical to unmodified `main`, as expected: `tools/` and `tests/semantic/` are byte-identical between `ubi/main` and this head | | GPU fixtures on MoltenVK/KosmicKrisp | **none run and none applicable**: `d3d12_xs_device.cpp` is a `WIN32`-only shim, the Vulkan backend is untouched by the change, and the file does not compile on this host at all | So the only thing I can contribute is the arithmetic and what the new predicate now depends on. **The bug is real and the fix is right.** `address != 0` was not evidence: the two words after a 16-byte `D3D12_DESCRIPTOR_HEAP_DESC` are whatever the caller holds next, and reading them as a console VA is exactly the kind of check that passes for the wrong reason. Requiring `size == NumDescriptors * 32` is a much better discriminator, and the helper is sound at its boundaries: `address == 0`, `size == 0`, `NumDescriptors == 0`, and `NumDescriptors > 0xFFFFFFFF/32` all reject, so the multiplication cannot wrap. One behaviour change worth knowing: a `NumDescriptors == 0` heap with a console address now goes to the PC call, which returns `E_INVALIDARG` for a zero-descriptor heap anyway — same outcome, different route. **1. The equality is now load-bearing, and the number it encodes is listed as unmeasured in this repository.** `docs/d3d12_vulkan.md` says, twice, that the *console's* heap increments are open: - `:3916` — "Are Xbox descriptor bytes GFX10 T#/S#, and what are the heap increments? … the increment values still need measuring." - `:3858-3859` — "descriptor bytes and heap increments are still **Open**. Slot 15 is forwarded unchanged, but the actual increment values were not measured." `kConsoleDescriptorSize = 32` is the PC increment (`runtime/shims/d3d12_com.h:418`), and the predicate now requires the console's own size word to agree with it exactly. If a retail descriptor heap reports a page-rounded size, or an increment other than 32, the console path silently stops being taken and the boot's `GetCPUDescriptorHandleForHeapStart() == address` check fails with the same symptom as the false positive — one layer further from the cause. Nothing else in the tree contradicts that today, but nothing confirms it either: `console_size_` is parsed, stored and **never read** (`runtime/shims/d3d12_vulkan_device.cpp:1710, 1773`), so the only witness to the equality is `runtime/test/d3d12_console_descriptor_heap_test.cpp:35-36`, which was written to the same assumption (`size = 8ull * 32ull`). The cheap closure is one `log_once` at the decision point, in the style already used for slot 62's extra words and for the console heap itself: ``` [rt] d3d12_xs slot 14: address 0x… size 0x… (32*NumDescriptors 0x…) ``` and, separately, one `log_once` on the rejection path when `address != 0` but the size disagrees. A single retail boot would then turn open question 4 from "Open" into measured for the heap sizes, and a false negative would show up as a line in the trace instead of as a wrong CPU handle in a `Create*View`. **2. Two 32s that must agree live in two files.** `kConsoleDescriptorSize` here vs `rt::d3d12::descriptor_size` (`d3d12_com.h:418`, used as `kDescriptorSize` at `d3d12_vulkan_device.cpp:60-65` for the heap's own stride). If the descriptor stride ever changes for one heap type, the predicate and the heap disagree with no compiler complaint. Using the existing constant, or a comment naming it, removes that. **3. The accept branch has no test.** `d3d12_console_descriptor_heap_test` calls `create_console_descriptor_heap` directly, so it never passes through `proxy_create_descriptor_heap`; the new predicate's true branch is pinned by nothing. `set_console_descriptor_heap_handler` (`d3d12_xs_device.h:118`) exists for exactly this: install a fake handler, pass a 32-byte desc with `size = 8*32`, and assert the handler received the address — otherwise a future tightening can disable the console path with every test still green, which is the mirror image of the bug you just fixed. The remaining false positive needs *both* trailing words to hold `N*32`, which is a drastically weaker coincidence than one non-zero word; a caller that keeps a computed `N*32` byte count next to the desc is the shape to imagine, and it would have to land in both slots. Your comment says "size alone is enough for the corpus here", which is an honest way to state it. The Windows numbers (278 → 296 of 300) are yours on MSVC/RTX 5070 Ti; I could not reproduce them and did not try. No game files. AI-assisted.
This discussion has been locked. Commenting is limited to contributors.
No description provided.