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

Closed
github-bot wants to merge 2 commits from github-bot/gh-449 into main AGit
Owner

@⁠lautarocherro on GitHub · 2026-11-27 19:55 UTC · original
lautarocherro:feat/texture-back-default → main · +130 −9 · 6 files · 2 commits · closed without merging

What this changes

Refs #46. Built on #451 (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)
**@⁠lautarocherro** on GitHub · 2026-11-27 19:55 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/449) `lautarocherro:feat/texture-back-default` → `main` · +130 −9 · 6 files · 2 commits · closed without merging ## What this changes Refs #46. Built on #451 (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`)
note_written read every record of a dispatch's bound resource tables
with plain loads, and since 95627c66 it runs for every dispatch. Part of
a table's span can be unreadable, which remirror_tables already handles
with safe_read. Both now read records through table_records (one
safe_read, entry by entry if that fails), and note_written looks the
views up with one lock per table (descriptor::views_of).
Copy-back runs unless VICTORY_TEXTURE_BACK=0. A read Metal refuses
(read_texture skips a transfer that does not fit, with no error) no
longer goes into title memory as zeros: download fills its buffer with
a marker byte first and treats an unchanged buffer as refused
(read_checked). A released queue's copy-back fence is dropped. Stats
counts copies, checks, bytes and time, logged as "textures copied back
so far".
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 19:57:13 +00:00
Author
Owner

@⁠derz92 on GitHub · 2026-11-27 21:06 UTC · original

Evidence for copy-back, from #441's tree (b998bb65 + #441) 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** on GitHub · 2026-11-27 21:06 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/449#issuecomment-7228136584) Evidence for copy-back, from #441's tree (b998bb65 + #441) 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.
Author
Owner

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

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 #460), 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.

**@⁠derz92** on GitHub · 2026-11-27 22:16 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/449#issuecomment-7229188724) 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 #460), 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.
github-bot changed title from native: copy GPU-written textures back by default to native: texture copy-back fixes and cost counters 2026-11-27 22:46:24 +00:00
github-bot force-pushed github-bot/gh-449 from d09f16dd23 to 3031622dfd 2026-11-27 22:46:28 +00:00 Compare
Author
Owner

@⁠Olima34 on GitHub · 2026-11-28 00:42 UTC · original · requested changes

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** on GitHub · 2026-11-28 00:42 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/449#pullrequestreview-6094714128) · **requested changes** 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.
Author
Owner

@⁠Olima34 on GitHub · 2026-11-28 00:46 UTC · original

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

**@⁠Olima34** on GitHub · 2026-11-28 00:46 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/449#issuecomment-7231187330) The maintainer is handling this one himself; please follow his lead rather than my review.
Author
Owner

@⁠lautarocherro on GitHub · 2026-11-28 06:25 UTC · original

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 (#340)" bullet. CI passes on the new head, and GitHub shows the PR as mergeable.

**@⁠lautarocherro** on GitHub · 2026-11-28 06:25 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/449#issuecomment-7235283404) 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 (#340)" bullet. CI passes on the new head, and GitHub shows the PR as mergeable.
github-bot closed this pull request 2026-11-29 02:28:03 +00:00

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.