native: texture copy-back fixes and cost counters #449

Closed
lautarocherro wants to merge 2 commits from upstream-pr/449 into main
lautarocherro commented 2026-11-27 19:55:53 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by lautarocherro on 2026-11-27T19:55:53Z.


What this changes

Refs #46. Built on #447 (its commit is the first here); review the last commit. First proposed as copy-back on by default; rescoped after a world run (below) showed the cost.

  • Copy-back stays behind VICTORY_TEXTURE_BACK=1.
  • A read Metal refuses (read_texture skips it with no error) no longer writes zeros into title memory: download checks the read happened (read_checked) and logs the texture as not copied back.
  • A released queue's copy-back fence is dropped.
  • The frame log's textures copied back so far line gives copies, checks, KiB and microseconds.

World run (M5 Pro, Series X, headless 480 s, switch on): 220 textures copied 9,320 times, 5.1 GiB, 44.9 s under the title lock (about 170 ms a world frame). 183 are over 8 KiB, mostly screen-sized intermediates. No copy wrote over another known texture or buffer. Turning it on needs a way to copy only what the title reads; docs/native-host.md and ROADMAP say so.

How it was tested

  • cargo test --target x86_64-apple-darwin -p victory-hle -p victory-loader -p victory: 391 passed.
  • cargo test -p victory-gpu (native arm64): 415 passed, with the switch unset and with =1. New: read_checked, copy-back off keeps title memory, counters in the copy-back test.
  • cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings: passes.
  • Ran the game: the world run above (with temporary overlap logging, not in this PR).

Checklist

  • No game files, game code, disassembly listings or SDK files are included
  • Guesses about undocumented console behaviour are marked in the code and in docs/native-host.md
  • New diagnostics are behind a VICTORY_* variable and documented (the cost line prints only with VICTORY_TEXTURE_BACK=1)
