d3d12: the title-texture upload ring gives back large idle buffers, and counts as staging (RT-TITLE-UPLOAD-TRIM) #2463

Open
github-bot wants to merge 2 commits from github-bot/gh-2463 into main AGit
Owner

@⁠kawaii-shakal on GitHub · 2026-11-27 12:26 UTC · original
kawaii-shakal:title-upload-staging-trim → main · +216 −7 · 7 files · 2 commits · open

Claimed in the coordination issue as: RT-TITLE-UPLOAD-TRIM

Overlaps #2021 (the same header, a different change): the two conflict only in runtime/CMakeLists.txt, where
each registers a test; whichever lands second keeps both lines.

What and why

TitleImageUpload (runtime/shims/d3d12_title_image_upload.h) is a ring of four slots. Each slot grew to the
largest whole-image upload that went through it and kept that buffer until the device was destroyed. The buffers
are host-visible, so on a discrete GPU they are system RAM: after a burst of large textures (a cutscene's, say)
up to four of the largest stayed allocated for the rest of the run. The ring's memory was also not named in the
mem probe, so it showed up as other.

  • trim(), called from the periodic title-texture pass (refresh_title_textures) under a try_lock, frees a
    slot whose buffer is over LEONIDA_TITLE_UPLOAD_KEEP_MB (4) and that has not been used for
    LEONIDA_TITLE_UPLOAD_IDLE_MS (2000), once its last transfer has completed. Completion is read with
    vkGetSemaphoreCounterValue; the pass never waits for the GPU, and a slot whose value can't be read stays.
    LEONIDA_TITLE_UPLOAD_IDLE_MS=0 keeps the old behaviour, for A/B runs.
  • The ring allocates under a memory_breakdown staging owner, so [rt] mem-probe breakdown shows it as staging.
    The registered image backing line now also says how many buffers were released.
  • The rule is runtime/src/title_upload_trim.h, tested by title_upload_trim_test: idle limit and size floor,
    a transfer still running, an empty slot, a clock read before the last use, 0 = off, malformed and huge values.
  • runtime/README.md and docs/d3d12_vulkan.md describe the two variables.

Tested

  • Linux (Ubuntu 24.04 container, g++ 13, Mesa lavapipe): ctest 117 of 117, with the new test.
  • The changed header compiled on Linux in a test translation unit that calls trim() and capacity() on a fake
    device (-Wall -Wextra, no warnings from these files).
  • Not built here: d3d12_vulkan_device.cpp is Windows-only. Its change is the trim() call and one log line.
    Needs the Windows CI or a local build.
  • Not run with the game, so the RAM saved is not measured. The way to see it: LEONIDA_MEM_PROBE=1 through a
    cutscene and after it, with LEONIDA_TITLE_UPLOAD_IDLE_MS=0 and with the default, comparing the staging part
    of the breakdown line and the buffer size on the registered image backing line.

AI-assisted: yes (Claude Code)

Checklist

  • Based on current main and merges cleanly.
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption.
  • A new translator rule is in the contract table of docs/design.md. (n/a: no translator change)

🤖 Generated with Claude Code

**@⁠kawaii-shakal** on GitHub · 2026-11-27 12:26 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2463) `kawaii-shakal:title-upload-staging-trim` → `main` · +216 −7 · 7 files · 2 commits · open Claimed in the coordination issue as: RT-TITLE-UPLOAD-TRIM Overlaps #2021 (the same header, a different change): the two conflict only in `runtime/CMakeLists.txt`, where each registers a test; whichever lands second keeps both lines. ### What and why `TitleImageUpload` (`runtime/shims/d3d12_title_image_upload.h`) is a ring of four slots. Each slot grew to the largest whole-image upload that went through it and kept that buffer until the device was destroyed. The buffers are host-visible, so on a discrete GPU they are system RAM: after a burst of large textures (a cutscene's, say) up to four of the largest stayed allocated for the rest of the run. The ring's memory was also not named in the mem probe, so it showed up as `other`. - `trim()`, called from the periodic title-texture pass (`refresh_title_textures`) under a `try_lock`, frees a slot whose buffer is over `LEONIDA_TITLE_UPLOAD_KEEP_MB` (4) and that has not been used for `LEONIDA_TITLE_UPLOAD_IDLE_MS` (2000), once its last transfer has completed. Completion is read with `vkGetSemaphoreCounterValue`; the pass never waits for the GPU, and a slot whose value can't be read stays. `LEONIDA_TITLE_UPLOAD_IDLE_MS=0` keeps the old behaviour, for A/B runs. - The ring allocates under a `memory_breakdown` staging owner, so `[rt] mem-probe breakdown` shows it as staging. The `registered image backing` line now also says how many buffers were released. - The rule is `runtime/src/title_upload_trim.h`, tested by `title_upload_trim_test`: idle limit and size floor, a transfer still running, an empty slot, a clock read before the last use, 0 = off, malformed and huge values. - `runtime/README.md` and `docs/d3d12_vulkan.md` describe the two variables. ### Tested - Linux (Ubuntu 24.04 container, g++ 13, Mesa lavapipe): `ctest` 117 of 117, with the new test. - The changed header compiled on Linux in a test translation unit that calls `trim()` and `capacity()` on a fake device (`-Wall -Wextra`, no warnings from these files). - **Not built here:** `d3d12_vulkan_device.cpp` is Windows-only. Its change is the `trim()` call and one log line. Needs the Windows CI or a local build. - Not run with the game, so the RAM saved is not measured. The way to see it: `LEONIDA_MEM_PROBE=1` through a cutscene and after it, with `LEONIDA_TITLE_UPLOAD_IDLE_MS=0` and with the default, comparing the `staging` part of the breakdown line and the buffer size on the `registered image backing` line. AI-assisted: yes (Claude Code) ### Checklist - [x] Based on current `main` and merges cleanly. - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption. - [ ] A new translator rule is in the contract table of `docs/design.md`. (n/a: no translator change) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
TitleImageUpload's four slots each grew to the largest whole-image upload that went through them and kept that
host-visible buffer (system RAM on a discrete GPU) until the device was destroyed, so after a burst of large
textures up to four of the largest stayed allocated. The periodic title-texture pass now calls trim(), which,
under a try_lock and without waiting for the GPU, releases a slot over LEONIDA_TITLE_UPLOAD_KEEP_MB (default 4)
that has been idle for LEONIDA_TITLE_UPLOAD_IDLE_MS (default 2000; 0 keeps the old behaviour) once its last
transfer's timeline value is reached. The rule is src/title_upload_trim.h, tested by title_upload_trim_test.

