[PR #2240] [MERGED] d3d12,xmem: sync TitleTexture readability against title_memory_map between passes (RT-TITLE-TEXTURE-MAP-GEN) #2244

Closed
opened 2026-11-26 21:20:32 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/2240
Author: @zmasi
Created: 11/26/2026
Status: ✅ Merged
Merged: 11/26/2026
Merged by: @aslan2142

Base: main ← Head: fix/title-texture-map-generation


📝 Commits (1)

  • d088ea7 Sync title texture readability with map journal between refresh passes

📊 Changes

7 files changed (+258 additions, -12 deletions)

View changed files

📝 runtime/shims/d3d12_vulkan_device.cpp (+13 -5)
📝 runtime/shims/xmem.cpp (+5 -3)
📝 runtime/shims/xmem.h (+1 -1)
📝 runtime/src/title_texture_memory.h (+26 -2)
📝 runtime/test/d3d12_existing_heap_test.cpp (+137 -0)
📝 runtime/test/title_memory_map_test.cpp (+44 -1)
📝 runtime/test/xmem_test.cpp (+32 -0)

📄 Description

Claimed in the coordination issue as: RT-TITLE-TEXTURE-MAP-GEN (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7188273837)

What and why

Device::title_texture_readable (runtime/shims/d3d12_vulkan_device.cpp) cached positive readability (generation = 0, cache_success = true) and relied solely on refresh_title_textures() (throttled to LEONIDA_TITLE_TEXTURE_PERIOD_MS = 16 ms ahead of ExecuteCommandLists) to drain leonida::title_memory_map::changes_since and call t.memory.retry().

When CopyPageMappingsBatchX or XMemMapPhysicalPages unmaps or maps 64 KiB tiles (title_memory_map::changed) and a title thread calls synchronous Slot-70 write_placed_texture_view (or the async fill worker runs) before the next 16 ms pass (!title_pass_):

  1. Unmap direction: title_texture_readable returned stale true without probing VirtualQuery, faulting inside hash_bytes (:239) while holding title_texture_mutex.
  2. Map direction: A texture previously marked pending() (cache_failure = true) returned stale false without re-probing until the next pass, delaying bindless publication of newly mapped tiles.
  3. Host guarded-read classification & no-builtin hardening: xmem::physical_page_fault (runtime/shims/xmem.cpp:1675) recorded read faults (access == 0) over unmapped window pages as FaultExit::left_to_title without checking title_code(pc), and mix_words / hash_bytes lacked LEONIDA_GUARDED_NO_BUILTIN (and called std::memcpy inside a __try callee).

Changes:

  • Track map_generation_ in TextureReadability::sync_map(pass_generation, cpu, size) (runtime/src/title_texture_memory.h), called from title_texture_readable when !title_pass_ && guard && !mapped. Unchanged generations cost one O(1) atomic load; non-overlapping map changes advance map_generation_ with 0 extra VirtualQuery probes; overlapping unmaps defer immediately (0 first-chance AVs) and overlapping maps wake pending textures immediately.
  • Add LEONIDA_GUARDED_NO_BUILTIN and a packed UnalignedWord64 load to mix_words / hash_bytes.
  • Check from_title (title_code(pc)) on access == 0 in xmem::physical_page_fault so host guarded reads exit via FaultExit::passed_guarded without false left_to_title counts, while title-code reads and all write faults retain left_to_title.

Tested

  • ctest --test-dir runtime/build -C RelWithDebInfo --output-on-failure:
    • title_memory_map: verifies sync_map (0 probes on non-overlapping change, immediate defer on overlapping unmap, immediate wake on overlapping map).
    • d3d12_existing_heap, d3d12_existing_heap_no_write_watch, d3d12_existing_heap_write_watch: new check_placed_view_map_changes case on both VK_EXT_host_image_copy and staged devices verifies 0 first-chance AVs via AddVectoredExceptionHandler after interior MEM_DECOMMIT + title_memory_map::changed on a 512 KiB (> 256 KiB sampled-hash) placed texture, and immediate bindless publication after MEM_COMMIT + title_memory_map::changed without ExecuteCommandLists.
    • xmem, xmem_pool_zero_read, xmem_no_write_watch, xmem_write_watch: new non-title executable-stub read test verifies FaultExit::passed_guarded increments with 0 left_to_title increments while title-image reads still increment left_to_title.
    • Full Windows CTest suite: 460 / 463 runnable tests pass (0 regressions vs main).
  • python -I tests/test_text_write_line_endings.py & python -I scripts/check_no_game_data.py across all 7 touched files (exit 0).

GPUs tested: NVIDIA GeForce RTX 3090, driver 610.88 (Vulkan 1.4.341), Windows 11 x64

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.

🔄 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/2240 **Author:** [@zmasi](https://github.com/zmasi) **Created:** 11/26/2026 **Status:** ✅ Merged **Merged:** 11/26/2026 **Merged by:** [@aslan2142](https://github.com/aslan2142) **Base:** `main` ← **Head:** `fix/title-texture-map-generation` --- ### 📝 Commits (1) - [`d088ea7`](https://github.com/ubiquitarianism/leonida/commit/d088ea79b8394c04a46ec19efb2922a7cd3faae3) Sync title texture readability with map journal between refresh passes ### 📊 Changes **7 files changed** (+258 additions, -12 deletions) <details> <summary>View changed files</summary> 📝 `runtime/shims/d3d12_vulkan_device.cpp` (+13 -5) 📝 `runtime/shims/xmem.cpp` (+5 -3) 📝 `runtime/shims/xmem.h` (+1 -1) 📝 `runtime/src/title_texture_memory.h` (+26 -2) 📝 `runtime/test/d3d12_existing_heap_test.cpp` (+137 -0) 📝 `runtime/test/title_memory_map_test.cpp` (+44 -1) 📝 `runtime/test/xmem_test.cpp` (+32 -0) </details> ### 📄 Description Claimed in the coordination issue as: `RT-TITLE-TEXTURE-MAP-GEN` (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7188273837) ### What and why `Device::title_texture_readable` (`runtime/shims/d3d12_vulkan_device.cpp`) cached positive readability (`generation = 0`, `cache_success = true`) and relied solely on `refresh_title_textures()` (throttled to `LEONIDA_TITLE_TEXTURE_PERIOD_MS = 16` ms ahead of `ExecuteCommandLists`) to drain `leonida::title_memory_map::changes_since` and call `t.memory.retry()`. When `CopyPageMappingsBatchX` or `XMemMapPhysicalPages` unmaps or maps 64 KiB tiles (`title_memory_map::changed`) and a title thread calls synchronous Slot-70 `write_placed_texture_view` (or the async fill worker runs) before the next 16 ms pass (`!title_pass_`): 1. **Unmap direction:** `title_texture_readable` returned stale `true` without probing `VirtualQuery`, faulting inside `hash_bytes` (`:239`) while holding `title_texture_mutex`. 2. **Map direction:** A texture previously marked `pending()` (`cache_failure = true`) returned stale `false` without re-probing until the next pass, delaying bindless publication of newly mapped tiles. 3. **Host guarded-read classification & no-builtin hardening:** `xmem::physical_page_fault` (`runtime/shims/xmem.cpp:1675`) recorded read faults (`access == 0`) over unmapped window pages as `FaultExit::left_to_title` without checking `title_code(pc)`, and `mix_words` / `hash_bytes` lacked `LEONIDA_GUARDED_NO_BUILTIN` (and called `std::memcpy` inside a `__try` callee). Changes: - Track `map_generation_` in `TextureReadability::sync_map(pass_generation, cpu, size)` (`runtime/src/title_texture_memory.h`), called from `title_texture_readable` when `!title_pass_ && guard && !mapped`. Unchanged generations cost one `O(1)` atomic load; non-overlapping map changes advance `map_generation_` with `0` extra `VirtualQuery` probes; overlapping unmaps defer immediately (`0` first-chance AVs) and overlapping maps wake pending textures immediately. - Add `LEONIDA_GUARDED_NO_BUILTIN` and a packed `UnalignedWord64` load to `mix_words` / `hash_bytes`. - Check `from_title` (`title_code(pc)`) on `access == 0` in `xmem::physical_page_fault` so host guarded reads exit via `FaultExit::passed_guarded` without false `left_to_title` counts, while title-code reads and all write faults retain `left_to_title`. ### Tested - `ctest --test-dir runtime/build -C RelWithDebInfo --output-on-failure`: - `title_memory_map`: verifies `sync_map` (`0` probes on non-overlapping change, immediate defer on overlapping unmap, immediate wake on overlapping map). - `d3d12_existing_heap`, `d3d12_existing_heap_no_write_watch`, `d3d12_existing_heap_write_watch`: new `check_placed_view_map_changes` case on both `VK_EXT_host_image_copy` and staged devices verifies `0` first-chance AVs via `AddVectoredExceptionHandler` after interior `MEM_DECOMMIT` + `title_memory_map::changed` on a `512 KiB` (`> 256 KiB` sampled-hash) placed texture, and immediate bindless publication after `MEM_COMMIT` + `title_memory_map::changed` without `ExecuteCommandLists`. - `xmem`, `xmem_pool_zero_read`, `xmem_no_write_watch`, `xmem_write_watch`: new non-title executable-stub read test verifies `FaultExit::passed_guarded` increments with `0` `left_to_title` increments while title-image reads still increment `left_to_title`. - Full Windows CTest suite: `460 / 463` runnable tests pass (`0` regressions vs `main`). - `python -I tests/test_text_write_line_endings.py` & `python -I scripts/check_no_game_data.py` across all 7 touched files (exit 0). GPUs tested: NVIDIA GeForce RTX 3090, driver 610.88 (Vulkan 1.4.341), Windows 11 x64 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. - [x] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 21:20:32 +01:00
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#2244
No description provided.