d3d12: a console heap's V# words are fixed once a pass, not once a slot (RT-CONSOLE-VSHARP-MEMO) #2117

Open
github-bot wants to merge 1 commit from github-bot/gh-2117 into main AGit
Owner

@⁠azsekazvamdimitar on GitHub · 2026-11-25 21:24 UTC · original
azsekazvamdimitar:console-vsharp-memo → main · +61 −12 · 2 files · 1 commits · draft

Claimed in the coordination issue as: RT-CONSOLE-VSHARP-MEMO (#1608)

What and why

After the story load, most of refresh_console_heap's time ("fixing copied slots" in its log line) goes to fix_vsharp on words the title repeats across thousands of slots of its console descriptor heap. Many are data that reads as a buffer V# into title memory with no copy: on my retail boot 3,000-27,000 of them a submission ("with no copy given no records"), most with identical words. Each one goes through vsharp_address into resolve_title_memory / resolve_pool_memory, which call VirtualQuery, and a failure adds no alias, so the next slot with the same words pays again. Under Wine VirtualQuery is slow: with LEONIDA_SAMPLE_MS=10 a third of the submitting thread's samples were VirtualQuery under fix_console_slot.

fix_heap_vsharp asks fix_vsharp once for each distinct V# (all four words) in a pass over a heap's slots and gives later slots with the same words the same answer. The answers last one pass: they are dropped after the pass over the copied slots, again after the invalidation pass (which runs because a buffer was released or an alias went), and are not used by the retries or the empty-slot probe. The log line gains "answered by an earlier slot of the pass".

The same retail boot, 900 s each, RTX 3090, GE-Proton, main db1a22d29 with #1851, #1957 and #1867, LEONIDA_ASYNC_PIPELINES=1, LEONIDA_TITLE_WATCHDOG=0, LEONIDA_TITLE_WINDOWS_MB/LEONIDA_ARENA_MB 4096, thread sampler on in both:

after the story load without with this pull request
heap refresh a submission (heaps in the submit-phase lines) 107.8 ms (max 5,332) 18.8 ms (max 1,109)
share of the submit wall time 31% 7%
submissions (from 120 s to 900 s) 1,977 2,527
presents in the run 4,929 5,614
device lost no no

One run each. The slot-133 shadow refresh (about 200-230 ms a submission) is now the larger cost; this doesn't touch it.

Tested

  • d3d12_unmapped_vsharp: its console heap already holds 128 identical unmapped V#s, which now take one answer between them. It gains a check that a slot written later with the words the first refresh had no copy for is fixed again once their alias exists: it fails when the answers are kept across refreshes, and passes with this change.
  • On this branch (rebased on main a73a57e13), cross-built with clang-cl: d3d12_unmapped_vsharp, d3d12_console_descriptor_heap and console_heap_vsharp_slots pass under WineHQ 11.22 (winewayland) and GE-Proton11-14 (winex11); console_heap_vsharp_slots passes natively on Linux.
  • The boot numbers are from the same change on db1a22d29. Not run on Windows.

GPUs tested: NVIDIA GeForce RTX 3090, driver 590.48.01, Debian 13 (Linux 6.12), Wine/Proton as above.

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.
**@⁠azsekazvamdimitar** on GitHub · 2026-11-25 21:24 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2117) `azsekazvamdimitar:console-vsharp-memo` → `main` · +61 −12 · 2 files · 1 commits · draft Claimed in the coordination issue as: RT-CONSOLE-VSHARP-MEMO (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608) ### What and why After the story load, most of `refresh_console_heap`'s time ("fixing copied slots" in its log line) goes to `fix_vsharp` on words the title repeats across thousands of slots of its console descriptor heap. Many are data that reads as a buffer V# into title memory with no copy: on my retail boot 3,000-27,000 of them a submission ("with no copy given no records"), most with identical words. Each one goes through `vsharp_address` into `resolve_title_memory` / `resolve_pool_memory`, which call VirtualQuery, and a failure adds no alias, so the next slot with the same words pays again. Under Wine VirtualQuery is slow: with `LEONIDA_SAMPLE_MS=10` a third of the submitting thread's samples were VirtualQuery under `fix_console_slot`. `fix_heap_vsharp` asks `fix_vsharp` once for each distinct V# (all four words) in a pass over a heap's slots and gives later slots with the same words the same answer. The answers last one pass: they are dropped after the pass over the copied slots, again after the invalidation pass (which runs because a buffer was released or an alias went), and are not used by the retries or the empty-slot probe. The log line gains "answered by an earlier slot of the pass". The same retail boot, 900 s each, RTX 3090, GE-Proton, main db1a22d29 with #1851, #1957 and #1867, `LEONIDA_ASYNC_PIPELINES=1`, `LEONIDA_TITLE_WATCHDOG=0`, `LEONIDA_TITLE_WINDOWS_MB`/`LEONIDA_ARENA_MB` 4096, thread sampler on in both: | after the story load | without | with this pull request | |---|---|---| | heap refresh a submission (`heaps` in the submit-phase lines) | 107.8 ms (max 5,332) | 18.8 ms (max 1,109) | | share of the submit wall time | 31% | 7% | | submissions (from 120 s to 900 s) | 1,977 | 2,527 | | presents in the run | 4,929 | 5,614 | | device lost | no | no | One run each. The slot-133 shadow refresh (about 200-230 ms a submission) is now the larger cost; this doesn't touch it. ### Tested - `d3d12_unmapped_vsharp`: its console heap already holds 128 identical unmapped V#s, which now take one answer between them. It gains a check that a slot written later with the words the first refresh had no copy for is fixed again once their alias exists: it fails when the answers are kept across refreshes, and passes with this change. - On this branch (rebased on main a73a57e13), cross-built with clang-cl: `d3d12_unmapped_vsharp`, `d3d12_console_descriptor_heap` and `console_heap_vsharp_slots` pass under WineHQ 11.22 (winewayland) and GE-Proton11-14 (winex11); `console_heap_vsharp_slots` passes natively on Linux. - The boot numbers are from the same change on db1a22d29. Not run on Windows. GPUs tested: NVIDIA GeForce RTX 3090, driver 590.48.01, Debian 13 (Linux 6.12), Wine/Proton as above. 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.
The title writes the same words into thousands of slots of its console
descriptor heap, many of them data that reads as a V# into title memory
with no copy, and each fix_vsharp of those costs VirtualQuery calls: a
third of the submitting thread's time after the story load under Wine.
refresh_console_heap now keeps fix_vsharp's answers for the pass over the
copied slots and, separately, for the invalidation pass, and drops them
after each.

