gpu(native): bound per-submission hot-texture probing in sync_dirty #28

Merged
claytonblythe merged 1 commit from upstream-pr/28 into main 2026-11-26 10:34:04 +00:00
claytonblythe commented 2026-11-26 10:06:06 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by claytonblythe on 2026-11-26T10:06:06Z.


Summary

During Story Mode world streaming, thousands of newly realized blank textures enter the hot set simultaneously (t.hot = HOT = 600). Previously, Title::sync_dirty() iterated the entire self.textures map on every ExecuteCommandLists and allocated a fresh Vec<u8> (32 KiB–4 MiB) + performed 8 read_guest calls for every hot texture on every submission, collapsing frame rate during streaming.

This change makes sync_dirty() bounded and allocation-free per submission:

  • Tracks unloaded: HashSet<usize> and hot_keys: Vec<usize> on Title<B> so sync_dirty() no longer scans the entire self.textures map.
  • Replaces per-texture probe: Vec<u8> snapshots with a 32-byte Option<blake3::Hash> (probe_hash), cutting memory overhead and eliminating per-submission heap allocations via a reusable probe_buf.
  • Reduces sampled stripe size from 4096 B to 256 B (still 8 evenly spaced stripes across the texture).
  • Bounds synchronous probing in sync_dirty() to MAX_SYNC_HOT = 32 textures per submission in round-robin order (hot_cursor). Small active sets (boot movie, glyph cache) are still probed every submission, while large bursts of streamed textures no longer stall the GPU thread.
  • Adds unit test native::textures::tests::probe_hash_detects_writes_in_sampled_and_whole_modes.

Verification

  • cargo test -p victory-gpu --target x86_64-apple-darwin --lib native::textures::tests — 1/1 passed.
  • cargo test -p victory-gpu --target x86_64-apple-darwin --lib native::tests::texture_tests — 7/7 passed on Metal.
  • cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings — 0 warnings.
  • cargo xtask policy — 363 files ok.
  • Live 240 s Story Mode run on a 16 GB Apple M4 (--console series-s, --headless, VICTORY_GUESS_GRAPHICS=1, VICTORY_DIAG=1):
    • Frame 1024 → 2048: 28.0 FPS (36.57 s) vs 16.2 FPS (63.30 s) before (1.73x faster).
    • Frames 1472 → 2432 during active Story Mode streaming: locked 30.0 FPS (2.13 s per 64 frames) vs 9.1–14.6 FPS (4.38–7.03 s per 64 frames) before.
