[PR #1273] runtime: track title host memory regions and import into Vulkan (RT-TITLE-HOST-REGION) #1307

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

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1273
Author: @madhyn
Created: 11/24/2026
Status: 🔄 Open

Base: main ← Head: exp/title-host-region


📝 Commits (3)

  • 71fed4a runtime: add RT-TITLE-HOST-REGION host memory import and VA lookup
  • ceed3d3 d3d12: translate TitleHostRegions VAs in CBV/SRV/UAV descriptors
  • 31c072a title_host_regions: retire before host free, multi-block VirtualQuery, and failure tracking

📊 Changes

8 files changed (+1282 additions, -28 deletions)

View changed files

📝 runtime/CMakeLists.txt (+9 -1)
📝 runtime/shims/d3d12_vulkan_device.cpp (+18 -5)
📝 runtime/shims/xmem.cpp (+46 -7)
➕ runtime/src/title_host_regions.h (+266 -0)
📝 runtime/src/vulkan_backend.h (+49 -15)
➕ runtime/src/vulkan_title_regions.h (+434 -0)
➕ runtime/test/title_host_region_gpu_test.cpp (+227 -0)
➕ runtime/test/title_host_regions_test.cpp (+233 -0)

📄 Description

Follow-up to #927 (which added the vk_host_region_import_test probe) for RT-TITLE-HOST-REGION on #14.

Summary

  • runtime/src/title_host_regions.h: Thread-safe (std::mutex) non-overlapping interval table (leonida::TitleHostRegions) mapping [host_va, host_va + size) to {gpu_bda, tag, handle} with O(\log N) find(), resolve_bda(), partial-unmap splitting in unregister_range(), pending_imports(), mark_imported(), take_retired(), and process-wide title_host_regions().
  • runtime/src/vulkan_title_regions.h: Lazy VK_EXT_external_memory_host importer (leonida::VulkanTitleRegions) creating VkBuffers with VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT, VirtualQuery committed-page validation on Windows, HOST_WRITE -> SHADER_READ barrier (record_host_write_barrier()), and vkDeviceWaitIdle cleanup of retired regions (collect_retired()).
    • Unlike whole-arena pinning, regions are imported piecewise as allocated/used, avoiding VK_ERROR_OUT_OF_HOST_MEMORY on 16 GB hosts.
  • runtime/src/vulkan_backend.h, runtime/shims/d3d12_vulkan_device.cpp, runtime/shims/xmem.cpp:
    • Registers/unregisters committed ranges in TitleVirtualAlloc, TitleVirtualFree (added to SHIM_TABLE(title_memory)), XMemVirtualAlloc (MEM_COMMIT), map_page, and unmap_page.
    • Configures VulkanContext::title_regions_ when host_pointer_alignment != 0, syncs pending imports and emits the host-write barrier at command-buffer start, and falls back to title_regions_.lookup(...) in replay_.buffer_at and replay_.host_at.
  • Tests:
    • runtime/test/title_host_regions_test.cpp: interval table, partial unmap splitting, retired handle lifecycle, and concurrent access.
    • runtime/test/title_host_region_gpu_test.cpp: end-to-end VulkanContext import, host_at / buffer_at / resolve_title_bda, GPU copy + readback verification of CPU-written bytes, and clean retirement before freeing host pages.

Verification (NVIDIA GeForce RTX 3060 Ti)

  • Linux (ctest): title_host_regions Passed (9.35 s), title_host_region_gpu Passed (0.23 s).
  • Windows cross-build (clang-cl + xwin) under Wine 11.22:
    • title_host_regions_test.exe: PASS
    • title_host_region_gpu_test.exe: ok (align=4096, bda supported)

AI-assisted: yes


🔄 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/1273 **Author:** [@madhyn](https://github.com/madhyn) **Created:** 11/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `exp/title-host-region` --- ### 📝 Commits (3) - [`71fed4a`](https://github.com/ubiquitarianism/leonida/commit/71fed4a27d9a6a0dcdf53f9b324689d1ad30711c) runtime: add RT-TITLE-HOST-REGION host memory import and VA lookup - [`ceed3d3`](https://github.com/ubiquitarianism/leonida/commit/ceed3d36b245dbc4dec6752c29acd330c413c1a1) d3d12: translate TitleHostRegions VAs in CBV/SRV/UAV descriptors - [`31c072a`](https://github.com/ubiquitarianism/leonida/commit/31c072a425cce6870ff72b4cc28be8eb54318a16) title_host_regions: retire before host free, multi-block VirtualQuery, and failure tracking ### 📊 Changes **8 files changed** (+1282 additions, -28 deletions) <details> <summary>View changed files</summary> 📝 `runtime/CMakeLists.txt` (+9 -1) 📝 `runtime/shims/d3d12_vulkan_device.cpp` (+18 -5) 📝 `runtime/shims/xmem.cpp` (+46 -7) ➕ `runtime/src/title_host_regions.h` (+266 -0) 📝 `runtime/src/vulkan_backend.h` (+49 -15) ➕ `runtime/src/vulkan_title_regions.h` (+434 -0) ➕ `runtime/test/title_host_region_gpu_test.cpp` (+227 -0) ➕ `runtime/test/title_host_regions_test.cpp` (+233 -0) </details> ### 📄 Description Follow-up to #927 (which added the `vk_host_region_import_test` probe) for **RT-TITLE-HOST-REGION** on #14. ### Summary - **`runtime/src/title_host_regions.h`**: Thread-safe (`std::mutex`) non-overlapping interval table (`leonida::TitleHostRegions`) mapping `[host_va, host_va + size)` to `{gpu_bda, tag, handle}` with $O(\log N)$ `find()`, `resolve_bda()`, partial-unmap splitting in `unregister_range()`, `pending_imports()`, `mark_imported()`, `take_retired()`, and process-wide `title_host_regions()`. - **`runtime/src/vulkan_title_regions.h`**: Lazy `VK_EXT_external_memory_host` importer (`leonida::VulkanTitleRegions`) creating `VkBuffer`s with `VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT`, `VirtualQuery` committed-page validation on Windows, `HOST_WRITE -> SHADER_READ` barrier (`record_host_write_barrier()`), and `vkDeviceWaitIdle` cleanup of retired regions (`collect_retired()`). - Unlike whole-arena pinning, regions are imported piecewise as allocated/used, avoiding `VK_ERROR_OUT_OF_HOST_MEMORY` on 16 GB hosts. - **`runtime/src/vulkan_backend.h`**, **`runtime/shims/d3d12_vulkan_device.cpp`**, **`runtime/shims/xmem.cpp`**: - Registers/unregisters committed ranges in `TitleVirtualAlloc`, `TitleVirtualFree` (added to `SHIM_TABLE(title_memory)`), `XMemVirtualAlloc` (`MEM_COMMIT`), `map_page`, and `unmap_page`. - Configures `VulkanContext::title_regions_` when `host_pointer_alignment != 0`, syncs pending imports and emits the host-write barrier at command-buffer start, and falls back to `title_regions_.lookup(...)` in `replay_.buffer_at` and `replay_.host_at`. - **Tests**: - `runtime/test/title_host_regions_test.cpp`: interval table, partial unmap splitting, retired handle lifecycle, and concurrent access. - `runtime/test/title_host_region_gpu_test.cpp`: end-to-end `VulkanContext` import, `host_at` / `buffer_at` / `resolve_title_bda`, GPU copy + readback verification of CPU-written bytes, and clean retirement before freeing host pages. ### Verification (NVIDIA GeForce RTX 3060 Ti) - Linux (`ctest`): `title_host_regions` **Passed** (9.35 s), `title_host_region_gpu` **Passed** (0.23 s). - Windows cross-build (`clang-cl` + `xwin`) under Wine 11.22: - `title_host_regions_test.exe`: **PASS** - `title_host_region_gpu_test.exe`: **`ok (align=4096, bda supported)`** AI-assisted: yes --- <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#1307
No description provided.