mem-probe: the line says VRAM used of the budget, not just the card's size #2793

Closed
github-bot wants to merge 1 commit from github-bot/gh-2793 into main AGit
Owner

@⁠fiestorra on GitHub · 2026-11-30 21:30 UTC · original
fiestorra:mem-probe-vram-budget → main · +14 −3 · 1 files · 1 commits · closed without merging

mem-probe prints the runtime's allocations and the card's numbers, but not the pair that decides whether an allocation survives: VK_EXT_memory_budget's heapUsage and heapBudget. This adds them to the line.

[rt] mem-probe t=182s: ...; fsdraw pipeline notes 0; VRAM 6.8/22.8 GB

Why it matters, and why the card's size is the wrong number: on this machine,

MiB
VkMemoryHeap.size, device-local 24,138
heapBudget, device-local 23,370
what a run reached 24,057

The budget is 768 MiB under the heap, and the run went 687 MiB past the budget. On the 8 GB class the gap is the whole bug: the title settles at 7.7 GB, which is already over that card's budget before the story's burst arrives - so "GPU usage reaches 7 GB" was reading the honest number and comparing it against the wrong ceiling.

What changed, in runtime/shims/d3d12_vulkan_device.cpp, 14 lines:

  • read_vram_budget(d.info) - it already exists, and memory_figures::VramBudget already has local_usage and local_budget, so this is the print, not new machinery;
  • text goes from 512 to 768 bytes, since the line grows by up to 24;
  • the part is empty, not 0/0, when there is nothing to report (available == false: no extension, no device, or no device-local budget) - the same rule vram_text follows;
  • no new include: memory_figures.h is not included by this file, so the two numbers are formatted here with the same double(x) / (1ull << 30) shape rather than pulling vram_text in.

Measured, on the RTX 4090 / driver 621.24 / main d8ca18240 plus this diff, Release, real run:

available:      ...; fsdraw pipeline notes 0; VRAM 1.4/22.8 GB      (at start)
                ...; fsdraw pipeline notes 0; VRAM 6.8/22.8 GB      (title up)
not available:  ...; fsdraw pipeline notes 0                        (guard forced off)

The last line is the control: with budget.available forced false the suffix disappears, so the empty case is the guard and not an accident of formatting, and the number tracks the run (1.4 → 6.8 as the title came up).

What this does not do: it does not gate on the budget. It makes the number visible so the next report can say "18.2 of a 19.4 GB budget" - deciding what to do at 90% of it is a separate change, and the gate is in runtime/shims/d3d12_vulkan_device.cpp around line 6447, which I did not touch.

AI-assisted: yes - DeepSeek v4.1 (flash) wrote, built, ran and mutated it on the machine above. Suggested from #2607, where the burst that loses an 8 GB card's device finally had a number to compare against.

Written with an AI assistant.

