[PR #2401] [MERGED] mem probe: a breakdown line of the runtime's Vulkan memory by consumer (RT-MEMORY-BREAKDOWN-AND-SPARSE-ARENA) #2401

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

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/2401
Author: @aslan2142
Created: 11/26/2026
Status: ✅ Merged
Merged: 11/26/2026
Merged by: @aslan2142

Base: main ← Head: memory-breakdown-line


📝 Commits (1)

  • aaff77b mem probe: a breakdown line of the runtime's Vulkan memory by consumer (RT-MEMORY-BREAKDOWN-AND-SPARSE-ARENA)

📊 Changes

7 files changed (+376 additions, -7 deletions)

View changed files

📝 runtime/CMakeLists.txt (+6 -0)
📝 runtime/README.md (+1 -0)
📝 runtime/shims/d3d12_geometry_views.h (+2 -0)
📝 runtime/shims/d3d12_vulkan_device.cpp (+34 -5)
📝 runtime/src/mem_probe.h (+63 -2)
➕ runtime/src/memory_breakdown.h (+152 -0)
➕ runtime/test/memory_breakdown_test.cpp (+118 -0)

📄 Description

Adds one diagnostic line to the memory probe: our Vulkan allocations broken down by consumer, so the VRAM the game
uses in the world can be attributed before anything is changed. No behaviour changes.

Claimed in the coordination issue as: RT-MEMORY-BREAKDOWN-AND-SPARSE-ARENA

What was measured

  • The HUD's VRAM figure matches the sum of our own vkAllocateMemory bytes in the device-local heap to within
    about 0.1-0.3 GB, so what needs explaining is in our allocations.
  • In a late world run about 7.5 GB of device-local-only memory (textures, render targets, image blocks) and up
    to 1.2 GB of the Resizable BAR type cannot be split by today's log lines.
  • The GPU address arena (LEONIDA_ARENA_MB=4095) had about 0.76 GB in use (peak about 1 GB); the rest of its
    4 GiB was allocated and never touched.

What changes

One commit:

  • [rt] mem-probe breakdown t=<s>: on every LEONIDA_MEM_PROBE tick. It prints:

    • the allocated total;
    • the arena, with its reserved, bound and in-use MiB (in use split into buffers, descriptor heaps, shader code
      and heaps);
    • geometry copies;
    • title windows and shadows;
    • upload heaps;
    • staging;
    • texture blocks;
    • sampled textures;
    • render targets and depth;
    • other.

    The parts add up to the total. Imported memory is shown apart. Bindless tables, shader modules, pipelines and
    swapchain images are shown beside the total, not in it.

  • src/memory_breakdown.h (new, standard library only): the consumers, an Owner scope that names the
    allocations a thread makes while it lives, the tally and the text.

  • src/mem_probe.h: the vkAllocateMemory wrapper records the thread's owner. vkCreateImage,
    vkDestroyImage and vkBindImageMemory are wrapped too, so unnamed memory that a dedicated image is bound to
    counts as a render target/depth buffer or a sampled texture.

  • Owner scopes at the allocation sites of the arena, geometry copies, title windows, slot-133 shadow buffers,
    upload/readback heaps, staging and copy scratch, and the texture blocks.

  • runtime/README.md: a LEONIDA_MEM_PROBE row that names the three probe lines.

The second half of the item, a sparse arena (memory bound only where allocations are), is not in this pull
request. Step 0 found what blocks it (below).

Device support

The breakdown line works on any device. Findings for the sparse arena, from a test program (Mesa 26.3.1, natively
and through Wine 11.22):

RX 7900 XTX (RADV) Radeon iGPU 1002:164e (RADV) llvmpipe
sparseBinding / sparseResidencyBuffer yes / yes yes / yes yes / yes
residencyNonResidentStrict yes yes no
sparseAddressSpaceSize 128 TiB 128 TiB 2 GiB (smaller than a 4095 MiB arena)
sparse buffer with every arena usage and a device address created, 64 KiB pages, BAR type allowed same created
bind, GPU read/write through the device address, unbind (reads 0), rebind pass pass pass
VK_EXT_map_memory_placed natively / under Wine yes / no yes / no no / no

What blocks the sparse arena is the CPU side, not the GPU. Today the arena has one contiguous CPU mapping
(arena.mapped + offset, about 50 uses). A sparse buffer has no mapping of its own: each backing block is mapped
by itself. Only VK_EXT_map_memory_placed can place those mappings into one contiguous range, and Wine's
winevulkan does not offer it to Windows programs. The design has to change first. Either the arena's CPU
contract becomes one mapping per backing block, with no allocation crossing a block and the whole-arena users
reworked, or Wine starts offering placed mappings.

Tests

  • memory_breakdown_test (CPU, new): the tally, owner scopes, image kinds and the text. It does not build on
    main.
  • Linux runtime build and ctest: 114 of 114 pass on llvmpipe and on the integrated GPU (RADV, Mesa 26.3.1).
  • Windows suite under Wine (clang-cl cross-build), compared test by test with main 2d43417d4:
    • llvmpipe: no test went from pass to fail. memory_breakdown is new and passes. d3d12_queue_handover
      failed on main and passed here.
    • iGPU: no test went from pass to fail. memory_breakdown is new and passes. The same 23 tests fail as on
      main (presentation tests under xvfb and other known failures).
  • tests/test_docs_*.py, tests/test_ci_registration.py, tests/test_text_write_line_endings.py and
    scripts/check_no_game_data.py on the changed files pass.

Not tested

  • The line in a game run: the consumer split is only checked on synthetic allocations.
  • No world run from this build. The line changes no behaviour; the next run here will read it at three points and report what the device-local memory consists of.

AI-assisted (Claude Code, Claude Opus 5.5 and Claude Fable 5.2)


🔄 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/2401 **Author:** [@aslan2142](https://github.com/aslan2142) **Created:** 11/26/2026 **Status:** ✅ Merged **Merged:** 11/26/2026 **Merged by:** [@aslan2142](https://github.com/aslan2142) **Base:** `main` ← **Head:** `memory-breakdown-line` --- ### 📝 Commits (1) - [`aaff77b`](https://github.com/ubiquitarianism/leonida/commit/aaff77b831a5167b4b255fe92b7cde4add593b98) mem probe: a breakdown line of the runtime's Vulkan memory by consumer (RT-MEMORY-BREAKDOWN-AND-SPARSE-ARENA) ### 📊 Changes **7 files changed** (+376 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `runtime/CMakeLists.txt` (+6 -0) 📝 `runtime/README.md` (+1 -0) 📝 `runtime/shims/d3d12_geometry_views.h` (+2 -0) 📝 `runtime/shims/d3d12_vulkan_device.cpp` (+34 -5) 📝 `runtime/src/mem_probe.h` (+63 -2) ➕ `runtime/src/memory_breakdown.h` (+152 -0) ➕ `runtime/test/memory_breakdown_test.cpp` (+118 -0) </details> ### 📄 Description Adds one diagnostic line to the memory probe: our Vulkan allocations broken down by consumer, so the VRAM the game uses in the world can be attributed before anything is changed. No behaviour changes. Claimed in the coordination issue as: [RT-MEMORY-BREAKDOWN-AND-SPARSE-ARENA](https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7201355992) ## What was measured - The HUD's VRAM figure matches the sum of our own `vkAllocateMemory` bytes in the device-local heap to within about 0.1-0.3 GB, so what needs explaining is in our allocations. - In a late world run about 7.5 GB of device-local-only memory (textures, render targets, image blocks) and up to 1.2 GB of the Resizable BAR type cannot be split by today's log lines. - The GPU address arena (`LEONIDA_ARENA_MB=4095`) had about 0.76 GB in use (peak about 1 GB); the rest of its 4 GiB was allocated and never touched. ## What changes One commit: - `[rt] mem-probe breakdown t=<s>:` on every `LEONIDA_MEM_PROBE` tick. It prints: - the allocated total; - the arena, with its reserved, bound and in-use MiB (in use split into buffers, descriptor heaps, shader code and heaps); - geometry copies; - title windows and shadows; - upload heaps; - staging; - texture blocks; - sampled textures; - render targets and depth; - `other`. The parts add up to the total. Imported memory is shown apart. Bindless tables, shader modules, pipelines and swapchain images are shown beside the total, not in it. - `src/memory_breakdown.h` (new, standard library only): the consumers, an `Owner` scope that names the allocations a thread makes while it lives, the tally and the text. - `src/mem_probe.h`: the `vkAllocateMemory` wrapper records the thread's owner. `vkCreateImage`, `vkDestroyImage` and `vkBindImageMemory` are wrapped too, so unnamed memory that a dedicated image is bound to counts as a render target/depth buffer or a sampled texture. - `Owner` scopes at the allocation sites of the arena, geometry copies, title windows, slot-133 shadow buffers, upload/readback heaps, staging and copy scratch, and the texture blocks. - `runtime/README.md`: a `LEONIDA_MEM_PROBE` row that names the three probe lines. The second half of the item, a sparse arena (memory bound only where allocations are), is **not** in this pull request. Step 0 found what blocks it (below). ## Device support The breakdown line works on any device. Findings for the sparse arena, from a test program (Mesa 26.3.1, natively and through Wine 11.22): | | RX 7900 XTX (RADV) | Radeon iGPU 1002:164e (RADV) | llvmpipe | |---|---|---|---| | `sparseBinding` / `sparseResidencyBuffer` | yes / yes | yes / yes | yes / yes | | `residencyNonResidentStrict` | yes | yes | no | | `sparseAddressSpaceSize` | 128 TiB | 128 TiB | 2 GiB (smaller than a 4095 MiB arena) | | sparse buffer with every arena usage and a device address | created, 64 KiB pages, BAR type allowed | same | created | | bind, GPU read/write through the device address, unbind (reads 0), rebind | pass | pass | pass | | `VK_EXT_map_memory_placed` natively / under Wine | yes / **no** | yes / **no** | no / no | What blocks the sparse arena is the CPU side, not the GPU. Today the arena has one contiguous CPU mapping (`arena.mapped + offset`, about 50 uses). A sparse buffer has no mapping of its own: each backing block is mapped by itself. Only `VK_EXT_map_memory_placed` can place those mappings into one contiguous range, and Wine's `winevulkan` does not offer it to Windows programs. The design has to change first. Either the arena's CPU contract becomes one mapping per backing block, with no allocation crossing a block and the whole-arena users reworked, or Wine starts offering placed mappings. ## Tests - `memory_breakdown_test` (CPU, new): the tally, owner scopes, image kinds and the text. It does not build on `main`. - Linux runtime build and `ctest`: 114 of 114 pass on llvmpipe and on the integrated GPU (RADV, Mesa 26.3.1). - Windows suite under Wine (clang-cl cross-build), compared test by test with `main` 2d43417d4: - llvmpipe: no test went from pass to fail. `memory_breakdown` is new and passes. `d3d12_queue_handover` failed on `main` and passed here. - iGPU: no test went from pass to fail. `memory_breakdown` is new and passes. The same 23 tests fail as on `main` (presentation tests under xvfb and other known failures). - `tests/test_docs_*.py`, `tests/test_ci_registration.py`, `tests/test_text_write_line_endings.py` and `scripts/check_no_game_data.py` on the changed files pass. ## Not tested - The line in a game run: the consumer split is only checked on synthetic allocations. - No world run from this build. The line changes no behaviour; the next run here will read it at three points and report what the device-local memory consists of. AI-assisted (Claude Code, Claude Opus 5.5 and Claude Fable 5.2) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 21:21:07 +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#2401
No description provided.