native: a null buffer view (address 0) is the null view for good #279

Merged
Tarraga merged 2 commits from upstream-pr/279 into main 2026-11-27 13:35:46 +00:00
Tarraga commented 2026-11-27 08:15:47 +00:00 (Migrated from github.com)

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::mirror took it for memory in no pool: the entry got the null view, pending_mirror recorded the pool table's generation, and remirror_tables tried 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 of mirror, 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 --lib on arm64: 316 pass. texture_tests::described_rectangle_list_draw_uses_supplied_triangles fails on this Mac with or without this change.
  • cargo xtask policy passes.
  • Clippy was not run locally; I'm leaving the Windows clippy gate to CI.

Docs: docs/native-host.md, "Views of memory in no pool".

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:5523415706 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/279). Originally posted by [Tarraga](https://github.com/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::mirror` took it for memory in no pool: the entry got the null view, `pending_mirror` recorded the pool table's generation, and `remirror_tables` tried 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 of `mirror`, 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 --lib` on arm64: 316 pass. `texture_tests::described_rectangle_list_draw_uses_supplied_triangles` fails on this Mac with or without this change. - `cargo xtask policy` passes. - Clippy was not run locally; I'm leaving the Windows clippy gate to CI. Docs: `docs/native-host.md`, "Views of memory in no pool".
LakshanSivakumar commented 2026-11-27 10:32:25 +00:00 (Migrated from github.com)

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:

  1. Your workflow has not run; it needs my approval.
  2. The speed-up (1.0 to 2.0 frames a second) is from one machine. Please say how you counted the 10,000 retries a submission (which trace line) and in how many runs.
  3. #267 changes the arm next to yours in mirror. Whichever lands second needs a rebase, so please look at it.
  4. Can a view of address 0 with a size that is not 0 mean something other than a null view? Please say how you know.

I have not run it.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7216006647 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/279#issuecomment-7216006647). Originally posted by [LakshanSivakumar](https://github.com/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: 1. Your workflow has not run; it needs my approval. 2. The speed-up (1.0 to 2.0 frames a second) is from one machine. Please say how you counted the 10,000 retries a submission (which trace line) and in how many runs. 3. #267 changes the arm next to yours in `mirror`. Whichever lands second needs a rebase, so please look at it. 4. Can a view of address 0 with a size that is not 0 mean something other than a null view? Please say how you know. I have not run it.
Tarraga commented 2026-11-27 11:14:20 +00:00 (Migrated from github.com)

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.

  1. Understood. It is ready for the workflow whenever you approve it.

  2. How the retries were counted, and in how many runs. I used a counter of our own, unmapped_tries, printed on the native draws so far line 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.

    • Without the change, two runs (r98, r100): 21,000 to 23,000 tries a frame in the world (2.9 M over frames 1664-1792, and 4.1 M over 1664-1856). Over the same frames: 0.9 and 1.1 fps.
    • With the change, two runs (r101, r102): unmapped_tries=0 for the whole run, and 2.0 to 2.1 fps over frames 1920-2240.
    • All four runs were on one Mac (M4 Pro, 48 GB): headless, Series S profile, same title build. Both runs without the change also had a diagnostic switch on for another question.
    • The "10,000 a submission" was a rough division and I can't back it up. Only whole-heap checks slower than 50 ms are logged, so I can't count submissions exactly. Per logged check it comes to 7,000 to 8,100. The commit message and native-host.md now give the per-frame figure. They also say what the speed-up was measured on, and that it has not been measured on main, where it is likely smaller.
  3. #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 in title_views. follow_title_pages then 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_it now 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.)

  4. Not on this host, and we know it from the code rather than from the game:

    • Title GPU addresses are this process's addresses. apps/victory/build.rs links with -pagezero_size 0x1000, so page 0 is never mapped. No pool can hold address 0, and title_alias needs 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.
    • No buffer object is at 0. Committed and placed memory never is, and a resource at an address refuses 0 (E_INVALIDARG in resource.rs). So an SRV or UAV of a buffer object never decodes to address 0. Only a CBV whose BufferLocation is 0, or a placed view record whose base is 0, gives a view at address 0.
    • We did not log the sizes of these views in game, and we don't know what the console's GPU does with a read at 0. Before and after this change the host gives the null view there. The test uses a size of 256 on purpose, so the non-zero case is covered.

Tests:

  • victory-gpu on arm64: 318 passed and 2 failed (described_rectangle_list_draw_uses_supplied_triangles and an_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.
  • I ran a_wrapped_view_follows_… and a_null_buffer_view_is_not_retried_… on x86_64 with that converter, and both pass.
  • cargo xtask policy passes. The Windows clippy gate isn't set up here, so CI will be the first to run it.
<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7216841624 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/279#issuecomment-7216841624). Originally posted by [Tarraga](https://github.com/Tarraga) on 2026-11-27T11:14:20Z. --- Thanks. I've rebased on main after #267 and force-pushed. There are two commits now. 1. Understood. It is ready for the workflow whenever you approve it. 2. How the retries were counted, and in how many runs. I used a counter of our own, `unmapped_tries`, printed on the `native draws so far` line 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. - Without the change, two runs (r98, r100): 21,000 to 23,000 tries a frame in the world (2.9 M over frames 1664-1792, and 4.1 M over 1664-1856). Over the same frames: 0.9 and 1.1 fps. - With the change, two runs (r101, r102): `unmapped_tries=0` for the whole run, and 2.0 to 2.1 fps over frames 1920-2240. - All four runs were on one Mac (M4 Pro, 48 GB): headless, Series S profile, same title build. Both runs without the change also had a diagnostic switch on for another question. - The "10,000 a submission" was a rough division and I can't back it up. Only whole-heap checks slower than 50 ms are logged, so I can't count submissions exactly. Per logged check it comes to 7,000 to 8,100. The commit message and native-host.md now give the per-frame figure. They also say what the speed-up was measured on, and that it has not been measured on main, where it is likely smaller. 3. #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 in `title_views`. `follow_title_pages` then 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_it` now 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.) 4. Not on this host, and we know it from the code rather than from the game: - Title GPU addresses are this process's addresses. `apps/victory/build.rs` links with `-pagezero_size 0x1000`, so page 0 is never mapped. No pool can hold address 0, and `title_alias` needs 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. - No buffer object is at 0. Committed and placed memory never is, and a resource at an address refuses 0 (`E_INVALIDARG` in `resource.rs`). So an SRV or UAV of a buffer object never decodes to address 0. Only a CBV whose `BufferLocation` is 0, or a placed view record whose base is 0, gives a view at address 0. - We did not log the sizes of these views in game, and we don't know what the console's GPU does with a read at 0. Before and after this change the host gives the null view there. The test uses a size of 256 on purpose, so the non-zero case is covered. Tests: - victory-gpu on arm64: 318 passed and 2 failed (`described_rectangle_list_draw_uses_supplied_triangles` and `an_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. - I ran `a_wrapped_view_follows_…` and `a_null_buffer_view_is_not_retried_…` on x86_64 with that converter, and both pass. - `cargo xtask policy` passes. The Windows clippy gate isn't set up here, so CI will be the first to run it.
LakshanSivakumar commented 2026-11-27 11:54:30 +00:00 (Migrated from github.com)

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 far lines of one run on ce2b786 with and without this change, without your counter.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7217613448 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/279#issuecomment-7217613448). Originally posted by [LakshanSivakumar](https://github.com/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 far` lines of one run on `ce2b786` with and without this change, without your counter.
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
LakshanSivakumar/Native-Victory-macOS!279
No description provided.