[PR #2407] [MERGED] d3d12: console heap slots record what their V#s resolved to; a release re-fixes only the slots naming it (RT-VSHARP-SLOT-RECORDS) #2407

Closed
opened 2026-11-26 22:36:08 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

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

Base: main ← Head: vsharp-slot-records


📝 Commits (1)

  • 84db5cd d3d12: console heap slots record what their V#s resolved to; a release re-fixes only the slots naming it (RT-VSHARP-SLOT-RECORDS)

📊 Changes

14 files changed (+909 additions, -770 deletions)

View changed files

📝 docs/d3d12_vulkan.md (+12 -2)
📝 docs/running.md (+1 -1)
📝 runtime/CMakeLists.txt (+4 -4)
📝 runtime/README.md (+1 -2)
📝 runtime/shims/d3d12_vulkan_device.cpp (+172 -203)
➕ runtime/src/console_heap_slot_records.h (+227 -0)
➖ runtime/src/console_heap_vsharp_slots.h (+0 -115)
➖ runtime/src/descriptor_range_changes.h (+0 -46)
📝 runtime/src/title_va_alias.h (+31 -16)
➕ runtime/test/console_heap_slot_records_test.cpp (+347 -0)
➖ runtime/test/console_heap_vsharp_slots_test.cpp (+0 -334)
📝 runtime/test/d3d12_unmapped_vsharp_test.cpp (+63 -15)
📝 runtime/test/geometry_views_test.cpp (+15 -11)
📝 runtime/test/title_va_alias_test.cpp (+36 -21)

📄 Description

A console heap's copy now keeps a record per V# of what it resolved to. A released buffer, a removed alias range or a
retired copy re-fixes only the slots that name it. Before this, every live slot of the heap was walked. Nothing walks
the heap any more.

Claimed in the coordination issue as: RT-VSHARP-SLOT-RECORDS

What was wrong

  • After any arena release, title-window or geometry block destroyed, or alias change, the next submission walked
    every live V# slot of the console heap: about 580,000 in our world runs.
  • With LEONIDA_CONSOLE_RELEASE_FILTER=1, the walk read words 0-2 of both halves of each slot from heap.copy. That
    copy is in ReBAR VRAM, so these were uncached reads. Without the variable, it fixed every live slot again.
  • One walk took 1.1-1.5 s whatever the scene. It did not get faster when it re-fixed 4,400 slots instead of 9,100.
  • In one world run, the walk was about 91% of the heap phase and about 2.9 s of a 4.6 s frame. The heap refresh lock
    was held for about 70% of the wall time.
  • The walk existed only because nothing recorded which slot had resolved to which backing.

What changes

  • runtime/src/console_heap_slot_records.h (new, portable). For each V# half (the buffer V# and the UAV counter),
    a record of:
    • the title's base and span;
    • the device address its copy names;
    • its state: resolved, waiting or none.
  • Two indexes, one by base and one by target. Each indexes per power-of-two span class and per granule of at least
    64 KiB, so a range lookup visits only the entries near the range.
  • The records are in host RAM and allocated with calloc, so pages for slots that are never written stay untouched.
  • fix_console_slot is still the only writer of a slot's copy, and now also the only writer of its records.
    • A zeroed range, a slot the fix budget deferred and a rewritten slot drop their records.
    • A destroyed heap takes its records with it.
  • Changes go on an unbounded per-device list. They are recorded under the locks the code already takes, with a leaf
    mutex for the list:
    • backing() add and release;
    • title_block_gone;
    • alias ranges added, removed or replaced, and forget_copy: TitleVaAliases now tells listeners as each change
      happens;
    • title memory added.
  • At each submission, refresh_console_heaps takes the whole list and every heap re-fixes exactly the slots it
    touches:
    • a release or removal: every half that names the range;
    • an addition: the waiting halves over the range.
  • A V# whose buffer or alias arrives after the descriptor is fixed at the next submission. Before, it waited for a
    probe of 8 slots every 32 submissions.
  • New heap log line, every 10 s: slot records per submission: N changes, N slots looked at, N fixed again, N ms.
  • This is a root fix: no new environment variable, no switch, and the old walk is not kept as a fallback.
  • Credit to VIctory (marvisak/victory) for the idea of per-slot records instead of a sweep. No code was taken from it.

What is removed

  • The live_vsharps walk and its bitset: src/console_heap_vsharp_slots.h and its test.
  • LEONIDA_CONSOLE_RELEASE_FILTER and its README row. LEONIDA_CONSOLE_GPU_FILTER (GPU heap pass, opt-in) now
    defaults to unset instead of copying that variable's value.
  • The release generation checks: released_backings and TitleVaAliases::invalidations().
  • The 4,096-entry DescriptorRangeChanges ring (src/descriptor_range_changes.h), whose overflow fell back to a full
    sweep, and changed_ranges().
  • The empty-slot probe (8 slots every 32 submissions) and retry_unmapped_slots. The second was never reached: no
    caller set its unmapped flag.
  • Kept: retry_console_slots, the T# retries. Textures are not backings, so they need their own index (step A3).

Tests

  • New console_heap_slot_records_test (portable, CPU only):
    • 60,010 recorded slots, 10 of them name buffer B. Releasing B looks at 10 entries and fixes 10 slots.
    • Cases: an alias moved, removed and added again; a slot overwritten after it was recorded; a zeroed slot; a release
      that only partly overlaps a slot's range; two slots naming the same backing; a buffer that comes back; a refused
      alias copy that is backed later; a large span; a destroyed heap.
    • A randomised differential case: after each of 400 rounds, the copy must equal a full re-resolution of every slot.
    • A mutation that drops releases fails it.
  • d3d12_unmapped_vsharp_test (Wine/Windows):
    • Before, it expected the round-robin probe to restore 16 of 128 waiting slots in 64 submissions. Now it expects
      all 128 restored at the first submission after their alias is added, and none after it is removed.
    • New case: the 10 slots naming a released committed buffer are null after the release; 10 other slots are kept.
  • title_va_alias_test and geometry_views_test check the listener in place of the ring and the invalidation counter.
  • Linux runtime build and ctest (RelWithDebInfo, Ryzen 9 7950X3D iGPU, RADV, Mesa 26.3.1): 113 of 113 pass,
    2 skipped (as on main).
  • Windows runtime, clang-cl with xwin under Wine, on the same iGPU and RADV, compared test by test with main
    2d43417d4: 423 pass, 23 fail, 39 skipped on both. The 23 failures are the same presentation, bcrypt and
    file-system tests as on main. The only differences are console_heap_slot_records added and
    console_heap_vsharp_slots removed. No test went from pass to fail.
  • tests/test_ci_registration.py, tests/test_docs_*.py, tests/test_text_write_line_endings.py and
    scripts/check_no_game_data.py on the changed files all pass.

World run

RX 7900 XTX, RADV (Mesa 26.3.1), Wine, from a local build of main fac8b4bb9 with this change and two others (RT-BINDLESS-DIMENSION-LIMITS and #2230), same settings as a run of plain main:

  • No rescans and no CPU release filter lines in the whole run.
  • The heaps phase of submit phases is 2.2 to 2.4 ms per submission in the world, where plain main had 32 to 321 ms at the same run time.
  • slot records per submission shows changes arriving and slots fixed again (for example 19.6 changes, 4,610 slots looked at, 22.5 fixed again, 0.074 ms).
  • In the busiest windows 83,000 to 397,000 slots are looked at for 1,450 to 3,150 fixed: the index buckets are coarse there. That is a performance follow-up, not a correctness problem.
  • The run ended about 100 s into the world in a graphics-ring timeout with every queue idle in the dispatch markers. That hang also ends runs of plain main here (three of nine earlier runs). In the windows before it there were no slot changes at all, and the paths that release or move a backing were checked again against the code; nothing shows this change as its cause. The run did not reach play, so the frame time in play is not measured yet.

Not tested

  • Frame time in play: the run ended before it. To read in a later run:
    • no rescans and no CPU release filter lines;
    • the slot records per submission line: slots looked at in the thousands, not about 580,000;
    • heaps ms per submission in submit phases;
    • the frame time.
  • MSVC was not run locally. The Windows build is clang-cl with xwin, under Wine.

AI-assisted (Claude Code, Claude Opus 5.5 and Claude Fable 5.2)


🔄 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/2407 **Author:** [@aslan2142](https://github.com/aslan2142) **Created:** 11/26/2026 **Status:** ✅ Merged **Merged:** 11/26/2026 **Merged by:** [@aslan2142](https://github.com/aslan2142) **Base:** `main` ← **Head:** `vsharp-slot-records` --- ### 📝 Commits (1) - [`84db5cd`](https://github.com/ubiquitarianism/leonida/commit/84db5cd02736759eab9ffb4deedc98c52027c050) d3d12: console heap slots record what their V#s resolved to; a release re-fixes only the slots naming it (RT-VSHARP-SLOT-RECORDS) ### 📊 Changes **14 files changed** (+909 additions, -770 deletions) <details> <summary>View changed files</summary> 📝 `docs/d3d12_vulkan.md` (+12 -2) 📝 `docs/running.md` (+1 -1) 📝 `runtime/CMakeLists.txt` (+4 -4) 📝 `runtime/README.md` (+1 -2) 📝 `runtime/shims/d3d12_vulkan_device.cpp` (+172 -203) ➕ `runtime/src/console_heap_slot_records.h` (+227 -0) ➖ `runtime/src/console_heap_vsharp_slots.h` (+0 -115) ➖ `runtime/src/descriptor_range_changes.h` (+0 -46) 📝 `runtime/src/title_va_alias.h` (+31 -16) ➕ `runtime/test/console_heap_slot_records_test.cpp` (+347 -0) ➖ `runtime/test/console_heap_vsharp_slots_test.cpp` (+0 -334) 📝 `runtime/test/d3d12_unmapped_vsharp_test.cpp` (+63 -15) 📝 `runtime/test/geometry_views_test.cpp` (+15 -11) 📝 `runtime/test/title_va_alias_test.cpp` (+36 -21) </details> ### 📄 Description A console heap's copy now keeps a record per V# of what it resolved to. A released buffer, a removed alias range or a retired copy re-fixes only the slots that name it. Before this, every live slot of the heap was walked. Nothing walks the heap any more. Claimed in the coordination issue as: [RT-VSHARP-SLOT-RECORDS](https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7201355992) ## What was wrong - After any arena release, title-window or geometry block destroyed, or alias change, the next submission walked every live V# slot of the console heap: about 580,000 in our world runs. - With `LEONIDA_CONSOLE_RELEASE_FILTER=1`, the walk read words 0-2 of both halves of each slot from `heap.copy`. That copy is in ReBAR VRAM, so these were uncached reads. Without the variable, it fixed every live slot again. - One walk took 1.1-1.5 s whatever the scene. It did not get faster when it re-fixed 4,400 slots instead of 9,100. - In one world run, the walk was about 91% of the heap phase and about 2.9 s of a 4.6 s frame. The heap refresh lock was held for about 70% of the wall time. - The walk existed only because nothing recorded which slot had resolved to which backing. ## What changes - `runtime/src/console_heap_slot_records.h` (new, portable). For each V# half (the buffer V# and the UAV counter), a record of: - the title's base and span; - the device address its copy names; - its state: resolved, waiting or none. - Two indexes, one by base and one by target. Each indexes per power-of-two span class and per granule of at least 64 KiB, so a range lookup visits only the entries near the range. - The records are in host RAM and allocated with `calloc`, so pages for slots that are never written stay untouched. - `fix_console_slot` is still the only writer of a slot's copy, and now also the only writer of its records. - A zeroed range, a slot the fix budget deferred and a rewritten slot drop their records. - A destroyed heap takes its records with it. - Changes go on an unbounded per-device list. They are recorded under the locks the code already takes, with a leaf mutex for the list: - `backing()` add and release; - `title_block_gone`; - alias ranges added, removed or replaced, and `forget_copy`: `TitleVaAliases` now tells listeners as each change happens; - title memory added. - At each submission, `refresh_console_heaps` takes the whole list and every heap re-fixes exactly the slots it touches: - a release or removal: every half that names the range; - an addition: the waiting halves over the range. - A V# whose buffer or alias arrives after the descriptor is fixed at the next submission. Before, it waited for a probe of 8 slots every 32 submissions. - New heap log line, every 10 s: `slot records per submission: N changes, N slots looked at, N fixed again, N ms`. - This is a root fix: no new environment variable, no switch, and the old walk is not kept as a fallback. - Credit to VIctory (marvisak/victory) for the idea of per-slot records instead of a sweep. No code was taken from it. ## What is removed - The `live_vsharps` walk and its bitset: `src/console_heap_vsharp_slots.h` and its test. - `LEONIDA_CONSOLE_RELEASE_FILTER` and its README row. `LEONIDA_CONSOLE_GPU_FILTER` (GPU heap pass, opt-in) now defaults to unset instead of copying that variable's value. - The release generation checks: `released_backings` and `TitleVaAliases::invalidations()`. - The 4,096-entry `DescriptorRangeChanges` ring (`src/descriptor_range_changes.h`), whose overflow fell back to a full sweep, and `changed_ranges()`. - The empty-slot probe (8 slots every 32 submissions) and `retry_unmapped_slots`. The second was never reached: no caller set its `unmapped` flag. - Kept: `retry_console_slots`, the T# retries. Textures are not backings, so they need their own index (step A3). ## Tests - New `console_heap_slot_records_test` (portable, CPU only): - 60,010 recorded slots, 10 of them name buffer B. Releasing B looks at 10 entries and fixes 10 slots. - Cases: an alias moved, removed and added again; a slot overwritten after it was recorded; a zeroed slot; a release that only partly overlaps a slot's range; two slots naming the same backing; a buffer that comes back; a refused alias copy that is backed later; a large span; a destroyed heap. - A randomised differential case: after each of 400 rounds, the copy must equal a full re-resolution of every slot. - A mutation that drops releases fails it. - `d3d12_unmapped_vsharp_test` (Wine/Windows): - Before, it expected the round-robin probe to restore 16 of 128 waiting slots in 64 submissions. Now it expects all 128 restored at the first submission after their alias is added, and none after it is removed. - New case: the 10 slots naming a released committed buffer are null after the release; 10 other slots are kept. - `title_va_alias_test` and `geometry_views_test` check the listener in place of the ring and the invalidation counter. - Linux runtime build and `ctest` (RelWithDebInfo, Ryzen 9 7950X3D iGPU, RADV, Mesa 26.3.1): 113 of 113 pass, 2 skipped (as on `main`). - Windows runtime, clang-cl with xwin under Wine, on the same iGPU and RADV, compared test by test with `main` `2d43417d4`: 423 pass, 23 fail, 39 skipped on both. The 23 failures are the same presentation, bcrypt and file-system tests as on `main`. The only differences are `console_heap_slot_records` added and `console_heap_vsharp_slots` removed. No test went from pass to fail. - `tests/test_ci_registration.py`, `tests/test_docs_*.py`, `tests/test_text_write_line_endings.py` and `scripts/check_no_game_data.py` on the changed files all pass. ## World run RX 7900 XTX, RADV (Mesa 26.3.1), Wine, from a local build of `main` `fac8b4bb9` with this change and two others (RT-BINDLESS-DIMENSION-LIMITS and #2230), same settings as a run of plain `main`: - No `rescans` and no `CPU release filter` lines in the whole run. - The heaps phase of `submit phases` is 2.2 to 2.4 ms per submission in the world, where plain `main` had 32 to 321 ms at the same run time. - `slot records per submission` shows changes arriving and slots fixed again (for example 19.6 changes, 4,610 slots looked at, 22.5 fixed again, 0.074 ms). - In the busiest windows 83,000 to 397,000 slots are looked at for 1,450 to 3,150 fixed: the index buckets are coarse there. That is a performance follow-up, not a correctness problem. - The run ended about 100 s into the world in a graphics-ring timeout with every queue idle in the dispatch markers. That hang also ends runs of plain `main` here (three of nine earlier runs). In the windows before it there were no slot changes at all, and the paths that release or move a backing were checked again against the code; nothing shows this change as its cause. The run did not reach play, so the frame time in play is not measured yet. ## Not tested - Frame time in play: the run ended before it. To read in a later run: - no `rescans` and no `CPU release filter` lines; - the `slot records per submission` line: slots looked at in the thousands, not about 580,000; - heaps ms per submission in `submit phases`; - the frame time. - MSVC was not run locally. The Windows build is clang-cl with xwin, under Wine. AI-assisted (Claude Code, Claude Opus 5.5 and Claude Fable 5.2) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 changed title from [PR #2407] d3d12: console heap slots record what their V#s resolved to; a release re-fixes only the slots naming it (RT-VSHARP-SLOT-RECORDS) to [PR #2407] [MERGED] d3d12: console heap slots record what their V#s resolved to; a release re-fixes only the slots naming it (RT-VSHARP-SLOT-RECORDS) 2026-11-26 22:46:10 +01:00
4ld0 closed this issue 2026-11-26 22:46:10 +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#2407
No description provided.