[PR #1291] [CLOSED] runtime: opt-in memory counters for the Vulkan device (RT-MEMORY-PROBE) #1322

Closed
opened 2026-11-26 20:20:51 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1291
Author: @Moriz82
Created: 11/24/2026
Status: ❌ Closed

Base: main ← Head: split/rt-memory-probe


📝 Commits (1)

  • 4aa1096 runtime: opt-in memory counters for the Vulkan device (RT-MEMORY-PROBE)

📊 Changes

4 files changed (+311 additions, -21 deletions)

View changed files

📝 runtime/CMakeLists.txt (+12 -0)
📝 runtime/shims/d3d12_vulkan_device.cpp (+5 -3)
📝 runtime/src/mem_probe.h (+45 -18)
➕ runtime/test/mem_probe_test.cpp (+249 -0)

📄 Description

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


🔄 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/1291 **Author:** [@Moriz82](https://github.com/Moriz82) **Created:** 11/24/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `split/rt-memory-probe` --- ### 📝 Commits (1) - [`4aa1096`](https://github.com/ubiquitarianism/leonida/commit/4aa1096723a152e395efcc9d13d165da00f7246e) runtime: opt-in memory counters for the Vulkan device (RT-MEMORY-PROBE) ### 📊 Changes **4 files changed** (+311 additions, -21 deletions) <details> <summary>View changed files</summary> 📝 `runtime/CMakeLists.txt` (+12 -0) 📝 `runtime/shims/d3d12_vulkan_device.cpp` (+5 -3) 📝 `runtime/src/mem_probe.h` (+45 -18) ➕ `runtime/test/mem_probe_test.cpp` (+249 -0) </details> ### 📄 Description Claimed in the coordination issue as: RT-MEMORY-PROBE ([claim](https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7144784981)). 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) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 20:20:51 +01:00
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#1322
No description provided.