gpu(native): back off unchanged whole texture checks and skip doomed partial reads #232

Manually merged
github merged 2 commits from github-bot/gh-232 into main 2026-11-27 02:45:02 +00:00 AGit
Owner

@⁠Sheffy007 on GitHub · 2026-11-27 02:11 UTC · original
Sheffy007:perf/native-texture-sync-whole-checks → main · +222 −32 · 3 files · 2 commits · merged 2026-11-27 02:33 UTC

Addresses the two open texture-sync bottlenecks noted on #179 (tracked under #15):

  1. Unchanged whole checks filling WHOLE_BUDGET (~410 MiB/s):
    On GFX10 tiled mipmapped textures (victory_formats::texture::Layout::tiled), the 64 KiB mip tail sits at the start of the allocation (with unused padding at byte 0 when fewer than all 12 tail slots are occupied) while the finest mips occupy the upper ~75% and remain VM_PROT_NONE while coarse mips stream in. When coarse mips are written, the 8 sampled probe windows miss the write, setting sampled_sees_writes = false. Previously, sampled_sees_writes stayed false across all 600 hot probes even when subsequent whole reads found nothing changed, queueing every-probe whole reads outside WHOLE_SPARE up to WHOLE_BUDGET (8 MiB/submission).

    • Keep the immediate next-probe whole check after a missed-sample write so back-to-back glyph bursts are still caught at the next submission.
    • Once a follow-up whole read finds no change (t.last == Some(r.hash)), return sampled_sees_writes to true (bounded by WHOLE_SPARE) and double the periodic check interval across consecutive unchanged whole checks (unchanged_whole, up to WHOLE_EVERY << 5 = 256 probes) while the background scanner continues watching every texture.
  2. Partially-mapped texture reads (Tracked::partial, Watch::partial):

    • Read a job's texture range in one read_into call rather than blind 1 MiB slices.
    • Remember when a texture's whole read met an unmapped or protected range (partial) in both Tracked and Watch, skipping the initial full-range mach_vm_read_overwrite that copies the mapped prefix in the kernel only to fail at the unmapped fine mips, and zeroing only the unmapped/non-readable gaps instead of upfront zeroing the entire buffer before overwriting readable spans.
    • Clear partial automatically once read_texture_chunk observes every byte covered by readable regions again.

Tests & Verification

  • Added native::tests::texture_tests::a_missed_write_not_followed_by_another_backs_off_whole_reads (verifies 64 idle submissions after a missed-sample write perform <= 4 whole reads instead of 64, while preserving existing immediate next-submission burst tests).
  • Added native::textures::tests::a_known_partial_chunk_skips_the_whole_read_until_every_page_is_readable.
  • cargo test -p victory-gpu -p victory-metal -p victory-hle -p victory -p victory-shader -p xtask (784 passed, 0 failed, 4 ignored)
  • cargo clippy --workspace --all-targets --target x86_64-pc-windows-gnullvm -- -D warnings
  • cargo xtask policy
  • cargo build --release --target x86_64-apple-darwin -p victory
**@⁠Sheffy007** on GitHub · 2026-11-27 02:11 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/232) `Sheffy007:perf/native-texture-sync-whole-checks` → `main` · +222 −32 · 3 files · 2 commits · merged 2026-11-27 02:33 UTC Addresses the two open texture-sync bottlenecks noted on #179 (tracked under #15): 1. **Unchanged whole checks filling `WHOLE_BUDGET` (~410 MiB/s):** On GFX10 tiled mipmapped textures (`victory_formats::texture::Layout::tiled`), the 64 KiB mip tail sits at the start of the allocation (with unused padding at byte 0 when fewer than all 12 tail slots are occupied) while the finest mips occupy the upper ~75% and remain `VM_PROT_NONE` while coarse mips stream in. When coarse mips are written, the 8 sampled probe windows miss the write, setting `sampled_sees_writes = false`. Previously, `sampled_sees_writes` stayed `false` across all 600 hot probes even when subsequent whole reads found nothing changed, queueing every-probe whole reads outside `WHOLE_SPARE` up to `WHOLE_BUDGET` (8 MiB/submission). - Keep the immediate next-probe whole check after a missed-sample write so back-to-back glyph bursts are still caught at the next submission. - Once a follow-up whole read finds no change (`t.last == Some(r.hash)`), return `sampled_sees_writes` to `true` (bounded by `WHOLE_SPARE`) and double the periodic check interval across consecutive unchanged whole checks (`unchanged_whole`, up to `WHOLE_EVERY << 5` = 256 probes) while the background scanner continues watching every texture. 2. **Partially-mapped texture reads (`Tracked::partial`, `Watch::partial`):** - Read a job's texture range in one `read_into` call rather than blind 1 MiB slices. - Remember when a texture's whole read met an unmapped or protected range (`partial`) in both `Tracked` and `Watch`, skipping the initial full-range `mach_vm_read_overwrite` that copies the mapped prefix in the kernel only to fail at the unmapped fine mips, and zeroing only the unmapped/non-readable gaps instead of upfront zeroing the entire buffer before overwriting readable spans. - Clear `partial` automatically once `read_texture_chunk` observes every byte covered by readable regions again. ### Tests & Verification - Added `native::tests::texture_tests::a_missed_write_not_followed_by_another_backs_off_whole_reads` (verifies 64 idle submissions after a missed-sample write perform <= 4 whole reads instead of 64, while preserving existing immediate next-submission burst tests). - Added `native::textures::tests::a_known_partial_chunk_skips_the_whole_read_until_every_page_is_readable`. - `cargo test -p victory-gpu -p victory-metal -p victory-hle -p victory -p victory-shader -p xtask` (784 passed, 0 failed, 4 ignored) - `cargo clippy --workspace --all-targets --target x86_64-pc-windows-gnullvm -- -D warnings` - `cargo xtask policy` - `cargo build --release --target x86_64-apple-darwin -p victory`
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 02:14:47 +00:00
github manually merged commit 50bee23fdf into main 2026-11-27 02:45:02 +00:00
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-27 02:33 UTC · original · approved these changes

Reviewed and tested together with the other open PRs on main (macOS x86_64 workspace tests, the setup shell tests, and Windows clippy). Thanks!

**@⁠LakshanSivakumar** on GitHub · 2026-11-27 02:33 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/232#pullrequestreview-6082737453) · **approved these changes** Reviewed and tested together with the other open PRs on main (macOS x86_64 workspace tests, the setup shell tests, and Windows clippy). Thanks!
This discussion has been locked. Commenting is limited to contributors.
No description provided.