**@⁠fiestorra** on GitHub · 2026-11-30 21:30 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/2793) `fiestorra:mem-probe-vram-budget` → `main` · +14 −3 · 1 files · 1 commits · closed without merging **`mem-probe` prints the runtime's allocations and the card's numbers, but not the pair that decides whether an allocation survives: `VK_EXT_memory_budget`'s `heapUsage` and `heapBudget`. This adds them to the line.** ``` [rt] mem-probe t=182s: ...; fsdraw pipeline notes 0; VRAM 6.8/22.8 GB ``` **Why it matters, and why the card's size is the wrong number:** on this machine, | | MiB | |---|---| | `VkMemoryHeap.size`, device-local | **24,138** | | `heapBudget`, device-local | **23,370** | | what a run reached | **24,057** | **The budget is 768 MiB under the heap, and the run went 687 MiB past the budget.** **On the 8 GB class the gap is the whole bug**: the title settles at **7.7 GB**, **which is already over that card's budget before the story's burst arrives** - **so "GPU usage reaches 7 GB" was reading the honest number and comparing it against the wrong ceiling.** **What changed, in `runtime/shims/d3d12_vulkan_device.cpp`, 14 lines:** - **`read_vram_budget(d.info)`** - **it already exists, and `memory_figures::VramBudget` already has `local_usage` and `local_budget`**, so this is the print, not new machinery; - **`text` goes from 512 to 768 bytes**, since the line grows by up to 24; - **the part is empty, not `0/0`, when there is nothing to report** (`available == false`: no extension, no device, or no device-local budget) - **the same rule `vram_text` follows**; - **no new include**: `memory_figures.h` is not included by this file, **so the two numbers are formatted here** with the same `double(x) / (1ull << 30)` shape rather than pulling `vram_text` in. **Measured, on the RTX 4090 / driver 621.24 / `main` `d8ca18240` plus this diff, Release, real run:** ``` available: ...; fsdraw pipeline notes 0; VRAM 1.4/22.8 GB (at start) ...; fsdraw pipeline notes 0; VRAM 6.8/22.8 GB (title up) not available: ...; fsdraw pipeline notes 0 (guard forced off) ``` **The last line is the control**: with `budget.available` forced false the suffix disappears, **so the empty case is the guard and not an accident of formatting**, **and the number tracks the run** (1.4 → 6.8 as the title came up). **What this does not do:** **it does not gate on the budget.** **It makes the number visible so the next report can say "18.2 of a 19.4 GB budget"** - **deciding what to do at 90% of it is a separate change, and the gate is in `runtime/shims/d3d12_vulkan_device.cpp` around line 6447, which I did not touch.** **AI-assisted:** yes - DeepSeek v4.1 (flash) wrote, built, ran and mutated it on the machine above. **Suggested from #2607, where the burst that loses an 8 GB card's device finally had a number to compare against.** Written with an AI assistant.
The probe prints the runtime's own allocations and the driver's numbers for the card, but not the two
that decide whether an allocation survives: VK_EXT_memory_budget's heapUsage and heapBudget over the
device-local heaps. read_vram_budget already reads them and memory_figures already has the struct, so
this is the print. On the RTX 4090 here it reads 'VRAM 1.4/22.8 GB' at start and 'VRAM 6.8/22.8 GB'
once the title is up; when the extension or the device does not report it the part is empty rather than
0/0, measured by forcing the guard off. The gap matters because the budget is 23370 MiB on a 24138
MiB heap, and it is the budget a title that settles at 7.7 GB already exceeds on an 8 GB card.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-30 21:33:53 +00:00
Author
Owner

@⁠OreoFR on GitHub · 2026-11-30 21:33 UTC · original

Verified by OreoFR on macOS 27.2.1, Apple M5, head 17667177a, main 0b6e0e3bc. Read-only review: runtime/shims/d3d12_vulkan_device.cpp is only built on Windows (gta6rt_d3d12_com), so the Mac can't compile or run this change.

READ IN CODE

  • read_vram_budget(const VulkanDeviceInfo&) is declared at line 3663 and defined at line 21738 of the PR's file, and is already used at lines 6446, 21778 and 30735. leonida::VramBudget (runtime/src/memory_figures.h:31) has available, local_usage and local_budget, so this is a new print only.
  • read_vram_budget returns {} (available == false) when memory_budget, get_instance_proc or instance is missing, so the part stays empty. It queries vkGetPhysicalDeviceMemoryProperties2 on the physical device, which needs no external sync, so calling it from the probe lambda without taking a lock is fine.
  • Sizes: the vram part is at most about 40 characters (; VRAM %.1f/%.1f GB), it fits in char[96], and text grows from 512 to 768. snprintf truncates in any case.
  • %s is the last conversion and vram the last argument, so the order matches. Nothing in the repo parses the end of the [rt] mem-probe line after pipeline notes. Only the LEONIDA_MEM_PROBE README row describes the line, and it does not list every field.

ASSUMED

  • That it compiles cleanly under MSVC /W4 and that the numbers match your table. A Windows build or a run is needed for both.

