runtime: opt-in memory counters for the Vulkan device (RT-MEMORY-PROBE) #1291

Closed
github-bot wants to merge 1 commit from gh-pr/1291/head into gh-pr/1291/base
Owner

@⁠Moriz82 on GitHub · 2026-11-24 21:19 UTC · original
split/rt-memory-probe → main · +311 −21 · 4 files · 1 commits · closed without merging

Claimed in the coordination issue as: RT-MEMORY-PROBE (claim).

Part of the split of #984 into small pull requests.

Depends on: none
Overlaps: #984 (integration source; there the probe also read title memory ranges, descriptor shadow counts and the pipeline cache size, which need code main does not have and are left out). #1104 answers the title's GlobalMemoryStatusEx. #576 dumps thread stacks. Neither counts where the runtime's memory goes.

What and why

A long boot can exhaust memory, and the log does not say whether it went to Vulkan allocations, to pipelines and shader modules, to the GPU address arena or to the process outside Vulkan.

LEONIDA_MEM_PROBE=<seconds> turns on a probe in the Vulkan device (runtime/src/mem_probe.h). Every <seconds>, and once more when the device is destroyed, it writes to stderr:

  • [rt] mem-probe t=...: live graphics and compute pipelines and how many were made, live shader modules and their SPIR-V bytes, VkDeviceMemory per memory type with allocated and imported apart, and the arena's size, use by kind and peak end.
  • [rt] mem-probe process: the working set and private bytes Windows counts for the process.
  • [rt] mem-probe smaps, under Wine on Linux only: /proc/<pid>/smaps of the process summed per kind of mapping (PE private memory, PE images, PE sections, memory the driver mapped for vkMapMemory, device mappings, other native anonymous memory, native files), with the names of the four largest mapped files.

The lines hold counts, sizes and file names. No line holds memory or file contents.

The Vulkan counts come from wrapping nine entries of the device's function table (allocate, free, map, unmap, shader module create and destroy, the two pipeline creates, pipeline destroy) before the device allocates anything. Only the first device of a process is wrapped. The sampling thread belongs to that device and is joined before the device's state is released.

With the variable unset, empty or 0, no entry is wrapped, no thread is started and nothing is written.

A line from the run below, on a real device at teardown:

[rt] mem-probe t=0s (14:53:28): pipelines live graphics 0 compute 0 (made 40 / 0); shader modules live 0, 0 MiB SPIR-V (made 90, 0 MiB); vk memory: type 1 DL heap 0: 4 x 0 MiB; type 3 HV+HC+HCa heap 1: 1 x 0 MiB; type 4 DL+HV+HC heap 0: 2 x 256 MiB; arena 256 MiB (type 4), in use 0 MiB (buffers 0, descriptor heaps 0, shaders 0, heaps 0), peak end 0 MiB

Tested

Cross-built on CachyOS Linux 7.3 with clang-cl 23.1.5 and the xwin SDK. Ran the Windows tests one at a time under Wine 11.22 (distribution build, fresh prefix) on a Ryzen 5 5600X, 16 GB RAM, NVIDIA GeForce RTX 4070 12 GB, driver 620.73.04.

cmake --build runtime/build/boot --target mem_probe_test d3d12_draw_test gta6rt -j6
wine mem_probe_test.exe
wine mem_probe_test.exe --on
wine d3d12_draw_test.exe
LEONIDA_MEM_PROBE=1 wine d3d12_draw_test.exe
python3 -I scripts/check_no_game_data.py
python3 -I tests/test_docs_env_vars.py
git diff --check

mem_probe_test needs no GPU. It gives the probe a stand-in function table and makes the same 11 calls in both forms: three allocations of which one is imported, one map, one free, two shader modules of which one is destroyed, three graphics pipelines and one compute pipeline, one pipeline destroyed.

