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

Open
opened 2026-11-26 20:20:30 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1190
Author: @Taffyyy-ops
Created: 11/24/2026
Status: 🔄 Open

Base: main ← Head: feat/existing-heap-placed-buffers


📝 Commits (1)

  • 3b27011 runtime: support placed buffers in OpenExistingHeapFromAddress heaps (RT-EXISTING-HEAP-PLACED)

📊 Changes

6 files changed (+949 additions, -32 deletions)

View changed files

📝 docs/README.md (+1 -0)
➕ docs/existing_heaps.md (+46 -0)
📝 runtime/CMakeLists.txt (+7 -0)
📝 runtime/shims/d3d12_vulkan_device.cpp (+149 -29)
➕ runtime/test/d3d12_existing_heap_placed_test.cpp (+731 -0)
📝 runtime/test/d3d12_existing_heap_test.cpp (+15 -3)

📄 Description

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)

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1190 **Author:** [@Taffyyy-ops](https://github.com/Taffyyy-ops) **Created:** 11/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `feat/existing-heap-placed-buffers` --- ### 📝 Commits (1) - [`3b27011`](https://github.com/ubiquitarianism/leonida/commit/3b27011f65f4933ec873ebb3e55aee1a44a3ac24) runtime: support placed buffers in OpenExistingHeapFromAddress heaps (RT-EXISTING-HEAP-PLACED) ### 📊 Changes **6 files changed** (+949 additions, -32 deletions) <details> <summary>View changed files</summary> 📝 `docs/README.md` (+1 -0) ➕ `docs/existing_heaps.md` (+46 -0) 📝 `runtime/CMakeLists.txt` (+7 -0) 📝 `runtime/shims/d3d12_vulkan_device.cpp` (+149 -29) ➕ `runtime/test/d3d12_existing_heap_placed_test.cpp` (+731 -0) 📝 `runtime/test/d3d12_existing_heap_test.cpp` (+15 -3) </details> ### 📄 Description 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) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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.

Dependencies

No dependencies set

Reference
starred/leonida#1222
No description provided.