Nit: the README's LEONIDA_MEM_PROBE row could mention the new VRAM used/budget part, but that's optional.

AI-assisted: Claude Code

**@⁠OreoFR** on GitHub · 2026-11-30 21:33 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/2793#issuecomment-7292577035) Verified by OreoFR on macOS 27.2.1, Apple M5, head `17667177a`, main `0b6e0e3bc`. Read-only review: `runtime/shims/d3d12_vulkan_device.cpp` is only built on Windows (`gta6rt_d3d12_com`), so the Mac can't compile or run this change. **READ IN CODE** - `read_vram_budget(const VulkanDeviceInfo&)` is declared at line 3663 and defined at line 21738 of the PR's file, and is already used at lines 6446, 21778 and 30735. `leonida::VramBudget` (`runtime/src/memory_figures.h:31`) has `available`, `local_usage` and `local_budget`, so this is a new print only. - `read_vram_budget` returns `{}` (`available == false`) when `memory_budget`, `get_instance_proc` or `instance` is missing, so the part stays empty. It queries `vkGetPhysicalDeviceMemoryProperties2` on the physical device, which needs no external sync, so calling it from the probe lambda without taking a lock is fine. - Sizes: the `vram` part is at most about 40 characters (`; VRAM %.1f/%.1f GB`), it fits in `char[96]`, and `text` grows from 512 to 768. `snprintf` truncates in any case. - `%s` is the last conversion and `vram` the last argument, so the order matches. Nothing in the repo parses the end of the `[rt] mem-probe` line after `pipeline notes`. Only the `LEONIDA_MEM_PROBE` README row describes the line, and it does not list every field. **ASSUMED** - That it compiles cleanly under MSVC `/W4` and that the numbers match your table. A Windows build or a run is needed for both. Nit: the README's `LEONIDA_MEM_PROBE` row could mention the new `VRAM used/budget` part, but that's optional. AI-assisted: Claude Code
Author
Owner

@⁠KelboLive on GitHub · 2026-12-01 05:40 UTC · original · reviewed

The pair is the right one: both numbers come from the same vkGetPhysicalDeviceMemoryProperties2 budget struct and are summed over the same DEVICE_LOCAL heaps (runtime/src/vulkan_memory_budget.h:19-43), and it is the reader the runtime's own "does a local allocation survive" gate already uses (d3d12_vulkan_device.cpp:6446-6450), so used and budget are comparable. On this machine the reader reports 301 of 15293 MiB against a 16 GB card, as the PR says.

Edge cases hold: no extension, no device or a zero local budget means available = false and no suffix (no 0/0), and used > budget is printed raw (23.5/22.8) with no division to blow up.

Two real gaps:

  1. Nothing tests the line. describe lives only in the shim and no runtime test prints it — the prebuilt d3d12_vram_budget_test, title_hud_test and dev_overlay_test all pass regardless of what this suffix says, so a swapped pair, a wrong scale or a dropped available guard would go unnoticed (your control was a manual run). Extracting a vram_suffix(const VramBudget&) (or a formatter in memory_figures.h) and testing available / unavailable / zero-budget / over-budget would make it a regression test rather than a checked-by-eye line.
  2. The line still reads VRAM 6.8/22.8 GB without the word "budget", which is exactly the confusion the PR sets out to end — a reader takes 22.8 for the card's size. VRAM 6.8 of 22.8 GB budget is enough; vram_text (memory_figures.h:45-49) already has a wording you could reuse, though it adds +shared and n/a.

