Skip to content

d3d12/xs: guard 48-bit host-import VAs and sync title-written descriptor heaps (D3D-RTX5070-HOST-HEAP-SYNC) - #644

Open
TanmaySatyam wants to merge 1 commit into
ProjectLeonida:mainfrom
TanmaySatyam:feature/rtx5070-fixes
Open

TanmaySatyam wants to merge 1 commit into
ProjectLeonida:mainfrom
TanmaySatyam:feature/rtx5070-fixes

Conversation

@TanmaySatyam

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: D3D-RTX5070-HOST-HEAP-SYNC

AI-assisted.

Summary

  1. 48-bit VA guard for host-imported slot-133 buffers (runtime/shims/d3d12_vulkan_device.cpp)
    • When VK_EXT_external_memory_host places a title-backed host import below heap_base, address - heap_base wraps in 64-bit unsigned arithmetic (bits 48..63 = 0xFFFF), corrupting 48-bit V# buffer descriptors.
    • Detects va >= (1ull << 48) after subtracting heap_base and falls back to the existing in-arena shadow buffer path cleanly.
  2. Custom CPU descriptor heap mirroring & pre-submit synchronization (runtime/shims/d3d12_xs_device.cpp)
    • Backs mapped console-extended descriptor heaps with a real GPU-arena heap, translates and mirrors device descriptor writes (slots 17–24 and Xbox slot 70) back to the title's CPU backing, and diffs/syncs title-written shader-visible descriptors into the GPU arena prior to queue ExecuteCommandLists / ExecuteCommandListsX.

Testing & Verification

  • Hardware / Driver: NVIDIA GeForce RTX 5070 (Driver 591.74, Windows 11, MSVC RelWithDebInfo, main@21625bca8)
  • Passed d3d12_existing_heap, d3d12_descriptor, and d3d12_console_descriptor_heap CTests under LEONIDA_VK_VALIDATION=1 and VK_VALIDATION_VALIDATE_SYNC=1 (3/3 passed, 0 validation errors).
  • Clean-room verified: python -I scripts/check_no_game_data.py runtime/shims/d3d12_vulkan_device.cpp runtime/shims/d3d12_xs_device.cpp exited 0.

@sodove

sodove commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Independent Windows review of exact head 23872cc on RTX 5070 Ti (610.74), MSVC 19.44 Release, and Khronos Vulkan validation 1.4.369. The stock existing-heap, descriptor, console-heap, xmem-placement and compute tests pass (5/5), with zero validation errors.

A test-only extension uses real, writable CPU storage behind the console heap descriptor and obtains two distinct, valid CBVs from the layer. The ordinary heap copy control passes. The device-write mirror and a direct CPU write made after creation both reach the new shader-visible backing at submission. Two other paths differ, in three runs with validation active and zero validation errors:

  1. Pre-filled custom heap on its first submit. An unchanged valid descriptor already in the CPU range when the heap is created never reaches the real backing on that submit. The nearby slot filled after creation does. register_descriptor_range initializes last_synced from the supplied CPU range without initializing the real backing, so the first diff treats those existing bytes as already copied.
  2. CPU-only custom heap as the source of a descriptor copy. After directly writing valid CBV bytes to CPU storage, neither CopyDescriptorsSimple nor CopyDescriptors copies the new descriptor to an ordinary destination. Recreating those same source CBVs via the proxy API makes both copies pass. The proxy translates the source handle to the real backing, which has not received the CPU-side write. These copy calls run immediately on the CPU timeline, as documented in Copying Descriptors.

All inputs were synthetic. AI-assisted.

@lixonik lixonik left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One additional coverage gap on 23872cc from code review. The existing-heap fixture leaves VulkanDeviceInfo::buffer_device_address unset. The device only calls create_arena() when that flag is enabled, so this fixture cannot exercise the new condition that requires both an arena address and an imported buffer address.

