mem-probe: say how full the shared texture blocks are (RT-MEMPROBE-TEXTURE-BLOCKS) #2547

Closed
leonida/mandy
Tyrannys wants to merge 0 commits from claude/memprobe-texture-blocks into main

Pull request closed

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

Tyrannys commented 2026-11-28 01:45:03 +00:00

Claimed in the coordination issue as: RT-MEMPROBE-TEXTURE-BLOCKS (https://github.com/ProjectLeonida/mandy/issues/1608#issuecomment-7231847971).

What and why

With LEONIDA_MEM_PROBE, the breakdown line counts the shared texture blocks (src/image_memory.h) only as driver allocations: texture blocks 4934 (77). In recent world runs they are the largest consumer of device-local memory, 4.9-6.5 GiB, and they never shrink. The line could not say whether that is texture data or free space kept inside the blocks: one empty block is kept per memory type, and released ranges leave holes.

The breakdown now adds, after the texture blocks:

texture blocks 4934 (77) [21000 textures in 4100 MiB, 834 MiB free inside the blocks (2 empty blocks, largest free piece 64)]

(numbers from the unit test, not a run). ImageMemoryPool::stats() gains what it needs: the bytes the ranges hold, the empty blocks and the largest free piece. They are read under the pool's own lock, once a probe tick. DeviceShare carries them to memory_breakdown::format. Nothing else changes; the bracket is left out when a device has no texture blocks.

Tested

  • image_memory_test: a full block has every byte in use and no free piece. With one block full, one emptied and one in another memory type: 65 MiB used of 192 MiB, 1 empty block, largest free piece 64 MiB.
  • memory_breakdown_test: the line carries the new bracket after the texture blocks, with the free bytes computed from block bytes minus used. Without the share it is left out.
  • Both pass; gta6rt_d3d12_com builds (MSVC 17, Release). CPU only, no GPU, no game data.

GPUs tested: n/a (CPU tests).

AI-assisted: yes (Claude Code)

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.

🤖 Generated with Claude Code

Claimed in the coordination issue as: RT-MEMPROBE-TEXTURE-BLOCKS (https://github.com/ProjectLeonida/mandy/issues/1608#issuecomment-7231847971). ### What and why With `LEONIDA_MEM_PROBE`, the breakdown line counts the shared texture blocks (`src/image_memory.h`) only as driver allocations: `texture blocks 4934 (77)`. In recent world runs they are the largest consumer of device-local memory, 4.9-6.5 GiB, and they never shrink. The line could not say whether that is texture data or free space kept inside the blocks: one empty block is kept per memory type, and released ranges leave holes. The breakdown now adds, after the texture blocks: ``` texture blocks 4934 (77) [21000 textures in 4100 MiB, 834 MiB free inside the blocks (2 empty blocks, largest free piece 64)] ``` (numbers from the unit test, not a run). `ImageMemoryPool::stats()` gains what it needs: the bytes the ranges hold, the empty blocks and the largest free piece. They are read under the pool's own lock, once a probe tick. `DeviceShare` carries them to `memory_breakdown::format`. Nothing else changes; the bracket is left out when a device has no texture blocks. ### Tested - `image_memory_test`: a full block has every byte in use and no free piece. With one block full, one emptied and one in another memory type: 65 MiB used of 192 MiB, 1 empty block, largest free piece 64 MiB. - `memory_breakdown_test`: the line carries the new bracket after the texture blocks, with the free bytes computed from block bytes minus used. Without the share it is left out. - Both pass; `gta6rt_d3d12_com` builds (MSVC 17, Release). CPU only, no GPU, no game data. GPUs tested: n/a (CPU tests). AI-assisted: yes (Claude Code) ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
akimfomin commented 2026-11-28 01:59:50 +00:00

The new live/free split can distinguish an active texture peak from retained allocator reserve. KytyPS5 #1394 has a useful independent mixed-size churn case, and AnyXboxX #550 distinguishes empty reserve at a budget threshold. A compact control for output would compare the same live byte count in two traces with different largest free spans. Peak block bytes alone would make them look the same.

The new live/free split can distinguish an active texture peak from retained allocator reserve. [KytyPS5 #1394](https://github.com/KytyPS5/KytyPS5/pull/1394) has a useful independent mixed-size churn case, and [AnyXboxX #550](https://github.com/LooperSalty/AnyXboxX/pull/550) distinguishes empty reserve at a budget threshold. A compact control for output would compare the same live byte count in two traces with different largest free spans. Peak block bytes alone would make them look the same.
Tyrannys commented 2026-11-28 02:08:48 +00:00

@akimfomin thank you for the pointers and the control idea. I added our own synthetic version in 627335d69 (image_memory_test, churn_stats), written here, not taken from either project:

  • A seeded mixed-size churn (64 KiB to 8 MiB textures, about a third of the steps releasing a random live one, 4000 steps). At every step it checks that the used bytes equal the live ranges' sum, the range count matches, and at most one block is empty. A drained pool keeps one empty block as a single free piece.
  • Your control: two pools with the same 32 MiB live in one 64 MiB block. One is packed; the other has every other texture of a full block released. They report the same used and block bytes, but a largest free piece of 32 MiB against 1 MiB. Block bytes alone would not tell them apart.

image_memory_test passes. AI-assisted (Claude Code).

@akimfomin thank you for the pointers and the control idea. I added our own synthetic version in 627335d69 (`image_memory_test`, `churn_stats`), written here, not taken from either project: - A seeded mixed-size churn (64 KiB to 8 MiB textures, about a third of the steps releasing a random live one, 4000 steps). At every step it checks that the used bytes equal the live ranges' sum, the range count matches, and at most one block is empty. A drained pool keeps one empty block as a single free piece. - Your control: two pools with the same 32 MiB live in one 64 MiB block. One is packed; the other has every other texture of a full block released. They report the same used and block bytes, but a largest free piece of 32 MiB against 1 MiB. Block bytes alone would not tell them apart. `image_memory_test` passes. AI-assisted (Claude Code).
zmasi commented 2026-11-28 07:05:23 +00:00

#2547 | head 627335d693509f6cdd6a18a7271c9948d087db6d (merged cleanly with main 09c153948386fd658fe2f999f6176efbaa8c8345) | ctest --test-dir runtime/build -C RelWithDebInfo -R "^(image_memory|memory_breakdown|d3d12_existing_heap)$" --output-on-failure (LEONIDA_VK_VALIDATION=1, LEONIDA_MEM_PROBE=1) | red on main: image_memory_test.cpp and memory_breakdown_test.cpp fail to compile (C2039: used_bytes, empty_blocks, largest_free missing on ImageMemoryPool::Stats, and texture_blocks / block_* missing on DeviceShare) | green on PR+main: 3/3 CTests pass (image_memory including churn_stats 4,000-step mixed-size churn and packed-vs-holed largest-free checks, memory_breakdown formatting texture blocks 4934 (1) [21000 textures in 4100 MiB, 834 MiB free inside the blocks (2 empty blocks, largest free piece 64)], and d3d12_existing_heap on RTX 3090 with LEONIDA_MEM_PROBE=1); check_no_game_data.py 0 violations | Windows 11, RTX 3090 (610.88), Vulkan SDK 1.4.363.1 | AI-assisted: yes

#2547 | head 627335d693509f6cdd6a18a7271c9948d087db6d (merged cleanly with main 09c153948386fd658fe2f999f6176efbaa8c8345) | `ctest --test-dir runtime/build -C RelWithDebInfo -R "^(image_memory|memory_breakdown|d3d12_existing_heap)$" --output-on-failure` (`LEONIDA_VK_VALIDATION=1`, `LEONIDA_MEM_PROBE=1`) | red on main: `image_memory_test.cpp` and `memory_breakdown_test.cpp` fail to compile (`C2039`: `used_bytes`, `empty_blocks`, `largest_free` missing on `ImageMemoryPool::Stats`, and `texture_blocks` / `block_*` missing on `DeviceShare`) | green on PR+main: `3/3` CTests pass (`image_memory` including `churn_stats` 4,000-step mixed-size churn and packed-vs-holed largest-free checks, `memory_breakdown` formatting `texture blocks 4934 (1) [21000 textures in 4100 MiB, 834 MiB free inside the blocks (2 empty blocks, largest free piece 64)]`, and `d3d12_existing_heap` on RTX 3090 with `LEONIDA_MEM_PROBE=1`); `check_no_game_data.py` `0` violations | Windows 11, RTX 3090 (610.88), Vulkan SDK 1.4.363.1 | AI-assisted: yes
lixonik approved these changes 2026-11-28 09:28:00 +00:00
lixonik left a comment

Reviewed the diff and tested merged onto main (493867366) with Ninja Release (MSVC).

Adding used_bytes, empty_blocks, and largest_free to ImageMemoryPool::Stats, surfacing them in memory_breakdown::format, and verifying mixed-size churn and fragmentation in image_memory_test is clean and non-intrusive.

Tests run

  • cmake --build <build> --target image_memory_test memory_breakdown_test gta6rt_d3d12_com: built cleanly.
  • ctest --output-on-failure -R "^(image_memory|memory_breakdown)$": 2/2 passed.

AI-assisted (Antigravity, Gemini).

Reviewed the diff and tested merged onto `main` (`493867366`) with Ninja Release (MSVC). Adding `used_bytes`, `empty_blocks`, and `largest_free` to `ImageMemoryPool::Stats`, surfacing them in `memory_breakdown::format`, and verifying mixed-size churn and fragmentation in `image_memory_test` is clean and non-intrusive. ### Tests run - `cmake --build <build> --target image_memory_test memory_breakdown_test gta6rt_d3d12_com`: built cleanly. - `ctest --output-on-failure -R "^(image_memory|memory_breakdown)$"`: **2/2 passed**. AI-assisted (Antigravity, Gemini).
KelboLive commented 2026-11-30 17:02:07 +00:00

Independent check on Windows (not the author), at 627335d69.

  • image_memory_test: pass — textures share blocks, and released ranges are used again.
  • memory_breakdown_test: pass (memory_breakdown: ok), including the new block-occupancy fields.

Environment: Ryzen 9 7950X3D, Windows 11 Pro 10.0.26200.9711.

AI-assisted: yes (opencode).

Independent check on Windows (not the author), at `627335d69`. - `image_memory_test`: **pass** — `textures share blocks, and released ranges are used again`. - `memory_breakdown_test`: **pass** (`memory_breakdown: ok`), including the new block-occupancy fields. Environment: Ryzen 9 7950X3D, Windows 11 Pro 10.0.26200.9711. AI-assisted: yes (opencode).
aslan2142 commented 2026-12-01 16:46:01 +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.