Scoping note: the suffix is local-only while vram_text shows +shared; the used/budget pair stays comparable, but if the title spills into shared heaps the displayed "used" understates total GPU memory — worth stating. Also, LEONIDA_VRAM_BUDGET_MB (#2765) is not in this tree yet; if it lands, decide whether this line shows the override or the driver's live budget, since they will differ.

**@⁠KelboLive** on GitHub · 2026-12-01 05:40 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/2793#pullrequestreview-6125749792) · **reviewed** The pair is the right one: both numbers come from the same `vkGetPhysicalDeviceMemoryProperties2` budget struct and are summed over the same DEVICE_LOCAL heaps (`runtime/src/vulkan_memory_budget.h:19-43`), and it is the reader the runtime's own "does a local allocation survive" gate already uses (`d3d12_vulkan_device.cpp:6446-6450`), so used and budget are comparable. On this machine the reader reports 301 of 15293 MiB against a 16 GB card, as the PR says. Edge cases hold: no extension, no device or a zero local budget means `available = false` and no suffix (no `0/0`), and used > budget is printed raw (`23.5/22.8`) with no division to blow up. Two real gaps: 1. **Nothing tests the line.** `describe` lives only in the shim and no runtime test prints it — the prebuilt `d3d12_vram_budget_test`, `title_hud_test` and `dev_overlay_test` all pass regardless of what this suffix says, so a swapped pair, a wrong scale or a dropped `available` guard would go unnoticed (your control was a manual run). Extracting a `vram_suffix(const VramBudget&)` (or a formatter in `memory_figures.h`) and testing available / unavailable / zero-budget / over-budget would make it a regression test rather than a checked-by-eye line. 2. **The line still reads `VRAM 6.8/22.8 GB` without the word "budget"**, which is exactly the confusion the PR sets out to end — a reader takes 22.8 for the card's size. `VRAM 6.8 of 22.8 GB budget` is enough; `vram_text` (`memory_figures.h:45-49`) already has a wording you could reuse, though it adds `+shared` and `n/a`. Scoping note: the suffix is local-only while `vram_text` shows `+shared`; the used/budget pair stays comparable, but if the title spills into shared heaps the displayed "used" understates total GPU memory — worth stating. Also, `LEONIDA_VRAM_BUDGET_MB` (#2765) is not in this tree yet; if it lands, decide whether this line shows the override or the driver's live budget, since they will differ.
Author
Owner

@⁠merzleckeier on GitHub · 2026-12-01 12:44 UTC · original

Measured the budget-suffix path on AMD and NVIDIA with 17667177a + 6c7f6b60c. I ran the exact suffix formatting against the project budget helper. A synthetic case with two device-local heaps and one host heap printed VRAM 6.5/7.5 GB. With no device-local budget or no budget result it emitted an empty suffix. With VK_EXT_memory_budget enabled on both live Vulkan devices, the helper returned local budgets of 10630 MiB (RADV) and 9221 MiB (NVIDIA), which formatted as 10.4 and 9.0 respectively. This exercised the device query and suffix formatting in an isolated native harness. The full runtime sampler was outside this run.

AI-assisted with OpenAI Codex.

**@⁠merzleckeier** on GitHub · 2026-12-01 12:44 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/2793#issuecomment-7311579916) Measured the budget-suffix path on AMD and NVIDIA with `17667177a` + `6c7f6b60c`. I ran the exact suffix formatting against the project budget helper. A synthetic case with two device-local heaps and one host heap printed `VRAM 6.5/7.5 GB`. With no device-local budget or no budget result it emitted an empty suffix. With `VK_EXT_memory_budget` enabled on both live Vulkan devices, the helper returned local budgets of 10630 MiB (RADV) and 9221 MiB (NVIDIA), which formatted as 10.4 and 9.0 respectively. This exercised the device query and suffix formatting in an isolated native harness. The full runtime sampler was outside this run. AI-assisted with OpenAI Codex.
Author
Owner

@⁠aslan2142 on GitHub · 2026-12-01 16:46 UTC · original

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.

**@⁠aslan2142** on GitHub · 2026-12-01 16:46 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/2793#issuecomment-7318222703) 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.
github-bot closed this pull request 2026-12-01 16:56:37 +00:00

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/ubiquitarianism--leonida!2793
No description provided.