Repository navigation
d3d12: memory probe reports how much of the title memory behind filled images is in RAM (RT-MEM-PROBE-DUPLICATE) - #1734
Conversation
…d images is in RAM (RT-MEM-PROBE-DUPLICATE) Step 1 of ProjectLeonida#1702: before any change that trims or shares those pages, the probe has to show how big the duplicate is. With LEONIDA_MEM_PROBE the registered-image line now adds the title pages behind images filled from memory and how much of them is resident, sampled with QueryWorkingSetEx (one page in 16, runtime/src/working_set.h). GPU-written images are left out. working_set_test covers written, untouched, reserved, half-written and trimmed ranges. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
lixonik
left a comment
There was a problem hiding this comment.
Independent native Windows verification at c870341f: built working_set_test with MSVC and ran it five times. All passed. A second synthetic check exercised two paired title addresses that resolve to one CPU range. The per-image sum can count that range twice. Details inline.
AI-assisted. CPU only, no title workload or GPU run.
| if (!t->device_local) host_heap_bytes += t->backing_bytes; | ||
| if (probe && t->fills && !t->gpu_written && t->layout_known && t->cpu && t->layout.layout.size) { | ||
| source_bytes += t->layout.layout.size; | ||
| resident_source_bytes += leonida::working_set::resident_bytes(t->cpu, t->layout.layout.size); |
There was a problem hiding this comment.
These totals sum per texture key, but two keys can refer to the same CPU pages. Registration keys the map by the original address and uses title_gpu_views::to_cpu for the backing. I paired two addresses using the real view mapper and pointed both synthetic entries at one touched 128 KiB range. Summing the helper results here produces 256 KiB resident, while the unique range is 128 KiB. If the diagnostic is meant to show the amount of distinct CPU memory behind the GPU copies, could it merge the CPU intervals before sampling? If the per-image sum is intentional, labeling it as such would make it clear that shared pages can be counted more than once.
There was a problem hiding this comment.
Thanks, you were right: two paired addresses that resolve to one CPU range were counted twice. Fixed in 355420e81 (in the current head, 516190908). The census now collects the CPU ranges of the filled images, merges overlapping and adjacent ones (working_set::merge_cpu_ranges), and samples residency once per merged range. The log line says "unique title memory behind filled images". working_set_test gained your case (two aliases of one 128 KiB range count as 128 KiB) plus nested, overlapping and adjacent ranges. The fix was made by Codex, who works on this with me; sorry for not saying so here earlier. AI-assisted (Claude Code, Claude Opus 5.5).
AI-assisted by Codex.
Codex resolved the documentation overlap, retaining both the unique-memory diagnostic and the upstream registry snapshot notes.
|
Native Windows check at I also tested two distinct CPU addresses mapped to offset zero in the same 4 MiB section. A write through the first view was visible through the second at every page. The current range union and working-set estimate both reported 8 MiB in all three runs, including when sampling every page. This exercises a different case from the resolved review, which merged two references to the same CPU address range. Leonida's page mapping code can create different CPU addresses for the same backing. Could the log label say CPU virtual bytes behind filled images and document that distinct views of one backing may count twice? The current probe is still useful with that interpretation. The effect in a title run remains unmeasured. Synthetic Windows test and AI-assisted interpretation reviewed with Claude Opus 5.5. |
…ws of one backing count twice Review of RT-MEM-PROBE-DUPLICATE (BadgersMC): two distinct CPU views of one backing both reported 8 MiB. merge_cpu_ranges merges by virtual address, so the same physical frames mapped at two addresses are counted in each, in the total and in the resident part. The log line now reads "CPU virtual bytes behind filled images ... (two views of one backing count twice)", and working_set.h and docs/d3d12_vulkan.md say so. Text and comments only; no behaviour change. Changes made by Claude Code (AI-assisted). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JPqXc6svM4pbBagTsVEYA3
|
@BadgersMC thanks, you are right:
Counting physical frames instead ( Not built here: the shim is Windows-only. Generated by Claude Code |
Claim: RT-MEM-PROBE-DUPLICATE, #1608 (comment) (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 instepwith oneQueryWorkingSetExcall 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: withLEONIDA_MEM_PROBE, the existingregistered image backingline now ends withtitle pages behind filled images X MiB, Y MiB of them resident in RAM. Only images filled from memory count (fills, a known layout, notgpu_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 ctestworking_set, Windows, psapi) checks these ranges:VirtualUnlock, which removes unlocked pages from the working set: under a quarter.d3d12_existing_heap_testwithLEONIDA_MEM_PROBE=1on an RTX 5070 Ti (NVIDIA 617.42, Windows 11 Pro 26300) passes and prints the new fields.gta6rtbuilds (MSVC 19.50).scripts/check_no_game_data.pyis 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