native: heap buffer views not linear in one pool read the title's own mapping instead of the null view (#258) #267
No reviewers
Labels
No labels
accessibility
bug
claimed
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
tester report
urgent
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/LakshanSivakumar--Native-Victory-macOS!267
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-267"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@Olima34 on GitHub · 2026-11-27 06:52 UTC · original
Olima34:fix/heap-views-title-alias→main· +519 −4 · 7 files · 2 commits · merged 2026-11-27 10:46 UTCThe fix announced on #258 for item 1: the G-buffer cullers read their instance data through a heap buffer view that the host wrote as the null view.
Bug.
NativeHost::mirrorwrote the null view for a heap buffer view whose range isn't one linear run of a pool (pool pages scattered, or in descending order), even when the title maps the whole range with no gap.ff826810673a0198reads its instance data from heap entry 17. That entry is title buffer0x24010000, 182,452,224 bytes: the "174 MB … not in a mapped pool" line in every run. Entry 9936 (0xd0eab0000, 52 MB) is nulled the same way.Fix. When the range isn't linear in one pool but the title maps it with no gap (new
PoolTable::covers),mirrorwraps the title's own addresses with the existingwrap_title_memoryinstead of writing the null view.NativeHost::title_aliasaligns the range to 16 KiB and caches the wrapped buffer by range, along with a signature of the title mappings the range crosses (PoolTable::signature). The buffer is reused while that signature holds and made again when the title remaps the range. The last 64 are kept; a pool release drops only wraps over that pool's pages, never one an entry shows.write_buffer, so it is resident exactly as pool buffers are, on both residency paths (the heap's residency set, and per-encoder naming on Macs without sets). It aliases title memory: it adds nothing tophys_footprint, and Metal'scurrentAllocatedSizecounts it once more.follow_title_pages). A remap gets a new wrap, an unmap gets the null view, and a gap mapped later gets wrapped. Shortcut: a partly unmapped range reads zeros as a whole.Tests.
native::tests::a_wrapped_view_follows_title_pages_remapped_or_unmapped_under_itremaps, then unmaps, under a wrapped view and checks the reads. Also:native::tests::a_buffer_view_across_title_pages_out_of_pool_order_reads_the_title_mappingmaps two real title pages (withmach_vm_remap) from pool pages 2 then 1, with 64 words across the boundary. Theheap_rwfixture reads them on the GPU through a heap view. Without the fix,mirrorrefuses the view and the test fails.In game (M5 Pro, Series S, windowed, on
2a3b03d1+ #253):v13againstmin(pyramid, 1.0), thenv_cmp_nge, which is true on NaN), where every lane is culled.Checks: victory-gpu 317 tests pass (arm64), and victory-hle, victory and xtask pass. Windows clippy is clean with
-D warnings.cargo xtask policypasses.docs/native-host.mdhas a new section, "Heap buffer views not linear in one pool (#258)", and theVICTORY_TRACE_ROOT_SPANline that said such views are refused is corrected.A buffer view in a descriptor heap was written as a view of the pool buffer that holds its range, which needs the range to be one linear run of one pool. The title maps its physical pages one 64 KiB page at a time, often in descending pool order, so a large buffer seldom is one, and such a view was the null view: the shader read zeros ("a descriptor was not mirrored ... is not in a mapped pool", about 500 to 3,000 a run). The world's G-buffer culling shaders read their instances that way (#258): culler ff826810673a0198's root constants name heap entry 17, a 182,452,224-byte buffer the title had filled. The host nulled it, so the culler read all-zero instances. A 52 MB one (entry 9936) was nulled too. Title memory is mapped at its own addresses in this process. A view whose range the title maps without a gap (PoolTable::covers), but not as one run of a pool, now wraps those addresses (NativeHost::title_alias: the backend's wrap_title_memory over whole 16 KiB host pages). The wrap is cached by range and dropped when a pool is released. A later remap of those pages is seen when the entry is mirrored again (marked shortcut). Test: tests::a_buffer_view_across_title_pages_out_of_pool_order_reads_ the_title_mapping maps two title pages for real from pool pages 2 then 1, puts 64 words across the boundary and reads them through a heap view on the GPU. The view was refused before. In game the 174 MB view is wrapped, with no GPU errors. The mesh records still stay zero after the GPU has run the frame, so this was one input the cullers lacked, not the last.82a25593ddto37670bfe29@LakshanSivakumar on GitHub · 2026-11-27 08:08 UTC · original
Thank you for the pull request. The test uses real remapped pages and fails without the change, and it is good to have the entry 17 and 9936 sizes in the text.
Before it can merge, two questions from my comment in #258 that the text only half answers:
remirror_tablesnever visits it again. Your shortcut says exactly that remap is not seen until it is mirrored again. For entry 17 that may be never. Please say whether the title remaps that range after the entry is written, or show that it does not (a log of the signature for entry 17 over a world load is enough).Please also give the resident size of the wrapped 174 MiB and 50 MiB views as the process footprint before and after, because the text says it adds no memory and I have not seen it measured. Ketan-Kapse says #267 and #264 together fill the records and neither alone does, so please run them together.
@Olima34 on GitHub · 2026-11-27 09:04 UTC · original
Thanks for the review. Short answers now, data to follow in the next revision:
newBufferWithBytesNoCopyover the title's addresses, and I don't know what Metal does when a page under it is unmapped: a fault, a stale page kept alive, or zeros. We'll add the test you describe (map, wrap, unmap one page, run), report what happens, and handle it.phys_footprintand Metal'scurrentAllocatedSizebefore and after, for the 174 MiB and 50 MiB views.@Olima34 on GitHub · 2026-11-27 09:43 UTC · original
Revision pushed (
ca22c393on top of37670bfe). Answers to your questions:1. A page remapped or unmapped under a wrap. Measured on M5 Pro, macOS 27: a no-copy wrap keeps the physical pages it was made over. After the title remaps the range to other pool pages, or unmaps it, the GPU keeps reading and writing the old pages. There's no fault and no zeros.
NativeHost::follow_title_pagesre-mirrors every heap entry that is wrapped, or left null because of a gap, whose mapping signature changed. A remap gets a new wrap, an unmap gets the null view (zeros), and a gap mapped later gets wrapped.native::tests::a_wrapped_view_follows_title_pages_remapped_or_unmapped_under_itremaps and then unmaps under a wrapped view. The view reads the new page, then zeros. Without the following, it reads the old page and fails.2. Entries loaded by the shader itself. The following covers every entry of every heap that holds a wrapped or gap-null view, not only bound tables, so entry 17 is covered.
0x1f7c0000+0xae00000) stayed the same from the 1st to the 1,000th look, from generation 6,742 to 321,276. So the title doesn't remap that range.3. Footprint. A wrap adds nothing to
phys_footprintand takes no process address space. Metal'scurrentAllocatedSizecounts it once more:phys_footprintcurrentAllocatedSizeEach large wrap logs these numbers ("a large buffer view wraps the title's own pages").
4. With #264 and #253 on this revision: the G-buffer peaks at 88% lit (153 s), then holds 11–13%. There's no
root parameter 255line and no GPU error.Checks: victory-hle, victory, victory-gpu (318) and xtask pass. Windows clippy is clean with
-D warnings, andcargo xtask policypasses. One unrelated test,texture_tests::a_missed_write_not_followed_by_another_backs_off_whole_reads, failed once under load (41) right after a reboot, then passed twice. The docs section is updated.ca22c393a3tof837d3bfd6@Olima34 on GitHub · 2026-11-27 10:43 UTC · original
Rebased on main
8fe4b63d(headf837d3bf). The only conflict was inNativeHeap: theusedfield from #292 andtitle_viewsfrom this PR now sit side by side. After the rebase, victory-gpu has 318 tests passing, Windows clippy is clean on the workspace, andcargo xtask policypasses.@LakshanSivakumar on GitHub · 2026-11-27 10:46 UTC · original
Thank you. This answers what I asked. You measured what a wrap does when the title remaps or unmaps a page under it, you followed the pages, and the test remaps and then unmaps. The log of entry 17 over 300 s shows the title does not remap it, and the footprint table shows the wrap adds nothing to
phys_footprint. You also ran it with #264 and #253. CI is green.I have not run this revision (
ca22c393); my run in #258 had the first one. It is behind main, and #279 and #264 change the same part ofmirror, so the second of them to land needs a rebase. Not blocking: when you have a number for whatfollow_title_pagescosts per submission, please post it, since the pool table changes about 2,600 times a second.Merged.
@LakshanSivakumar on GitHub · 2026-11-27 10:46 UTC · original
I ran these five together on my Mac before merging (#101, #267, #288, #289, #291 on main, M5 Pro 48 GB, Series S, warm cache, three runs): two runs stayed in the world until the time limit (139 s and 202 s there, about 2 fps, no failed command buffer, no fault); one ended at the start of the world with a title fault I had not seen before (first chance at image+0x4fafef8, a read of 0x30000065c), with no GPU error before it. I could not tie that one to any of the five. If you see it, please say so.
@Olima34 on GitHub · 2026-11-27 11:16 UTC · original
The number you asked for: in our world run, one
follow_title_pagespass cost about 3 ms, with the pool lock held, at about 12 passes a second. The title copies the same descriptor into many heap slots, and each copy re-walked the same range. The follow-up PR walks each distinct range once per pass: about 70–80 µs per pass, under 1 ms of CPU a second. The table and the harness are in the PR.