Could the 48-bit check get a deterministic regression case? The boundary inputs are a buffer address just below the arena, offsets of 0 and 2^48 - 1, and an offset of 2^48. The valid offsets should still be accepted and the out-of-range ones should take the shadow path.

AI-assisted static review. No GPU run for this observation.

@lixonik

lixonik commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up hardware Vulkan smoke test on Windows using the CI runtime artifact for this PR at 23872cc. I ran the test executables in an AppContainer without network capabilities. With the packaged synthetic shader fixtures in place, d3d12_descriptor_test and d3d12_console_descriptor_heap_test both exited 0.

d3d12_existing_heap_test terminated with 0xC0000008 in that restricted environment. I do not have a matching main artifact to compare, so that outcome is inconclusive. The console-heap smoke test exercises the fixed-address fixture and does not verify the new mapped-heap branch. The 48-bit guard observation in the earlier review still needs a focused case.

AI-assisted. Synthetic inputs only. Vulkan validation layers were not enabled.

Update: the matching base artifact at 21625bca is available now. With the same AppContainer setup and packaged synthetic fixtures, both descriptor tests also exit 0 on the base, and d3d12_existing_heap_test terminates with the identical 0xC0000008. All three outcomes match between base and PR in this harness. This comparison does not establish the cause of the existing-heap failure.

@Timon360SB

Copy link
Copy Markdown
Contributor

Independent regression verification — Turing and Blackwell

Baseline:
21625bc

PR head:
23872cc

Environment

Configuration RTX 2060 SUPER RTX 5070
Architecture Turing Blackwell
NVIDIA driver 621.14 621.14
Windows 11 build 28000 26200
Vulkan SDK 1.4.363.0 1.4.363.0
MSVC 19.44.35230 19.44.35230
Build RelWithDebInfo RelWithDebInfo
Generator Ninja Multi-Config Ninja Multi-Config

LEONIDA_VK_VALIDATION=1 and
VK_VALIDATION_VALIDATE_SYNC=1 were set.
GPU-assisted validation was also enabled.

Results

Three repetitions per revision on each GPU.

Test 2060S BASE 2060S HEAD 5070 BASE 5070 HEAD
d3d12_existing_heap 3/3 3/3 3/3 3/3
d3d12_descriptor 3/3 3/3 3/3 3/3
d3d12_console_descriptor_heap 3/3 3/3 3/3 3/3

36/36 test executions passed.
No skipped tests or reported Vulkan validation errors.

Additional observations

  • All 8 OpenExistingHeapFromAddress comparison
    cases matched both native hardware D3D12 and WARP.
  • Slot-133 buffer import and ordinary-buffer
    fallback checks passed on both revisions.
  • HEAD logs confirm that descriptor slots
    18, 19, 21, 22, 23 and 24 now execute
    the CPU-handle translation handlers.

Scope and limitations

No regressions were observed in the selected tests.

BASE already passes all selected cases, so these
results do not independently reproduce or prove
the fix for the original 48-bit VA underflow.

The console heap test logs indicate a heap not
backed by title memory. Full title-written
descriptor synchronization is therefore not
established by these results.

Synchronization validation was requested, but
the dedicated positive-control test was not run.

Synthetic fixtures only. No game files used.
AI-assisted test automation and result analysis.

@TanmaySatyam

Copy link
Copy Markdown
Contributor Author

