gpu(native): detile big textures on the rayon pool #604

Open
AnastasisKon wants to merge 1 commit from upstream-pr/604 into main
AnastasisKon commented 2026-11-28 11:57:02 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by AnastasisKon on 2026-11-28T11:57:02Z.


Refs #179

What

A changed texture was detiled mip by mip, slice by slice on a single submission thread. A 4K RGBA texture (32 MiB mip 0) spent its whole detile serialized on one core while the other 11 idled — the dominant CPU cost of uploading a big streamed texture, and exactly what stands between the native host and Series X-class frame times on M1.

Each (mip, slice) level reads the tiled bytes and writes only its own staging buffer, so levels are independent: detile_changed now collects the work items and runs them on the rayon pool when the texture is at least 1 MiB. Smaller textures stay serial (no pool scheduling overhead). The all-zero fine-mip skip now checks its slices with into_par_iter().all(..) on big textures, and is_all_zero checks ranges >= 1 MiB with par_iter as well.

Results are sorted back into (mip, slice) order, so upload order and the detiled_mips bitmask are exactly what the serial loop produced. Error behavior: the first error is reported, as before.

Adds rayon as a workspace dependency of victory-gpu (already in the lock via blake3's rayon feature; the rayon crate itself is new to the lock).

Correctness

A unit test detile a 1024x1024 array-of-4 RGBA texture (22 MiB, takes the parallel path) with uploaded_mips = u32::MAX and compares every level — mip, slice, row, slice_pitch, and every texel byte — against the serial per-level detile_level, plus the bitmask.

Testing

  • cargo test -p victory-hle -p victory -p victory-gpu -p xtask (host arm64) — all pass, incl. detile_changed_parallel_path_matches_serial_level_by_level
  • cargo test --target x86_64-apple-darwin -p victory-gpu --lib textures:: — 19 pass, 0 fail
  • cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings — clean
  • cargo xtask policy — 404 files ok

Checklist

  • One change, one PR
  • Branch vibe/detile-rayon-1705ac from upstream/main, pushed to my fork only
  • No game/GDK files, no dumps/logs in the repo
  • No AI attribution in the diff
<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:5539874982 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/604). Originally posted by [AnastasisKon](https://github.com/AnastasisKon) on 2026-11-28T11:57:02Z. --- Refs #179 ## What A changed texture was detiled mip by mip, slice by slice on a single submission thread. A 4K RGBA texture (32 MiB mip 0) spent its whole detile serialized on one core while the other 11 idled — the dominant CPU cost of uploading a big streamed texture, and exactly what stands between the native host and Series X-class frame times on M1. Each (mip, slice) level reads the tiled bytes and writes only its own staging buffer, so levels are independent: `detile_changed` now collects the work items and runs them on the rayon pool when the texture is at least 1 MiB. Smaller textures stay serial (no pool scheduling overhead). The all-zero fine-mip skip now checks its slices with `into_par_iter().all(..)` on big textures, and `is_all_zero` checks ranges >= 1 MiB with `par_iter` as well. Results are sorted back into (mip, slice) order, so upload order and the `detiled_mips` bitmask are exactly what the serial loop produced. Error behavior: the first error is reported, as before. Adds `rayon` as a workspace dependency of `victory-gpu` (already in the lock via blake3's rayon feature; the `rayon` crate itself is new to the lock). ## Correctness A unit test detile a 1024x1024 array-of-4 RGBA texture (22 MiB, takes the parallel path) with `uploaded_mips = u32::MAX` and compares every level — mip, slice, row, slice_pitch, and every texel byte — against the serial per-level `detile_level`, plus the bitmask. ## Testing - [x] `cargo test -p victory-hle -p victory -p victory-gpu -p xtask` (host arm64) — all pass, incl. `detile_changed_parallel_path_matches_serial_level_by_level` - [x] `cargo test --target x86_64-apple-darwin -p victory-gpu --lib textures::` — 19 pass, 0 fail - [x] `cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings` — clean - [x] `cargo xtask policy` — 404 files ok ## Checklist - [x] One change, one PR - [x] Branch `vibe/detile-rayon-1705ac` from `upstream/main`, pushed to my fork only - [x] No game/GDK files, no dumps/logs in the repo - [x] No AI attribution in the diff
AnastasisKon commented 2026-11-28 12:05:08 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by AnastasisKon on 2026-11-28T12:05:08Z.


CI green (check + macos-scripts SUCCESS), marked ready for review.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7238982885 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/604#issuecomment-7238982885). Originally posted by [AnastasisKon](https://github.com/AnastasisKon) on 2026-11-28T12:05:08Z. --- CI green (check + macos-scripts SUCCESS), marked ready for review.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/604:upstream-pr/604'
git switch 'upstream-pr/604'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/604'
git switch 'upstream-pr/604'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/604'
git switch 'upstream-pr/604'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/604'
git switch 'main'
git merge --squash 'upstream-pr/604'
git switch 'main'
git merge --ff-only 'upstream-pr/604'
git switch 'main'
git merge 'upstream-pr/604'
git push origin 'main'
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!604
No description provided.