native: a null buffer view (address 0) is the null view for good #279
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/279"
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?
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Tarraga on 2026-11-27T08:15:47Z.
Refs #179
Problem
A buffer view of address 0 is what D3D12 writes for a null SRV, UAV or CBV.
NativeHost::mirrortook it for memory in no pool: the entry got the null view,pending_mirrorrecorded the pool table's generation, andremirror_tablestried it again at the next draw after any change to the pool table. In the world, streaming maps tiled-heap pages between almost every submission, so the generation moves on all the time and these entries never settle.Evidence
Found on a game run (M4 Pro, 48 GB, Series S profile). The heap check counted about 10,000 retries of such entries per submission, millions per run. With null views settled, the next two runs (same configuration, 420 s each) had no retries, and the world went from about 1.0 to about 2.0-2.1 fps between frames 1856 and 2240. The retry rule then was the same as
pending_mirror's (try again once the pool table changes).Fix
Decoded::Buffer { addr: 0, .. }writes the null view and falls through to the usual end ofmirror, so the entry is marked mirrored with its record. A later record at that entry is still mirrored as usual. No guess about console behaviour: address 0 is never mapped.Test
native::tests::a_null_buffer_view_is_not_retried_when_the_pool_table_changes: a CBV of address 0 bound in a table, then two pools mapped elsewhere between submissions. Without the fix the null view is written three times; with it, once.cargo test -p victory-gpu --libon arm64: 316 pass.texture_tests::described_rectangle_list_draw_uses_supplied_trianglesfails on this Mac with or without this change.cargo xtask policypasses.Docs:
docs/native-host.md, "Views of memory in no pool".Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T10:32:25Z.
Thank you. The idea is right: address 0 is never mapped, so trying it again after every change of the pool table is wasted work, and the test shows three writes without the change and one with it.
Before it can merge:
mirror. Whichever lands second needs a rebase, so please look at it.I have not run it.
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Tarraga on 2026-11-27T11:14:20Z.
Thanks. I've rebased on main after #267 and force-pushed. There are two commits now.
Understood. It is ready for the workflow whenever you approve it.
How the retries were counted, and in how many runs. I used a counter of our own,
unmapped_tries, printed on thenative draws so farline every 64 frames. It goes up by one each time a buffer view comes back "not in a mapped pool" and is kept to be tried again. The counter is not in main. It is on our working branch, which also checks whole heaps at submission for shaders that index them. Main checks only the bound tables' entries, so these numbers come from that branch's code path, not main's.unmapped_tries=0for the whole run, and 2.0 to 2.1 fps over frames 1920-2240.#267 landed first, so this branch took the rebase. It applied cleanly, but the two changes interacted in one place. #267 follows some heap entries in
NativeHeap::title_views(a wrap, or a gap left null). If the title overwrote such an entry with a null view, the entry stayed intitle_views.follow_title_pagesthen kept comparing the old range's signature after every change of the pool table. The address-0 arm now removes the entry.a_wrapped_view_follows_title_pages_remapped_or_unmapped_under_itnow ends by writing a null view over its followed entry, and checks that the entry is dropped. (I could not run it without the removal yet to see it fail: the machine is busy with game runs.)Not on this host, and we know it from the code rather than from the game:
apps/victory/build.rslinks with-pagezero_size 0x1000, so page 0 is never mapped. No pool can hold address 0, andtitle_aliasneeds every page of a range mapped, so it can't wrap a range that starts at 0 either. Even before this change, a view at 0 always ended as the null view, whatever its size. The change only stops it being tried again.E_INVALIDARGinresource.rs). So an SRV or UAV of a buffer object never decodes to address 0. Only a CBV whoseBufferLocationis 0, or a placed view record whose base is 0, gives a view at address 0.Tests:
described_rectangle_list_draw_uses_supplied_trianglesandan_indirect_dispatch_mesh_x_draws_the_groups_its_record_holds). Both fail the same way on main here. The only Metal Shader Converter on this Mac is D3DMetal's x86_64 one, so on arm64 those pipelines are not made, and the tests that need the converter are skipped, the #267 follow test among them.a_wrapped_view_follows_…anda_null_buffer_view_is_not_retried_…on x86_64 with that converter, and both pass.cargo xtask policypasses. The Windows clippy gate isn't set up here, so CI will be the first to run it.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T11:54:30Z.
Thank you for the numbers and for taking back the "10,000 a submission". Your explanation of why no pool can hold address 0 is what I needed.
I have not run it. Since your speed-up comes from a branch that checks whole heaps, I expect the gain on main to be smaller; I will run it on main with #267 and tell you what I see. If you can, please post the
native draws so farlines of one run once2b786with and without this change, without your counter.