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

Closed
Taffyyy-ops wants to merge 1 commit from upstream-pr/1190 into main
Taffyyy-ops commented 2026-11-24 19:55:07 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Taffyyy-ops on 2026-11-24T19:55:07Z.


Claimed in the coordination issue as: RT-EXISTING-HEAP-PLACED (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7142144089)

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)
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5479294903 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1190). Originally posted by [Taffyyy-ops](https://github.com/Taffyyy-ops) on 2026-11-24T19:55:07Z. --- Claimed in the coordination issue as: `RT-EXISTING-HEAP-PLACED` (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7142144089) ### 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 - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] 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)
Deedlyy commented 2026-11-24 20:08:40 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Deedlyy on 2026-11-24T20:08:40Z.


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

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7143102490 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1190#issuecomment-7143102490). Originally posted by [Deedlyy](https://github.com/Deedlyy) on 2026-11-24T20:08:40Z. --- **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 commented 2026-11-25 10:45:23 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Taffyyy-ops on 2026-11-25T10:45:23Z.


@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.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7160129441 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1190#issuecomment-7160129441). Originally posted by [Taffyyy-ops](https://github.com/Taffyyy-ops) on 2026-11-25T10:45:23Z. --- @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.
aslan2142 commented 2026-12-01 17:22:07 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T17:22:07Z.


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:7319187298 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1190#issuecomment-7319187298). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T17:22:07Z. --- 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!1190
No description provided.