The ring's allocations now run under a memory_breakdown staging owner, so the mem probe's breakdown line shows
them as staging instead of other, and its texture line says how many buffers were released.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01JPqXc6svM4pbBagTsVEYA3
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01JPqXc6svM4pbBagTsVEYA3
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 12:27:25 +00:00
Author
Owner

@⁠ecox982745 on GitHub · 2026-11-27 12:37 UTC · original

Native Windows check on d14a81479. The Windows-only d3d12_vulkan_device.cpp compiled with MSVC 19.44 and gta6rt.exe linked in Release. The stock title_upload_trim CPU test and d3d12_mapped_plane_async RTX 4090 test both passed.

I also measured the ring through the production refresh path on Windows 11, RTX 4090, NVIDIA 616.64. I adapted the test's mapped-plane fixture locally to upload four 4096×2048 R8 textures, each filled with a different byte. I disabled host image copy on the test device to exercise staging. Each copy completed and its full 8 MiB readback matched before the next upload. After 10.5 s idle, an empty queue submission triggered the next refresh and let the regular memory probe print the counters.

Settings Completed staged fills Ring capacity after idle Buffers released idle
Defaults (2,000 ms, 4 MiB) 4 0 MiB 4
LEONIDA_TITLE_UPLOAD_IDLE_MS=0 4 32 MiB 0

A fifth 8 MiB upload with a new fill byte passed full GPU readback in both processes. Khronos validation was enabled and reported zero errors. This checks retention, release and reuse of the staging ring with synthetic textures. The 32 MiB is the ring-capacity difference for this fixture.

**@⁠ecox982745** on GitHub · 2026-11-27 12:37 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2463#issuecomment-7218471409) **Native Windows check on `d14a81479`.** The Windows-only `d3d12_vulkan_device.cpp` compiled with MSVC 19.44 and `gta6rt.exe` linked in Release. The stock `title_upload_trim` CPU test and `d3d12_mapped_plane_async` RTX 4090 test both passed. I also measured the ring through the production refresh path on Windows 11, RTX 4090, NVIDIA 616.64. I adapted the test's mapped-plane fixture locally to upload four 4096×2048 R8 textures, each filled with a different byte. I disabled host image copy on the test device to exercise staging. Each copy completed and its full 8 MiB readback matched before the next upload. After 10.5 s idle, an empty queue submission triggered the next refresh and let the regular memory probe print the counters. | Settings | Completed staged fills | Ring capacity after idle | Buffers released idle | |---|---:|---:|---:| | Defaults (2,000 ms, 4 MiB) | 4 | 0 MiB | 4 | | `LEONIDA_TITLE_UPLOAD_IDLE_MS=0` | 4 | 32 MiB | 0 | A fifth 8 MiB upload with a new fill byte passed full GPU readback in both processes. Khronos validation was enabled and reported zero errors. This checks retention, release and reuse of the staging ring with synthetic textures. The 32 MiB is the ring-capacity difference for this fixture.
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/2463/head:github-bot/gh-2463'
git switch 'github-bot/gh-2463'

Merge

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