native: a byte budget on host texture copies (copies nothing uses go first) #301

Closed
m0rff wants to merge 6 commits from upstream-pr/301 into main
m0rff commented 2026-11-27 09:39:18 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by m0rff on 2026-11-27T09:39:18Z.


Refs #294 (a piece of #8; proposed in #110)

What this changes

Host texture copies had no bound: a copy is made when a view first names a texture (Title::realize, called from glue::mirror for every view the device writes, staging heaps included) and kept until the title releases the texture. On electrifie's 16 GB M4 run in #8 (Series S), the host made about 13,000 copies during the first load while the footprint grew about 7.6 GB, then kIOGPUCommandBufferCallbackErrorOutOfMemory.

  • Budget (off by default, changed after review). Nothing is given up unless VICTORY_METAL_TEXTURE_BUDGET_MB=<n> sets a budget of n MiB (0 or anything that is not a number: off). It is logged at startup as texture_budget_mib on the native host: Metal line, next to the two numbers from #149 and suggested_texture_budget_mib, the figure to try on that Mac: recommendedMaxWorkingSetSize less the title's memory, at least 1536 MiB (4348 MiB on that M4; Series X on 16 GB gets the floor).

  • What goes. When a submission finds the copies over budget (Title::keep_to_budget, before its textures are synced), the least recently used copies that may go are given up until the total is back under budget. A copy may go only if all of these hold:

    • it is a sampled texture filled only from title memory: not a render target, not depth, not GPU-copied, and never viewed for unordered access;
    • no heap entry shows it;
    • no recorded or submitted list holds an Rc of it.

    Shaders index heaps themselves (#79), so a copy that an entry shows counts as used, even if no bound table has named it in a long time. D3D12 forbids rewriting an entry that submitted work still reads, so a copy that no entry shows is not reachable by work in flight.

  • Coming back. A given-up copy is released through release_resource, like a released texture, and its description goes back to Title::pending. A device-written view makes it again, and it is uploaded at the next submission.

  • Tables a submission binds (changed after review). A record the title stores into a heap with plain stores is mirrored only when a list that binds its table is encoded, which happens after the sync. An entry that names a copy not made yet is cleared, and a shader samples a cleared entry as transparent black ((0, 0, 0, 0) on an M2 Pro, macOS 26.6; victory-metal sampling_a_cleared_entry_reads_transparent_black). So before each submission's sync, when over budget or with any copy given up, the host reads the records of every table that the submission's draws and dispatches bind, plus those of work held behind fences (Title::keep_named, NativeHost::resources_named, the same entries remirror_tables checks). A given-up copy those records name is made again and uploaded at that sync, and no copy they name is given up at it. The names read stay out of the budget's reach until the submission is with its queue (Title::let_named_go after submit_synced, counted per submission), so a sync that comes in between, while glue::submit has the title lock let go, cannot give them up (changed after review). Under budget with nothing given up, nothing is read, except at the submission the trace logs at (once a second). Left (marked shortcut): a record the title changes after that read but before held work is encoded, and an entry mirrored outside a submission. Those stay cleared until the next submission.

  • Trace. With VICTORY_TRACE_TEXTURE_SYNC=1, once a second: live copy MiB, budget, MiB shown by heap entries or named by the submission's tables, MiB that could be given up, MiB given up, how many were made again, MiB of distinct title memory under the copies, and MiB of copies outside the title's pools. These are the per-second numbers electrifie asked for. The figures are the same with the budget off: at the submission it logs at, the trace reads that submission's tables itself.

What this may not do. Olima34's 48 GB table in #79 puts 9.2 GB of textures in the heap sets. If most copies are shown by heap entries, this budget frees little, and the levers are the ones named in #79 (one copy instead of two, fewer top mips). The trace line answers that from a 16 GB run.

How it relates to other open work

  • VICTORY_METAL_RESIDENCY_SETS=heap. No second release path: an evicted copy leaves the heap residency set the same way a released texture does (its last reference goes, 0133b82e). A copy that an entry shows, which is exactly what the heap set holds, is never evicted. So the two cannot fight.
  • #296 (Tarraga, command buffers of at most 8 passes). No overlap. That PR changes victory-metal (gfx.rs, metal.rs): how a submission is split into command buffers, and the command-buffer timeout. This one changes which host textures exist, in victory-gpu, before encoding.
  • #292 (Olima34, VICTORY_TRACE_HEAP_SET) and #267 (Olima34, wrapped heap buffer views), both merged. Both behaviours are kept. #292 is a diagnostic of what the heap sets hold, and this PR doesn't touch the sets. #267's mirror rewrite only handles buffer views. This PR's evicted-texture branch is in the texture arm. The two traces complement each other: #292's covers bytes held by heap entries, this one's covers all host copies and what can be given up.
  • 60baf130 (main: R9G9B9E5 placed views share an R32_UINT object's texture; GPU-written targets are not refilled). Rebased onto it. A placed view that shares an object's texture holds a third Rc of it in the host's resources, so the object is never given up while the view is there (and an R32_UINT object compute writes is viewed for unordered access, which keeps it anyway). texture_released, which giving up calls, also releases that shared view, as on main. Textures the GPU drew into, cleared or wrote are gpu_written there, and the budget already never gives those up.
  • #252 (hot-texture expiry) and 2d4cd0a1 (sync off the lock). Neither bounds how many copies exist. They change probing and sync cost.

How it was tested

  • New tests in native::texture_tests, on Metal, arm64:

    • the_least_recently_used_textures_go_first_until_the_excess_is_freed
    • the_texture_budget_is_off_unless_set
    • a_texture_named_by_a_submission_in_flight_is_not_given_up_by_another: submission A's tables name a copy through a record that was never mirrored. Submission B's keep_named and sync run before A is queued, over budget. The copy stays until A lets its names go, then it is given up. Without the fix (B's read replaced A's names), it fails at "the first submission still names it".
    • over_budget_only_textures_nothing_uses_are_given_up_and_come_back: a copy a heap entry shows, a copy a recorded list holds (a copy command), a render target, and a copy once viewed for unordered access all stay. The held copy goes once the list is dropped. The idle copy comes back with its texels.
    • an_entry_copied_with_plain_stores_gets_an_evicted_texture_back (now the fallback outside a submission's scan)
    • a_texture_given_up_is_back_for_the_draw_whose_table_names_it and a_texture_the_submission_names_is_not_given_up_under_its_draw: a real draw (tri_vs/tri_ps) samples, over budget, through a record stored with plain stores, and the test reads the pixel back. Without the fix the pixel was [0, 0, 0, 0]. Now it is the texel. Removing the remake fails the first test, and removing the protection fails both.
    • victory-metal sampling_a_cleared_entry_reads_transparent_black: what a cleared entry samples.

    I checked that the guards are what make the tests pass. With the Rc check removed, the held test fails. With the heap-entry check removed, both tests fail.

  • On main 60baf130: cargo test -p victory-hle -p victory -p victory-gpu -p xtask (victory-gpu native arm64: 360 passed, 3 ignored); cargo clippy --workspace --all-targets --target x86_64-pc-windows-gnullvm -- -D warnings clean; cargo xtask policy 384 files ok. Native clippy shows no warning in the lines this adds (two useless vec! lints in its tests fixed).

  • Ran the game: not yet. I need 16 GB and 24 GB testers on #8.

Checklist

  • No game files, game code, disassembly listings or SDK files are included
  • Guesses are marked in the code and in docs/native-host.md (the 1536 MiB floor; "least recently used" means last seen shown or named)
  • The switch is a VICTORY_* variable, off by default, documented in docs/native-host.md
<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:5524432346 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/301). Originally posted by [m0rff](https://github.com/m0rff) on 2026-11-27T09:39:18Z. --- Refs #294 (a piece of #8; proposed in #110) ## What this changes Host texture copies had no bound: a copy is made when a view first names a texture (`Title::realize`, called from `glue::mirror` for every view the device writes, staging heaps included) and kept until the title releases the texture. On electrifie's 16 GB M4 run in #8 (Series S), the host made about 13,000 copies during the first load while the footprint grew about 7.6 GB, then `kIOGPUCommandBufferCallbackErrorOutOfMemory`. - **Budget (off by default, changed after review).** Nothing is given up unless `VICTORY_METAL_TEXTURE_BUDGET_MB=<n>` sets a budget of `n` MiB (`0` or anything that is not a number: off). It is logged at startup as `texture_budget_mib` on the `native host: Metal` line, next to the two numbers from #149 and `suggested_texture_budget_mib`, the figure to try on that Mac: `recommendedMaxWorkingSetSize` less the title's memory, at least 1536 MiB (4348 MiB on that M4; Series X on 16 GB gets the floor). - **What goes.** When a submission finds the copies over budget (`Title::keep_to_budget`, before its textures are synced), the least recently used copies that may go are given up until the total is back under budget. A copy may go only if all of these hold: - it is a sampled texture filled only from title memory: not a render target, not depth, not GPU-copied, and never viewed for unordered access; - no heap entry shows it; - no recorded or submitted list holds an `Rc` of it. Shaders index heaps themselves (#79), so a copy that an entry shows counts as used, even if no bound table has named it in a long time. D3D12 forbids rewriting an entry that submitted work still reads, so a copy that no entry shows is not reachable by work in flight. - **Coming back.** A given-up copy is released through `release_resource`, like a released texture, and its description goes back to `Title::pending`. A device-written view makes it again, and it is uploaded at the next submission. - **Tables a submission binds (changed after review).** A record the title stores into a heap with plain stores is mirrored only when a list that binds its table is encoded, which happens after the sync. An entry that names a copy not made yet is cleared, and a shader samples a cleared entry as transparent black (`(0, 0, 0, 0)` on an M2 Pro, macOS 26.6; `victory-metal` `sampling_a_cleared_entry_reads_transparent_black`). So before each submission's sync, when over budget or with any copy given up, the host reads the records of every table that the submission's draws and dispatches bind, plus those of work held behind fences (`Title::keep_named`, `NativeHost::resources_named`, the same entries `remirror_tables` checks). A given-up copy those records name is made again and uploaded at that sync, and no copy they name is given up at it. The names read stay out of the budget's reach until the submission is with its queue (`Title::let_named_go` after `submit_synced`, counted per submission), so a sync that comes in between, while `glue::submit` has the title lock let go, cannot give them up (changed after review). Under budget with nothing given up, nothing is read, except at the submission the trace logs at (once a second). Left (marked shortcut): a record the title changes after that read but before held work is encoded, and an entry mirrored outside a submission. Those stay cleared until the next submission. - **Trace.** With `VICTORY_TRACE_TEXTURE_SYNC=1`, once a second: live copy MiB, budget, MiB shown by heap entries or named by the submission's tables, MiB that could be given up, MiB given up, how many were made again, MiB of distinct title memory under the copies, and MiB of copies outside the title's pools. These are the per-second numbers electrifie asked for. The figures are the same with the budget off: at the submission it logs at, the trace reads that submission's tables itself. **What this may not do.** Olima34's 48 GB table in #79 puts 9.2 GB of textures in the heap sets. If most copies are shown by heap entries, this budget frees little, and the levers are the ones named in #79 (one copy instead of two, fewer top mips). The trace line answers that from a 16 GB run. ## How it relates to other open work - **`VICTORY_METAL_RESIDENCY_SETS=heap`.** No second release path: an evicted copy leaves the heap residency set the same way a released texture does (its last reference goes, `0133b82e`). A copy that an entry shows, which is exactly what the heap set holds, is never evicted. So the two cannot fight. - **#296 (Tarraga, command buffers of at most 8 passes).** No overlap. That PR changes `victory-metal` (`gfx.rs`, `metal.rs`): how a submission is split into command buffers, and the command-buffer timeout. This one changes which host textures exist, in `victory-gpu`, before encoding. - **#292 (Olima34, `VICTORY_TRACE_HEAP_SET`) and #267 (Olima34, wrapped heap buffer views), both merged.** Both behaviours are kept. #292 is a diagnostic of what the heap sets hold, and this PR doesn't touch the sets. #267's `mirror` rewrite only handles buffer views. This PR's evicted-texture branch is in the texture arm. The two traces complement each other: #292's covers bytes held by heap entries, this one's covers all host copies and what can be given up. - **`60baf130` (main: R9G9B9E5 placed views share an R32_UINT object's texture; GPU-written targets are not refilled).** Rebased onto it. A placed view that shares an object's texture holds a third `Rc` of it in the host's resources, so the object is never given up while the view is there (and an R32_UINT object compute writes is viewed for unordered access, which keeps it anyway). `texture_released`, which giving up calls, also releases that shared view, as on main. Textures the GPU drew into, cleared or wrote are `gpu_written` there, and the budget already never gives those up. - **#252 (hot-texture expiry) and `2d4cd0a1` (sync off the lock).** Neither bounds how many copies exist. They change probing and sync cost. ## How it was tested - [x] New tests in `native::texture_tests`, on Metal, arm64: - `the_least_recently_used_textures_go_first_until_the_excess_is_freed` - `the_texture_budget_is_off_unless_set` - `a_texture_named_by_a_submission_in_flight_is_not_given_up_by_another`: submission A's tables name a copy through a record that was never mirrored. Submission B's `keep_named` and sync run before A is queued, over budget. The copy stays until A lets its names go, then it is given up. Without the fix (B's read replaced A's names), it fails at "the first submission still names it". - `over_budget_only_textures_nothing_uses_are_given_up_and_come_back`: a copy a heap entry shows, a copy a recorded list holds (a copy command), a render target, and a copy once viewed for unordered access all stay. The held copy goes once the list is dropped. The idle copy comes back with its texels. - `an_entry_copied_with_plain_stores_gets_an_evicted_texture_back` (now the fallback outside a submission's scan) - `a_texture_given_up_is_back_for_the_draw_whose_table_names_it` and `a_texture_the_submission_names_is_not_given_up_under_its_draw`: a real draw (`tri_vs`/`tri_ps`) samples, over budget, through a record stored with plain stores, and the test reads the pixel back. Without the fix the pixel was `[0, 0, 0, 0]`. Now it is the texel. Removing the remake fails the first test, and removing the protection fails both. - `victory-metal` `sampling_a_cleared_entry_reads_transparent_black`: what a cleared entry samples. I checked that the guards are what make the tests pass. With the `Rc` check removed, the held test fails. With the heap-entry check removed, both tests fail. - [x] On main `60baf130`: `cargo test -p victory-hle -p victory -p victory-gpu -p xtask` (victory-gpu native arm64: 360 passed, 3 ignored); `cargo clippy --workspace --all-targets --target x86_64-pc-windows-gnullvm -- -D warnings` clean; `cargo xtask policy` 384 files ok. Native clippy shows no warning in the lines this adds (two `useless vec!` lints in its tests fixed). - [ ] Ran the game: not yet. I need 16 GB and 24 GB testers on #8. ## Checklist - [x] No game files, game code, disassembly listings or SDK files are included - [x] Guesses are marked in the code and in docs/native-host.md (the 1536 MiB floor; "least recently used" means last seen shown or named) - [x] The switch is a `VICTORY_*` variable, off by default, documented in docs/native-host.md
LakshanSivakumar commented 2026-11-27 10:32:35 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T10:32:35Z.


This is a draft, so only a first look. The guards (render targets, depth, GPU-written, shown by a heap entry, held by a list) are the right ones, and it is good that each has a test that fails without the check.

Two questions. You say yourself the budget may free little if most copies are shown by heap entries. Please post the trace of one run on a 16 or 24 GB Mac before you mark it ready, so we know if it matters. And "until then, that one entry shows nothing for that one submission": what happens to a draw that samples that entry in that submission? A black draw is worse than a late one, so please say. I have not run it.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7216010400 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/301#issuecomment-7216010400). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-27T10:32:35Z. --- This is a draft, so only a first look. The guards (render targets, depth, GPU-written, shown by a heap entry, held by a list) are the right ones, and it is good that each has a test that fails without the check. Two questions. You say yourself the budget may free little if most copies are shown by heap entries. Please post the trace of one run on a 16 or 24 GB Mac before you mark it ready, so we know if it matters. And "until then, that one entry shows nothing for that one submission": what happens to a draw that samples that entry in that submission? A black draw is worse than a late one, so please say. I have not run it.
m0rff commented 2026-11-27 11:10:16 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by m0rff on 2026-11-27T11:10:16Z.


Thanks. Rebased onto main ce2b7860 (#267 and #292 merged in with no conflict, both behaviours kept). There is one new commit, 846ec4d1, and the PR stays a draft.

(1) Trace from a 16 or 24 GB Mac. I can't post one: the machine I work on has no copy of the game, so I have no run of my own and no numbers. The request to testers is on #8. What I need from such a run:

VICTORY_TRACE_TEXTURE_SYNC=1 tools/macos/run-native.sh <game folder>

Then, from runs/<date>/victory.log:

  • the startup line native host: Metal, with console, title_memory_mib, recommended_working_set_mib and texture_budget_mib;
  • the per-second lines host texture copies: <MiB>, budget <MiB>; <MiB> shown by heap entries, named by the submission's tables or viewed for unordered access, <MiB> could be given up; given up in the last second <n> (<MiB>), made again <n>, from the world load until the run ends or hits kIOGPUCommandBufferCallbackErrorOutOfMemory.

If "shown by heap entries" makes up most of the copies, the budget frees little and #79's levers are the ones that matter. I won't mark this ready until such a run is posted.

(2) What does a draw read through that entry in that submission? Transparent black, so you were right to ask. I measured it on Metal: victory-metal sampling_a_cleared_entry_reads_transparent_black samples an entry after clear_entry and gets (0, 0, 0, 0) on an M2 Pro, macOS 26.6. That is a measurement, not a documented Metal guarantee. The path was:

  • the title's plain-store records are mirrored only when the list that binds the table is encoded (remirror_tables), after the submission's sync;
  • an entry that names a copy not made at that point was cleared, and the draw sampled black.

There were two ways in:

  • a copy given up before;
  • a live copy that no mirrored entry showed, given up at that very sync, right under the draw.

A new test draws through such a record over budget (tri_vs/tri_ps) and reads the pixel back: [0, 0, 0, 0] for both cases before the fix.

Fixed the way you preferred, so the draw is late (one upload) rather than black. Before each submission's sync, when over budget or with any copy given up, the host now reads the records of every table that the submission's draws and dispatches bind, plus those of work held behind fences. It checks the same entries remirror_tables does (Title::keep_named, NativeHost::resources_named; the span is shared as NativeHost::table_span). A given-up copy those records name is made again and uploaded at that sync, and no copy they name is given up at it. Under budget with nothing given up, nothing is read.

The tests are a_texture_given_up_is_back_for_the_draw_whose_table_names_it and a_texture_the_submission_names_is_not_given_up_under_its_draw. Both now read the texel. Removing the remake fails the first, and removing the protection fails both.

What is left, marked as a shortcut in the code and in docs/native-host.md:

  • a record the title rewrites after that read but before held work is encoded;
  • an entry mirrored outside a submission.

Those still get the cleared entry until the next submission. Closing them would mean making textures during encoding, which needs the title's texture state inside NativeHost::execute. That is a larger change, and I'd rather wait for a trace that shows it matters. The cost of the scan is one read of each distinct bound table range per submission, and only while over budget or after an eviction.

Checks: cargo test -p victory-hle -p victory -p victory-gpu -p xtask passes (victory-gpu on arm64, 325 passed), Windows clippy with -D warnings is clean, and cargo xtask policy is ok. I've updated the PR description and docs/native-host.md.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7216762316 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/301#issuecomment-7216762316). Originally posted by [m0rff](https://github.com/m0rff) on 2026-11-27T11:10:16Z. --- Thanks. Rebased onto main `ce2b7860` (#267 and #292 merged in with no conflict, both behaviours kept). There is one new commit, `846ec4d1`, and the PR stays a draft. **(1) Trace from a 16 or 24 GB Mac.** I can't post one: the machine I work on has no copy of the game, so I have no run of my own and no numbers. The request to testers is on #8. What I need from such a run: ``` VICTORY_TRACE_TEXTURE_SYNC=1 tools/macos/run-native.sh <game folder> ``` Then, from `runs/<date>/victory.log`: - the startup line `native host: Metal`, with `console`, `title_memory_mib`, `recommended_working_set_mib` and `texture_budget_mib`; - the per-second lines `host texture copies: <MiB>, budget <MiB>; <MiB> shown by heap entries, named by the submission's tables or viewed for unordered access, <MiB> could be given up; given up in the last second <n> (<MiB>), made again <n>`, from the world load until the run ends or hits `kIOGPUCommandBufferCallbackErrorOutOfMemory`. If "shown by heap entries" makes up most of the copies, the budget frees little and #79's levers are the ones that matter. I won't mark this ready until such a run is posted. **(2) What does a draw read through that entry in that submission?** Transparent black, so you were right to ask. I measured it on Metal: `victory-metal` `sampling_a_cleared_entry_reads_transparent_black` samples an entry after `clear_entry` and gets `(0, 0, 0, 0)` on an M2 Pro, macOS 26.6. That is a measurement, not a documented Metal guarantee. The path was: - the title's plain-store records are mirrored only when the list that binds the table is encoded (`remirror_tables`), after the submission's sync; - an entry that names a copy not made at that point was cleared, and the draw sampled black. There were two ways in: - a copy given up before; - a live copy that no mirrored entry showed, given up at that very sync, right under the draw. A new test draws through such a record over budget (`tri_vs`/`tri_ps`) and reads the pixel back: `[0, 0, 0, 0]` for both cases before the fix. Fixed the way you preferred, so the draw is late (one upload) rather than black. Before each submission's sync, when over budget or with any copy given up, the host now reads the records of every table that the submission's draws and dispatches bind, plus those of work held behind fences. It checks the same entries `remirror_tables` does (`Title::keep_named`, `NativeHost::resources_named`; the span is shared as `NativeHost::table_span`). A given-up copy those records name is made again and uploaded at that sync, and no copy they name is given up at it. Under budget with nothing given up, nothing is read. The tests are `a_texture_given_up_is_back_for_the_draw_whose_table_names_it` and `a_texture_the_submission_names_is_not_given_up_under_its_draw`. Both now read the texel. Removing the remake fails the first, and removing the protection fails both. What is left, marked as a shortcut in the code and in docs/native-host.md: - a record the title rewrites after that read but before held work is encoded; - an entry mirrored outside a submission. Those still get the cleared entry until the next submission. Closing them would mean making textures during encoding, which needs the title's texture state inside `NativeHost::execute`. That is a larger change, and I'd rather wait for a trace that shows it matters. The cost of the scan is one read of each distinct bound table range per submission, and only while over budget or after an eviction. Checks: `cargo test -p victory-hle -p victory -p victory-gpu -p xtask` passes (victory-gpu on arm64, 325 passed), Windows clippy with `-D warnings` is clean, and `cargo xtask policy` is ok. I've updated the PR description and docs/native-host.md.
alicans commented 2026-11-27 11:39:59 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by alicans on 2026-11-27T11:39:59Z.


A trace from a 24 GB Mac, as asked: M4 Pro, 24 GB, macOS 15.8.2, --console series-s, windowed, VICTORY_TRACE_TEXTURE_SYNC=1.

The build was main ce2b786 with this PR's 846ec4d1 applied on top. #263, #253, #264, #278 and #304 were also applied (#296 too, at its new default of 0), plus a local title-watchdog patch. This run had no texture-level experiment and no VICTORY_METAL_RESIDENCY_SETS.

On 24 GB the budget never comes into play.

  • Startup line: title_memory_mib=7776 recommended_working_set_mib=16384 texture_budget_mib=8608. Metal recommends 16 GB here, so the budget is 8.4 GB.

  • Host texture copies, from the once-a-second line:

    time copies (MiB) shown by heap entries, tables or UAV views could be given up
    +50 s (story load) 2447 2399 7
    +93 s 2765 2683 42
    +101 s 4010 3917 52
    +106 s 6566 6466 60
  • Nothing was given up in the whole run. The copies never reached the budget.

  • Meanwhile the macOS memory level (kern.memorystatus_level) held at 35 % until +90 s, then fell to 14 % by +108 s. I stop runs at 15 % so that the Mac does not freeze. The game was still alive at render frame 1536, at the world load, with no GPU errors.

  • The last sync line before the stop covered 2.7 s: 2232 textures (2152 of them for the first time, 824 partly unreadable), 1932 MiB.

On this machine, then, the limit is system memory, not Metal's working set:

  • The copies grew by about 4.1 GB in about 15 s at the world load.
  • At no point could more than about 1.5 % of them be given up.
  • A budget taken from recommendedMaxWorkingSetSize lands above what a 24 GB Mac can hold next to the title's 7.6 GB.

I have not tried a lower VICTORY_METAL_TEXTURE_BUDGET_MB, because there was almost nothing for it to give up.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7217336180 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/301#issuecomment-7217336180). Originally posted by [alicans](https://github.com/alicans) on 2026-11-27T11:39:59Z. --- A trace from a **24 GB** Mac, as asked: M4 Pro, 24 GB, macOS 15.8.2, `--console series-s`, windowed, `VICTORY_TRACE_TEXTURE_SYNC=1`. The build was main `ce2b786` with this PR's `846ec4d1` applied on top. #263, #253, #264, #278 and #304 were also applied (#296 too, at its new default of 0), plus a local title-watchdog patch. This run had no texture-level experiment and no `VICTORY_METAL_RESIDENCY_SETS`. **On 24 GB the budget never comes into play.** - Startup line: `title_memory_mib=7776 recommended_working_set_mib=16384 texture_budget_mib=8608`. Metal recommends 16 GB here, so the budget is 8.4 GB. - Host texture copies, from the once-a-second line: | time | copies (MiB) | shown by heap entries, tables or UAV views | could be given up | |---|---|---|---| | +50 s (story load) | 2447 | 2399 | 7 | | +93 s | 2765 | 2683 | 42 | | +101 s | 4010 | 3917 | 52 | | +106 s | 6566 | 6466 | 60 | - Nothing was given up in the whole run. The copies never reached the budget. - Meanwhile the macOS memory level (`kern.memorystatus_level`) held at 35 % until +90 s, then fell to 14 % by +108 s. I stop runs at 15 % so that the Mac does not freeze. The game was still alive at render frame 1536, at the world load, with no GPU errors. - The last sync line before the stop covered 2.7 s: 2232 textures (2152 of them for the first time, 824 partly unreadable), 1932 MiB. On this machine, then, the limit is system memory, not Metal's working set: - The copies grew by about 4.1 GB in about 15 s at the world load. - At no point could more than about 1.5 % of them be given up. - A budget taken from `recommendedMaxWorkingSetSize` lands above what a 24 GB Mac can hold next to the title's 7.6 GB. I have not tried a lower `VICTORY_METAL_TEXTURE_BUDGET_MB`, because there was almost nothing for it to give up.
daidalos4 commented 2026-11-27 11:40:55 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by daidalos4 on 2026-11-27T11:40:55Z.


Tested on a 16 GB Mac, as a follow-up to the residency-set run on #8.

Setup: MacBook Pro M1 (MacBookPro17,1), 16 GB, macOS 27.0.1, --console series-s, VICTORY_METAL_RESIDENCY_SETS=heap, this branch (846ec4d1) merged onto main plus the read cache.

Result: startup logs texture_budget_mib=4348 (recommended 12124, title 7776). The story loading screens ran for 22 minutes with no kIOGPUCommandBufferCallbackErrorOutOfMemory. Without the budget, the same load hit it at heap_set_mb=10651. heap_set_mb climbed from 1849 to 10379 and stayed there.

time (UTC) heap_set_mb
11:19 1849
11:21 3127
11:24 9671
11:34 10035
11:39 (crash) 10379

The run still ends at frame ~17000 on the same access violation as the two earlier runs: 0xc0000005 at image+0x55e56f8, info=[0, 0] (a read of address 0), r8=r10=0. On my runs this crash turned out to be independent of the GPU OOM. It hits at the same address with or without the OOM, so it looks like a separate bug further into the load.

Edit: image+0x55e56f8 is not the first fault. In all three runs, a first-chance write to address 0 comes 1 to 5 s earlier, with info=[1, 0] and rax=0. It hit image+0x23cf683 in runs 1-2 and image+0x2215c35 in this one. The title's crash reporter (Breakpad/WER lines) then runs and faults at 0x55e56f8. So the real failure looks like a null pointer being written through, possibly an allocation that came back empty, rather than anything in the crash path.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7217353837 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/301#issuecomment-7217353837). Originally posted by [daidalos4](https://github.com/daidalos4) on 2026-11-27T11:40:55Z. --- Tested on a 16 GB Mac, as a follow-up to the residency-set run on #8. **Setup:** MacBook Pro M1 (MacBookPro17,1), 16 GB, macOS 27.0.1, `--console series-s`, `VICTORY_METAL_RESIDENCY_SETS=heap`, this branch (`846ec4d1`) merged onto main plus the read cache. **Result:** startup logs `texture_budget_mib=4348` (recommended 12124, title 7776). The story loading screens ran for 22 minutes with **no `kIOGPUCommandBufferCallbackErrorOutOfMemory`**. Without the budget, the same load hit it at `heap_set_mb=10651`. `heap_set_mb` climbed from 1849 to 10379 and stayed there. | time (UTC) | heap_set_mb | |---|---| | 11:19 | 1849 | | 11:21 | 3127 | | 11:24 | 9671 | | 11:34 | 10035 | | 11:39 (crash) | 10379 | The run still ends at frame ~17000 on the same access violation as the two earlier runs: `0xc0000005 at image+0x55e56f8`, info=[0, 0] (a read of address 0), r8=r10=0. On my runs this crash turned out to be independent of the GPU OOM. It hits at the same address with or without the OOM, so it looks like a separate bug further into the load. **Edit:** `image+0x55e56f8` is not the first fault. In all three runs, a first-chance write to address 0 comes 1 to 5 s earlier, with `info=[1, 0]` and `rax=0`. It hit `image+0x23cf683` in runs 1-2 and `image+0x2215c35` in this one. The title's crash reporter (Breakpad/WER lines) then runs and faults at `0x55e56f8`. So the real failure looks like a null pointer being written through, possibly an allocation that came back empty, rather than anything in the crash path.
ItsMariusBC commented 2026-11-27 11:42:41 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by ItsMariusBC on 2026-11-27T11:42:41Z.


A second 24 GB Mac, and it agrees with @alicans: the budget has almost nothing it may give up. Two things this adds: the run goes on into the world for the full 480 s, and I tried the lower budget.

Caveat first: this is the head before the rebase, e656ddd, merged onto main c1b9587, so without keep_named. Apple M5 Pro, 24 GB, macOS 27.2.1, Series S, windowed, warm shader cache, VICTORY_HOLD_BYTE=1471b6330:1. The build also carried a local change that writes each shader container to disk when it is first translated (file writes in the first run's prewarm, none in the second). The log says title_memory_mib=7776 recommended_working_set_mib=18186 texture_budget_mib=10410.

Run with VICTORY_METAL_TEXTURE_BUDGET_MB=4096 VICTORY_TRACE_TEXTURE_SYNC=1, from the once-a-second line:

At Copies (MiB) Shown by heap entries or UAV Could be given up
+37 s 2,447 2,399 7
+62 s 2,533 2,467 26
+76 s 7,914 7,795 79
+91 s 8,815 8,741 33
+149 s 9,596 9,556 0
+238 s (the most) 10,099 10,033
  • Over the whole run the budget gave up 6,989 copies, 310 MiB in all, and 152 were made again. No single line could have given up more than 100 MiB.
  • The copies are 3.8 GB over the 4096 MiB budget at +76 s and 6 GB over from +238 s to the end.
  • They peak under this Mac's default budget (10,099 against 10,410), so here the default would not come into play either.

Free memory (memory_pressure, every 15 s) goes from 67 % at the start to 4 % at +76 s, where the copies jump from 2.5 to 7.9 GB, and to 0 % in the world. A run with the default budget also went down to 0 %.

The freeze before the world is the same with and without the budget: 64 frames take 152 s with 4096, 143 s with the default, 185 s on plain main this morning. Each run then loses command buffers in the world (run-summary.sh counts one out-of-memory failure in each, at +311 s and +439 s).

One thing I cannot explain from the log: the copies add up to 10.1 GB counted by their size in title memory, while the title has 7.8 GB in all.

I can run the rebased head, or other switches, if that helps.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7217386656 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/301#issuecomment-7217386656). Originally posted by [ItsMariusBC](https://github.com/ItsMariusBC) on 2026-11-27T11:42:41Z. --- A second 24 GB Mac, and it agrees with @alicans: the budget has almost nothing it may give up. Two things this adds: the run goes on into the world for the full 480 s, and I tried the lower budget. Caveat first: this is the head before the rebase, `e656ddd`, merged onto main `c1b9587`, so without `keep_named`. Apple M5 Pro, 24 GB, macOS 27.2.1, Series S, windowed, warm shader cache, `VICTORY_HOLD_BYTE=1471b6330:1`. The build also carried a local change that writes each shader container to disk when it is first translated (file writes in the first run's prewarm, none in the second). The log says `title_memory_mib=7776 recommended_working_set_mib=18186 texture_budget_mib=10410`. Run with `VICTORY_METAL_TEXTURE_BUDGET_MB=4096 VICTORY_TRACE_TEXTURE_SYNC=1`, from the once-a-second line: | At | Copies (MiB) | Shown by heap entries or UAV | Could be given up | | --- | --- | --- | --- | | +37 s | 2,447 | 2,399 | 7 | | +62 s | 2,533 | 2,467 | 26 | | +76 s | 7,914 | 7,795 | 79 | | +91 s | 8,815 | 8,741 | 33 | | +149 s | 9,596 | 9,556 | 0 | | +238 s (the most) | 10,099 | 10,033 | | - Over the whole run the budget gave up 6,989 copies, 310 MiB in all, and 152 were made again. No single line could have given up more than 100 MiB. - The copies are 3.8 GB over the 4096 MiB budget at +76 s and 6 GB over from +238 s to the end. - They peak under this Mac's default budget (10,099 against 10,410), so here the default would not come into play either. Free memory (`memory_pressure`, every 15 s) goes from 67 % at the start to 4 % at +76 s, where the copies jump from 2.5 to 7.9 GB, and to 0 % in the world. A run with the default budget also went down to 0 %. The freeze before the world is the same with and without the budget: 64 frames take 152 s with 4096, 143 s with the default, 185 s on plain main this morning. Each run then loses command buffers in the world (`run-summary.sh` counts one out-of-memory failure in each, at +311 s and +439 s). One thing I cannot explain from the log: the copies add up to 10.1 GB counted by their size in title memory, while the title has 7.8 GB in all. I can run the rebased head, or other switches, if that helps.
alicans commented 2026-11-27 11:44:14 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by alicans on 2026-11-27T11:44:14Z.


@daidalos4 on the first fault: image+0x23cf683 is the title's own watchdog, not an empty allocation. It is a deliberate null write; docs/ROADMAP.md lists it ("the game's watchdog fires 30 s into the frame: a deliberate null write at image+0x23cf683, then the fault at image+0x55e56f8").

image+0x2215c35 looks like the same watchdog's other path. It lies a few bytes after the call into that handler at image+0x2215c27, and a local patch that skips that call (with the code right after it) and the write at 0x23cf683 stops both on my runs.

When I've seen the write at 0x23cf683, it came about 30 s after the last frame. So on your runs it most likely means that something stalled for 30 s at frame ~17000, not that an allocation came back empty.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7217416131 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/301#issuecomment-7217416131). Originally posted by [alicans](https://github.com/alicans) on 2026-11-27T11:44:14Z. --- @daidalos4 on the first fault: `image+0x23cf683` is the title's own watchdog, not an empty allocation. It is a deliberate null write; docs/ROADMAP.md lists it ("the game's watchdog fires 30 s into the frame: a deliberate null write at `image+0x23cf683`, then the fault at `image+0x55e56f8`"). `image+0x2215c35` looks like the same watchdog's other path. It lies a few bytes after the call into that handler at `image+0x2215c27`, and a local patch that skips that call (with the code right after it) and the write at `0x23cf683` stops both on my runs. When I've seen the write at `0x23cf683`, it came about 30 s after the last frame. So on your runs it most likely means that something stalled for 30 s at frame ~17000, not that an allocation came back empty.
LakshanSivakumar commented 2026-11-27 11:54:33 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T11:54:33Z.


Thank you for the new commit, and the draw that is late instead of black is what I preferred.

The traces are in now. They say two things. On 16 GB (daidalos4) the budget kept the run free of OutOfMemory for 22 minutes. On 24 GB (alicans, ItsMariusBC) there is almost nothing to give up: 310 MiB over a whole run with a 4 GB budget, because the copies are mostly named by heap entries. So this helps on 16 GB and not on 24 GB.

ItsMariusBC also saw 10.1 GB of copies against 7.8 GB of title memory. Please look at what is counted twice (for example a copy made for each view of the same memory). Keep it as a draft until you have an answer for that.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7217614416 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/301#issuecomment-7217614416). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-27T11:54:33Z. --- Thank you for the new commit, and the draw that is late instead of black is what I preferred. The traces are in now. They say two things. On 16 GB (daidalos4) the budget kept the run free of `OutOfMemory` for 22 minutes. On 24 GB (alicans, ItsMariusBC) there is almost nothing to give up: 310 MiB over a whole run with a 4 GB budget, because the copies are mostly named by heap entries. So this helps on 16 GB and not on 24 GB. ItsMariusBC also saw 10.1 GB of copies against 7.8 GB of title memory. Please look at what is counted twice (for example a copy made for each view of the same memory). Keep it as a draft until you have an answer for that.
m0rff commented 2026-11-27 12:22:20 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by m0rff on 2026-11-27T12:22:20Z.


Rebased onto main 465db23b (27 new commits, #263 included); the two commits applied cleanly. New commit f6265aa2. Still a draft.

Short answer: nothing is counted twice, but some memory is held twice. The counter matches the host textures that exist. The 10.1 GB against 7.8 GB means the host keeps more than one copy of some title memory. Code alone can't say how much of the 2.3 GB this explains, so I've added a trace figure that will.

What the counter counts. One entry per title texture, at its layout's size in title memory: all mips, slices and planes (Title::realize adds it, texture_released takes it off). A title texture is one of two things:

  • a resource object (keyed by its address);
  • for a view of memory the title placed itself, its address plus its resource description (placed_key).

So:

  • Views do not add copies. Several views of one object, in other formats or of other mips, all name that object and share its one host texture. The heap entry a view writes is a Metal texture view (create_texture_view), with no storage of its own. The same goes for several placed views of one description: the view's own description is not part of the key. views_of_one_texture_share_one_copy_counted_once, placed_views_of_one_description_share_one_key.
  • Untiling, format expansion and Metal padding cannot push the count past title memory. It counts the title-side size, not the Metal one. That size is never more than the footprint the title was told to allocate, across mips, arrays, BC formats and mip tails: a_textures_counted_size_is_never_more_than_its_footprint. So the count has no overcount of its own to fix.
  • Textures over the same memory each get their own copy, and each is counted. The host has no map from memory to copies. Two objects aliasing one heap offset each get a host texture, and so does a placed description that starts inside another texture's memory. textures_over_one_memory_each_hold_a_copy_of_their_own makes three over 16 KiB: three Metal textures, the count is the sum, and the memory under them is 16 KiB. This is real memory, not a bookkeeping error.
  • Stale placed copies. A placed copy goes only when another description is placed at exactly its address, or when its pool is released (texture_placed, release_placed). If the title streams something else into that memory at other start addresses, the old copy stays. If a heap entry still holds the old record, that copy also counts as "shown".

Committed resources come from the title's allocator (XMemAlloc), so they should sit inside the pools; the trace checks that too.

The trace that settles it. The once-a-second VICTORY_TRACE_TEXTURE_SYNC=1 line now ends:

...; <MiB> of distinct title memory under the copies, <MiB> of copies outside the title's pools

How to read it:

  • Distinct memory well below the copies: overlapping copies (aliasing, stale placed copies). The gap is how much is held twice.
  • Distinct memory about equal to the copies, but above 7.8 GB: the excess is in copies outside the pools (second figure).

Copies in a pool are placed by their pool offset, so pages the title maps at two addresses (use_page_mapper) count once (textures_over_one_memory_each_hold_a_copy_of_their_own maps one pool at a second address; a_copy_outside_the_titles_pools_is_logged_so).

The texture sync line's "replaced at their address" count shows how often placed descriptions take one address from each other. @ItsMariusBC, @alicans: one world-load run of this head with the trace on would answer this. The quickest way to compare is the copies, distinct and outside figures at the peak.

What I'd build, if the trace shows a large overlap. Not started; your call. Two textures over one range would share one Metal texture where the formats allow a view of each other, as alias_source/TEXTURES_AT already does on Windows. A placed copy would also go once something else is placed over its memory, not only at its exact address. The first changes which texture a draw samples, and the second needs care with entries that still name the old copy. So I'd rather see the numbers first.

Checks: cargo test -p victory-hle -p victory -p victory-gpu -p xtask passes (victory-gpu on arm64: 333 passed). Windows clippy with -D warnings is clean, and cargo xtask policy is ok. a_texture_uploaded_blank_is_probed_at_each_submission and a_texture_rewritten_whole_is_read_whole_only_now_and_then flake about 2 runs in 5, and do the same on the head before this commit. The cause is other tests' textures sharing the probe's time budget, not this change. docs/native-host.md has a new paragraph under the budget section ("What the count counts, and why it can pass the title's memory").

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7218163309 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/301#issuecomment-7218163309). Originally posted by [m0rff](https://github.com/m0rff) on 2026-11-27T12:22:20Z. --- Rebased onto main `465db23b` (27 new commits, #263 included); the two commits applied cleanly. New commit `f6265aa2`. Still a draft. **Short answer: nothing is counted twice, but some memory is held twice.** The counter matches the host textures that exist. The 10.1 GB against 7.8 GB means the host keeps more than one copy of some title memory. Code alone can't say how much of the 2.3 GB this explains, so I've added a trace figure that will. **What the counter counts.** One entry per title texture, at its layout's size in title memory: all mips, slices and planes (`Title::realize` adds it, `texture_released` takes it off). A title texture is one of two things: - a resource object (keyed by its address); - for a view of memory the title placed itself, its address plus its resource description (`placed_key`). So: - **Views do not add copies.** Several views of one object, in other formats or of other mips, all name that object and share its one host texture. The heap entry a view writes is a Metal texture view (`create_texture_view`), with no storage of its own. The same goes for several placed views of one description: the view's own description is not part of the key. `views_of_one_texture_share_one_copy_counted_once`, `placed_views_of_one_description_share_one_key`. - **Untiling, format expansion and Metal padding cannot push the count past title memory.** It counts the title-side size, not the Metal one. That size is never more than the footprint the title was told to allocate, across mips, arrays, BC formats and mip tails: `a_textures_counted_size_is_never_more_than_its_footprint`. So the count has no overcount of its own to fix. - **Textures over the same memory each get their own copy, and each is counted.** The host has no map from memory to copies. Two objects aliasing one heap offset each get a host texture, and so does a placed description that starts inside another texture's memory. `textures_over_one_memory_each_hold_a_copy_of_their_own` makes three over 16 KiB: three Metal textures, the count is the sum, and the memory under them is 16 KiB. This is real memory, not a bookkeeping error. - **Stale placed copies.** A placed copy goes only when another description is placed at *exactly* its address, or when its pool is released (`texture_placed`, `release_placed`). If the title streams something else into that memory at other start addresses, the old copy stays. If a heap entry still holds the old record, that copy also counts as "shown". Committed resources come from the title's allocator (`XMemAlloc`), so they should sit inside the pools; the trace checks that too. **The trace that settles it.** The once-a-second `VICTORY_TRACE_TEXTURE_SYNC=1` line now ends: ``` ...; <MiB> of distinct title memory under the copies, <MiB> of copies outside the title's pools ``` How to read it: - **Distinct memory well below the copies:** overlapping copies (aliasing, stale placed copies). The gap is how much is held twice. - **Distinct memory about equal to the copies, but above 7.8 GB:** the excess is in copies outside the pools (second figure). Copies in a pool are placed by their pool offset, so pages the title maps at two addresses (`use_page_mapper`) count once (`textures_over_one_memory_each_hold_a_copy_of_their_own` maps one pool at a second address; `a_copy_outside_the_titles_pools_is_logged_so`). The texture sync line's "replaced at their address" count shows how often placed descriptions take one address from each other. @ItsMariusBC, @alicans: one world-load run of this head with the trace on would answer this. The quickest way to compare is the copies, distinct and outside figures at the peak. **What I'd build, if the trace shows a large overlap. Not started; your call.** Two textures over one range would share one Metal texture where the formats allow a view of each other, as `alias_source`/`TEXTURES_AT` already does on Windows. A placed copy would also go once something else is placed over its memory, not only at its exact address. The first changes which texture a draw samples, and the second needs care with entries that still name the old copy. So I'd rather see the numbers first. Checks: `cargo test -p victory-hle -p victory -p victory-gpu -p xtask` passes (victory-gpu on arm64: 333 passed). Windows clippy with `-D warnings` is clean, and `cargo xtask policy` is ok. `a_texture_uploaded_blank_is_probed_at_each_submission` and `a_texture_rewritten_whole_is_read_whole_only_now_and_then` flake about 2 runs in 5, and do the same on the head before this commit. The cause is other tests' textures sharing the probe's time budget, not this change. docs/native-host.md has a new paragraph under the budget section ("What the count counts, and why it can pass the title's memory").
daidalos4 commented 2026-11-27 12:44:54 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by daidalos4 on 2026-11-27T12:44:54Z.


@alicans thanks, that was it. With VICTORY_HOLD_BYTE=1471b6330:1 on the same 16 GB M1 (game partly on a network share), three more runs on this branch:

  • Default budget (4348), heap residency sets: 40 min with no watchdog fault and no OutOfMemory. Frames stopped after about 30 min at heap_set_mb=11924, with a fence wait held for over 130 s ("signal of 16138 queued 134.9s ago, GPU at 16136").
  • VICTORY_METAL_TEXTURE_BUDGET_MB=2048, heap residency sets: OutOfMemory after 9 min at heap_set_mb of about 10.3 GB. On 16 GB the heap set alone takes most of Metal's 12124 MiB, so lowering the texture budget does not help there.
  • Default budget, no residency sets: a host crash 5 min in, at frame ~7300. It was a SIGSEGV at address 0 with this stack:
_sigtramp
NativeHost<Metal>::register_texture
textures::<Title<Metal>>::realize
glue::mirror
descriptor::record
descriptor::create_placed_srv
victory_bridge_to_host

The top frame above _sigtramp is outside any image, so the fault may have hit while a signal was being handled in that path. This happened only once so far.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7218625664 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/301#issuecomment-7218625664). Originally posted by [daidalos4](https://github.com/daidalos4) on 2026-11-27T12:44:54Z. --- @alicans thanks, that was it. With `VICTORY_HOLD_BYTE=1471b6330:1` on the same 16 GB M1 (game partly on a network share), three more runs on this branch: - **Default budget (4348), heap residency sets:** 40 min with no watchdog fault and no `OutOfMemory`. Frames stopped after about 30 min at `heap_set_mb=11924`, with a fence wait held for over 130 s ("signal of 16138 queued 134.9s ago, GPU at 16136"). - **`VICTORY_METAL_TEXTURE_BUDGET_MB=2048`, heap residency sets:** `OutOfMemory` after 9 min at `heap_set_mb` of about 10.3 GB. On 16 GB the heap set alone takes most of Metal's 12124 MiB, so lowering the texture budget does not help there. - **Default budget, no residency sets:** a host crash 5 min in, at frame ~7300. It was a SIGSEGV at address 0 with this stack: ``` _sigtramp NativeHost<Metal>::register_texture textures::<Title<Metal>>::realize glue::mirror descriptor::record descriptor::create_placed_srv victory_bridge_to_host ``` The top frame above `_sigtramp` is outside any image, so the fault may have hit while a signal was being handled in that path. This happened only once so far.
alicans commented 2026-11-27 12:54:45 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by alicans on 2026-11-27T12:54:45Z.


@m0rff two world-load runs of f6265aa2 with the trace on. Same Mac as before: M4 Pro, 24 GB, macOS 15.8.2, Series S. The build was main c5d7f4d0 with this PR and #296 on top. Neither run reached the first world frame, so these are the figures at the end of the load.

run copies (MiB) distinct title memory under them copies outside the pools
A: budget off (VICTORY_METAL_TEXTURE_BUDGET_MB=0), no local texture change, +90 s 4002 1319 170
B: default budget (8608), sampled textures without their two most detailed levels, +100 s (peak) 10029 2004 174

So most of it is overlap: 3 times the distinct memory in A, 5 times in B. On the story loading screens (+40 to +80 s) it is already 2447 MiB of copies over 1087 MiB in both runs.

In run B the budget gave up copies for the first time on this Mac: 6678 copies (140 MiB) at +89 s, then 211 more, then 91, with 37, 8, 5, 2 and 33 made again in the following seconds. At +103 s the process aborted:

  • malloc found its free list corrupted (_tiny_check_and_zero_inline_meta_from_freelist, then abort);
  • on the title thread, inside -[AGXTexture newTextureViewWithPixelFormat:textureType:levels:slices:];
  • called from ResourceBackend::create_texture_view, NativeHost::mirror, glue::heap_of, glue::set_heaps.

It was one run, and run A (budget off) ended differently, so I can't say it is the budget. But it is the only abort of this kind I've had, and it came 14 s after the first copies were given up. A view made from a copy that was given up seems worth a look.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7218825901 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/301#issuecomment-7218825901). Originally posted by [alicans](https://github.com/alicans) on 2026-11-27T12:54:45Z. --- @m0rff two world-load runs of `f6265aa2` with the trace on. Same Mac as before: M4 Pro, 24 GB, macOS 15.8.2, Series S. The build was main `c5d7f4d0` with this PR and #296 on top. Neither run reached the first world frame, so these are the figures at the end of the load. | run | copies (MiB) | distinct title memory under them | copies outside the pools | |---|---|---|---| | A: budget off (`VICTORY_METAL_TEXTURE_BUDGET_MB=0`), no local texture change, +90 s | 4002 | 1319 | 170 | | B: default budget (8608), sampled textures without their two most detailed levels, +100 s (peak) | 10029 | 2004 | 174 | So most of it is overlap: 3 times the distinct memory in A, 5 times in B. On the story loading screens (+40 to +80 s) it is already 2447 MiB of copies over 1087 MiB in both runs. In run B the budget gave up copies for the first time on this Mac: 6678 copies (140 MiB) at +89 s, then 211 more, then 91, with 37, 8, 5, 2 and 33 made again in the following seconds. At +103 s the process aborted: - `malloc` found its free list corrupted (`_tiny_check_and_zero_inline_meta_from_freelist`, then `abort`); - on the title thread, inside `-[AGXTexture newTextureViewWithPixelFormat:textureType:levels:slices:]`; - called from `ResourceBackend::create_texture_view`, `NativeHost::mirror`, `glue::heap_of`, `glue::set_heaps`. It was one run, and run A (budget off) ended differently, so I can't say it is the budget. But it is the only abort of this kind I've had, and it came 14 s after the first copies were given up. A view made from a copy that was given up seems worth a look.
alicans commented 2026-11-27 12:56:04 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by alicans on 2026-11-27T12:56:04Z.


@daidalos4's SIGSEGV and my abort come through the same host path. Both are under glue::mirror:

  • theirs: create_placed_srv, then glue::mirror, realize and register_texture;
  • mine: set_heaps, then heap_of, NativeHost::mirror and create_texture_view.

Both ran with a budget on: theirs at the 16 GB default of 4348 MiB, mine 14 s after the first copies were given up. That's two single runs, so not proof. Still, it could be worth checking whether a mirror can reach a copy the budget has let go. @daidalos4, did your trace show copies given up before the crash?

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7218854676 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/301#issuecomment-7218854676). Originally posted by [alicans](https://github.com/alicans) on 2026-11-27T12:56:04Z. --- @daidalos4's SIGSEGV and my abort come through the same host path. Both are under `glue::mirror`: - theirs: `create_placed_srv`, then `glue::mirror`, `realize` and `register_texture`; - mine: `set_heaps`, then `heap_of`, `NativeHost::mirror` and `create_texture_view`. Both ran with a budget on: theirs at the 16 GB default of 4348 MiB, mine 14 s after the first copies were given up. That's two single runs, so not proof. Still, it could be worth checking whether a mirror can reach a copy the budget has let go. @daidalos4, did your trace show copies given up before the crash?
LakshanSivakumar commented 2026-11-27 13:03:18 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T13:03:18Z.


Review note, not merging yet (it is still a draft, and my 10.1 GB question is open).

  • The budget is on by default on every Mac, 24 GB included. I would like it off by default until there are runs on more machines.
  • In glue::submit the title lock is released between keep_named/sync_jobs and submit_synced. Another queue's submission can run keep_to_budget in that gap and give up a texture that a table of this submission names through a record the title stored without a device call. The entry is then cleared and the draw samples transparent black.

Holding the names of the submission in flight out of the budget's reach until submit_synced returns would close it.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7219000440 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/301#issuecomment-7219000440). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-27T13:03:18Z. --- Review note, not merging yet (it is still a draft, and my 10.1 GB question is open). - The budget is on by default on every Mac, 24 GB included. I would like it off by default until there are runs on more machines. - In `glue::submit` the title lock is released between `keep_named`/`sync_jobs` and `submit_synced`. Another queue's submission can run `keep_to_budget` in that gap and give up a texture that a table of this submission names through a record the title stored without a device call. The entry is then cleared and the draw samples transparent black. Holding the names of the submission in flight out of the budget's reach until `submit_synced` returns would close it.
alicans commented 2026-11-27 13:06:19 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by alicans on 2026-11-27T13:06:19Z.


@m0rff a third run, with the same settings as run A above: budget off, all texture levels, VICTORY_HOLD_BYTE. This time it got past the crash and further into the load (render frame 2240, +116 s). Then the copies took the Mac's memory:

time copies (MiB) distinct title memory under them outside the pools macOS memory level
+115 s 3147 1190 155 35 %
+118 s 4291 1321 155
+120 s 6405 1402 155 14 %
+127 s 8544 1670 161 9 % (stopped)

In those 12 s the copies grew by 5.4 GB over 0.48 GB of new distinct memory, about 11 copies per byte. The process RSS stayed at 6 GB, so the copies themselves are what used the memory. No GPU errors and no fault; I stopped it at 9 %.

So on 24 GB it is the overlap, not the budget, that stops the world load. If one Metal texture per range is what you'd build next, this Mac would be a good test for it. Run B fits the same picture: with the two top levels dropped it got to 10 GB of copies over 2 GB.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7219062099 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/301#issuecomment-7219062099). Originally posted by [alicans](https://github.com/alicans) on 2026-11-27T13:06:19Z. --- @m0rff a third run, with the same settings as run A above: budget off, all texture levels, `VICTORY_HOLD_BYTE`. This time it got past the crash and further into the load (render frame 2240, +116 s). Then the copies took the Mac's memory: | time | copies (MiB) | distinct title memory under them | outside the pools | macOS memory level | |---|---|---|---|---| | +115 s | 3147 | 1190 | 155 | 35 % | | +118 s | 4291 | 1321 | 155 | | | +120 s | 6405 | 1402 | 155 | 14 % | | +127 s | 8544 | 1670 | 161 | 9 % (stopped) | In those 12 s the copies grew by 5.4 GB over 0.48 GB of new distinct memory, about 11 copies per byte. The process RSS stayed at 6 GB, so the copies themselves are what used the memory. No GPU errors and no fault; I stopped it at 9 %. So on 24 GB it is the overlap, not the budget, that stops the world load. If one Metal texture per range is what you'd build next, this Mac would be a good test for it. Run B fits the same picture: with the two top levels dropped it got to 10 GB of copies over 2 GB.
alicans commented 2026-11-27 13:14:20 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by alicans on 2026-11-27T13:14:20Z.


A correction to my two comments above about the malloc abort: it is not the budget. A run with the budget off (VICTORY_METAL_TEXTURE_BUDGET_MB=0) on main d35ba927 with this PR aborted the same way, 30 s in. It was still on the loading screens, before any copy could be given up, this time in a shader prewarm thread (_tiny_check_and_zero_inline_meta_from_freelist under a hashbrown reserve in victory_shader::structure). So the free list is corrupted earlier, and the stack only shows where malloc noticed it.

Both aborts had my local change that drops the two most detailed levels of sampled textures. The runs without it had none (two, budget off), so the cause is more likely on my side than in this PR. Please disregard the link I drew between the abort and the budget. @daidalos4's register_texture crash may be a separate thing. The race you found in glue::submit stands on its own.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7219228563 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/301#issuecomment-7219228563). Originally posted by [alicans](https://github.com/alicans) on 2026-11-27T13:14:20Z. --- A correction to my two comments above about the `malloc` abort: it is not the budget. A run with the budget off (`VICTORY_METAL_TEXTURE_BUDGET_MB=0`) on main `d35ba927` with this PR aborted the same way, 30 s in. It was still on the loading screens, before any copy could be given up, this time in a shader prewarm thread (`_tiny_check_and_zero_inline_meta_from_freelist` under a `hashbrown` reserve in `victory_shader::structure`). So the free list is corrupted earlier, and the stack only shows where `malloc` noticed it. Both aborts had my local change that drops the two most detailed levels of sampled textures. The runs without it had none (two, budget off), so the cause is more likely on my side than in this PR. Please disregard the link I drew between the abort and the budget. @daidalos4's `register_texture` crash may be a separate thing. The race you found in `glue::submit` stands on its own.
m0rff commented 2026-11-27 13:38:15 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by m0rff on 2026-11-27T13:38:15Z.


Rebased onto main 60baf130 and pushed. Still a draft. In order:

1. Names of a submission in flight (glue::submit). Done, with one correction to how the gap was described. Today another submission cannot get into that gap: glue::submit takes ORDER (glue.rs:179) before keep_named and holds it until submit_synced returns. keep_to_budget is reached only through sync_jobs, whose only caller outside tests is glue::submit, and nothing else gives a copy up. But the title shouldn't depend on that lock to get this right, so it now holds the names itself:

  • keep_named adds the names it reads to a per-key count and returns them.
  • keep_to_budget skips any key with a count. It no longer takes the set, so a second submission's read cannot replace the first one's.
  • Title::let_named_go lowers the counts after submit_synced. It is also called on the ensure_queue error path, so those copies can be given up again later.

Test: a_texture_named_by_a_submission_in_flight_is_not_given_up_by_another.

  • Submission A's table names a copy through a record that was never mirrored. That matters: a mirrored entry would protect the copy whether or not the fix is there.
  • Over budget, submission B's keep_named and sync run before A is queued. The copy stays.
  • After A lets its names go, the copy is given up.

With the old code, where B's read replaced A's names, the test fails at "the first submission still names it". Left as before: under budget with nothing given up, keep_named reads nothing. Because of ORDER, nothing can go over budget in between.

2. Off by default. VICTORY_METAL_TEXTURE_BUDGET_MB=<n> turns it on at n MiB. Unset, 0, or anything that is not a number means off. The startup line still shows texture_budget_mib (0 when off). Next to it, suggested_texture_budget_mib gives the figure to try on that Mac: the working set less the title's memory, at least 1536 MiB, so testers on other machines know what to set. The trace works the same with the budget off. At the submission the trace logs at (once a second), keep_named also reads that submission's tables, so the "named by the submission's tables" and "could be given up" figures match a run with the budget on. docs/native-host.md, the ROADMAP line and the PR description are updated.

3. @daidalos4's SIGSEGV in register_texture under glue::mirror. I can't show from the code that a mirror reaches a released copy. What I checked:

  • Copies are Rcs. Giving one up (evict_texture) removes the host's entry for it (release_resource) and the title's Tracked. The Metal texture is freed only when the last Rc goes, and any list or entry still using it holds one. Nothing in this PR keeps a raw pointer to a copy. Its one raw read is safe_read of descriptor records in resources_named, which is not on that stack.
  • A mirror that names a given-up key goes through realize. The key is in pending, so a new texture is made and registered. register_texture itself only touches RefCell maps (the evicted set, resources, the heaps' take_gone). That is safe code, with no path to address 0 apart from an allocator fault.
  • After the rebase onto 60baf130, an R32_UINT object that a placed R9G9B9E5 view shares has a third Rc held by the host under the placed key. So evictable (strong_count <= 2) is false and it is never given up while the view is there. texture_released, which giving up calls, releases that shared view too, as on main.
  • The stack itself points away from a released copy. The frame above _sigtramp is at PC 0, outside any image. So a signal reached the thread while it was in register_texture, and the fault happened on the delivery side: the stack shows where the thread was, not that register_texture faulted. register_texture doesn't call any Metal object. It clones an Rc and edits maps, and on that stack the texture it registers was made a moment earlier by host.texture in realize. A use of a freed Metal texture would crash inside Metal/AGX or objc_msgSend, not at PC 0 under a signal trampoline.

@alicans has since seen malloc free-list corruption with the budget off, in a thread that has nothing to do with textures. I don't know what corrupted it.

@daidalos4: did the trace show any copies given up (given up in the last second <n> above 0) before frame ~7300? And could you repeat that configuration with the budget off, which is now the default? If it crashes the same way with nothing given up, it is not the budget.

4. The 10.1 GB question. @alicans' third run (budget off) points to copies holding the same title memory several times over, not to a counting error. Between +115 s and +127 s of the world load, copies grew from 3147 to 8544 MiB (+5.4 GB) while the distinct title memory under them grew from 1190 to 1670 MiB (+0.48 GB): about 11 bytes of copies per new byte, and 5 times the distinct memory overall at the end. The process RSS stayed at 6 GB, and the free-memory level macOS reports fell to 9 % before they stopped it. Run A (4.0 GB over 1.3 GB) and run B (10.0 GB over 2.0 GB) fit the same pattern, as does the 10.1 GB against 7.8 GB on the M5 Pro. Caveats:

  • One run on one Mac: M4 Pro, 24 GB, macOS 15.8.2, Series S.
  • The build was main c5d7f4d0 with this PR and #296 on top, run with VICTORY_HOLD_BYTE.
  • "Copies" are each texture's size in title memory, not what Metal allocated, which can be more (padding, expanded formats) or less.
  • "Distinct" is counted once per pool offset. Memory outside the pools (about 160 MiB) is counted by address.
  • The ratio of 11 is marginal over 12 s of loading. It is not a steady state.
  • Run B also had alicans' local change dropping the two top mip levels, and that change is the likely cause of their aborts, so B's figures are less clean than A's.

A possible next step, which I haven't built: one Metal texture per range of title memory.

  • Today. Each title key (an object's address, or a placed address with its description) gets its own copy, uploaded from the same bytes as any other key over that memory. 60baf130 already shares one texture in one case: a placed R9G9B9E5 view laid out exactly like a live R32_UINT object.
  • Generalised. The host keeps one texture for each title range (pool offset and length), and each key maps to that range's texture. An entry whose layout matches (same dimensions, swizzle, mip and slice count, a format Metal can reinterpret) gets a texture view of it (create_texture_view, no storage), as R9G9B9E5 does now.
  • What changes which texture a draw samples. When a key with an incompatible layout covers an overlapping range (another swizzle, size, or start inside the range), the newest uploaded description owns the range. This is a guess, and it would be marked as one. For resource objects, D3D12 requires an aliasing barrier and a discard or full write before another alias over the same memory is used, so an older alias's contents are undefined by then. Views the title places over raw memory are not resource objects, and whether the title keeps to that rule for them on the console is not known. Older keys over that range become like a given-up copy: their entries are cleared (sampling transparent black, as an entry naming a given-up copy does now), and they are made again from title memory if a view or a submission's tables name them. That reuses this PR's pending, take_wanted and keep_named path.
  • What changes for the title. A draw that samples an older alias after the title has moved on to a newer one gets the newer upload or black instead of a stale private copy. That is allowed by D3D12, but it is a behaviour change, and it needs world runs.
  • Where it breaks. If the title reads two incompatible layouts over the same memory in the same frame, the range would either be uploaded again at every submission or one of the two would sample black. A trace of how often a range changes owner would show whether that happens before anything is switched over.
  • What it can't save. Subresources placed at other starts, such as separately placed mips or slices of one chain, can share only if their GFX10 layout inside the parent matches a standalone one. The packed mip tail does not, so those stay separate copies.
  • Size. Bounded by alicans' figures: at most about 6.8 GB of the 8.5 GB in the third run, less whatever falls into the last case.

@LakshanSivakumar: is this wanted, and if so, as a separate PR after this one? I'd keep it out of #301. And is "the newest description owns the range" acceptable, given the same-frame case above, or should a range keep one copy per layout and share only between identical layouts? That would be safer, but it saves only the identical-layout part of the overlap.

Checks:

  • cargo test -p victory-hle -p victory -p victory-gpu -p xtask, with victory-gpu run natively on arm64: all passed. victory-gpu: 360 passed, 3 ignored.
  • cargo clippy --workspace --all-targets --target x86_64-pc-windows-gnullvm -- -D warnings: clean.
  • cargo xtask policy: 384 files ok.
  • Native clippy found two useless vec! lints in this PR's own tests. Both are fixed.
<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7219744786 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/301#issuecomment-7219744786). Originally posted by [m0rff](https://github.com/m0rff) on 2026-11-27T13:38:15Z. --- Rebased onto main `60baf130` and pushed. Still a draft. In order: **1. Names of a submission in flight (`glue::submit`).** Done, with one correction to how the gap was described. Today another submission cannot get into that gap: `glue::submit` takes `ORDER` (`glue.rs:179`) before `keep_named` and holds it until `submit_synced` returns. `keep_to_budget` is reached only through `sync_jobs`, whose only caller outside tests is `glue::submit`, and nothing else gives a copy up. But the title shouldn't depend on that lock to get this right, so it now holds the names itself: - `keep_named` adds the names it reads to a per-key count and returns them. - `keep_to_budget` skips any key with a count. It no longer takes the set, so a second submission's read cannot replace the first one's. - `Title::let_named_go` lowers the counts after `submit_synced`. It is also called on the `ensure_queue` error path, so those copies can be given up again later. Test: `a_texture_named_by_a_submission_in_flight_is_not_given_up_by_another`. - Submission A's table names a copy through a record that was never mirrored. That matters: a mirrored entry would protect the copy whether or not the fix is there. - Over budget, submission B's `keep_named` and sync run before A is queued. The copy stays. - After A lets its names go, the copy is given up. With the old code, where B's read replaced A's names, the test fails at "the first submission still names it". Left as before: under budget with nothing given up, `keep_named` reads nothing. Because of `ORDER`, nothing can go over budget in between. **2. Off by default.** `VICTORY_METAL_TEXTURE_BUDGET_MB=<n>` turns it on at `n` MiB. Unset, `0`, or anything that is not a number means off. The startup line still shows `texture_budget_mib` (0 when off). Next to it, `suggested_texture_budget_mib` gives the figure to try on that Mac: the working set less the title's memory, at least 1536 MiB, so testers on other machines know what to set. The trace works the same with the budget off. At the submission the trace logs at (once a second), `keep_named` also reads that submission's tables, so the "named by the submission's tables" and "could be given up" figures match a run with the budget on. docs/native-host.md, the ROADMAP line and the PR description are updated. **3. @daidalos4's SIGSEGV in `register_texture` under `glue::mirror`.** I can't show from the code that a mirror reaches a released copy. What I checked: - Copies are `Rc`s. Giving one up (`evict_texture`) removes the host's entry for it (`release_resource`) and the title's `Tracked`. The Metal texture is freed only when the last `Rc` goes, and any list or entry still using it holds one. Nothing in this PR keeps a raw pointer to a copy. Its one raw read is `safe_read` of descriptor records in `resources_named`, which is not on that stack. - A mirror that names a given-up key goes through `realize`. The key is in `pending`, so a new texture is made and registered. `register_texture` itself only touches `RefCell` maps (the `evicted` set, resources, the heaps' `take_gone`). That is safe code, with no path to address 0 apart from an allocator fault. - After the rebase onto `60baf130`, an R32_UINT object that a placed R9G9B9E5 view shares has a third `Rc` held by the host under the placed key. So `evictable` (`strong_count <= 2`) is false and it is never given up while the view is there. `texture_released`, which giving up calls, releases that shared view too, as on main. - The stack itself points away from a released copy. The frame above `_sigtramp` is at PC 0, outside any image. So a signal reached the thread while it was in `register_texture`, and the fault happened on the delivery side: the stack shows where the thread was, not that `register_texture` faulted. `register_texture` doesn't call any Metal object. It clones an `Rc` and edits maps, and on that stack the texture it registers was made a moment earlier by `host.texture` in `realize`. A use of a freed Metal texture would crash inside Metal/AGX or `objc_msgSend`, not at PC 0 under a signal trampoline. @alicans has since seen `malloc` free-list corruption with the budget off, in a thread that has nothing to do with textures. I don't know what corrupted it. @daidalos4: did the trace show any copies given up (`given up in the last second <n>` above 0) before frame ~7300? And could you repeat that configuration with the budget off, which is now the default? If it crashes the same way with nothing given up, it is not the budget. **4. The 10.1 GB question.** @alicans' third run (budget off) points to copies holding the same title memory several times over, not to a counting error. Between +115 s and +127 s of the world load, copies grew from 3147 to 8544 MiB (+5.4 GB) while the distinct title memory under them grew from 1190 to 1670 MiB (+0.48 GB): about 11 bytes of copies per new byte, and 5 times the distinct memory overall at the end. The process RSS stayed at 6 GB, and the free-memory level macOS reports fell to 9 % before they stopped it. Run A (4.0 GB over 1.3 GB) and run B (10.0 GB over 2.0 GB) fit the same pattern, as does the 10.1 GB against 7.8 GB on the M5 Pro. Caveats: - One run on one Mac: M4 Pro, 24 GB, macOS 15.8.2, Series S. - The build was main `c5d7f4d0` with this PR and #296 on top, run with `VICTORY_HOLD_BYTE`. - "Copies" are each texture's size in title memory, not what Metal allocated, which can be more (padding, expanded formats) or less. - "Distinct" is counted once per pool offset. Memory outside the pools (about 160 MiB) is counted by address. - The ratio of 11 is marginal over 12 s of loading. It is not a steady state. - Run B also had alicans' local change dropping the two top mip levels, and that change is the likely cause of their aborts, so B's figures are less clean than A's. A possible next step, which I haven't built: **one Metal texture per range of title memory.** - **Today.** Each title key (an object's address, or a placed address with its description) gets its own copy, uploaded from the same bytes as any other key over that memory. `60baf130` already shares one texture in one case: a placed R9G9B9E5 view laid out exactly like a live R32_UINT object. - **Generalised.** The host keeps one texture for each title range (pool offset and length), and each key maps to that range's texture. An entry whose layout matches (same dimensions, swizzle, mip and slice count, a format Metal can reinterpret) gets a texture view of it (`create_texture_view`, no storage), as R9G9B9E5 does now. - **What changes which texture a draw samples.** When a key with an incompatible layout covers an overlapping range (another swizzle, size, or start inside the range), the newest uploaded description owns the range. This is a guess, and it would be marked as one. For resource objects, D3D12 requires an aliasing barrier and a discard or full write before another alias over the same memory is used, so an older alias's contents are undefined by then. Views the title places over raw memory are not resource objects, and whether the title keeps to that rule for them on the console is not known. Older keys over that range become like a given-up copy: their entries are cleared (sampling transparent black, as an entry naming a given-up copy does now), and they are made again from title memory if a view or a submission's tables name them. That reuses this PR's `pending`, `take_wanted` and `keep_named` path. - **What changes for the title.** A draw that samples an older alias after the title has moved on to a newer one gets the newer upload or black instead of a stale private copy. That is allowed by D3D12, but it is a behaviour change, and it needs world runs. - **Where it breaks.** If the title reads two incompatible layouts over the same memory in the same frame, the range would either be uploaded again at every submission or one of the two would sample black. A trace of how often a range changes owner would show whether that happens before anything is switched over. - **What it can't save.** Subresources placed at other starts, such as separately placed mips or slices of one chain, can share only if their GFX10 layout inside the parent matches a standalone one. The packed mip tail does not, so those stay separate copies. - **Size.** Bounded by alicans' figures: at most about 6.8 GB of the 8.5 GB in the third run, less whatever falls into the last case. @LakshanSivakumar: is this wanted, and if so, as a separate PR after this one? I'd keep it out of #301. And is "the newest description owns the range" acceptable, given the same-frame case above, or should a range keep one copy per layout and share only between identical layouts? That would be safer, but it saves only the identical-layout part of the overlap. Checks: - `cargo test -p victory-hle -p victory -p victory-gpu -p xtask`, with victory-gpu run natively on arm64: all passed. victory-gpu: 360 passed, 3 ignored. - `cargo clippy --workspace --all-targets --target x86_64-pc-windows-gnullvm -- -D warnings`: clean. - `cargo xtask policy`: 384 files ok. - Native clippy found two `useless vec!` lints in this PR's own tests. Both are fixed.
m0rff commented 2026-11-27 14:15:11 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by m0rff on 2026-11-27T14:15:11Z.


The one-copy-per-range change is up as a separate draft, #359 (Refs #356). It is stacked on this PR, so #301 stays as it is.

#359 does two things:

  • Identical copies share one texture. A texture laid out exactly like a live copy over the same memory uses that copy's texture.
  • Covered placed copies go once unused. A placed copy that another placement covers at a different start is given up at a later sync, once no heap entry shows it, no list holds it and no submission in flight names it. Only then, so work already on the GPU never loses it. That it can go at all is a guess, marked in the code; a copy still in use is made again when something names it.

@alicans, if the 24 GB Mac is free: a world load of #359's head with the budget off and VICTORY_TRACE_TEXTURE_SYNC=1 would show whether it helps. Compare the copies, the distinct memory and "made again" with your third run. The same line now also has "shared", "covered, given up" and "covered still in use".

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7220545271 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/301#issuecomment-7220545271). Originally posted by [m0rff](https://github.com/m0rff) on 2026-11-27T14:15:11Z. --- The one-copy-per-range change is up as a separate draft, #359 (Refs #356). It is stacked on this PR, so #301 stays as it is. #359 does two things: - **Identical copies share one texture.** A texture laid out exactly like a live copy over the same memory uses that copy's texture. - **Covered placed copies go once unused.** A placed copy that another placement covers at a different start is given up at a later sync, once no heap entry shows it, no list holds it and no submission in flight names it. Only then, so work already on the GPU never loses it. That it can go at all is a guess, marked in the code; a copy still in use is made again when something names it. @alicans, if the 24 GB Mac is free: a world load of #359's head with the budget off and `VICTORY_TRACE_TEXTURE_SYNC=1` would show whether it helps. Compare the copies, the distinct memory and "made again" with your third run. The same line now also has "shared", "covered, given up" and "covered still in use".
LakshanSivakumar commented 2026-11-27 14:25:30 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T14:25:30Z.


A second finding, and this one crashes. I merged this PR (budget off) into a local measuring branch and it died in the menus twice, at 43 s (SIGABRT from malloc, no panic text) and at 54 s (SIGSEGV).

Cause: the PR moves the snapshot of the submitted lists in glue::submit (list.segments(), which runs NativeList::snapshot()) out from under the title lock. The snapshot copies thousands of Rc references to heaps, pipelines and textures while the recording thread copies and drops the same references under the lock. Rc counts are not atomic, so they get corrupted: a double free or a use after free. It happens on every submission, with the budget on or off.

The tests cannot see it, because under cfg(test) submit keeps the lock throughout.

Fix I used locally: take the snapshots under the title lock again, once for keep_named (dropped inside the lock) and once for the submit, as before this PR. Please fold that in, together with the lock gap from my earlier note.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7220765633 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/301#issuecomment-7220765633). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-27T14:25:30Z. --- A second finding, and this one crashes. I merged this PR (budget off) into a local measuring branch and it died in the menus twice, at 43 s (SIGABRT from malloc, no panic text) and at 54 s (SIGSEGV). Cause: the PR moves the snapshot of the submitted lists in `glue::submit` (`list.segments()`, which runs `NativeList::snapshot()`) out from under the title lock. The snapshot copies thousands of `Rc` references to heaps, pipelines and textures while the recording thread copies and drops the same references under the lock. `Rc` counts are not atomic, so they get corrupted: a double free or a use after free. It happens on every submission, with the budget on or off. The tests cannot see it, because under `cfg(test)` submit keeps the lock throughout. Fix I used locally: take the snapshots under the title lock again, once for `keep_named` (dropped inside the lock) and once for the submit, as before this PR. Please fold that in, together with the lock gap from my earlier note.
m0rff commented 2026-11-27 14:42:05 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by m0rff on 2026-11-27T14:42:05Z.


Thanks, that is the bug. Folded in and pushed (a0fbd51a, rebased onto main 728845d1). Still a draft.

The fix. glue::submit takes the lists' snapshots under the title lock again, as you did it locally:

  • once inside the first with_title, for keep_named; it is dropped there, before sync_jobs;
  • once in the last with_title, for the submission, where main had it.

Nothing holding an Rc crosses the unlocked reads now. On the ensure_queue error path the snapshot is not made at all.

The compiler now rejects the old shape. TitleList::segments takes a &Title argument, and only code inside with_title has one. I put the old loop (snapshot before the lock) back as a check, and it no longer compiles.

Audit of the rest of this PR for Rcs created, cloned or dropped outside the lock:

  • keep_named clones the held lists' Rcs, and keep_to_budget, evict_texture and texture_released drop texture Rcs. All of them take &mut Title, so they run under the lock.
  • let_named_go and the names-in-flight counts are HashSet<usize> and HashMap<usize, _>: no Rc.
  • Job and Prepared (the unlocked prepare) hold no Rc. prepare hands &Job to scoped threads, so the compiler already requires them to be Sync.
  • The cfg(test) path (Title::submit) is fully under the lock.

What stays untested, plainly:

  • No test exercises the cross-thread race itself. Under cfg(test), submit keeps the lock throughout.
  • The guard covers where a snapshot is made, not where it is dropped. A snapshot taken under the lock could still be moved out through a captured variable and dropped later. Review is what catches that.

The lock gap from your earlier note is covered by the names-in-flight counts from the last commit, which stay as they were:

  • keep_named counts each name per key.
  • keep_to_budget skips any key with a count.
  • let_named_go lowers the counts after submit_synced, or on the ensure_queue error path.

Test: a_texture_named_by_a_submission_in_flight_is_not_given_up_by_another.

Crashes reported here. @daidalos4's SIGSEGV in register_texture and @alicans' malloc aborts (one of them with the budget off, in a shader prewarm thread) may have this cause:

  • The corruption happened at every submission, budget on or off.
  • An Rc freed twice shows up later wherever the allocator next notices, which fits a fault in an unrelated thread.

That is not shown. @alicans traced their aborts to a local change, and only a run of this head would tell.

Stacked drafts. #355 and #359 are rebased onto this head and pushed. I checked their own commits for the same mistake: everything they add runs through &mut Title or inside with_title, and they add no snapshot or Rc work outside the lock. Both stay drafts.

Checks on all three heads:

  • cargo test -p victory-hle -p victory -p victory-gpu -p xtask, with victory-gpu run natively on arm64: all passed (victory-gpu: 373 passed on this PR, 376 on #355 and #359).
  • cargo clippy --workspace --all-targets --target x86_64-pc-windows-gnullvm -- -D warnings: clean.
  • cargo xtask policy: ok.

The rebase onto 728845d1 also needed used: 0 in two test initialisers that main added for Tracked. That is folded into the first commit.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7221117571 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/301#issuecomment-7221117571). Originally posted by [m0rff](https://github.com/m0rff) on 2026-11-27T14:42:05Z. --- Thanks, that is the bug. Folded in and pushed (`a0fbd51a`, rebased onto main `728845d1`). Still a draft. **The fix.** `glue::submit` takes the lists' snapshots under the title lock again, as you did it locally: - once inside the first `with_title`, for `keep_named`; it is dropped there, before `sync_jobs`; - once in the last `with_title`, for the submission, where main had it. Nothing holding an `Rc` crosses the unlocked reads now. On the `ensure_queue` error path the snapshot is not made at all. **The compiler now rejects the old shape.** `TitleList::segments` takes a `&Title` argument, and only code inside `with_title` has one. I put the old loop (snapshot before the lock) back as a check, and it no longer compiles. **Audit of the rest of this PR** for `Rc`s created, cloned or dropped outside the lock: - `keep_named` clones the held lists' `Rc`s, and `keep_to_budget`, `evict_texture` and `texture_released` drop texture `Rc`s. All of them take `&mut Title`, so they run under the lock. - `let_named_go` and the names-in-flight counts are `HashSet<usize>` and `HashMap<usize, _>`: no `Rc`. - `Job` and `Prepared` (the unlocked `prepare`) hold no `Rc`. `prepare` hands `&Job` to scoped threads, so the compiler already requires them to be `Sync`. - The `cfg(test)` path (`Title::submit`) is fully under the lock. **What stays untested**, plainly: - No test exercises the cross-thread race itself. Under `cfg(test)`, submit keeps the lock throughout. - The guard covers where a snapshot is made, not where it is dropped. A snapshot taken under the lock could still be moved out through a captured variable and dropped later. Review is what catches that. **The lock gap from your earlier note** is covered by the names-in-flight counts from the last commit, which stay as they were: - `keep_named` counts each name per key. - `keep_to_budget` skips any key with a count. - `let_named_go` lowers the counts after `submit_synced`, or on the `ensure_queue` error path. Test: `a_texture_named_by_a_submission_in_flight_is_not_given_up_by_another`. **Crashes reported here.** @daidalos4's SIGSEGV in `register_texture` and @alicans' `malloc` aborts (one of them with the budget off, in a shader prewarm thread) may have this cause: - The corruption happened at every submission, budget on or off. - An `Rc` freed twice shows up later wherever the allocator next notices, which fits a fault in an unrelated thread. That is not shown. @alicans traced their aborts to a local change, and only a run of this head would tell. **Stacked drafts.** #355 and #359 are rebased onto this head and pushed. I checked their own commits for the same mistake: everything they add runs through `&mut Title` or inside `with_title`, and they add no snapshot or `Rc` work outside the lock. Both stay drafts. Checks on all three heads: - `cargo test -p victory-hle -p victory -p victory-gpu -p xtask`, with victory-gpu run natively on arm64: all passed (victory-gpu: 373 passed on this PR, 376 on #355 and #359). - `cargo clippy --workspace --all-targets --target x86_64-pc-windows-gnullvm -- -D warnings`: clean. - `cargo xtask policy`: ok. The rebase onto `728845d1` also needed `used: 0` in two test initialisers that main added for `Tracked`. That is folded into the first commit.
LakshanSivakumar commented 2026-11-27 16:23:35 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T16:23:35Z.


This is on main through #359 (merged in 582670f1, which contains these commits; your rebase only changed docs context). Same checks as noted on #359, budget off only. Closing since it is fully on main. Thanks.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7223207305 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/301#issuecomment-7223207305). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-27T16:23:35Z. --- This is on main through #359 (merged in 582670f1, which contains these commits; your rebase only changed docs context). Same checks as noted on #359, budget off only. Closing since it is fully on main. Thanks.
alicans commented 2026-11-27 16:30:17 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by alicans on 2026-11-27T16:30:17Z.


Thanks, that race fits both malloc aborts I reported here: both runs had this PR, the second with the budget off. So my guess that my local level-dropping change caused them was probably wrong. A later world load with the fix (main 4cf84c83 with #359) had no abort in 81 s, until my memory limit stopped it; that run did not have my local change.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7223337961 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/301#issuecomment-7223337961). Originally posted by [alicans](https://github.com/alicans) on 2026-11-27T16:30:17Z. --- Thanks, that race fits both `malloc` aborts I reported here: both runs had this PR, the second with the budget off. So my guess that my local level-dropping change caused them was probably wrong. A later world load with the fix (main `4cf84c83` with #359) had no abort in 81 s, until my memory limit stopped it; that run did not have my local change.

Pull request closed

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!301
No description provided.