<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:5532352237 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/449). Originally posted by [lautarocherro](https://github.com/lautarocherro) on 2026-11-27T19:55:53Z. --- ## What this changes Refs #46. Built on #447 (its commit is the first here); review the last commit. First proposed as copy-back on by default; rescoped after a world run (below) showed the cost. - Copy-back stays behind `VICTORY_TEXTURE_BACK=1`. - A read Metal refuses (`read_texture` skips it with no error) no longer writes zeros into title memory: `download` checks the read happened (`read_checked`) and logs the texture as not copied back. - A released queue's copy-back fence is dropped. - The frame log's `textures copied back so far` line gives copies, checks, KiB and microseconds. World run (M5 Pro, Series X, headless 480 s, switch on): 220 textures copied 9,320 times, 5.1 GiB, 44.9 s under the title lock (about 170 ms a world frame). 183 are over 8 KiB, mostly screen-sized intermediates. No copy wrote over another known texture or buffer. Turning it on needs a way to copy only what the title reads; docs/native-host.md and ROADMAP say so. ## How it was tested - [x] `cargo test --target x86_64-apple-darwin -p victory-hle -p victory-loader -p victory`: 391 passed. - [x] `cargo test -p victory-gpu` (native arm64): 415 passed, with the switch unset and with `=1`. New: `read_checked`, copy-back off keeps title memory, counters in the copy-back test. - [x] `cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings`: passes. - [x] Ran the game: the world run above (with temporary overlap logging, not in this PR). ## Checklist - [x] No game files, game code, disassembly listings or SDK files are included - [x] Guesses about undocumented console behaviour are marked in the code and in docs/native-host.md - [x] New diagnostics are behind a `VICTORY_*` variable and documented (the cost line prints only with `VICTORY_TEXTURE_BACK=1`)
derz92 commented 2026-11-27 21:06:16 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by derz92 on 2026-11-27T21:06:16Z.


Evidence for copy-back, from #437's tree (b998bb65 + #437) on an M5 Max, 36 GB, macOS 26.5, Series S, mode 1. Main's opt-in VICTORY_TEXTURE_BACK=1 behaves the same as this PR's default.

  • Without copy-back: on a warm cache the prologue cutscene stops presenting at frame about 1490 to 1570, two runs out of two. That's at 260% CPU with nothing queued on the GPU, the title's main thread in WaitForSingleObject and two title threads busy. (The cold run got past it, probably just by being slower.)
  • With copy-back: the cutscene plays through, still presenting at frame 1920 by the 360 s cap. 274 textures were copied back. But the output fills with blocky pink and green speckle and coloured radial streaks, which aren't there in the same shot without copy-back.
  • Copy-back limited to textures of 8 KiB or less (a local experiment: info.size > min(env, BACK_LIMIT) in write_back): 51 copied, 214 skipped as larger. The cutscene still plays through to the title's "move around / move the camera" prompt (frame about 1980), and the image is clean, with no speckle or streaks. The small ones copied were things like 1x1 format 3 (256 B), 54x30, 27x15 and 20x12 format 42, and 10x6 format 2.

So on this title, the stall needs only small GPU results back, and writing back the large textures is what corrupts the image. Maybe a tiled layout that doesn't match, or the title reusing that memory. Copying everything by default would trade the stall for the noise. A size or kind limit, or finding which large textures go wrong, could keep both. I haven't yet narrowed down which large texture causes the noise; I can bisect by size if that helps.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7228136584 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/449#issuecomment-7228136584). Originally posted by [derz92](https://github.com/derz92) on 2026-11-27T21:06:16Z. --- Evidence for copy-back, from #437's tree (b998bb65 + #437) on an M5 Max, 36 GB, macOS 26.5, Series S, mode 1. Main's opt-in `VICTORY_TEXTURE_BACK=1` behaves the same as this PR's default. - **Without copy-back:** on a warm cache the prologue cutscene stops presenting at frame about 1490 to 1570, two runs out of two. That's at 260% CPU with nothing queued on the GPU, the title's main thread in `WaitForSingleObject` and two title threads busy. (The cold run got past it, probably just by being slower.) - **With copy-back:** the cutscene plays through, still presenting at frame 1920 by the 360 s cap. 274 textures were copied back. **But the output fills with blocky pink and green speckle and coloured radial streaks**, which aren't there in the same shot without copy-back. - **Copy-back limited to textures of 8 KiB or less** (a local experiment: `info.size > min(env, BACK_LIMIT)` in `write_back`): 51 copied, 214 skipped as larger. The cutscene still plays through to the title's "move around / move the camera" prompt (frame about 1980), and **the image is clean, with no speckle or streaks**. The small ones copied were things like 1x1 format 3 (256 B), 54x30, 27x15 and 20x12 format 42, and 10x6 format 2. So on this title, the stall needs only small GPU results back, and writing back the large textures is what corrupts the image. Maybe a tiled layout that doesn't match, or the title reusing that memory. Copying everything by default would trade the stall for the noise. A size or kind limit, or finding which large textures go wrong, could keep both. I haven't yet narrowed down which large texture causes the noise; I can bisect by size if that helps.
derz92 commented 2026-11-27 22:16:50 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by derz92 on 2026-11-27T22:16:50Z.


A correction to my comment above. The stall I credited copy-back with fixing doesn't depend on it. In a controlled run on one binary, alternating copy-back on and off (3 each, details on #456), none of the six runs froze. So "the stall needs small GPU results back" doesn't hold up. What still stands: the one run with full copy-back showed blocky pink and green noise that the same scene without it doesn't have. That's one run, though, so treat it as a lead, not a result.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7229188724 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/449#issuecomment-7229188724). Originally posted by [derz92](https://github.com/derz92) on 2026-11-27T22:16:50Z. --- A correction to my comment above. The stall I credited copy-back with fixing doesn't depend on it. In a controlled run on one binary, alternating copy-back on and off (3 each, details on #456), none of the six runs froze. So "the stall needs small GPU results back" doesn't hold up. What still stands: the one run with full copy-back showed blocky pink and green noise that the same scene without it doesn't have. That's one run, though, so treat it as a lead, not a result.
Olima34 commented 2026-11-28 00:42:42 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Olima34 on 2026-11-28T00:42:42Z.

Review: CHANGES_REQUESTED


Thanks @lautarocherro. We read the whole diff (3031622d) while helping the maintainer clear the queue, and it holds up: keeping copy-back opt-in, read_checked so a refused read no longer writes zeros into title memory, dropping a released queue's fence, and the cost counters, with tests for each. The world-run numbers in docs and ROADMAP are useful too.

The only blocker: the maintainer just landed another batch on main (226645f9), and this branch now conflicts with it in docs/native-host.md. Could you merge current main into the branch (a merge commit is fine) and keep both sides of that paragraph? Once GitHub shows it as mergeable and CI is green on the new head, we'll merge it.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:review:6094714128 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/449#pullrequestreview-6094714128). Originally posted by [Olima34](https://github.com/Olima34) on 2026-11-28T00:42:42Z. **Review:** CHANGES_REQUESTED --- Thanks @lautarocherro. We read the whole diff (3031622d) while helping the maintainer clear the queue, and it holds up: keeping copy-back opt-in, `read_checked` so a refused read no longer writes zeros into title memory, dropping a released queue's fence, and the cost counters, with tests for each. The world-run numbers in docs and ROADMAP are useful too. The only blocker: the maintainer just landed another batch on main (226645f9), and this branch now conflicts with it in `docs/native-host.md`. Could you merge current `main` into the branch (a merge commit is fine) and keep both sides of that paragraph? Once GitHub shows it as mergeable and CI is green on the new head, we'll merge it.
Olima34 commented 2026-11-28 00:46:58 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Olima34 on 2026-11-28T00:46:58Z.


The maintainer is handling this one himself; please follow his lead rather than my review.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7231187330 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/449#issuecomment-7231187330). Originally posted by [Olima34](https://github.com/Olima34) on 2026-11-28T00:46:58Z. --- The maintainer is handling this one himself; please follow his lead rather than my review.
lautarocherro commented 2026-11-28 06:25:17 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by lautarocherro on 2026-11-28T06:25:17Z.


Merged current main (bf9cdf17) into the branch in cd1848c5. The conflict in docs/native-host.md keeps both sides: this PR's copy-back bullets and main's "Not into a pool the view left (#339)" bullet. CI passes on the new head, and GitHub shows the PR as mergeable.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7235283404 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/449#issuecomment-7235283404). Originally posted by [lautarocherro](https://github.com/lautarocherro) on 2026-11-28T06:25:17Z. --- Merged current main (`bf9cdf17`) into the branch in `cd1848c5`. The conflict in `docs/native-host.md` keeps both sides: this PR's copy-back bullets and main's "Not into a pool the view left (#339)" bullet. CI passes on the new head, and GitHub shows the PR as mergeable.

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