[PR #1734] d3d12: memory probe reports how much of the title memory behind filled images is in RAM (RT-MEM-PROBE-DUPLICATE) #1747

Open
opened 2026-11-26 21:18:49 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1734
Author: @kawaii-shakal
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: mem-probe-duplicates


📝 Commits (5)

  • c870341 d3d12: memory probe reports how much of the title memory behind filled images is in RAM (RT-MEM-PROBE-DUPLICATE)
  • 355420e d3d12: count overlapping image source memory once
  • 5161909 Merge upstream main into mem-probe-duplicates
  • 12767d1 Merge upstream main into mem-probe-duplicates
  • 523b09f mem-probe: the census line says "CPU virtual bytes", and that two views of one backing count twice

📊 Changes

5 files changed (+183 additions, -5 deletions)

View changed files

📝 docs/d3d12_vulkan.md (+6 -1)
📝 runtime/CMakeLists.txt (+11 -0)
📝 runtime/shims/d3d12_vulkan_device.cpp (+21 -4)
➕ runtime/src/working_set.h (+72 -0)
➕ runtime/test/working_set_test.cpp (+73 -0)

📄 Description

Claim: RT-MEM-PROBE-DUPLICATE, https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7159332414 (step 1 of #1702)

What and why

#1702 shows that the GPU-read title data is kept twice: once in the title's own pages (committed, much of it resident) and again as Vulkan copies. On the retail boot the slot-70 and slot-133 images alone came to about 7.4 GB of VRAM. Before anything trims or shares those pages, the probe has to say how big the duplicate is. Today it reports only the GPU side.

  • runtime/src/working_set.h (new, header-only): leonida::working_set::resident_bytes(base, size, step = 16). It estimates how much of a range is resident in RAM by sampling one 4 KiB page in step with one QueryWorkingSetEx call per range. Pages that are not committed or not mapped read as not resident. Off Windows it returns 0.
  • runtime/shims/d3d12_vulkan_device.cpp, log_title_census: with LEONIDA_MEM_PROBE, the existing registered image backing line now ends with title pages behind filled images X MiB, Y MiB of them resident in RAM. Only images filled from memory count (fills, a known layout, not gpu_written). The working set is queried only when the probe is on.
  • docs/d3d12_vulkan.md: the probe paragraph says this.

Test

  • working_set_test (new ctest working_set, Windows, psapi) checks these ranges:
    • 8 MiB written: all resident;
    • 8 MiB committed but never touched: 0;
    • reserved only: 0;
    • half written: half;
    • the written range after VirtualUnlock, which removes unlocked pages from the working set: under a quarter.
  • d3d12_existing_heap_test with LEONIDA_MEM_PROBE=1 on an RTX 5070 Ti (NVIDIA 617.42, Windows 11 Pro 26300) passes and prints the new fields.
  • gta6rt builds (MSVC 19.50). scripts/check_no_game_data.py is clean.

Not done here: a retail boot with this branch, so the size of the duplicate on 1.0.2.1 is not measured yet. That boot is the point of this PR. Title windows and arena shadows (buffers) are not counted; only images are.

AI-assisted: yes (Claude Code, Claude Opus 5.5).

🤖 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/1734 **Author:** [@kawaii-shakal](https://github.com/kawaii-shakal) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `mem-probe-duplicates` --- ### 📝 Commits (5) - [`c870341`](https://github.com/ubiquitarianism/leonida/commit/c870341fa441e911e804c7f67e33bdb847cdeecc) d3d12: memory probe reports how much of the title memory behind filled images is in RAM (RT-MEM-PROBE-DUPLICATE) - [`355420e`](https://github.com/ubiquitarianism/leonida/commit/355420e812dd729663f551725b0f206e36af82cc) d3d12: count overlapping image source memory once - [`5161909`](https://github.com/ubiquitarianism/leonida/commit/516190908cf7683aa935aa4911d64b78107a2625) Merge upstream main into mem-probe-duplicates - [`12767d1`](https://github.com/ubiquitarianism/leonida/commit/12767d1f29e4bb56d1b6744b61fea2485d61d199) Merge upstream main into mem-probe-duplicates - [`523b09f`](https://github.com/ubiquitarianism/leonida/commit/523b09fd3e918744c97bd47ff33b27a7d4a18842) mem-probe: the census line says "CPU virtual bytes", and that two views of one backing count twice ### 📊 Changes **5 files changed** (+183 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `docs/d3d12_vulkan.md` (+6 -1) 📝 `runtime/CMakeLists.txt` (+11 -0) 📝 `runtime/shims/d3d12_vulkan_device.cpp` (+21 -4) ➕ `runtime/src/working_set.h` (+72 -0) ➕ `runtime/test/working_set_test.cpp` (+73 -0) </details> ### 📄 Description Claim: RT-MEM-PROBE-DUPLICATE, https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7159332414 (step 1 of #1702) ### What and why #1702 shows that the GPU-read title data is kept twice: once in the title's own pages (committed, much of it resident) and again as Vulkan copies. On the retail boot the slot-70 and slot-133 images alone came to about 7.4 GB of VRAM. Before anything trims or shares those pages, the probe has to say how big the duplicate is. Today it reports only the GPU side. - `runtime/src/working_set.h` (new, header-only): `leonida::working_set::resident_bytes(base, size, step = 16)`. It estimates how much of a range is resident in RAM by sampling one 4 KiB page in `step` with one `QueryWorkingSetEx` call per range. Pages that are not committed or not mapped read as not resident. Off Windows it returns 0. - `runtime/shims/d3d12_vulkan_device.cpp`, `log_title_census`: with `LEONIDA_MEM_PROBE`, the existing `registered image backing` line now ends with `title pages behind filled images X MiB, Y MiB of them resident in RAM`. Only images filled from memory count (`fills`, a known layout, not `gpu_written`). The working set is queried only when the probe is on. - `docs/d3d12_vulkan.md`: the probe paragraph says this. ### Test - `working_set_test` (new ctest `working_set`, Windows, psapi) checks these ranges: - 8 MiB written: all resident; - 8 MiB committed but never touched: 0; - reserved only: 0; - half written: half; - the written range after `VirtualUnlock`, which removes unlocked pages from the working set: under a quarter. - `d3d12_existing_heap_test` with `LEONIDA_MEM_PROBE=1` on an RTX 5070 Ti (NVIDIA 617.42, Windows 11 Pro 26300) passes and prints the new fields. - `gta6rt` builds (MSVC 19.50). `scripts/check_no_game_data.py` is clean. Not done here: a retail boot with this branch, so the size of the duplicate on 1.0.2.1 is not measured yet. That boot is the point of this PR. Title windows and arena shadows (buffers) are not counted; only images are. AI-assisted: yes (Claude Code, Claude Opus 5.5). 🤖 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>
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#1747
No description provided.