d3d12: require a console heap address to be 64 KiB aligned before slot 14 reads it #1328

Closed
robot00f wants to merge 1 commit from upstream-pr/1328 into main
robot00f commented 2026-11-24 21:56:50 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by robot00f on 2026-11-24T21:56:50Z.


Claim: https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7145591230 (ID D3D12-CONSOLE-HEAP-ALIGN; fixes the d3d12_subgroup SegFault in #1150)

d3d12_subgroup crashed deterministically (3/3) in Device::CreateRenderTargetView, writing the 16-byte view to a handle whose value was the ASCII text ps_probe -- the bytes of a shader name.

Cause

Device slot 14 reads a console descriptor heap as a PC D3D12_DESCRIPTOR_HEAP_DESC with an address at +0x10 and a size at +0x18, and keeps console_heap_range_plausible() to tell that layout from a PC desc whose trailing words are whatever the caller's next local holds. That guard checked only that the size equalled NumDescriptors * 32. The test's neighbour happened to supply exactly 32, so the garbage word was accepted as a console address, GetCPUDescriptorHandleForHeapStart returned it, and the first view write went to 0x65626f72705f7370.

Fix

The predicate now also requires the address to be 64 KiB aligned -- what a heap range the title supplies always is, and what a neighbouring local almost never is. Nothing else changes: a real console heap and an ordinary PC heap both behave as before.

d3d12_console_descriptor_heap_test gains the exact case: a desc whose following words are 0x65626f72705f7370 with a matching size, asserting the handle does not become that word.

Tested

  • d3d12_subgroup_test: SegFault 3/3 before, passes 3/3 after.
  • d3d12_console_descriptor_heap_test 3/3 (covers the aligned console path through the proxy).
  • No regression: d3d12_clear_test, d3d12_descriptor_test, d3d12_typeless_rtv_test, device_proxy_test, xs_proxy_mock_test all pass.
  • check_no_game_data.py -> exit 0.

Not tested: the retail executable's slot 14 call sites (no game files run here). The alignment is an assumption about console heap VAs; if a measurement ever shows a title passing an unaligned one, this is where it would show.

GPUs tested: NVIDIA GPU (Pascal class, 4 GB), driver 582.28, Windows 10 19045.

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.)
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5481003155 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1328). Originally posted by [robot00f](https://github.com/robot00f) on 2026-11-24T21:56:50Z. --- Claim: https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7145591230 (ID `D3D12-CONSOLE-HEAP-ALIGN`; fixes the `d3d12_subgroup` SegFault in #1150) `d3d12_subgroup` crashed deterministically (3/3) in `Device::CreateRenderTargetView`, writing the 16-byte view to a handle whose value was the ASCII text `ps_probe` -- the bytes of a shader name. ### Cause Device slot 14 reads a console descriptor heap as a PC `D3D12_DESCRIPTOR_HEAP_DESC` with an address at +0x10 and a size at +0x18, and keeps `console_heap_range_plausible()` to tell that layout from a PC desc whose trailing words are whatever the caller's next local holds. That guard checked only that the size equalled `NumDescriptors * 32`. The test's neighbour happened to supply exactly 32, so the garbage word was accepted as a console address, `GetCPUDescriptorHandleForHeapStart` returned it, and the first view write went to `0x65626f72705f7370`. ### Fix The predicate now also requires the address to be 64 KiB aligned -- what a heap range the title supplies always is, and what a neighbouring local almost never is. Nothing else changes: a real console heap and an ordinary PC heap both behave as before. `d3d12_console_descriptor_heap_test` gains the exact case: a desc whose following words are `0x65626f72705f7370` with a matching size, asserting the handle does not become that word. ### Tested - `d3d12_subgroup_test`: SegFault 3/3 before, passes 3/3 after. - `d3d12_console_descriptor_heap_test` 3/3 (covers the aligned console path through the proxy). - No regression: `d3d12_clear_test`, `d3d12_descriptor_test`, `d3d12_typeless_rtv_test`, `device_proxy_test`, `xs_proxy_mock_test` all pass. - `check_no_game_data.py` -> exit 0. Not tested: the retail executable's slot 14 call sites (no game files run here). The alignment is an assumption about console heap VAs; if a measurement ever shows a title passing an unaligned one, this is where it would show. GPUs tested: NVIDIA GPU (Pascal class, 4 GB), driver 582.28, Windows 10 19045. 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.)
whoalin1 commented 2026-11-24 23:08:22 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by whoalin1 on 2026-11-24T23:08:22Z.


Independent verification (AI-assisted, overnight shift worker). Built the PR head (a55007b) and origin/main (51a6074) with the same RelWithDebInfo/Ninja config and ran ctest -C RelWithDebInfo -R d3d12 -j8 on both GPUs (TEMP/TMP pointed at the user profile; VK_LOADER_LAYERS_DISABLE=implicit).

AMD iGPU (VK_LOADER_DRIVERS_SELECT=*amd-vulkan* LEONIDA_VK_DEVICE=radeon LEONIDA_VK_VALIDATION=1 LEONIDA_PC_TAIL_UBO=1):

  • PR head: 92/118 passed, 26 failed. Baseline main: 93/120 passed, 27 failed. Every PR-head failure also fails identically on baseline (the AMD push-constant 144>128 family plus the known xdxr_rt_check BIBHEAP/box16, d3d12_clear NaN, execute_indirect parity, pipeline_library_host 0xc0000409). Baseline's extra failure, d3d12_multi_viewport, does not exist at this PR's base. No regressions.
  • d3d12_subgroup fails the same way before and after on this iGPU: pipelines need 144 bytes of push constants ... maxPushConstantsSize 128 then the !result.failure assert — the claimed CreateRenderTargetView SegFault does not reproduce here on baseline either (the test stops earlier at the PSO), so the crash fix could not be observed directly, but the new d3d12_console_descriptor_heap test passes and the guard change is a strict tightening (64 KiB alignment AND the existing size check).

NVIDIA RTX 4070 SUPER (VK_LOADER_DRIVERS_SELECT=*nv-vk* LEONIDA_VK_DEVICE=4070):

  • PR head: 116/118 passed. Failures: d3d12_execute_indirect_validation (the known WARP/HW parity diffs; it passed in isolation on baseline) and d3d12_pipeline_library_host (0xc0000409 — reproduces identically on baseline main, pre-existing). d3d12_subgroup and d3d12_console_descriptor_heap pass.

No game files used. Verified on this machine only.

— AI-assisted verification

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7147058205 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1328#issuecomment-7147058205). Originally posted by [whoalin1](https://github.com/whoalin1) on 2026-11-24T23:08:22Z. --- Independent verification (AI-assisted, overnight shift worker). Built the PR head (a55007b) and origin/main (51a6074) with the same RelWithDebInfo/Ninja config and ran `ctest -C RelWithDebInfo -R d3d12 -j8` on both GPUs (TEMP/TMP pointed at the user profile; VK_LOADER_LAYERS_DISABLE=~implicit~). **AMD iGPU** (`VK_LOADER_DRIVERS_SELECT=*amd-vulkan* LEONIDA_VK_DEVICE=radeon LEONIDA_VK_VALIDATION=1 LEONIDA_PC_TAIL_UBO=1`): - PR head: 92/118 passed, 26 failed. Baseline main: 93/120 passed, 27 failed. Every PR-head failure also fails identically on baseline (the AMD push-constant 144>128 family plus the known xdxr_rt_check BIBHEAP/box16, d3d12_clear NaN, execute_indirect parity, pipeline_library_host 0xc0000409). Baseline's extra failure, d3d12_multi_viewport, does not exist at this PR's base. **No regressions.** - `d3d12_subgroup` fails the same way before and after on this iGPU: `pipelines need 144 bytes of push constants ... maxPushConstantsSize 128` then the `!result.failure` assert — the claimed CreateRenderTargetView SegFault does not reproduce here on baseline either (the test stops earlier at the PSO), so the crash fix could not be observed directly, but the new `d3d12_console_descriptor_heap` test passes and the guard change is a strict tightening (64 KiB alignment AND the existing size check). **NVIDIA RTX 4070 SUPER** (`VK_LOADER_DRIVERS_SELECT=*nv-vk* LEONIDA_VK_DEVICE=4070`): - PR head: 116/118 passed. Failures: `d3d12_execute_indirect_validation` (the known WARP/HW parity diffs; it passed in isolation on baseline) and `d3d12_pipeline_library_host` (0xc0000409 — reproduces identically on baseline main, pre-existing). `d3d12_subgroup` and `d3d12_console_descriptor_heap` pass. No game files used. Verified on this machine only. — AI-assisted verification
OreoFR commented 2026-11-29 00:14:38 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-29T00:14:38Z.


Verified by OreoFR

  • Base: main a8465211f + PR head a55007b60 (merged with --no-ff, no conflict; tested in a package with other PRs that share no file with it)
  • Test: ctest -R ^d3d12_console_descriptor_heap$ (also xs_proxy_mock)
  • Red on main: with main's shim and the PR's test, d3d12_console_descriptor_heap passes (no red), and xs_proxy_mock passed 5/5
  • Green with the PR: d3d12_console_descriptor_heap fails every run: writable backing: expected console handle for a console heap address that is 16-byte but not 64 KiB aligned, so the existing case now gets no console handle. xs_proxy_mock also failed 3 of 10 runs at line 4599 (g_tear.torn == 0 && g_tear.reads > 0), 0 of 5 without this PR's shim change (not proven to be caused by it)
  • Verdict: FAILS (the 64 KiB alignment requirement breaks an existing console-heap case on current main)
  • Machine: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Intel Core Ultra 7 155H, Windows 11
  • Note: shares runtime/shims/d3d12_xs_device.cpp with the open #2566; a rebase may be needed if #2566 lands first.

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

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7247976373 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1328#issuecomment-7247976373). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-29T00:14:38Z. --- **Verified by OreoFR** - Base: main `a8465211f` + PR head `a55007b60` (merged with --no-ff, no conflict; tested in a package with other PRs that share no file with it) - Test: `ctest -R ^d3d12_console_descriptor_heap$` (also xs_proxy_mock) - Red on main: with main's shim and the PR's test, `d3d12_console_descriptor_heap` passes (no red), and `xs_proxy_mock` passed 5/5 - Green with the PR: `d3d12_console_descriptor_heap` fails every run: `writable backing: expected console handle` for a console heap address that is 16-byte but not 64 KiB aligned, so the existing case now gets no console handle. `xs_proxy_mock` also failed 3 of 10 runs at line 4599 (`g_tear.torn == 0 && g_tear.reads > 0`), 0 of 5 without this PR's shim change (not proven to be caused by it) - Verdict: FAILS (the 64 KiB alignment requirement breaks an existing console-heap case on current main) - Machine: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Intel Core Ultra 7 155H, Windows 11 - Note: shares `runtime/shims/d3d12_xs_device.cpp` with the open #2566; a rebase may be needed if #2566 lands first. AI-assisted (Claude Code, Claude Opus 5.5).
zmasi commented 2026-11-29 00:30:58 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-29T00:30:58Z.


#1328 | head a55007b601 (auto-merges cleanly with main 829530dbd0, regression on PR + main) | ctest --test-dir runtime/build -C RelWithDebInfo -R "^(d3d12_console_descriptor_heap|d3d12_descriptor|d3d12_clear|d3d12_typeless_rtv|device_proxy|xs_proxy_mock)$" --output-on-failure (LEONIDA_VK_VALIDATION=1) | flagged on PR+main: d3d12_console_descriptor_heap fails (writable backing: expected console handle, got ...) when merged onto current main (829530dbd0), while the other 5/5 CTests (device_proxy, xs_proxy_mock, d3d12_descriptor, d3d12_clear, d3d12_typeless_rtv) pass in 12.38 s on RTX 3090 with 0 Khronos validation errors: (1) main subsequently added check_xs_proxy_slot14 (runtime/test/d3d12_console_descriptor_heap_test.cpp:97-125), which passes a stack-allocated alignas(64) unsigned char storage[4096]{} (64-byte aligned, not 64 KiB aligned) through DeviceProxy slot 14 expecting check_start("writable backing", true), and address % 0x10000 rejects it (note also d3d12_xs_device.cpp:4794-4796: the title carves descriptor heaps out of a larger slot-133 buffer, so worth confirming whether carved sub-heaps are always 64 KiB aligned vs 64 B/4 KiB aligned before tightening check_xs_proxy_slot14 to VirtualAlloc), and (2) check_unaligned_tail_is_not_a_console_heap(device.get()) calls CreateDescriptorHeap on the unwrapped Vulkan ID3D12Device instead of the d3d12_xs DeviceProxy slot 14, and main (d3d12_xs_device.cpp:4805) now checks accessible_range(..., true) so unmapped 0x65626f72705f7370ull ("ps_probe") is already rejected on main; check_no_game_data.py 0 violations | Windows 11, MSVC 19.44, RTX 3090, Vulkan SDK 1.4.363.1 | AI-assisted: yes

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7248165963 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1328#issuecomment-7248165963). Originally posted by [zmasi](https://github.com/zmasi) on 2026-11-29T00:30:58Z. --- #1328 | head a55007b6014d7c19df24d8899c246a5ec3e82d35 (auto-merges cleanly with main 829530dbd0196aa817dbec74aaafc79407b94b57, **regression on `PR + main`**) | `ctest --test-dir runtime/build -C RelWithDebInfo -R "^(d3d12_console_descriptor_heap|d3d12_descriptor|d3d12_clear|d3d12_typeless_rtv|device_proxy|xs_proxy_mock)$" --output-on-failure` (`LEONIDA_VK_VALIDATION=1`) | **flagged on PR+main:** `d3d12_console_descriptor_heap` **fails** (`writable backing: expected console handle, got ...`) when merged onto current `main` (`829530dbd0`), while the other `5/5` CTests (`device_proxy`, `xs_proxy_mock`, `d3d12_descriptor`, `d3d12_clear`, `d3d12_typeless_rtv`) pass in `12.38 s` on RTX 3090 with `0` Khronos validation errors: (1) `main` subsequently added `check_xs_proxy_slot14` (`runtime/test/d3d12_console_descriptor_heap_test.cpp:97-125`), which passes a stack-allocated `alignas(64) unsigned char storage[4096]{}` (`64`-byte aligned, not `64 KiB` aligned) through `DeviceProxy` slot 14 expecting `check_start("writable backing", true)`, and `address % 0x10000` rejects it (note also `d3d12_xs_device.cpp:4794-4796`: the title carves descriptor heaps out of a larger slot-133 buffer, so worth confirming whether carved sub-heaps are always `64 KiB` aligned vs `64 B`/`4 KiB` aligned before tightening `check_xs_proxy_slot14` to `VirtualAlloc`), and (2) `check_unaligned_tail_is_not_a_console_heap(device.get())` calls `CreateDescriptorHeap` on the unwrapped Vulkan `ID3D12Device` instead of the `d3d12_xs` `DeviceProxy` slot 14, and `main` (`d3d12_xs_device.cpp:4805`) now checks `accessible_range(..., true)` so unmapped `0x65626f72705f7370ull` (`"ps_probe"`) is already rejected on `main`; `check_no_game_data.py` `0` violations | Windows 11, MSVC 19.44, RTX 3090, Vulkan SDK 1.4.363.1 | AI-assisted: yes
fiestorra commented 2026-11-30 08:50:06 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by fiestorra on 2026-11-30T08:50:06Z.


Independent verification on this machine (Windows 11, RTX 4090, MSVC 19.44.35226): this pull request applies, builds, and its own test fails - deterministically.

1. It applies. merge-tree clean; a55007b60 cherry-picks onto main e236b19c6 without a conflict. Two files: runtime/shims/d3d12_xs_device.cpp (the fix) and runtime/test/d3d12_console_descriptor_heap_test.cpp (the check).

2. The target builds:

[5/5] Linking CXX executable d3d12_console_descriptor_heap_test.exe

3. The test fails, twice, with the same message:

ctest -R '^d3d12_console_descriptor_heap$' --output-on-failure
***Failed    0.39 sec
writable backing: expected console handle, got 0x23d45e71150 (console address 0x753076e340)

direct .exe run: exit=1
writable backing: expected console handle, got 0x267373ef500 (console address 0x5375dce2c0)

4. On main, the same test target passes - so this is the branch's own check failing on the branch's own tree, not a pre-existing red.

What the addresses suggest, and I am flagging it as a suggestion rather than a diagnosis: the console address in both runs ends in 0x340 and 0x2c0 - neither is 64 KiB aligned, and the commit is titled "require a console heap address to be 64 KiB aligned before slot …". So either the fix does not produce the alignment the test then demands, or the check reads the address before the fix rewrites it. The two runs got different addresses (ASLR), so this is not one unlucky allocation.

What I did not do: change the test or the shim to see which of the two is wrong. That is the author's call, and a stranger editing either would be guessing at intent.

How it was found: a sweep of open pull requests that replay onto main, building what each test's command[0] says, and running it through ctest -R. Of the 25 in this batch, this is the only one whose test fails; five built and passed.

Written with an AI assistant.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7273402492 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1328#issuecomment-7273402492). Originally posted by [fiestorra](https://github.com/fiestorra) on 2026-11-30T08:50:06Z. --- Independent verification on this machine (Windows 11, RTX 4090, MSVC 19.44.35226): **this pull request applies, builds, and its own test fails - deterministically.** **1. It applies.** `merge-tree` clean; `a55007b60` cherry-picks onto `main` `e236b19c6` without a conflict. Two files: `runtime/shims/d3d12_xs_device.cpp` (the fix) and `runtime/test/d3d12_console_descriptor_heap_test.cpp` (the check). **2. The target builds:** ``` [5/5] Linking CXX executable d3d12_console_descriptor_heap_test.exe ``` **3. The test fails, twice, with the same message:** ``` ctest -R '^d3d12_console_descriptor_heap$' --output-on-failure ***Failed 0.39 sec writable backing: expected console handle, got 0x23d45e71150 (console address 0x753076e340) direct .exe run: exit=1 writable backing: expected console handle, got 0x267373ef500 (console address 0x5375dce2c0) ``` **4. On `main`, the same test target passes** - so this is the branch's own check failing on the branch's own tree, not a pre-existing red. **What the addresses suggest, and I am flagging it as a suggestion rather than a diagnosis:** the console address in both runs ends in `0x340` and `0x2c0` - **neither is 64 KiB aligned**, and the commit is titled *"require a console heap address to be 64 KiB aligned before slot …"*. So either the fix does not produce the alignment the test then demands, or the check reads the address before the fix rewrites it. **The two runs got different addresses** (ASLR), so this is not one unlucky allocation. **What I did not do:** change the test or the shim to see which of the two is wrong. That is the author's call, and a stranger editing either would be guessing at intent. **How it was found:** a sweep of open pull requests that replay onto `main`, building what each test's `command[0]` says, and running it through `ctest -R`. **Of the 25 in this batch, this is the only one whose test fails; five built and passed.** Written with an AI assistant.
aslan2142 commented 2026-12-01 16:34:54 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T16:34:54Z.


Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (d3d12/) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, d3d12/, or general docs), please feel free to reopen it.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7317842922 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1328#issuecomment-7317842922). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T16:34:54Z. --- Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (`d3d12/`) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, `d3d12/`, or general docs), please feel free to reopen it.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
ProjectLeonida/mandy!1328
No description provided.