Skip to content

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

Open
robot00f wants to merge 1 commit into
ProjectLeonida:mainfrom
robot00f:fix/console-heap-alignment
Open

robot00f wants to merge 1 commit into
ProjectLeonida:mainfrom
robot00f:fix/console-heap-alignment

Conversation

@robot00f

Copy link
Copy Markdown
Contributor

Claim: #14 (comment) (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.)

@whoalin1

Copy link
Copy Markdown
Contributor

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

OreoFR commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

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 [integration] PageMirror, GPU detile, async queue & RDNA2->SPIR-V performance stack (INTEGRATION-PERF-CPU-GPU-R6) #2566; a rebase may be needed if [integration] PageMirror, GPU detile, async queue & RDNA2->SPIR-V performance stack (INTEGRATION-PERF-CPU-GPU-R6) #2566 lands first.

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

@zmasi

zmasi commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

#1328 | head a55007b (auto-merges cleanly with main 829530d, 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

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.

4 participants