<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:6624242411 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/28). Originally posted by [claytonblythe](https://github.com/claytonblythe) on 2026-11-26T10:06:06Z. --- ## Summary During Story Mode world streaming, thousands of newly realized blank textures enter the `hot` set simultaneously (`t.hot = HOT = 600`). Previously, `Title::sync_dirty()` iterated the entire `self.textures` map on every `ExecuteCommandLists` and allocated a fresh `Vec<u8>` (32 KiB–4 MiB) + performed 8 `read_guest` calls for every hot texture on every submission, collapsing frame rate during streaming. This change makes `sync_dirty()` bounded and allocation-free per submission: - Tracks `unloaded: HashSet<usize>` and `hot_keys: Vec<usize>` on `Title<B>` so `sync_dirty()` no longer scans the entire `self.textures` map. - Replaces per-texture `probe: Vec<u8>` snapshots with a 32-byte `Option<blake3::Hash>` (`probe_hash`), cutting memory overhead and eliminating per-submission heap allocations via a reusable `probe_buf`. - Reduces sampled stripe size from 4096 B to 256 B (still 8 evenly spaced stripes across the texture). - Bounds synchronous probing in `sync_dirty()` to `MAX_SYNC_HOT = 32` textures per submission in round-robin order (`hot_cursor`). Small active sets (boot movie, glyph cache) are still probed every submission, while large bursts of streamed textures no longer stall the GPU thread. - Adds unit test `native::textures::tests::probe_hash_detects_writes_in_sampled_and_whole_modes`. ## Verification - `cargo test -p victory-gpu --target x86_64-apple-darwin --lib native::textures::tests` — 1/1 passed. - `cargo test -p victory-gpu --target x86_64-apple-darwin --lib native::tests::texture_tests` — 7/7 passed on Metal. - `cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings` — 0 warnings. - `cargo xtask policy` — 363 files ok. - Live 240 s Story Mode run on a 16 GB Apple M4 (`--console series-s`, `--headless`, `VICTORY_GUESS_GRAPHICS=1`, `VICTORY_DIAG=1`): - Frame 1024 → 2048: **28.0 FPS** (`36.57 s`) vs **16.2 FPS** (`63.30 s`) before (**1.73x faster**). - Frames 1472 → 2432 during active Story Mode streaming: locked **30.0 FPS** (`2.13 s` per 64 frames) vs **9.1–14.6 FPS** (`4.38–7.03 s` per 64 frames) before.
LakshanSivakumar commented 2026-11-26 10:09:55 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T10:09:55Z.

Review: CHANGES_REQUESTED


Nice find, and the streaming numbers look great. CI fails on Windows, though: probe_hash_detects_writes_in_sampled_and_whole_modes asserts that hashes differ, but native::safe_read is a no-op returning false off macOS, so every probe hashes zeros there. Please gate the test with #[cfg(target_os = "macos")] (as native::tests is) and push again.

Two follow-ups while you're in there:

  1. With MAX_SYNC_HOT = 32 in round-robin order, a title write to a hot texture can now take up to ceil(hot/32) submissions to be noticed. Could you add a one-line shortcut: comment stating that limit, and when to raise it?
  2. You mention a 240 s Story Mode run reaching active world streaming. On our side, story load stalls on the loading art (#15). What exactly did your run show: the world drawing, or still the loading screen while it streams? Which commit and env vars did you use? That would help a lot with #15.
<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:review:6072144719 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/28#pullrequestreview-6072144719). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-26T10:09:55Z. **Review:** CHANGES_REQUESTED --- Nice find, and the streaming numbers look great. CI fails on Windows, though: `probe_hash_detects_writes_in_sampled_and_whole_modes` asserts that hashes differ, but `native::safe_read` is a no-op returning `false` off macOS, so every probe hashes zeros there. Please gate the test with `#[cfg(target_os = "macos")]` (as `native::tests` is) and push again. Two follow-ups while you're in there: 1. With `MAX_SYNC_HOT = 32` in round-robin order, a title write to a hot texture can now take up to ceil(hot/32) submissions to be noticed. Could you add a one-line `shortcut:` comment stating that limit, and when to raise it? 2. You mention a 240 s Story Mode run reaching active world streaming. On our side, story load stalls on the loading art (#15). What exactly did your run show: the world drawing, or still the loading screen while it streams? Which commit and env vars did you use? That would help a lot with #15.
LakshanSivakumar commented 2026-11-26 10:29:59 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T10:29:59Z.

Review: DISMISSED


Pushed two small test fixes on top: the probe_hash test now only runs on macOS (safe_read is a no-op elsewhere), and texture_tests' blank-upload test syncs ceil(hot/MAX_SYNC_HOT) times, because other tests in the binary leave textures hot and the round-robin bound otherwise made it fail in the full run. The full suite passes three times in a row with clippy clean. Great speedup, thanks!

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:review:6072458602 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/28#pullrequestreview-6072458602). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-26T10:29:59Z. **Review:** DISMISSED --- Pushed two small test fixes on top: the probe_hash test now only runs on macOS (safe_read is a no-op elsewhere), and texture_tests' blank-upload test syncs ceil(hot/MAX_SYNC_HOT) times, because other tests in the binary leave textures hot and the round-robin bound otherwise made it fail in the full run. The full suite passes three times in a row with clippy clean. Great speedup, thanks!
claytonblythe commented 2026-11-26 10:30:30 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by claytonblythe on 2026-11-26T10:30:30Z.


Thanks for the review! Addressed both code items and rebased onto main (a9399d9):

  • Gated native::textures::tests with #[cfg(all(test, target_os = "macos"))] so Windows CI doesn't run the safe_read test where safe_read is a no-op.
  • Added the shortcut: comment on MAX_SYNC_HOT = 32 noting the ceil(hot / MAX_SYNC_HOT) submission bound and when to raise it.

Re: #15 / the 240 s Story Mode run:

  • That run was --headless on a 16 GB Apple M4 (--console series-s, VICTORY_GUESS_GRAPHICS=1, VICTORY_DIAG=1, VICTORY_KEYS pressing Enter through setup + selecting Story Mode), first on 3d4ca18 + this PR, and then on a2940ab + #25 + #28 + #30.
  • It was still in Story Mode loading (not yet drawing the 3D world — mesh=0 indirect=0), actively streaming story000.rpf, story000_restofworld.rpf, story000_bvh4.rpf, and story000_script.rpf via DirectStorage, activating spatial audio streams around frame 2788, and reaching frame 2880+ (recorded=16593 encoded=16593 no_pipeline=0 no_texture=0) before hitting an access violation (0xc0000005 at image+0x2215c35, info=[1, 0]) at ~240 s.
  • Running a headed run with periodic screenshots next to confirm visually what is on screen during that phase.
<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7189458484 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/28#issuecomment-7189458484). Originally posted by [claytonblythe](https://github.com/claytonblythe) on 2026-11-26T10:30:30Z. --- Thanks for the review! Addressed both code items and rebased onto `main` (`a9399d9`): - Gated `native::textures::tests` with `#[cfg(all(test, target_os = "macos"))]` so Windows CI doesn't run the `safe_read` test where `safe_read` is a no-op. - Added the `shortcut:` comment on `MAX_SYNC_HOT = 32` noting the `ceil(hot / MAX_SYNC_HOT)` submission bound and when to raise it. Re: #15 / the 240 s Story Mode run: - That run was `--headless` on a 16 GB Apple M4 (`--console series-s`, `VICTORY_GUESS_GRAPHICS=1`, `VICTORY_DIAG=1`, `VICTORY_KEYS` pressing Enter through setup + selecting Story Mode), first on `3d4ca18` + this PR, and then on `a2940ab` + #25 + #28 + #30. - It was still in Story Mode loading (not yet drawing the 3D world — `mesh=0 indirect=0`), actively streaming `story000.rpf`, `story000_restofworld.rpf`, `story000_bvh4.rpf`, and `story000_script.rpf` via DirectStorage, activating spatial audio streams around frame 2788, and reaching frame 2880+ (`recorded=16593 encoded=16593 no_pipeline=0 no_texture=0`) before hitting an access violation (`0xc0000005` at `image+0x2215c35`, `info=[1, 0]`) at ~240 s. - Running a headed run with periodic screenshots next to confirm visually what is on screen during that phase.
LakshanSivakumar commented 2026-11-26 10:34:00 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T10:34:00Z.

Review: APPROVED


Re-approving after the rebase: the full victory-gpu suite passes 3x on macOS and CI is green. Thanks for the detailed #15 notes!

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:review:6072520634 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/28#pullrequestreview-6072520634). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-26T10:34:00Z. **Review:** APPROVED --- Re-approving after the rebase: the full victory-gpu suite passes 3x on macOS and CI is green. Thanks for the detailed #15 notes!
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!28
No description provided.