Command Result
mem_probe_test (variable unset) Passed in 3 runs: the table is untouched, all 11 calls reach the stand-in driver, no thread starts, stderr is empty.
mem_probe_test --on Passed in 3 runs: 9 entries wrapped, a second table left alone, all 11 calls reach the driver with their handles unchanged, 4 samples with the expected counts (one direct, two timed, one at stop), a process line per sample, the process's own smaps read, nothing written after the stop, and a hand-written smaps file classified into the 7 kinds.
d3d12_draw_test Passed, 0 probe lines.
LEONIDA_MEM_PROBE=1 d3d12_draw_test Passed, 4 probe lines: the install line and one sample (Vulkan, process, smaps) taken when the device was destroyed.
python3 -I scripts/check_no_game_data.py, tests/test_docs_env_vars.py, git diff --check Passed.
Python CI loop over the non-semantic test files, and python3 -I scripts/run_semantic_tests.py tests/semantic -j 2 One failing file, tests/test_imhex_patterns.py, as on the base. None added. Semantic suite: 470 files, 6,168 tests, 0 failing files.

The base has no LEONIDA_MEM_PROBE, so there is no base run of the new test: the evidence for the switch is the two forms above and the two d3d12_draw_test runs.

Not run: native Windows (there the smaps line is absent and the process line comes from Windows itself), Proton, AMD and Intel GPUs, a timed sample on a real device (the device tests here end within a second, so only the sample at teardown was seen), CTest itself, and a boot of the title.

GPUs tested: NVIDIA GeForce RTX 4070, driver 620.73.04, Linux under Wine 11.22 (d3d12_draw_test only; mem_probe_test uses no GPU).
AI-assisted: yes (Claude Code).

Checklist

  • Based on upstream main at the cut, one commit.
  • One topic: one opt-in diagnostic switch, its documentation and its test.
  • Off by default. The unset form of the test shows an untouched table, no thread and no output.
  • Synthetic test, no game data. Content guard and whitespace check passed.
  • No translator rule changed.

🤖 Generated with Claude Code

