Skip to content

runtime: support placed buffers in OpenExistingHeapFromAddress heaps (RT-EXISTING-HEAP-PLACED) - #1190

Open
Taffyyy-ops wants to merge 1 commit into
ProjectLeonida:mainfrom
Taffyyy-ops:feat/existing-heap-placed-buffers
Open

Taffyyy-ops wants to merge 1 commit into
ProjectLeonida:mainfrom
Taffyyy-ops:feat/existing-heap-placed-buffers

Conversation

@Taffyyy-ops

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: RT-EXISTING-HEAP-PLACED (#14 (comment))

What and why

  • Placed buffers in ID3D12Device3::OpenExistingHeapFromAddress existing heaps (runtime/shims/d3d12_vulkan_device.cpp):
    • Replaced the blanket E_NOTIMPL for existing heaps in Device::create_placed so CreatePlacedResource, CreatePlacedResource1, and CreatePlacedResource2 bind placed buffers directly onto the heap's VK_EXT_external_memory_host VkDeviceMemory at heap_offset via Resource::create_existing_heap_buffer. Placed textures in existing heaps remain explicitly E_NOTIMPL.
    • Enforced the measured Windows D3D12 cross-adapter parity rule: any heap carrying D3D12_HEAP_FLAG_SHARED_CROSS_ADAPTER (including OpenExistingHeapFromAddress) requires D3D12_RESOURCE_FLAG_ALLOW_CROSS_ADAPTER (E_INVALIDARG otherwise), while keeping ALLOW_CROSS_ADAPTER refused on non-cross-adapter heaps and preserving GetDesc().Flags.
    • Intersected VkMemoryHostPointerPropertiesEXT::memoryTypeBits with VkBuffer memory requirements (DeviceState::host_buffer_info) and gated VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT / VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT behind DeviceState::need_buffer_device_address().
    • Set Map(0, nullptr, &ptr) to return heap_host_address + heap_offset, preserved pre-filled host pages (non-zeroing), set binding.host_readable = true for TRANSFER -> HOST_READ barriers, and ordered teardown (wait_retire_ticket -> vkDestroyBuffer before heap_range_.reset() -> vkFreeMemory).
  • Intel WDDM asynchronous host-import unpin fix (DeviceState::flush_host_import_unpin):
    • Probing vulkan-1.dll on Intel RaptorLake-S (0x8086) showed that vkFreeMemory on VK_EXT_external_memory_host memory followed immediately by VirtualFree without a real GPU submission in between leaves Intel's Windows WDDM paging engine unpinning freed pages, causing VK_ERROR_DEVICE_LOST (-4) on subsequent queue submits (which caused the pre-existing failure in d3d12_existing_heap on Intel). Neither vkDeviceWaitIdle, vkQueueWaitIdle, nor an empty command buffer flushed it, whereas submitting a barrier-only list via staging_queue + idle() resolved it cleanly for both PAGE_READWRITE and PAGE_READWRITE | PAGE_WRITECOMBINE.
  • Synthetic regression suite and docs:
    • Added runtime/test/d3d12_existing_heap_placed_test.cpp (registered in runtime/CMakeLists.txt as d3d12_existing_heap_placed with SKIP_RETURN_CODE 77), updated runtime/test/d3d12_existing_heap_test.cpp, added docs/existing_heaps.md, and indexed it in docs/README.md (without touching docs/d3d12_vulkan.md).

Tested

  • Full MSVC 19.44 + Ninja runtime build (cmake --build runtime/build): 101/101 targets built cleanly (0 errors, 0 new /W4 /permissive- warnings).
  • LEONIDA_VK_DEVICE="RTX 5060" CTest (8/8 passed in 21.58s): d3d12_vulkan_device, d3d12_placed_dimensions, d3d12_placed_heap_lifetime, d3d12_existing_heap (8/8 heap parity cases vs host RTX 5060 and WARP + placed buffer + slot 133), d3d12_existing_heap_placed (15/15 placed parity cases vs host RTX 5060 and WARP + no-bda & bda+arena bidirectional coherence + aliasing + heap-before-buffer lifetime + 64-iter stress + Xbox proxy slot 29), d3d12_xmem_placed, d3d12_method_variants, d3d12_heap_properties.
  • LEONIDA_VK_DEVICE="Intel" CTest (8/8 passed in 10.51s): exact same 8 suites, including 8/8 and 15/15 parity vs host Intel UHD Graphics and WARP, with the previous Intel WDDM ExecuteCommandLists failure resolved.
  • Proxy / mock CTest (8/8 passed in 0.38s): device_proxy, device_proxy_trace, xs_proxy_mock, xs_proxy_mock_no_reserve, xs_proxy_mock_no_protect, xs_proxy_mock_no_handler, xs_proxy_mock_env_slots, xs_proxy_mock_env_slots_invalid.
  • Repository checks:
    • python -I tests/test_ctest_registration.py (4 tests OK)
    • All 12 python -I tests/test_docs_*.py suites (47 tests total OK)
    • python -I scripts/check_no_game_data.py on all 6 changed/added files (exit 0)
    • git diff --cached --check (exit 0)

GPUs tested:

  • NVIDIA GeForce RTX 5060 Laptop GPU (driver 32.0.16.2124 / 621.24, Windows 11)
  • Intel(R) RaptorLake-S Mobile Graphics Controller / Intel(R) UHD Graphics (driver 32.0.101.7026, Windows 11)
  • Microsoft Basic Render Driver / WARP (host reference on Windows 11)

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a — no translator rules changed)

…(RT-EXISTING-HEAP-PLACED)

Implement CreatePlacedResource/1/2 for buffers inside existing heaps backed by VK_EXT_external_memory_host, enforce host D3D12 SHARED_CROSS_ADAPTER -> ALLOW_CROSS_ADAPTER validation, and flush Intel WDDM asynchronous host-import unpins before VirtualFree.

AI-assisted; 100% synthetic tests only, no game data.
@Deedlyy

Deedlyy commented Nov 24, 2026

Copy link
Copy Markdown

Recommendation: [WAIT]

Reasoning: Replaces the blanket E_NOTIMPL for placed buffers in OpenExistingHeapFromAddress heaps by binding them onto the heap's host-imported memory (placed textures still refused), with a 731-line new test and docs. A substantial runtime change (+949) with no reviews or independent runs yet. It also overlaps #1100 and draft #1192 in the existing-heap code and test. Before merging, get an independent run on at least one vendor and sort out the merge order with #1100/#1192. CI (label, change-scope, no-game-data and the Runtime jobs) is still queued awaiting maintainer workflow approval, so nothing has run in CI yet; GitHub reports no merge conflict with main.

Impact level: 6/10

@Taffyyy-ops

Copy link
Copy Markdown
Contributor Author

@Deedlyy Thanks for the review and [WAIT] note! Understood — we'll hold #1190 until the merge order with #1100 and #1192 is settled (and rebase cleanly onto main including #1539's kernel_writes::hold/release host-import pinning), or once an independent vendor run is completed.

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.

2 participants