[PR #1694] vulkan_present: the capture buffer is made of host-cached memory (RT-PRESENT-CAPTURE-CACHED) #1708

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

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1694
Author: @DadaCap
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: present-capture-cached


📝 Commits (1)

  • 3768be5 vulkan_present: the capture buffer is made of host-cached memory (RT-PRESENT-CAPTURE-CACHED)

📊 Changes

1 file changed (+11 additions, -4 deletions)

View changed files

📝 runtime/src/vulkan_present.h (+11 -4)

📄 Description

Claimed in the coordination issue as: RT-PRESENT-CAPTURE-CACHED (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7157004451)

What and why

VulkanPresenter::make_capture_buffer took the first memory type that is host visible and coherent. On NVIDIA the first such type is uncached (flags 0x6 on this RTX 5080; the cached one, 0xe, comes after it), and a host read of uncached memory is many times slower than of cached memory.

That did not matter much while the buffer was read once per capture. Since the launch splash (#939), finish_startup_frame reads the whole buffer on the CPU for every frame the title presents before its first non-black one, with the submit and tracker locks held. On a large window that scan takes over the boot:

  • one title thread sits in the scan at 97 % CPU (29 of 30 samples of an external sampler, and the same frame in two LEONIDA_STACKS dumps 20 s apart: submit_now -> present -> PresentX);
  • the other submissions starve: device-stall: could not sample the submit lock for 15 s; submitted ticket 424, last observed retired ticket 328;
  • the title's game state stays 2, it never accepts A, and its hang watchdog ends the run at the landing screen.

The change: choose a host-cached, non-device-local type first and fall back to the first host-visible coherent one, exactly as probe_read_source in the same file already does. One function, 11 lines.

Measured

Native Windows 11, RTX 5080 16 GB, NVIDIA 621.24, 64 GB, own 1.0.2.1, MSVC RelWithDebInfo with SDL3. Window client area 3824x1841 when the first frame is presented. Every run: keyboard pad with A every 5 s from 30 s, LEONIDA_SKIP_INT3=1, LEONIDA_PEEK=0x7446510,0x98f828c, an existing save, shaders from main's translator.

tree switches game state 3 A accepted (session d) how the run ends
main 3f81d46ac LEONIDA_TITLE_WINDOWS_MB=4096 LEONIDA_ARENA_MB=4096 LEONIDA_DEVICE_FAULT=1 never never title's hang watchdog at 125.8 s, still at the landing screen; fewer than 1,500 presents in the whole run
main + #1558 + #1631 LEONIDA_ARENA_MB=2048 never never watchdog at 107.8 s; a second run was still at the landing screen at its 160 s limit
main + #1558 + #1631, LEONIDA_WINDOW=960x540 (no code change, 14 times fewer texels to scan) LEONIDA_ARENA_MB=2048 95 s 105 s reaches the world phase
main + #1558 + #1631 + this change LEONIDA_ARENA_MB=2048 25 s 35 s reaches the world phase; 1,501 presents by about 22 s
main + this change only (this branch) same as the first row 25 s 35 s story load reads from about 35 s to 90 s, then the world phase; the run ends at 179.8 s on the title's hang watchdog there, which is the stop already described in #1537, not this one

So on this machine the first and last rows differ only by this commit. Before #939 (main 3ff2a2adc) the same launcher passed the landing screen every time, which is how I found it.

It probably costs time on smaller windows too, in proportion to the texel count: the report on #939 of 182 to 362 PresentX in 51 to 74 s on an RTX 4070 SUPER is a few presents a second. I have not measured another machine.

Tested

  • The ten presenter tests of runtime/ pass on this branch on the same GPU: xbox_present_readback_size, vk_presenter_capture_colour, present_window, xs_present_lazy, vk_present_dump, vk_present_dump_default, vk_present_dump_invalid, vk_presenter_sync, d3d12_present, xbox_present.
  • The real boot, as in the table. No new test: which memory type a driver lists first is a property of the device, and the effect only shows with a real swapchain and the title presenting black frames.

Not done, not tested

  • The scan itself still runs under the submit and tracker locks; this only makes it fast. Moving it out of the locks, or ending it earlier, is a separate change I am not claiming.
  • AMD, Intel, Linux: not run. On a device whose first host-visible coherent type is already cached, nothing changes.
  • I did not time the scan in isolation; the evidence is the thread samples and the before/after boots.
  • #1223 adds a guard in the same function, a few lines above; the two do not overlap.

Counters, switch names and addresses of the executable only; no game data. AI-assisted (Claude Code).

🤖 Generated with Claude Code


🔄 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/1694 **Author:** [@DadaCap](https://github.com/DadaCap) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `present-capture-cached` --- ### 📝 Commits (1) - [`3768be5`](https://github.com/ubiquitarianism/leonida/commit/3768be5020d4d142bbb3fddfd781a1b252a18af7) vulkan_present: the capture buffer is made of host-cached memory (RT-PRESENT-CAPTURE-CACHED) ### 📊 Changes **1 file changed** (+11 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `runtime/src/vulkan_present.h` (+11 -4) </details> ### 📄 Description Claimed in the coordination issue as: RT-PRESENT-CAPTURE-CACHED (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7157004451) ### What and why `VulkanPresenter::make_capture_buffer` took the first memory type that is host visible and coherent. On NVIDIA the first such type is uncached (flags `0x6` on this RTX 5080; the cached one, `0xe`, comes after it), and a host read of uncached memory is many times slower than of cached memory. That did not matter much while the buffer was read once per capture. Since the launch splash (#939), `finish_startup_frame` reads the whole buffer on the CPU for **every frame the title presents before its first non-black one**, with the submit and tracker locks held. On a large window that scan takes over the boot: - one title thread sits in the scan at 97 % CPU (29 of 30 samples of an external sampler, and the same frame in two `LEONIDA_STACKS` dumps 20 s apart: `submit_now` -> `present` -> `PresentX`); - the other submissions starve: `device-stall: could not sample the submit lock for 15 s; submitted ticket 424, last observed retired ticket 328`; - the title's game state stays 2, it never accepts A, and its hang watchdog ends the run at the landing screen. The change: choose a host-cached, non-device-local type first and fall back to the first host-visible coherent one, exactly as `probe_read_source` in the same file already does. One function, 11 lines. ### Measured Native Windows 11, RTX 5080 16 GB, NVIDIA 621.24, 64 GB, own 1.0.2.1, MSVC RelWithDebInfo with SDL3. Window client area 3824x1841 when the first frame is presented. Every run: keyboard pad with A every 5 s from 30 s, `LEONIDA_SKIP_INT3=1`, `LEONIDA_PEEK=0x7446510,0x98f828c`, an existing save, shaders from `main`'s translator. | tree | switches | game state 3 | A accepted (session `d`) | how the run ends | |---|---|---|---|---| | `main` 3f81d46ac | `LEONIDA_TITLE_WINDOWS_MB=4096 LEONIDA_ARENA_MB=4096 LEONIDA_DEVICE_FAULT=1` | never | never | title's hang watchdog at 125.8 s, still at the landing screen; fewer than 1,500 presents in the whole run | | `main` + #1558 + #1631 | `LEONIDA_ARENA_MB=2048` | never | never | watchdog at 107.8 s; a second run was still at the landing screen at its 160 s limit | | `main` + #1558 + #1631, `LEONIDA_WINDOW=960x540` (no code change, 14 times fewer texels to scan) | `LEONIDA_ARENA_MB=2048` | 95 s | 105 s | reaches the world phase | | `main` + #1558 + #1631 + **this change** | `LEONIDA_ARENA_MB=2048` | 25 s | 35 s | reaches the world phase; 1,501 presents by about 22 s | | `main` + **this change only** (this branch) | same as the first row | 25 s | 35 s | story load reads from about 35 s to 90 s, then the world phase; the run ends at 179.8 s on the title's hang watchdog there, which is the stop already described in #1537, not this one | So on this machine the first and last rows differ only by this commit. Before #939 (`main` 3ff2a2adc) the same launcher passed the landing screen every time, which is how I found it. It probably costs time on smaller windows too, in proportion to the texel count: the report on #939 of 182 to 362 PresentX in 51 to 74 s on an RTX 4070 SUPER is a few presents a second. I have not measured another machine. ### Tested - The ten presenter tests of `runtime/` pass on this branch on the same GPU: `xbox_present_readback_size`, `vk_presenter_capture_colour`, `present_window`, `xs_present_lazy`, `vk_present_dump`, `vk_present_dump_default`, `vk_present_dump_invalid`, `vk_presenter_sync`, `d3d12_present`, `xbox_present`. - The real boot, as in the table. No new test: which memory type a driver lists first is a property of the device, and the effect only shows with a real swapchain and the title presenting black frames. ### Not done, not tested - The scan itself still runs under the submit and tracker locks; this only makes it fast. Moving it out of the locks, or ending it earlier, is a separate change I am not claiming. - AMD, Intel, Linux: not run. On a device whose first host-visible coherent type is already cached, nothing changes. - I did not time the scan in isolation; the evidence is the thread samples and the before/after boots. - #1223 adds a guard in the same function, a few lines above; the two do not overlap. Counters, switch names and addresses of the executable only; no game data. AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <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#1708
No description provided.