Thanks @sodove, @lixonik, and @Timon360SB for the thorough reviews and hardware checks! Rebased onto \main\ (\d0da7dade) and pushed a follow-up commit addressing every review finding:

  1. Pre-filled custom shader-visible heap on first submit (@sodove test_make_game_argparse: the --jobs 10 case no longer needs 10 hardware threads #1):

    • egister_descriptor_range\ now seeds \last_synced\ from
      eal_start\ instead of \custom_start, so valid descriptors already sitting in title memory before \CreateDescriptorHeap\ are detected as dirty and synced on the very first \ExecuteCommandLists.
  2. CPU-only custom heap as source of \CopyDescriptors\ / \CopyDescriptorsSimple\ (@sodove D3D12: fix the slot-14 and acphal build breaks, report slot-133 texture GPU VAs #2):
    • Added \sync_title_source_descriptors\ and call it for every source range in \proxy_copy_descriptors\ (slot 23) and \proxy_copy_descriptors_simple\ (slot 24) before forwarding to \self->real->CopyDescriptors*, so direct CPU writes into any mirrored custom heap reach the destination immediately on the CPU timeline.
  3. Deterministic 48-bit V# VA guard & live BDA-arena regression tests (@lixonik):
    • Extracted
      t::d3d12::host_import_va_in_vsharp_range(arena_address, buffer_va)\ in
      untime/shims/d3d12_com.h\ and added deterministic boundary checks in \d3d12_existing_heap_test\ (zero guards, \�rena - 1, low VA \

@lixonik

lixonik commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Thanks for adding the deterministic boundary cases and the live BDA fixture. One static follow-up on 2c136008: in check_title_placed_with_bda, VirtualFree(pages, ...) runs before the local Ref<ID3D12Resource> buffer destructor releases the resource. On a successful direct import, the Vulkan memory object can still refer to those pages. The spec requires the host range to remain valid for the lifetime of the imported memory object.

Could the buffer be scoped so it is destroyed before VirtualFree, as in the existing placed-buffer checks? Fixture · Vulkan host-pointer lifetime

AI-assisted static follow-up. No GPU run on this head yet.

@TanmaySatyam

Copy link
Copy Markdown
Contributor Author

Good catch @lixonik — scoped \Ref buffer\ inside a block before \VirtualFree(pages, 0, MEM_RELEASE)\ in \check_title_placed_with_bda\ so any imported host-memory object is always released before the host pages are freed. Re-verified \d3d12_existing_heap_test\ on RTX 5070 (Driver 591.74, Windows 11, \LEONIDA_VK_VALIDATION=1, \VK_VALIDATION_VALIDATE_SYNC=1): PASS with 0 validation errors.

@MalexAson

Copy link
Copy Markdown

Tested c4b11a8 applied on main 6293c1c, on Intel Iris Xe (Raptor Lake-P, 8086:a7a0), Intel 32.0.101.7092, Windows 11 24H2 (26100.6584): this pull request's own cases pass; d3d12_existing_heap as a whole is red on this GPU before and after, for a reason that is already on main.

ctest -R "^(d3d12_existing_heap|d3d12_descriptor|d3d12_console_descriptor_heap)$", layer on the Iris Xe (the NVIDIA driver was kept out of the process with VK_LOADER_DRIVERS_SELECT):

main 6293c1c with this change
d3d12_descriptor pass pass
d3d12_console_descriptor_heap pass pass
d3d12_existing_heap fails fails, the same lines

The new cases in d3d12_existing_heap run here and pass:

vsharp 48-bit range guard: deterministic boundary cases passed
vulkan slot-133 buffer (BDA arena): returned valid GPU VA 0x10000 (arena shadow fallback)

The guard is what answers in the BDA fixture on this driver: the layer logs title-placed host import lies outside V# 48-bit range above heap_base; using arena shadow instead; bits 48-63: 65535. So on this Intel driver a host import does land below heap_base, the case the guard is for.

What keeps the test red is not from this pull request. In the existing check_title_placed cases (no BDA arena) the import succeeds and the copy out of the buffer is then refused, three times, identically with and without the change:

[rt] d3d12: ExecuteCommandLists failed: unsupported; nothing was submitted
vulkan slot-133 buffer line 219: SUCCEEDED(queue->Signal(fence.p, 1))

That is the finding in #14 (comment). It passed on the RTX 4060 Laptop GPU of the same machine earlier today on main.

Not run: the layer on the NVIDIA GPU (its driver was being updated during this run). Built with MSVC 19.50 + Ninja, RelWithDebInfo; the change applies cleanly on current main.

AI-assisted: this run was made with a coding agent.

@QemmHD

QemmHD commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

Independent test of head c4b11a8c3 on Windows 11 / RTX 4070 SUPER (NVIDIA 621.24, VS 2022, Ninja, RelWithDebInfo), merged alone onto main 66d4f5a:

  • existing_heap, console_descriptor_heap, descriptor, xs_proxy_mock, device_proxy and queue_proxy pass 6/6, both plain and with LEONIDA_VK_VALIDATION=1 (0 VUIDs).
  • The repo-consistency set gives 573 passed / 5 skipped / 0 failed. No game data. It merges cleanly onto current main.

I'm leaving the merge decision to the owner rather than merging it myself, because it changes runtime behaviour beyond a fix. Some notes for whoever decides:

  1. On this NVIDIA card the BDA-arena fixture also hits the new 48-bit guard ("bits 48-63: 65535", arena-shadow fallback), the same thing MalexAson saw on Intel. So on NVIDIA, too, title-placed host imports in BDA mode now take the shadow fallback instead of producing a wrapped V#.
  2. A readable console slot-14 heap no longer takes the console-addressed path. Its GPU start becomes the arena offset instead of the title VA. The CPU start still equals the title address, which is what the retail boot checks.
  3. Every ExecuteCommandLists memcmps each mirrored shader-visible heap, so the per-submit cost grows with heap size. A dirty-range or generation check would keep it flat.
  4. Descriptor mirroring writes into title memory after only a readable_range check. A writable check, or catching the write fault, would be safer.

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

@github-actions github-actions Bot added the needs rebase Conflicts with the base branch: rebase it on main label Nov 24, 2026
@QemmHD

QemmHD commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

A data point from another project for whoever decides on this. fxceless/victory-fork (a VIctory fork that renders gameplay on an RTX 4070) just landed the same idea in its commit a26859f, "The first room renders right": descriptor records the title copies into its heap as bytes are mirrored before each submission, with a per-slot fingerprint so only changed records are copied. They count about 40,000 records a frame in the first gameplay room, and that change is what made the room render correctly there. That supports #644's direction (title-written descriptors synced per ExecuteCommandLists). It also suggests the per-submit cost note from my earlier test can be addressed with a per-slot fingerprint or dirty tracking rather than a full memcmp.

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

@QemmHD

QemmHD commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

Update for when you rebase: this head (c4b11a8, based on d0da7da) no longer merges onto current main. A test merge onto c7e82e2 conflicts in d3d12_vulkan_device.cpp, d3d12_xs_device.cpp and both test files. Also, main now has an overlapping mechanism from #939: LEONIDA_DESC_MIRROR (on by default) stores descriptor writes to a title-backed heap at the title's address as well, and list slots 35/36 pull the title's descriptors into the bound table. It would help reviewers if the rebased PR says what it adds on top of that, e.g. picking up records the title byte-copies itself, which is the case the VIctory fork commit I mentioned covers.

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

…scriptor heaps

Rebased onto upstream main on top of ProjectLeonida#939 (LEONIDA_DESC_MIRROR) and the below-arena guard:
- d3d12_com.h / d3d12_vulkan_device.cpp: add rt::d3d12::host_import_va_in_vsharp_range() so positive offsets >= 2^48 above heap_base also fall back to the arena shadow while preserving LEONIDA_IMPORT_BELOW_ARENA=1 for below-arena imports; add deterministic 48-bit boundary + BDA arena tests in d3d12_existing_heap_test.cpp.
- d3d12_xs_device.cpp: layer two missing sync paths directly on top of LEONIDA_DESC_MIRROR and local_accessible():
  1) local_sync_source() before CopyDescriptors / CopyDescriptorsSimple so direct CPU writes to custom-backed source heaps reach destinations immediately on the CPU timeline.
  2) Per-slot 64-bit fingerprint sync (local_sync_shader_visible_heaps) before queue ExecuteCommandLists (slots 10/35) for shader-visible custom-backed heaps, picking up pre-filled slots on first submit and title-byte-copied descriptors outside 64-slot root-table binds without copying unchanged slots.
- d3d12_console_descriptor_heap_test.cpp: add unit coverage for pre-filled first-submit sync, post-creation direct writes, and CopyDescriptorsSimple / CopyDescriptors from custom-backed heaps.
@TanmaySatyam

Copy link
Copy Markdown
Contributor Author

Rebased cleanly onto main (3f81d46ac) on top of #939 (LEONIDA_DESC_MIRROR) and the below-arena host-import guard, addressing @sodove's findings and @QemmHD's review notes:

What this adds on top of current main:

  1. Upper 48-bit V# overflow guard + unit tests (d3d12_com.h, d3d12_vulkan_device.cpp, d3d12_existing_heap_test.cpp): Main now catches buffer_va < arena.address (unless LEONIDA_IMPORT_BELOW_ARENA=1), but not positive offsets >= 2^48 above heap_base. rt::d3d12::host_import_va_in_vsharp_range() guards both bounds while preserving LEONIDA_IMPORT_BELOW_ARENA=1 for below-arena imports, with deterministic boundary and BDA-arena tests.
  2. CopyDescriptors / CopyDescriptorsSimple source sync (d3d12_xs_device.cpp local_sync_source): Main's LEONIDA_DESC_MIRROR mirrors writes out to the title's backing (local_write_through) and pulls 64-slot tables on list slots 35/36, but does not pull direct CPU writes from a custom-backed source heap before CopyDescriptors* reads the real heap (addressing @sodove's finding D3D12: fix the slot-14 and acphal build breaks, report slot-133 texture GPU VAs #2).
  3. Per-slot 64-bit fingerprint sync before ExecuteCommandLists (local_sync_shader_visible_heaps): Layered directly onto DescriptorRange, local_desc_mirror() (LEONIDA_DESC_MIRROR=0 disables it too), and local_accessible() (writable/readable checks, addressing @QemmHD's note d3d12_xs: only take the console slot-14 layout when the descriptor size agrees #4). Uses 8-byte per-slot fingerprints (4x smaller than a full 32-byte shadow copy, skipping unchanged/empty slots on submit, addressing @QemmHD's note slot 14: a normal 16-byte descriptor heap description is read as the console layout, and d3d12_descriptor SEGFAULTs #3), initialized to 0 so pre-filled slots sync on the first submit (@sodove's finding test_make_game_argparse: the --jobs 10 case no longer needs 10 hardware threads #1), and picks up title-byte-copied descriptors across the whole shader-visible custom heap rather than only 64-slot root-table binds.

Verified locally (Windows 11, NVIDIA GeForce RTX 5070, MSVC RelWithDebInfo, LEONIDA_VK_VALIDATION=1, 0 VUIDs):

  • ctest -R "^(d3d12_existing_heap|d3d12_console_descriptor_heap|d3d12_descriptor|xs_proxy_mock|device_proxy|queue_proxy)$" -> 6/6 passed.
  • python -I scripts/check_no_game_data.py on all 5 changed files -> exit 0.

AI-assisted.

@sodove

sodove commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Retested exact head 2ec2ca450 on native Windows 11 build 26100, RTX 5070 Ti (610.74), MSVC 19.44 RelWithDebInfo. All six requested CTest cases passed, with zero VUIDs and Khronos validation 1.4.369 active on the GPU tests.

The two cases from my earlier review are now covered by the stock console descriptor heap test and passed here. A valid descriptor placed in slot 0 before heap creation reached the real backing on the first submit. Both CopyDescriptorsSimple and CopyDescriptors observed a direct CPU write to a custom-backed source heap. The existing-heap test also passed its deterministic 48-bit boundary cases.

Synthetic inputs only. This verifies those regressions on Blackwell. AI-assisted: yes (OpenAI Codex).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs rebase Conflicts with the base branch: rebase it on main

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants