Improve post-load GPU memory and pipeline handling (RT-POST-LOAD-GPU-MEMORY) #2098

Merged
Moriz82 merged 12 commits from upstream-pr/2098 into main 2026-11-26 00:01:15 +00:00
Moriz82 commented 2026-11-25 20:31:16 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Moriz82 on 2026-11-25T20:31:16Z.


This draft follows #1723. When the shared Vulkan buffer arena fills, an eligible committed buffer can now use a dedicated allocation. An earlier Proton run stopped during upscaler initialization when no arena slice fit the requested buffer.

Claimed as RT-POST-LOAD-GPU-MEMORY. Coordination issue

Changes

  • Update console heap descriptors on the GPU, track invalidated backing ranges, and retain upstream's host-side bitset for live buffer descriptors.
  • Journal completed pipeline cache entries, move eligible compilation work off the submission thread, and reuse compute shader seeds across runs.
  • Replay indirect mesh records through the GPU clamp. Record the original mesh dimensions before clamping and clear the counters when a readback slot is reused.
  • Preserve scripted button presses until the title reads them. Update translator handling for buffer offsets, image views, and wave64 control flow.

Independent review work overlaps the fixed-count and counted indirect mesh paths and pipeline compile workers. Fixed-count mesh dispatches · Count-buffer mesh dispatches · Pipeline compile workers

Verification

Build Result
Public rebase on db1a22d29, Linux 6,327 translator tests across 493 files, zero failing files. The descriptor-cache check passed. The compute pipeline suite ran four tests with one skip.
Public rebase, Windows x64 cross-build Release gta6rt.exe and gta6rt_tls_host.dll linked on Linux with clang-cl and the Windows SDK.
Public rebase, SPIR-V Both embedded runtime compute shaders passed Vulkan 1.2 validation. The regression for the mesh counter instructions passed.
Public rebase, repository checks Tracked-file game-data scan, forbidden extension check, added-content secret scan, and whitespace check passed.
Source integration, Linux and Proton 6,303 translator tests across 491 files, zero failing files. All 12 focused runtime suites passed, including the compute allocation fallback and pipeline cache journal.
Earlier allocation-fix build, Proton Loading ended at 170 seconds. The title frame counter advanced from 2,369 at 300 seconds to 2,830 at 600 seconds. The run recorded zero upscaler exceptions. Whether it exercised the dedicated fallback is unknown.

The public commit still needs a title boot. Native Windows and playable world rendering remain unverified.

GPU used for the source integration was an NVIDIA GeForce RTX 4070 on Linux under Proton. Public-head runtime checks are in progress.

Contributors include Plaaasma and ivanepsilondelta. AI-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5498683506 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2098). Originally posted by [Moriz82](https://github.com/Moriz82) on 2026-11-25T20:31:16Z. --- This draft follows #1723. When the shared Vulkan buffer arena fills, an eligible committed buffer can now use a dedicated allocation. An earlier Proton run stopped during upscaler initialization when no arena slice fit the requested buffer. Claimed as **RT-POST-LOAD-GPU-MEMORY**. [Coordination issue](https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7173693934) ### Changes - Update console heap descriptors on the GPU, track invalidated backing ranges, and retain upstream's host-side bitset for live buffer descriptors. - Journal completed pipeline cache entries, move eligible compilation work off the submission thread, and reuse compute shader seeds across runs. - Replay indirect mesh records through the GPU clamp. Record the original mesh dimensions before clamping and clear the counters when a readback slot is reused. - Preserve scripted button presses until the title reads them. Update translator handling for buffer offsets, image views, and wave64 control flow. Independent review work overlaps the fixed-count and counted indirect mesh paths and pipeline compile workers. [Fixed-count mesh dispatches](https://github.com/ubiquitarianism/leonida/pull/424) · [Count-buffer mesh dispatches](https://github.com/ubiquitarianism/leonida/pull/429) · [Pipeline compile workers](https://github.com/ubiquitarianism/leonida/pull/2077) ### Verification | Build | Result | | --- | --- | | Public rebase on `db1a22d29`, Linux | 6,327 translator tests across 493 files, zero failing files. The descriptor-cache check passed. The compute pipeline suite ran four tests with one skip. | | Public rebase, Windows x64 cross-build | Release gta6rt.exe and gta6rt_tls_host.dll linked on Linux with clang-cl and the Windows SDK. | | Public rebase, SPIR-V | Both embedded runtime compute shaders passed Vulkan 1.2 validation. The regression for the mesh counter instructions passed. | | Public rebase, repository checks | Tracked-file game-data scan, forbidden extension check, added-content secret scan, and whitespace check passed. | | Source integration, Linux and Proton | 6,303 translator tests across 491 files, zero failing files. All 12 focused runtime suites passed, including the compute allocation fallback and pipeline cache journal. | | Earlier allocation-fix build, Proton | Loading ended at 170 seconds. The title frame counter advanced from 2,369 at 300 seconds to 2,830 at 600 seconds. The run recorded zero upscaler exceptions. Whether it exercised the dedicated fallback is unknown. | The public commit still needs a title boot. Native Windows and playable world rendering remain unverified. GPU used for the source integration was an NVIDIA GeForce RTX 4070 on Linux under Proton. Public-head runtime checks are in progress. Contributors include Plaaasma and ivanepsilondelta. AI-assisted.
Snooozs commented 2026-11-25 20:48:18 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Snooozs on 2026-11-25T20:48:18Z.


Native Windows boot of this draft (9f98dcc61), one run. Counts only, no game data.

Machine: Windows 10 19045, RTX 5060 Ti 16 GB, NVIDIA 621.01, 32 GB RAM, own 1.0.2.1, MSVC RelWithDebInfo (builds clean). Shaders from my work folder (47,772 loaded, 0 refused), cold pipeline cache, LEONIDA_ARENA_MB=2048 LEONIDA_TITLE_WINDOWS_MB=1024 LEONIDA_DEVICE_TYPE=6 LEONIDA_TITLE_WATCHDOG=0 LEONIDA_MEM_PROBE=20, no other change. Run time 431 s, ended by me. No device loss, no driver error in the event log.

Reached: the loading screens and the world start. Then it stops the same way as my runs without it: the last submission is number 2,216 at t=217 s, list values stays at 7,685 recorded / 7,528 landed (157 pending), 14 gates held, 0 met, 14 timed out (9 of them at the short timeout), while the process sits idle except for one pipeline build thread. So the draft does not cause the stall and does not remove it, on this machine (RT-LIST-VALUES-STALL-SNAPSHOT, tiguan26, is the one to watch). 825 compute and 54 graphics pipelines were made, 141.6 s and 65.2 s in vkCreate*Pipelines; indirect draws: 9,446 recorded, 512 emitted.

What it does save, against my earlier runs:

this draft my runs on main + DadaCap's mesh branch + #1592 + #1896 + #1889 + #1914
lowest free RAM in the run 8.0 GB (world start, 431 s) 2.1 to 3.5 GB (n25, n27 to n33)
peak commit of the system 42.7 GB 51 to 68 GB
longest heaps phase of a submission 88 ms up to 2.6 s without #1887 (n21: 3.6 s); 0.03 s with it (n22) while loading

Not a clean comparison: the runs differ in much (geometry copies, a 1.1 to 1.6 GB heavy pipeline cache in most of mine, host copies). One thing stands out either way: LEONIDA_MEM_PROBE says pipeline cache 0 MiB here, where mine held a 1.1 to 1.6 GB cache in memory, and the journal of this run was 791 files, 1.6 MB.

The loading was slow here: 1 to 4 frames/s from 20 to 60 s, because the cache was cold. Is there anything you want measured with a warm journal or a switch (LEONIDA_COMPILE_HELPER=1, LEONIDA_ASYNC_PIPELINES=1)? I can run it. What I would watch for: whether the helper lowers the RAM peak further.

A question on the stall, since your title frame counter advanced to 2,830 at 600 s under Proton: did list values ... recorded / landed keep moving there, and what are your last counters?

AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7174210650 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2098#issuecomment-7174210650). Originally posted by [Snooozs](https://github.com/Snooozs) on 2026-11-25T20:48:18Z. --- Native Windows boot of this draft (`9f98dcc61`), one run. Counts only, no game data. **Machine:** Windows 10 19045, RTX 5060 Ti 16 GB, NVIDIA 621.01, 32 GB RAM, own 1.0.2.1, MSVC RelWithDebInfo (builds clean). Shaders from my work folder (47,772 loaded, 0 refused), cold pipeline cache, `LEONIDA_ARENA_MB=2048 LEONIDA_TITLE_WINDOWS_MB=1024 LEONIDA_DEVICE_TYPE=6 LEONIDA_TITLE_WATCHDOG=0 LEONIDA_MEM_PROBE=20`, no other change. Run time 431 s, ended by me. No device loss, no driver error in the event log. **Reached:** the loading screens and the world start. Then it stops the same way as my runs without it: the last submission is number 2,216 at t=217 s, `list values` stays at 7,685 recorded / 7,528 landed (157 pending), 14 gates held, 0 met, 14 timed out (9 of them at the short timeout), while the process sits idle except for one pipeline build thread. So the draft does not cause the stall and does not remove it, on this machine (RT-LIST-VALUES-STALL-SNAPSHOT, tiguan26, is the one to watch). 825 compute and 54 graphics pipelines were made, 141.6 s and 65.2 s in `vkCreate*Pipelines`; indirect draws: 9,446 recorded, 512 emitted. **What it does save, against my earlier runs:** | | this draft | my runs on main + DadaCap's mesh branch + #1592 + #1896 + #1889 + #1914 | |---|---|---| | lowest free RAM in the run | **8.0 GB** (world start, 431 s) | 2.1 to 3.5 GB (n25, n27 to n33) | | peak commit of the system | 42.7 GB | 51 to 68 GB | | longest `heaps` phase of a submission | 88 ms | up to 2.6 s without #1887 (n21: 3.6 s); 0.03 s with it (n22) while loading | Not a clean comparison: the runs differ in much (geometry copies, a 1.1 to 1.6 GB heavy pipeline cache in most of mine, host copies). One thing stands out either way: `LEONIDA_MEM_PROBE` says `pipeline cache 0 MiB` here, where mine held a 1.1 to 1.6 GB cache in memory, and the journal of this run was 791 files, 1.6 MB. The loading was slow here: 1 to 4 frames/s from 20 to 60 s, because the cache was cold. Is there anything you want measured with a warm journal or a switch (`LEONIDA_COMPILE_HELPER=1`, `LEONIDA_ASYNC_PIPELINES=1`)? I can run it. What I would watch for: whether the helper lowers the RAM peak further. A question on the stall, since your title frame counter advanced to 2,830 at 600 s under Proton: did `list values ... recorded / landed` keep moving there, and what are your last counters? AI-assisted (Claude Code, Claude Opus 5.5).
TheGeogeo commented 2026-11-25 21:17:00 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by TheGeogeo on 2026-11-25T21:17:00Z.


Overlap with #1889 (RT-BIG-COMPUTE-BUDGET), so that neither of us finds out at the merge. Read from the code of 9f98dcc6 and from trial merges; I have not built or run this pull request. I do not have the game, so I cannot test on it directly: what I check is the project's own tests and synthetic modules.

  • Conflict: this pull request is clean with main 72006d61, and has six hunks with #1889 at 0bf7ef80: d3d12_vulkan_device.cpp 5, vulkan_replay.h 1. #1889 now lists it in Depends on:; neither builds on the other, and whichever lands second rebases.
  • More than text: build_compute_pipeline keeps the static big_compile mutex for modules over 128 KiB. #1889 replaces it by default with a place at big_compile_gate() (by estimate, what a submission waits for before the warm-up), and keeps the mutex for LEONIDA_SERIAL_BIG_COMPILES=1 only. With both in, the place has to be taken before the PSO's variants_mutex_ (enter_build), because a thread that waits for memory must hold no PSO lock. LEONIDA_COMPILE_HELPER builds are in another process, so the gate does not count them; it only sees that the free memory is lower. If #1889 lands second I do that rebase.
  • A number I need: the comment at LEONIDA_COMPILE_HELPER_THREADS says about 3.5 GB of host memory for a module over 3 MB. #1889 estimates 512 bytes for each byte of SPIR-V, from synthetic modules on NVIDIA and from RADV. If those are modules near 3 MB, 3.5 GB is more than twice that. Which module sizes, GPU and driver was that, and was it one compile alone, as peak private memory of the process? If it holds, the estimate should go up, not down.

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7174865287 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2098#issuecomment-7174865287). Originally posted by [TheGeogeo](https://github.com/TheGeogeo) on 2026-11-25T21:17:00Z. --- Overlap with #1889 (RT-BIG-COMPUTE-BUDGET), so that neither of us finds out at the merge. Read from the code of 9f98dcc6 and from trial merges; I have not built or run this pull request. I do not have the game, so I cannot test on it directly: what I check is the project's own tests and synthetic modules. - **Conflict:** this pull request is clean with `main` 72006d61, and has six hunks with #1889 at 0bf7ef80: `d3d12_vulkan_device.cpp` 5, `vulkan_replay.h` 1. #1889 now lists it in `Depends on:`; neither builds on the other, and whichever lands second rebases. - **More than text:** `build_compute_pipeline` keeps the static `big_compile` mutex for modules over 128 KiB. #1889 replaces it by default with a place at `big_compile_gate()` (by estimate, what a submission waits for before the warm-up), and keeps the mutex for `LEONIDA_SERIAL_BIG_COMPILES=1` only. With both in, the place has to be taken before the PSO's `variants_mutex_` (`enter_build`), because a thread that waits for memory must hold no PSO lock. `LEONIDA_COMPILE_HELPER` builds are in another process, so the gate does not count them; it only sees that the free memory is lower. If #1889 lands second I do that rebase. - **A number I need:** the comment at `LEONIDA_COMPILE_HELPER_THREADS` says about 3.5 GB of host memory for a module over 3 MB. #1889 estimates 512 bytes for each byte of SPIR-V, from synthetic modules on NVIDIA and from RADV. If those are modules near 3 MB, 3.5 GB is more than twice that. Which module sizes, GPU and driver was that, and was it one compile alone, as peak private memory of the process? If it holds, the estimate should go up, not down. AI-assisted (Claude Code).
OreoFR commented 2026-11-25 21:32:28 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-25T21:32:28Z.


A note on the async texture refresh (LEONIDA_TEXTURE_REFRESH_ASYNC), from working on the same pass (RT-TITLE-EVERY-BUDGET): with async on, the submission only calls request_title_refresh(), so a mapped texture that has never been filled can be sampled empty by its first draw (a video plane, for example). In my local async branch I fill only those textures (mapped && !fills) synchronously in the before-execute hook, with try_to_lock on the registry and no wait if the worker holds it (waiting could deadlock on a fill that needs this queue), then wake the worker for everything else. It only visits textures that have never been filled. Untested on your branch, just a suggestion. Our two PRs also touch the same loop in refresh_title_textures; whichever lands second rebases.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7175213427 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2098#issuecomment-7175213427). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-25T21:32:28Z. --- A note on the async texture refresh (`LEONIDA_TEXTURE_REFRESH_ASYNC`), from working on the same pass (RT-TITLE-EVERY-BUDGET): with async on, the submission only calls `request_title_refresh()`, so a mapped texture that has never been filled can be sampled empty by its first draw (a video plane, for example). In my local async branch I fill only those textures (`mapped && !fills`) synchronously in the before-execute hook, with `try_to_lock` on the registry and no wait if the worker holds it (waiting could deadlock on a fill that needs this queue), then wake the worker for everything else. It only visits textures that have never been filled. Untested on your branch, just a suggestion. Our two PRs also touch the same loop in `refresh_title_textures`; whichever lands second rebases.
aslan2142 commented 2026-11-26 00:01:18 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-11-26T00:01:18Z.


Merged, thanks, @Moriz82, for the post-load memory and pipeline work, and to Snooozs, TheGeogeo and OreoFR for the boot run, the #1889 overlap map and the async-refresh catch.

  • Pipeline path: pipelines build through main's PipelineCompiles/PipelineWorkers path within the #1889 budget again; the pre-pass is gone, at the maintainers' decision. The record-time build request and the compile-helper deferral are kept on top of it.
  • Fixes we made: a dangling pNext chain in the 2D mirror view (the 120 s hangs in d3d12_existing_heap, d3d12_r9g9b9e5_uav, d3d12_depth_stencil_uav and the Xbox depth-storage tests); the table scan no longer nulls V#s of the layer's own upload buffers below the arena (the iGPU compute failures); three test targets that did not build, a byte-order mark, and an xg_xs check that contradicted main.
  • Async refresh: a mapped texture that was never filled is filled before its first submission (OreoFR's point), with d3d12_mapped_plane_async, which fails 3 of 3 runs without the fix.
  • Switches: LEONIDA_COMPUTE_WARMUP_LIVE_MAX_BYTES is opt-in (0 by default, so main's warm-up stays as it was), and 30 switches are documented.
  • Tested: the full Windows suite under Wine on llvmpipe and the gfx1036 iGPU (RADV), on main 33bd07cf8 merged with this: no pass to fail from this PR. d3d12_set_descriptor_heaps fails on main alone too, and xmem and xbox_present pass alone on llvmpipe (xbox_present fails on the iGPU with or without this PR). The translator suite passes (495 files, 6,333 tests).
  • For later: the new vk_presenter_sparse_capture fails under Wine, where creating its temp folder with an owner-rights access rule fails.
  • Checked on main 33bd07cf8 + fc7153488: it merges cleanly; the semantic suite passes (495 files, 6,333 tests, 0 files failed); the 15 docs and writer tests pass; check_no_game_data.py is clean on the 113 changed files.

AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7178308059 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2098#issuecomment-7178308059). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-11-26T00:01:18Z. --- Merged, thanks, @Moriz82, for the post-load memory and pipeline work, and to Snooozs, TheGeogeo and OreoFR for the boot run, the #1889 overlap map and the async-refresh catch. - **Pipeline path:** pipelines build through `main`'s `PipelineCompiles`/`PipelineWorkers` path within the #1889 budget again; the pre-pass is gone, at the maintainers' decision. The record-time build request and the compile-helper deferral are kept on top of it. - **Fixes we made:** a dangling `pNext` chain in the 2D mirror view (the 120 s hangs in `d3d12_existing_heap`, `d3d12_r9g9b9e5_uav`, `d3d12_depth_stencil_uav` and the Xbox depth-storage tests); the table scan no longer nulls V#s of the layer's own upload buffers below the arena (the iGPU compute failures); three test targets that did not build, a byte-order mark, and an `xg_xs` check that contradicted `main`. - **Async refresh:** a mapped texture that was never filled is filled before its first submission (OreoFR's point), with `d3d12_mapped_plane_async`, which fails 3 of 3 runs without the fix. - **Switches:** `LEONIDA_COMPUTE_WARMUP_LIVE_MAX_BYTES` is opt-in (0 by default, so `main`'s warm-up stays as it was), and 30 switches are documented. - **Tested:** the full Windows suite under Wine on llvmpipe and the gfx1036 iGPU (RADV), on `main` `33bd07cf8` merged with this: no pass to fail from this PR. `d3d12_set_descriptor_heaps` fails on `main` alone too, and `xmem` and `xbox_present` pass alone on llvmpipe (`xbox_present` fails on the iGPU with or without this PR). The translator suite passes (495 files, 6,333 tests). - **For later:** the new `vk_presenter_sparse_capture` fails under Wine, where creating its temp folder with an owner-rights access rule fails. - **Checked on `main` `33bd07cf8` + `fc7153488`:** it merges cleanly; the semantic suite passes (495 files, 6,333 tests, 0 files failed); the 15 docs and writer tests pass; `check_no_game_data.py` is clean on the 113 changed files. AI-assisted (Claude Code, Claude Opus 5.5).
ammonium231 commented 2026-11-26 14:16:47 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by ammonium231 on 2026-11-26T14:16:47Z.


RTX 3090 / 621.40: xbox_present fails the resize present_planes check (xbox_present_test.cpp:1226 on main). First bad is 9f98dcc61; reverting only its captured_ gating in vulkan_present.h passes. After a resize recreate captured_ stays false, so read_back fails. LEONIDA_COMPILE_GATE=0 and the dxgi_swapchain.h hunk don't change the result.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7194550597 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2098#issuecomment-7194550597). Originally posted by [ammonium231](https://github.com/ammonium231) on 2026-11-26T14:16:47Z. --- RTX 3090 / 621.40: xbox_present fails the resize present_planes check (xbox_present_test.cpp:1226 on main). First bad is 9f98dcc61; reverting only its captured_ gating in vulkan_present.h passes. After a resize recreate captured_ stays false, so read_back fails. LEONIDA_COMPILE_GATE=0 and the dxgi_swapchain.h hunk don't change the result.
Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
ProjectLeonida/mandy!2098
No description provided.