Retail boot, Proton, RTX 3090, 900 s: heap refresh after the story load
107.8 -> 18.8 ms a submission (max 5,332 -> 1,109), submissions after it
1,977 -> 2,527.

AI-assisted; tested under WineHQ 11.22 and GE-Proton11-14 on an RTX 3090
(NVIDIA 590.48.01).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:18:26 +00:00
Author
Owner

@⁠qhukz13 on GitHub · 2026-11-25 22:59 UTC · original

Review at ad58ebc86 (code reading plus a native Windows run, see the end).

  • The memo is complete: fix_vsharp writes only words 0-2 (w[0] = w[1] = w[2] = 0 for an empty answer, w[0]/w[1] when rebased), and the key holds all four words, so a slot answered from answers ends up with the same words as the first one with the same V#. The path cannot differ within a heap (heap.scratch is fixed), and answers is cleared after the copied-slots pass and after the invalidation pass, as described.
  • One thing that only lasts a pass: within one pass, an earlier slot's V# can make a window or alias that would now back a later V# whose words were already answered "empty" by a slot before it. The memo then gives the later slot "empty" too. Those slots are unsettled and go to retry_console_slots, which does not use the memo, so it heals there; just noting it, no change needed.
  • std::unordered_map::clear() keeps the bucket array, so the per-pass map does not rehash every submission. Good.

Native Windows run, since the description has Wine only: GTX 1050 Ti, Windows 10 Pro 19045, NVIDIA 582.66, MSVC RelWithDebInfo, this head merged onto main 5fab93967 (clean). d3d12_unmapped_vsharp (including the new rewritten-slot check), d3d12_console_descriptor_heap, console_heap_vsharp_slots, d3d12_title_va, d3d12_title_window_cap, d3d12_api_descriptor_copy, d3d12_rebound_tables, d3d12_title_index_window, d3d12_title_vertex_window and xbox_geometry_upload_batch: 10/10, 3 runs each, plain and with LEONIDA_VK_VALIDATION=1, no validation messages. No timings here (no retail run on this machine yet).

AI-assisted (Claude Code).

