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

Closed
leonida/mandy
kawaii-shakal wants to merge 0 commits from title-upload-staging-trim into main

Pull request closed

This pull request cannot be reopened because the branch was deleted.

kawaii-shakal commented 2026-11-27 12:26:38 +00:00

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).
  • Windows build cross-compiled on Linux (clang-cl 21.1.8, lld-link, xwin MSVC CRT and SDK 10.0.26100): all
    1,091 targets, including d3d12_vulkan_device.cpp. Its tests under Wine 9.0 with Xvfb on Mesa lavapipe: 464 of
    490 pass; the 26 that fail fail the same way on main (checked by building main's two files in the same tree).
  • 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

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). - Windows build cross-compiled on Linux (clang-cl 21.1.8, lld-link, xwin MSVC CRT and SDK 10.0.26100): all 1,091 targets, including `d3d12_vulkan_device.cpp`. Its tests under Wine 9.0 with Xvfb on Mesa lavapipe: 464 of 490 pass; the 26 that fail fail the same way on main (checked by building main's two files in the same tree). - 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)
ecox982745 commented 2026-11-27 12:37:10 +00:00

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.

**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.
lixonik reviewed 2026-11-27 15:20:35 +00:00
lixonik left a comment
No description provided.
Reviewed and tested at `d14a81479` (merged cleanly onto `main` `ec91d695c`). The trim policy header (`runtime/src/title_upload_trim.h`), non-blocking timeline check in `transfer_done()`, atomic `capacity()` / `trimmed()` counters, and `Consumer::staging` accounting are clean and pass CPU and GPU tests. Two notes inline: 1. **Small uploads on the round-robin ring can keep oversized slots alive indefinitely**: `write()` rotates `slots_` round-robin and stamps `slot.last_used_ns = now_ns()` on every upload regardless of size, so steady small uploads (<= 4 MiB) every ~0.5 s keep resetting `last_used_ns` on all 4 oversized slots and prevent `trim()` from reclaiming them. 2. **Minor portability note**: sibling `std::getenv(...)` calls in one argument list in `trim()`. Verified locally on Windows 11 (MSVC 19.44.35230.0, Ninja Release, NVIDIA GeForce RTX 5070, driver 610.88, Vulkan 1.4.341; note `VK_LAYER_KHRONOS_validation` is not installed locally so Vulkan validation layers did not run): - `title_upload_trim` (CPU): passed - `d3d12_existing_heap` and `d3d12_host_prefix` (GPU): 2/2 passed - `scripts/check_no_game_data.py` and `git diff --check`: clean AI-assisted. **`runtime/shims/d3d12_title_image_upload.h` line 97:** > Because `write()` rotates `slots_` strictly round-robin (`next_ = (next_ + 1) % kSlots`), `prepare()` retains any existing buffer when `size <= slot.capacity`, and `slot.last_used_ns = now_ns()` is updated unconditionally on every upload regardless of `bytes`, steady small uploads (<= `keep_bytes`) at even 2-3 uploads/second touch all 4 slots within every 2 s window. > > After a burst of large textures (e.g. 64 MiB cutscene uploads) grows all 4 slots, ongoing small uploads will continuously reset `last_used_ns` on every oversized slot so none of the 4 large buffers is ever released by `trim()`. Tracking when a slot last carried an upload larger than `keep_bytes` (or avoiding stamping `last_used_ns` when `bytes <= settings.keep_bytes` and `slot.capacity > settings.keep_bytes`) would let oversized slots actually be reclaimed under steady small-texture traffic. **`runtime/shims/d3d12_title_image_upload.h` line 38:** > Minor: calling `std::getenv` twice as sibling arguments to `settings_from(...)` relies on the second call not overwriting the buffer returned by the first (the C/C++ standard allows a single static buffer; safe on MSVC UCRT today, easy to avoid by reading/copying the first value or using `GetEnvironmentVariableA` / `getenv_s`).
djrolfes commented 2026-11-27 15:26:27 +00:00

Independent Linux/Wine + NVIDIA check at head d14a81479 (merged cleanly onto origin/main ec91d695c in a local integration stack alongside #2467, #2470, #2469, #2461, #2126, #2091, and two local V# patches).

  • Environment: Linux 7.2.15, wine-11.22, clang-cl + xwin cross-build, NVIDIA GeForce RTX 3070 Ti 8 GB, driver 620.73.04, Ryzen 7 5800X, 32 GB RAM. No game files.
  • Build & CTest: gta6rt and title_upload_trim_test cross-compiled cleanly with clang-cl + xwin; title_upload_trim passed (4.39 s) under Wine.
  • Code review: relaxed atomic capacity()/trimmed() counters and non-blocking vkGetSemaphoreCounterValue check in transfer_done() before releasing idle slots look clean.

AI-assisted.

Independent Linux/Wine + NVIDIA check at head `d14a81479` (merged cleanly onto `origin/main` `ec91d695c` in a local integration stack alongside `#2467`, `#2470`, `#2469`, `#2461`, `#2126`, `#2091`, and two local V# patches). - **Environment:** Linux `7.2.15`, `wine-11.22`, `clang-cl` + `xwin` cross-build, NVIDIA GeForce RTX 3070 Ti 8 GB, driver `620.73.04`, Ryzen 7 5800X, 32 GB RAM. No game files. - **Build & CTest:** `gta6rt` and `title_upload_trim_test` cross-compiled cleanly with `clang-cl` + `xwin`; `title_upload_trim` **passed** (`4.39 s`) under Wine. - **Code review:** relaxed atomic `capacity()`/`trimmed()` counters and non-blocking `vkGetSemaphoreCounterValue` check in `transfer_done()` before releasing idle slots look clean. AI-assisted.
kawaii-shakal commented 2026-11-27 16:28:09 +00:00

@lixonik thanks, both were right. Changed by Claude Code (AI-assisted) in 07326dfb:

  1. write() no longer stamps a slot on every upload. Only an upload over LEONIDA_TITLE_UPLOAD_KEEP_MB counts
    (title_upload_trim::counts_as_use), so small uploads going round the ring no longer keep a large buffer from
    a burst alive; a small one fits the buffer trim() leaves behind. title_upload_trim_test has the case you
    described: 1 MiB uploads every 0.5 s after a 64 MiB one, and the slot is released 2 s after the large one.
  2. The settings are read by title_upload_trim::settings_from_env, which copies each value before the next read
    (_dupenv_s on Windows, so the CRT's getenv deprecation warning is gone too).

Tested: Linux ctest 117/117; Windows build cross-compiled with clang-cl 21 and xwin (gta6rt,
title_upload_trim_test), the test passing under Wine 9.0.

@ecox982745 @djrolfes the change is small but it touches what you measured: a re-run of your adapted fixture on
this head would confirm the four buffers still go.


Generated by Claude Code

@lixonik thanks, both were right. Changed by Claude Code (AI-assisted) in 07326dfb: 1. `write()` no longer stamps a slot on every upload. Only an upload over `LEONIDA_TITLE_UPLOAD_KEEP_MB` counts (`title_upload_trim::counts_as_use`), so small uploads going round the ring no longer keep a large buffer from a burst alive; a small one fits the buffer `trim()` leaves behind. `title_upload_trim_test` has the case you described: 1 MiB uploads every 0.5 s after a 64 MiB one, and the slot is released 2 s after the large one. 2. The settings are read by `title_upload_trim::settings_from_env`, which copies each value before the next read (`_dupenv_s` on Windows, so the CRT's getenv deprecation warning is gone too). Tested: Linux `ctest` 117/117; Windows build cross-compiled with clang-cl 21 and xwin (`gta6rt`, `title_upload_trim_test`), the test passing under Wine 9.0. @ecox982745 @djrolfes the change is small but it touches what you measured: a re-run of your adapted fixture on this head would confirm the four buffers still go. --- _Generated by [Claude Code](https://claude.ai/code)_
kawaii-shakal commented 2026-11-27 16:53:09 +00:00

Note on #2464, which came out after this PR: it lists runtime/shims/d3d12_title_image_upload.h among the files
the performance rewrite owns. @aslan2142 if the rewrite covers the upload ring, feel free to close this or take
the change into it; the rule and its test (src/title_upload_trim.h, title_upload_trim_test) are separate files
and can move as they are. The measured effect is in ecox982745's comment above.


Generated by Claude Code

Note on #2464, which came out after this PR: it lists `runtime/shims/d3d12_title_image_upload.h` among the files the performance rewrite owns. @aslan2142 if the rewrite covers the upload ring, feel free to close this or take the change into it; the rule and its test (`src/title_upload_trim.h`, `title_upload_trim_test`) are separate files and can move as they are. The measured effect is in ecox982745's comment above. --- _Generated by [Claude Code](https://claude.ai/code)_
lixonik approved these changes 2026-11-27 20:10:56 +00:00
lixonik left a comment

Re-reviewed 07326dfb8 and re-tested:

  • Both earlier comments are cleanly addressed:
    1. write() now only updates slot.last_used_ns when title_upload_trim::counts_as_use(bytes, trim_settings()) is true (bytes > keep_bytes), so steady small uploads rotating through the ring no longer keep oversized buffers alive indefinitely while in-flight transfers remain protected by the timeline semaphore check in trim().
    2. title_upload_trim::settings_from_env() reads both environment variables via env_copy() (_dupenv_s on Windows, owned std::string copy on POSIX), avoiding sibling std::getenv pointer aliasing and MSVC C4996 warnings.
  • Tested on NVIDIA GeForce RTX 5070 (Windows 11, driver 610.88, Vulkan 1.4.341, MSVC 19.44; VK_LAYER_KHRONOS_validation not installed locally):
    • title_upload_trim: passed (0.02 s).
    • d3d12_mapped_plane_async: passed (0.21 s).

Looks good to merge (maintainers can weigh overlap with #2464 perf work on d3d12_title_image_upload.h).

AI-assisted (Antigravity, Gemini).

Re-reviewed `07326dfb8` and re-tested: - Both earlier comments are cleanly addressed: 1. `write()` now only updates `slot.last_used_ns` when `title_upload_trim::counts_as_use(bytes, trim_settings())` is true (`bytes > keep_bytes`), so steady small uploads rotating through the ring no longer keep oversized buffers alive indefinitely while in-flight transfers remain protected by the timeline semaphore check in `trim()`. 2. `title_upload_trim::settings_from_env()` reads both environment variables via `env_copy()` (`_dupenv_s` on Windows, owned `std::string` copy on POSIX), avoiding sibling `std::getenv` pointer aliasing and MSVC C4996 warnings. - Tested on NVIDIA GeForce RTX 5070 (Windows 11, driver 610.88, Vulkan 1.4.341, MSVC 19.44; `VK_LAYER_KHRONOS_validation` not installed locally): - `title_upload_trim`: passed (0.02 s). - `d3d12_mapped_plane_async`: passed (0.21 s). Looks good to merge (maintainers can weigh overlap with #2464 perf work on `d3d12_title_image_upload.h`). AI-assisted (Antigravity, Gemini).
timbot103 commented 2026-11-28 02:02:32 +00:00

Reviewed at head 07326dfb8 on Windows 11 (MSVC 2022 19.44).

Verification

  • Built title_upload_trim_test and gta6rt.
  • title_upload_trim_test: ok.

Notes (non-blocking)

  • Lock ordering (texture mutex -> try upload mutex), retirement gating on slot timeline values (retaining on counter query failure), once-per-mapping capacity accounting, staging classification in the memory probe, and the updates for large-upload-only timestamping + copied env values (d3d12_title_image_upload.h:93-98, 160-299; title_upload_trim.h:53-77; d3d12_vulkan_device.cpp:15661-15668) all look solid.
  • Minor perf note (d3d12_title_image_upload.h:37-47, 160-172; title_upload_trim.h:80-85): The periodic trim evaluates transfer_done(d, slot) (polling vkGetSemaphoreCounterValue) for every non-empty slot even when size/age already disqualify it. Checking size and age first — and querying the shared timeline at most once if any candidate qualifies — avoids redundant Vulkan calls under both locks during steady small uploads.

Approve.

AI-assisted review + local MSVC verification.

Reviewed at head `07326dfb8` on Windows 11 (MSVC 2022 `19.44`). ### Verification - Built `title_upload_trim_test` and `gta6rt`. - `title_upload_trim_test`: **ok**. ### Notes (non-blocking) - Lock ordering (texture mutex -> try upload mutex), retirement gating on slot timeline values (retaining on counter query failure), once-per-mapping capacity accounting, staging classification in the memory probe, and the updates for large-upload-only timestamping + copied env values (`d3d12_title_image_upload.h:93-98`, `160-299`; `title_upload_trim.h:53-77`; `d3d12_vulkan_device.cpp:15661-15668`) all look solid. - **Minor perf note (`d3d12_title_image_upload.h:37-47`, `160-172`; `title_upload_trim.h:80-85`):** The periodic trim evaluates `transfer_done(d, slot)` (polling `vkGetSemaphoreCounterValue`) for every non-empty slot even when size/age already disqualify it. Checking size and age first — and querying the shared timeline at most once if any candidate qualifies — avoids redundant Vulkan calls under both locks during steady small uploads. Approve. AI-assisted review + local MSVC verification.
zmasi commented 2026-11-28 23:23:23 +00:00

#2463 | head c9e75ba74a80f77dd399076cf26ce93a63b0083a (merged cleanly with main adfb3821a23612263c1c5b195453ed01c4c114db — no conflicts on current main) | ctest --test-dir runtime/build -C RelWithDebInfo -R "^(title_upload_trim|memory_breakdown|d3d12_mapped_plane_async)$" --output-on-failure (LEONIDA_VK_VALIDATION=1, LEONIDA_MEM_PROBE=1, LEONIDA_FSDRAW_PROBE=1, LEONIDA_TITLE_UPLOAD_IDLE_MS=1, LEONIDA_TITLE_UPLOAD_KEEP_MB=0) | red mutation: forcing title_upload_trim::release() in runtime/src/title_upload_trim.h to return false fails title_upload_trim at line 33: tt::release(64 * kMiB, t0, t0 + 2000 * kMs, true, s) | green on PR+main: 3/3 CTests (title_upload_trim, memory_breakdown, and d3d12_mapped_plane_async logging [rt] mem-probe: registered image backing: ... staged fills 1, 0.001 s, buffer 0.0 MiB (0 released idle)) pass in 1.02 s on RTX 3090 with 0 Khronos validation errors; test_docs_encoding.py & test_docs_repo_paths.py (6/6 OK) and check_no_game_data.py (0 violations) pass | Windows 11, MSVC 19.44, RTX 3090, Vulkan SDK 1.4.363.1 | AI-assisted: yes

#2463 | head c9e75ba74a80f77dd399076cf26ce93a63b0083a (merged cleanly with main adfb3821a23612263c1c5b195453ed01c4c114db — no conflicts on current `main`) | `ctest --test-dir runtime/build -C RelWithDebInfo -R "^(title_upload_trim|memory_breakdown|d3d12_mapped_plane_async)$" --output-on-failure` (`LEONIDA_VK_VALIDATION=1`, `LEONIDA_MEM_PROBE=1`, `LEONIDA_FSDRAW_PROBE=1`, `LEONIDA_TITLE_UPLOAD_IDLE_MS=1`, `LEONIDA_TITLE_UPLOAD_KEEP_MB=0`) | red mutation: forcing `title_upload_trim::release()` in `runtime/src/title_upload_trim.h` to `return false` fails `title_upload_trim` at `line 33: tt::release(64 * kMiB, t0, t0 + 2000 * kMs, true, s)` | green on PR+main: `3/3` CTests (`title_upload_trim`, `memory_breakdown`, and `d3d12_mapped_plane_async` logging `[rt] mem-probe: registered image backing: ... staged fills 1, 0.001 s, buffer 0.0 MiB (0 released idle)`) pass in `1.02 s` on RTX 3090 with `0` Khronos validation errors; `test_docs_encoding.py` & `test_docs_repo_paths.py` (`6/6 OK`) and `check_no_game_data.py` (`0` violations) pass | Windows 11, MSVC 19.44, RTX 3090, Vulkan SDK 1.4.363.1 | AI-assisted: yes
timbot103 reviewed 2026-11-29 04:29:02 +00:00
timbot103 left a comment
No description provided.
Static audit of `c9e75ba74`. No builds or GPU runs were performed for this review. - **[MINOR] `runtime/test/title_upload_trim_test.cpp:29`** — The policy test supplies the completion flag, leaving the production timeline check at `runtime/shims/d3d12_title_image_upload.h:164` untested. If an oversized slot reaches the idle threshold with a copy still pending, accepting a successful counter query below the slot's ticket would free the source buffer early and leave the policy test green. Please add a ring-level test with a fake Vulkan counter that returns below the ticket and then reaches it. Check that the first trim retains the buffer and capacity, and the second frees the allocation exactly once and decrements capacity. The upload ring records the ticket when the primary copy submission succeeds, before submitting waits on the consumer queues. The refresh path takes the registry mutex before trying the upload mutex, and slot mutation stays under the upload mutex. Teardown joins the fill worker and waits for device idle before releasing the ring. The memory probe records staging allocations by handle and erases them on free, including cleanup after bind or map failure. Ring capacity is added only after mapping succeeds and subtracted by the shared release path. The policy test is registered in `runtime/CMakeLists.txt` and exercises the MSVC and POSIX environment-reading branches on their respective platforms. AI-assisted.
kawaii-shakal commented 2026-11-30 08:37:05 +00:00

Thanks, both addressed in 15531782:

  • [MINOR] the ring-level test: runtime/test/title_upload_ring_trim_test.cpp drives TitleImageUpload::trim itself over a fake device whose vkGetSemaphoreCounterValue, vkDestroyBuffer and vkFreeMemory count their calls (a test-only friend seeds a submitted slot). With the counter below the slot's ticket the first trim keeps the buffer and capacity(); with it at the ticket the second frees buffer and memory exactly once, capacity() drops to 0 and trimmed() is 1, and a third frees nothing. A counter read that fails (VK_ERROR_DEVICE_LOST) or a missing entry point keeps the buffer, and each slot goes by its own ticket.
  • The perf note: trim() now checks size and age first, so a slot they keep costs no counter read under the locks; the test counts the reads.

Built with clang-cl 21 + xwin (the flags the CMake target gets) and run under Wine: 3/3 pass; with the reached < slot.value comparison removed from transfer_done() it fails 3/3 at the first-trim check. Not built with MSVC here. Merges cleanly into main e236b19c.

AI-assisted (Claude Code); I ran the builds and checked the results.


Generated by Claude Code

Thanks, both addressed in 15531782: - [MINOR] the ring-level test: `runtime/test/title_upload_ring_trim_test.cpp` drives `TitleImageUpload::trim` itself over a fake device whose `vkGetSemaphoreCounterValue`, `vkDestroyBuffer` and `vkFreeMemory` count their calls (a test-only friend seeds a submitted slot). With the counter below the slot's ticket the first trim keeps the buffer and `capacity()`; with it at the ticket the second frees buffer and memory exactly once, `capacity()` drops to 0 and `trimmed()` is 1, and a third frees nothing. A counter read that fails (`VK_ERROR_DEVICE_LOST`) or a missing entry point keeps the buffer, and each slot goes by its own ticket. - The perf note: `trim()` now checks size and age first, so a slot they keep costs no counter read under the locks; the test counts the reads. Built with clang-cl 21 + xwin (the flags the CMake target gets) and run under Wine: 3/3 pass; with the `reached < slot.value` comparison removed from `transfer_done()` it fails 3/3 at the first-trim check. Not built with MSVC here. Merges cleanly into main e236b19c. AI-assisted (Claude Code); I ran the builds and checked the results. --- _Generated by [Claude Code](https://claude.ai/code)_
ecox982745 commented 2026-11-30 09:04:29 +00:00

Native Windows follow-up on 15531782. I merged it locally into dcba958e5 (tree 1bee9a100) and built the unmodified test targets with MSVC 19.44 in Release.

  • title_upload_ring_trim, title_upload_trim, and memory_breakdown each passed 3/3. The new ring test uses a fake Vulkan device. It covers the below-ticket hold, the exactly-once free at the ticket, counter lookup failures, and independent slot tickets.
  • d3d12_mapped_plane_async also passed 3/3 on the RTX 4090 (NVIDIA 616.64, Windows 11) with Khronos Vulkan validation 1.4.369 enabled and no diagnostics. This was the stock synthetic GPU smoke test. Ring trimming itself was verified by the CPU fixture above.

AI-assisted with OpenAI Codex (GPT-6.2 Sol).

Native Windows follow-up on `15531782`. I merged it locally into `dcba958e5` (tree `1bee9a100`) and built the unmodified test targets with MSVC 19.44 in Release. - `title_upload_ring_trim`, `title_upload_trim`, and `memory_breakdown` each passed 3/3. The new ring test uses a fake Vulkan device. It covers the below-ticket hold, the exactly-once free at the ticket, counter lookup failures, and independent slot tickets. - `d3d12_mapped_plane_async` also passed 3/3 on the RTX 4090 (NVIDIA 616.64, Windows 11) with Khronos Vulkan validation 1.4.369 enabled and no diagnostics. This was the stock synthetic GPU smoke test. Ring trimming itself was verified by the CPU fixture above. AI-assisted with OpenAI Codex (GPT-6.2 Sol).
merzleckeier commented 2026-11-30 09:38:53 +00:00

Independent live-ring check of 15531782 merged onto main 4014af7fe. CachyOS, clang++ 23.1.5, RTX 4070 SUPER (NVIDIA 620.73.04) and Radeon 610M/Raphael (RADV 26.3.1), Khronos validation 1.4.363. The three stock CPU fixtures (title_upload_ring_trim, title_upload_trim, memory_breakdown) also passed.

I used a test-only friend to call the production ring's prepare, submit and trim paths with real Vulkan resources. The ring allocated and mapped an 8 MiB source and submitted a copy to a coherent readback buffer. I added an unsignalled timeline wait to that submission so trim() ran while the transfer was pending. I set the slot's last-use timestamp to zero to select an already-idle slot without sleeping.

  • With trim on (KEEP_MB=4, IDLE_MS=1), the real counter was 0 against ticket 1 and the first trim kept all 8 MiB. I opened the gate, waited for ticket 1, and all 8,388,608 bytes matched. The next trim dropped capacity to zero and counted one release. An extra trim kept that count at one.

  • With LEONIDA_TITLE_UPLOAD_IDLE_MS=0, the same transfer and full readback passed. The ring kept all 8 MiB and counted zero releases until normal teardown.

Measured: 3/3 repetitions for each mode on each GPU, 12/12 total with zero validation diagnostics. This exercises the real map, submission timeline and release path using a synthetic buffer copy. The fixture supplies the command and idle timestamp.

AI-assisted: yes (OpenAI Codex).

Independent live-ring check of `15531782` merged onto `main` `4014af7fe`. CachyOS, clang++ 23.1.5, RTX 4070 SUPER (NVIDIA 620.73.04) and Radeon 610M/Raphael (RADV 26.3.1), Khronos validation 1.4.363. The three stock CPU fixtures (`title_upload_ring_trim`, `title_upload_trim`, `memory_breakdown`) also passed. I used a test-only friend to call the production ring's `prepare`, `submit` and `trim` paths with real Vulkan resources. The ring allocated and mapped an 8 MiB source and submitted a copy to a coherent readback buffer. I added an unsignalled timeline wait to that submission so `trim()` ran while the transfer was pending. I set the slot's last-use timestamp to zero to select an already-idle slot without sleeping. - With trim on (`KEEP_MB=4`, `IDLE_MS=1`), the real counter was `0` against ticket `1` and the first trim kept all 8 MiB. I opened the gate, waited for ticket `1`, and all 8,388,608 bytes matched. The next trim dropped capacity to zero and counted one release. An extra trim kept that count at one. - With `LEONIDA_TITLE_UPLOAD_IDLE_MS=0`, the same transfer and full readback passed. The ring kept all 8 MiB and counted zero releases until normal teardown. **Measured:** 3/3 repetitions for each mode on each GPU, 12/12 total with zero validation diagnostics. This exercises the real map, submission timeline and release path using a synthetic buffer copy. The fixture supplies the command and idle timestamp. AI-assisted: yes (OpenAI Codex).
kawaii-shakal commented 2026-11-30 13:16:48 +00:00

Main's rewrite of d3d12_title_image_upload.h (variable slots with best-fit, batched uploads, GPU detile, from fix/rendering-correctness) replaces the four-slot ring this PR trims, so it no longer merges. Does the new ring still want idle large slots given back? If so I'll port the trim (release a slot over LEONIDA_TITLE_UPLOAD_KEEP_MB that is idle and whose ticket the timeline has reached, staging accounting, and the fake-device ring test) onto it; if the rewrite covers this or it isn't wanted, I'll close this one.


Generated by Claude Code

Main's rewrite of `d3d12_title_image_upload.h` (variable slots with best-fit, batched uploads, GPU detile, from `fix/rendering-correctness`) replaces the four-slot ring this PR trims, so it no longer merges. Does the new ring still want idle large slots given back? If so I'll port the trim (release a slot over `LEONIDA_TITLE_UPLOAD_KEEP_MB` that is idle and whose ticket the timeline has reached, staging accounting, and the fake-device ring test) onto it; if the rewrite covers this or it isn't wanted, I'll close this one. --- _Generated by [Claude Code](https://claude.ai/code)_
ecox982745 commented 2026-11-30 14:10:03 +00:00

I checked the variable-slot uploader on main f44904d21 to see what it retains today. Native Windows 11, MSVC 19.44 Release, RTX 4090 (NVIDIA 616.64) and Khronos Vulkan validation 1.4.369. I reused the earlier synthetic fixture, which forces staging and checks every byte of four sequential 4096×2048 R8 image readbacks. After 10.5 s idle, I submitted and fenced an empty command list, then did a fifth upload and readback.

Both runs reported four staged fills and 8 MiB of staging capacity still held after the idle submission, with zero live slot-70 or slot-133 backing at that point. The fifth upload matched in full, and both runs had zero validation errors. The earlier fixture on the four-slot ring with trimming off retained 32 MiB. Best-fit reuse reduced retention for this sequential case. The new ring still kept its idle allocation.

This confirms retained staging on the merged uploader. The fixture only exercises a sequential stream, so it leaves the multi-slot burst and in-game tradeoff open. AI-assisted with OpenAI Codex (GPT-6.2 Sol).

I checked the variable-slot uploader on `main` `f44904d21` to see what it retains today. Native Windows 11, MSVC 19.44 Release, RTX 4090 (NVIDIA 616.64) and Khronos Vulkan validation 1.4.369. I reused the earlier synthetic fixture, which forces staging and checks every byte of four sequential 4096×2048 R8 image readbacks. After 10.5 s idle, I submitted and fenced an empty command list, then did a fifth upload and readback. Both runs reported four staged fills and **8 MiB of staging capacity still held after the idle submission**, with zero live slot-70 or slot-133 backing at that point. The fifth upload matched in full, and both runs had zero validation errors. The earlier fixture on the four-slot ring with trimming off retained 32 MiB. Best-fit reuse reduced retention for this sequential case. The new ring still kept its idle allocation. This confirms retained staging on the merged uploader. The fixture only exercises a sequential stream, so it leaves the multi-slot burst and in-game tradeoff open. AI-assisted with OpenAI Codex (GPT-6.2 Sol).
aslan2142 commented 2026-12-01 16:44:48 +00:00

Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (d3d12/) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, d3d12/, or general docs), please feel free to reopen it.

Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (`d3d12/`) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, `d3d12/`, or general docs), please feel free to reopen it.
Sign in to join this conversation.
No description provided.