**@⁠Moriz82** on GitHub · 2026-11-24 21:19 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1291) `split/rt-memory-probe` → `main` · +311 −21 · 4 files · 1 commits · closed without merging Claimed in the coordination issue as: RT-MEMORY-PROBE ([claim](https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14)). Part of the split of #984 into small pull requests. Depends on: none Overlaps: #984 (integration source; there the probe also read title memory ranges, descriptor shadow counts and the pipeline cache size, which need code main does not have and are left out). #1104 answers the title's `GlobalMemoryStatusEx`. #576 dumps thread stacks. Neither counts where the runtime's memory goes. ### What and why A long boot can exhaust memory, and the log does not say whether it went to Vulkan allocations, to pipelines and shader modules, to the GPU address arena or to the process outside Vulkan. `LEONIDA_MEM_PROBE=<seconds>` turns on a probe in the Vulkan device (`runtime/src/mem_probe.h`). Every `<seconds>`, and once more when the device is destroyed, it writes to stderr: - `[rt] mem-probe t=...`: live graphics and compute pipelines and how many were made, live shader modules and their SPIR-V bytes, `VkDeviceMemory` per memory type with allocated and imported apart, and the arena's size, use by kind and peak end. - `[rt] mem-probe process`: the working set and private bytes Windows counts for the process. - `[rt] mem-probe smaps`, under Wine on Linux only: `/proc/<pid>/smaps` of the process summed per kind of mapping (PE private memory, PE images, PE sections, memory the driver mapped for `vkMapMemory`, device mappings, other native anonymous memory, native files), with the names of the four largest mapped files. The lines hold counts, sizes and file names. No line holds memory or file contents. The Vulkan counts come from wrapping nine entries of the device's function table (allocate, free, map, unmap, shader module create and destroy, the two pipeline creates, pipeline destroy) before the device allocates anything. Only the first device of a process is wrapped. The sampling thread belongs to that device and is joined before the device's state is released. With the variable unset, empty or `0`, no entry is wrapped, no thread is started and nothing is written. A line from the run below, on a real device at teardown: ``` [rt] mem-probe t=0s (14:53:28): pipelines live graphics 0 compute 0 (made 40 / 0); shader modules live 0, 0 MiB SPIR-V (made 90, 0 MiB); vk memory: type 1 DL heap 0: 4 x 0 MiB; type 3 HV+HC+HCa heap 1: 1 x 0 MiB; type 4 DL+HV+HC heap 0: 2 x 256 MiB; arena 256 MiB (type 4), in use 0 MiB (buffers 0, descriptor heaps 0, shaders 0, heaps 0), peak end 0 MiB ``` ### Tested Cross-built on CachyOS Linux 7.3 with clang-cl 23.1.5 and the xwin SDK. Ran the Windows tests one at a time under Wine 11.22 (distribution build, fresh prefix) on a Ryzen 5 5600X, 16 GB RAM, NVIDIA GeForce RTX 4070 12 GB, driver 620.73.04. ```sh cmake --build runtime/build/boot --target mem_probe_test d3d12_draw_test gta6rt -j6 wine mem_probe_test.exe wine mem_probe_test.exe --on wine d3d12_draw_test.exe LEONIDA_MEM_PROBE=1 wine d3d12_draw_test.exe python3 -I scripts/check_no_game_data.py python3 -I tests/test_docs_env_vars.py git diff --check ``` `mem_probe_test` needs no GPU. It gives the probe a stand-in function table and makes the same 11 calls in both forms: three allocations of which one is imported, one map, one free, two shader modules of which one is destroyed, three graphics pipelines and one compute pipeline, one pipeline destroyed. | Command | Result | |---|---| | `mem_probe_test` (variable unset) | Passed in 3 runs: the table is untouched, all 11 calls reach the stand-in driver, no thread starts, stderr is empty. | | `mem_probe_test --on` | Passed in 3 runs: 9 entries wrapped, a second table left alone, all 11 calls reach the driver with their handles unchanged, 4 samples with the expected counts (one direct, two timed, one at stop), a process line per sample, the process's own smaps read, nothing written after the stop, and a hand-written smaps file classified into the 7 kinds. | | `d3d12_draw_test` | Passed, 0 probe lines. | | `LEONIDA_MEM_PROBE=1` `d3d12_draw_test` | Passed, 4 probe lines: the install line and one sample (Vulkan, process, smaps) taken when the device was destroyed. | | `python3 -I scripts/check_no_game_data.py`, `tests/test_docs_env_vars.py`, `git diff --check` | Passed. | | Python CI loop over the non-semantic test files, and `python3 -I scripts/run_semantic_tests.py tests/semantic -j 2` | One failing file, `tests/test_imhex_patterns.py`, as on the base. None added. Semantic suite: 470 files, 6,168 tests, 0 failing files. | The base has no `LEONIDA_MEM_PROBE`, so there is no base run of the new test: the evidence for the switch is the two forms above and the two `d3d12_draw_test` runs. Not run: native Windows (there the smaps line is absent and the process line comes from Windows itself), Proton, AMD and Intel GPUs, a timed sample on a real device (the device tests here end within a second, so only the sample at teardown was seen), CTest itself, and a boot of the title. GPUs tested: NVIDIA GeForce RTX 4070, driver 620.73.04, Linux under Wine 11.22 (`d3d12_draw_test` only; `mem_probe_test` uses no GPU). AI-assisted: yes (Claude Code). ### Checklist - [x] Based on upstream main at the cut, one commit. - [x] One topic: one opt-in diagnostic switch, its documentation and its test. - [x] Off by default. The unset form of the test shows an untouched table, no thread and no output. - [x] Synthetic test, no game data. Content guard and whitespace check passed. - [x] No translator rule changed. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
A long boot can run out of memory, and nothing says whether it went to
Vulkan allocations, pipelines, the GPU address arena or the process
itself.

LEONIDA_MEM_PROBE=<seconds> wraps nine entries of the device's function
table and writes, every <seconds> and once more when the device is
destroyed, the live pipelines by kind, the
shader modules and their SPIR-V bytes, VkDeviceMemory per memory type
(allocated and imported apart), the arena's use, and the working set and
private bytes of the process. Under Wine on Linux it also sums the
process's smaps per kind of mapping. The lines hold counts, sizes and
file names. Unset, nothing is wrapped, no thread is started and nothing
is written. The sampling thread ends with the device.

Cross-built gta6rt and mem_probe_test. The test drives a stand-in
function table: unset, the table is untouched and nothing is written;
set, the entries are wrapped, all calls still reach the driver and the
lines carry the expected counts. Both forms passed under Wine 11.22.
d3d12_draw_test passed with the variable unset and set on an RTX 4070.

AI-assisted (Claude Code).

Co-authored-by: Plaaasma <[email protected]>
Co-Authored-By: Claude Fable 5.2 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:46:15 +00:00
github-bot closed this pull request 2026-11-26 09:46:15 +00:00

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.