**@⁠qhukz13** on GitHub · 2026-11-25 22:59 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2117#issuecomment-7177012579) Review at `ad58ebc86` (code reading plus a native Windows run, see the end). - The memo is complete: `fix_vsharp` writes only words 0-2 (`w[0] = w[1] = w[2] = 0` for an empty answer, `w[0]`/`w[1]` when rebased), and the key holds all four words, so a slot answered from `answers` ends up with the same words as the first one with the same V#. The path cannot differ within a heap (`heap.scratch` is fixed), and `answers` is cleared after the copied-slots pass and after the invalidation pass, as described. - One thing that only lasts a pass: within one pass, an earlier slot's V# can make a window or alias that would now back a later V# whose words were already answered "empty" by a slot before it. The memo then gives the later slot "empty" too. Those slots are unsettled and go to `retry_console_slots`, which does not use the memo, so it heals there; just noting it, no change needed. - `std::unordered_map::clear()` keeps the bucket array, so the per-pass map does not rehash every submission. Good. Native Windows run, since the description has Wine only: GTX 1050 Ti, Windows 10 Pro 19045, NVIDIA 582.66, MSVC RelWithDebInfo, this head merged onto main `5fab93967` (clean). `d3d12_unmapped_vsharp` (including the new rewritten-slot check), `d3d12_console_descriptor_heap`, `console_heap_vsharp_slots`, `d3d12_title_va`, `d3d12_title_window_cap`, `d3d12_api_descriptor_copy`, `d3d12_rebound_tables`, `d3d12_title_index_window`, `d3d12_title_vertex_window` and `xbox_geometry_upload_batch`: 10/10, 3 runs each, plain and with `LEONIDA_VK_VALIDATION=1`, no validation messages. No timings here (no retail run on this machine yet). AI-assisted (Claude Code).
github-bot force-pushed github-bot/gh-2117 from f71c29bbb5 to ecc72eef71 2026-11-26 11:25:02 +00:00 Compare
Author
Owner

@⁠OreoFR on GitHub · 2026-11-27 00:01 UTC · original

Data point from Windows/NVIDIA, which shows this isn't only a Wine cost. RTX 4070 Laptop, NVIDIA 621.40, main d1dff7949, with the world recipe from docs/running.md (LEONIDA_ARENA_MB=4095, LEONIDA_TITLE_WINDOWS_MB=4096, LEONIDA_GEOMETRY_MB=6144): 308 title windows, against 3 with the default 64 MiB.

During the story load, at the stall, refresh_console_heap shows:

  • (copy): ... 373.4 KiB each in 388.243 ms on average (... fixing copied slots 385.282 ...)
  • changed slots per submission: ... 8928.6 V# pairs ...; V# resolutions since the last line: alias 10181, alias refused 1133, arena 48623, ...

The heaps phase peaked at 5,342 ms per submission (max 6,274), and the title's main loop starved (finding in #1608: #1608). With the 64 MiB default the heap copy averaged 59 ms, so more windows make "fixing copied slots" much heavier, and that is this PR's case. It now conflicts with main. If you rebase it, I can run it with the same recipe and post before/after numbers. AI-assisted (Claude Code, Claude Opus 5.5).

**@⁠OreoFR** on GitHub · 2026-11-27 00:01 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2117#issuecomment-7206107971) Data point from Windows/NVIDIA, which shows this isn't only a Wine cost. RTX 4070 Laptop, NVIDIA 621.40, `main` `d1dff7949`, with the world recipe from `docs/running.md` (`LEONIDA_ARENA_MB=4095`, `LEONIDA_TITLE_WINDOWS_MB=4096`, `LEONIDA_GEOMETRY_MB=6144`): 308 title windows, against 3 with the default 64 MiB. During the story load, at the stall, `refresh_console_heap` shows: - `(copy): ... 373.4 KiB each in 388.243 ms on average (... fixing copied slots 385.282 ...)` - `changed slots per submission: ... 8928.6 V# pairs ...; V# resolutions since the last line: alias 10181, alias refused 1133, arena 48623, ...` The heaps phase peaked at 5,342 ms per submission (max 6,274), and the title's main loop starved (finding in #1608: https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608). With the 64 MiB default the heap copy averaged 59 ms, so more windows make "fixing copied slots" much heavier, and that is this PR's case. It now conflicts with `main`. If you rebase it, I can run it with the same recipe and post before/after numbers. AI-assisted (Claude Code, Claude Opus 5.5).
github-bot force-pushed github-bot/gh-2117 from ecc72eef71 to 2a191041ff 2026-11-27 11:04:38 +00:00 Compare
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2117/head:github-bot/gh-2117'
git switch 'github-bot/gh-2117'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2117'
git switch 'github-bot/gh-2117'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2117'
git switch 'github-bot/gh-2117'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2117'
git switch 'main'
git merge --squash 'github-bot/gh-2117'
git switch 'main'
git merge --ff-only 'github-bot/gh-2117'
git switch 'main'
git merge 'github-bot/gh-2117'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.