One host texture per range: share identical copies, give up placed copies another placement overlaps #359

Closed
opened 2026-11-27 13:54:39 +00:00 by github-bot · 6 comments
Owner

@⁠m0rff on GitHub · 2026-11-27 13:50 UTC · original

On a 24 GB M4 Pro (Series S, budget off), host texture copies reached 8.5 GB over 1.7 GB of distinct title memory during the world load and stopped it (#301, alicans' third run). Each title key (an object, or a placed address with its description) gets its own copy, even when other keys cover the same memory.

Two changes, stacked on #301:

  1. One texture for identical copies. A title texture laid out exactly as a live copy over the same memory (same start, size, layout, dimensions, host format, no format conversion, not a render target or depth) uses that copy's texture instead of making its own, as the R9G9B9E5-over-R32_UINT case already does. Draws sample the same bytes either way.
  2. A placed copy goes when another is placed over its memory at another start. Today it goes only when another description is placed at exactly its address, or with its pool. It is given up the way the budget gives copies up, so an entry or a submission's tables that still name it get it made again (one late upload, not black). Copies that hold what title memory does not (render targets, depth, GPU-written, viewed for unordered access) are kept. This is a guess that the title is done with a placed view once it places another over the memory, and it will be marked as one.

Proven with unit tests. Needs world runs before it can be judged.

**@⁠m0rff** on GitHub · 2026-11-27 13:50 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/356) On a 24 GB M4 Pro (Series S, budget off), host texture copies reached 8.5 GB over 1.7 GB of distinct title memory during the world load and stopped it (#301, alicans' third run). Each title key (an object, or a placed address with its description) gets its own copy, even when other keys cover the same memory. Two changes, stacked on #301: 1. **One texture for identical copies.** A title texture laid out exactly as a live copy over the same memory (same start, size, layout, dimensions, host format, no format conversion, not a render target or depth) uses that copy's texture instead of making its own, as the R9G9B9E5-over-R32_UINT case already does. Draws sample the same bytes either way. 2. **A placed copy goes when another is placed over its memory at another start.** Today it goes only when another description is placed at exactly its address, or with its pool. It is given up the way the budget gives copies up, so an entry or a submission's tables that still name it get it made again (one late upload, not black). Copies that hold what title memory does not (render targets, depth, GPU-written, viewed for unordered access) are kept. This is a guess that the title is done with a placed view once it places another over the memory, and it will be marked as one. Proven with unit tests. Needs world runs before it can be judged.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 13:54:39 +00:00
Author
Owner

@⁠m0rff on GitHub · 2026-11-27 13:50 UTC · original

/claim

**@⁠m0rff** on GitHub · 2026-11-27 13:50 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/356#issuecomment-7220009930) /claim
Author
Owner

@⁠github-actions[bot] on GitHub · 2026-11-27 13:50 UTC · original

Claimed by @⁠m0rff. Open a draft pull request with Refs #356 in its description within 24 hours, or the claim expires.

**@⁠github-actions[bot]** on GitHub · 2026-11-27 13:50 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/356#issuecomment-7220013897) Claimed by @⁠m0rff. Open a draft pull request with `Refs #356` in its description within 24 hours, or the claim expires.
github-bot referenced this issue from a commit 2026-11-27 16:23:10 +00:00
Author
Owner

@⁠alicans on GitHub · 2026-11-27 16:27 UTC · original

The world-load run m0rff asked for on #362, on 24 GB (M4 Pro), Series S, budget off, VICTORY_TRACE_TEXTURE_SYNC=1. The code was main 4cf84c83 merged with #362 at 69d0038a, so the same as main 1ba9f696 apart from docs context; it does not have 582670f1. My script stopped it at 81 s when free memory fell to 9 %, like the third run on #301 (that one at 127 s).

The last trace line before the stop, with the third run in brackets:

  • copies: 7507 MiB over 1566 MiB of distinct title memory (8544 over 1670)
  • textures sharing an identical copy: 0 on every line of the run
  • covered placed copies given up: 4451 in all, 236 MiB; covered still in use: 5750 on the last line
  • made again: 349 in all; 153 MiB of copies outside the title's pools

Most of the growth came at the end: over the last 8 lines (about one a second) the copies went from 3128 to 7507 MiB while distinct memory went from 1186 to 1566 MiB. No GPU errors; it was still at about 26 fps when stopped.

Is there a trace you'd like on for the next run, for example one that names the formats or views of the new copies?

**@⁠alicans** on GitHub · 2026-11-27 16:27 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/356#issuecomment-7223292595) The world-load run m0rff asked for on #362, on 24 GB (M4 Pro), Series S, budget off, `VICTORY_TRACE_TEXTURE_SYNC=1`. The code was main `4cf84c83` merged with #362 at `69d0038a`, so the same as main `1ba9f696` apart from docs context; it does not have `582670f1`. My script stopped it at 81 s when free memory fell to 9 %, like the third run on #301 (that one at 127 s). The last trace line before the stop, with the third run in brackets: - copies: 7507 MiB over 1566 MiB of distinct title memory (8544 over 1670) - textures sharing an identical copy: 0 on every line of the run - covered placed copies given up: 4451 in all, 236 MiB; covered still in use: 5750 on the last line - made again: 349 in all; 153 MiB of copies outside the title's pools Most of the growth came at the end: over the last 8 lines (about one a second) the copies went from 3128 to 7507 MiB while distinct memory went from 1186 to 1566 MiB. No GPU errors; it was still at about 26 fps when stopped. Is there a trace you'd like on for the next run, for example one that names the formats or views of the new copies?
Author
Owner

@⁠m0rff on GitHub · 2026-11-27 22:51 UTC · original

@⁠alicans thank you for the run.

Your run shows that #362's sharing did not reduce the growth. No texture shared an identical copy on any line, so none of the 7507 MiB came from copies that sharing would have removed. The covered give-up freed 236 MiB, while 5750 covered copies were still in use at the end.

Here is what the code says about why sharing found nothing. It applies only when two copies are alive at the same title address with the same description: two resource objects over one address, or a placed view over an object's memory. Two placed copies at one address can never share. texture_placed releases the copy of another description at that address before the new one is made, and the same description at the same address is already the same key. Your trace does not split placed copies from objects, so I can't tell from it whether that is what your copies were.

For the next run, could you do a world load of the #358 head (10892d1b, on main b998bb65) with both of these on, set up as before (Series S, budget off, the same stop script):

VICTORY_TRACE_TEXTURE_OVERLAP=1 VICTORY_TRACE_TEXTURE_SYNC=1
  • VICTORY_TRACE_TEXTURE_SYNC=1 gives the same host texture copies: .. line as your run (copies, distinct memory, sharing, covered given up and still in use, made again), so the two runs can be compared line by line.
  • VICTORY_TRACE_TEXTURE_OVERLAP=1 adds host texture copies overlap: .. once a second. It answers two things:
    • Which kind of overlap the extra memory is (about 5.9 GB in your run). Identical layouts at one start means the same pool offset and layout in another host format, or the same pages reached through two title addresses. Sharing goes by title address and the same format, so it misses both, but one texture with views could serve them. Different layouts means another start or layout over the same bytes, which no sharing of one texture can serve.
    • Whether copies over one range take it from each other. Each upload into another copy's range is counted by what that copy was: a live identical layout, a live different one (where one texture per range would cost an upload each time, or black), or a copy that is gone (memory being reused).

I'm leaving a trace that names formats and views for later. This one says first which kind of copy the memory goes to. I'm keeping this issue open.

**@⁠m0rff** on GitHub · 2026-11-27 22:51 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/356#issuecomment-7229677569) @⁠alicans thank you for the run. Your run shows that #362's sharing did not reduce the growth. No texture shared an identical copy on any line, so none of the 7507 MiB came from copies that sharing would have removed. The covered give-up freed 236 MiB, while 5750 covered copies were still in use at the end. Here is what the code says about why sharing found nothing. It applies only when two copies are alive at the same title address with the same description: two resource objects over one address, or a placed view over an object's memory. Two placed copies at one address can never share. `texture_placed` releases the copy of another description at that address before the new one is made, and the same description at the same address is already the same key. Your trace does not split placed copies from objects, so I can't tell from it whether that is what your copies were. For the next run, could you do a world load of the #358 head (`10892d1b`, on main `b998bb65`) with both of these on, set up as before (Series S, budget off, the same stop script): ``` VICTORY_TRACE_TEXTURE_OVERLAP=1 VICTORY_TRACE_TEXTURE_SYNC=1 ``` - **`VICTORY_TRACE_TEXTURE_SYNC=1`** gives the same `host texture copies: ..` line as your run (copies, distinct memory, sharing, covered given up and still in use, made again), so the two runs can be compared line by line. - **`VICTORY_TRACE_TEXTURE_OVERLAP=1`** adds `host texture copies overlap: ..` once a second. It answers two things: - **Which kind of overlap the extra memory is** (about 5.9 GB in your run). *Identical layouts at one start* means the same pool offset and layout in another host format, or the same pages reached through two title addresses. Sharing goes by title address and the same format, so it misses both, but one texture with views could serve them. *Different layouts* means another start or layout over the same bytes, which no sharing of one texture can serve. - **Whether copies over one range take it from each other.** Each upload into another copy's range is counted by what that copy was: a live identical layout, a live different one (where one texture per range would cost an upload each time, or black), or a copy that is gone (memory being reused). I'm leaving a trace that names formats and views for later. This one says first which kind of copy the memory goes to. I'm keeping this issue open.
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-28 00:36 UTC · original

Thank you for this. It is fixed on main by 55219dfa. I have not checked every case from this report in the game myself, so please retest on main a6a58361 and reopen this if you still see it. Closing as fixed.

**@⁠LakshanSivakumar** on GitHub · 2026-11-28 00:36 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/356#issuecomment-7231045753) Thank you for this. It is fixed on main by 55219dfa. I have not checked every case from this report in the game myself, so please retest on main a6a58361 and reopen this if you still see it. Closing as fixed.
Author
Owner

@⁠m0rff on GitHub · 2026-11-28 10:06 UTC · original

A note in case it was missed: #362 (55219dfa) did not fix the growth in alicans' 24 GB run. No texture shared an identical copy, and copies still reached 7507 MiB over 1566 MiB of distinct title memory before the run was stopped on free memory. I have no newer run, so main may behave differently now. The overlap trace in #358 is meant to show where the copies come from. Reopen or leave closed as you prefer.

**@⁠m0rff** on GitHub · 2026-11-28 10:06 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/356#issuecomment-7237680097) A note in case it was missed: #362 (55219dfa) did not fix the growth in alicans' 24 GB run. No texture shared an identical copy, and copies still reached 7507 MiB over 1566 MiB of distinct title memory before the run was stopped on free memory. I have no newer run, so main may behave differently now. The overlap trace in #358 is meant to show where the copies come from. Reopen or leave closed as you prefer.
This discussion has been locked. Commenting is limited to contributors.
No description provided.