gpu(native): read big texture memory chunk-parallel on the rayon pool #605

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

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


Refs #179

What

The texture sync read each watched texture's memory on a single thread — the scanner's chunk loop, Job::read, and the GPU-written copy-back all copied a 4K texture's 32 MiB serially while the other 11 cores idled. Memory copy is bandwidth-bound, so this was pure lost throughput on every changed big texture.

read_into now splits buffers larger than 1 MiB into par_chunks_mut(1 MiB) and reads the chunks independently on the rayon pool (the PoolTable mutex is only taken to walk the maps; the copies run outside it, so chunks don't serialize on it). The unreadable flag is OR-ed across chunks. Buffers at or below 1 MiB keep the single serial call. All read_into callers get this: Job::read, the copy-back path, read_memory.

In scan_round, a texture over 1 MiB is now read whole in one read_into call (chunk-parallel inside) and hashed with one blake3::hash; smaller textures still stream through the scanner's 1 MiB buffer chunk by chunk with incremental hashing, unchanged.

Adds rayon as a workspace dependency of victory-gpu.

Correctness

Chunk boundaries: a unit test reads buffers of 1 MiB-1, 1 MiB, 1 MiB+1 and 3 MiB+123 (the last two take the parallel path) from a source pattern and asserts byte-for-byte equality and a clear unreadable flag.

Testing

  • cargo test -p victory-hle -p victory -p victory-gpu -p xtask (host arm64) — all pass, incl. read_into_parallel_chunks_match_the_source_byte_for_byte
  • 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/read-par-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:5539894212 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/605). Originally posted by [AnastasisKon](https://github.com/AnastasisKon) on 2026-11-28T11:59:31Z. --- Refs #179 ## What The texture sync read each watched texture's memory on a single thread — the scanner's chunk loop, `Job::read`, and the GPU-written copy-back all copied a 4K texture's 32 MiB serially while the other 11 cores idled. Memory copy is bandwidth-bound, so this was pure lost throughput on every changed big texture. `read_into` now splits buffers larger than 1 MiB into `par_chunks_mut(1 MiB)` and reads the chunks independently on the rayon pool (the `PoolTable` mutex is only taken to walk the maps; the copies run outside it, so chunks don't serialize on it). The unreadable flag is OR-ed across chunks. Buffers at or below 1 MiB keep the single serial call. All `read_into` callers get this: `Job::read`, the copy-back path, `read_memory`. In `scan_round`, a texture over 1 MiB is now read whole in one `read_into` call (chunk-parallel inside) and hashed with one `blake3::hash`; smaller textures still stream through the scanner's 1 MiB buffer chunk by chunk with incremental hashing, unchanged. Adds `rayon` as a workspace dependency of `victory-gpu`. ## Correctness Chunk boundaries: a unit test reads buffers of 1 MiB-1, 1 MiB, 1 MiB+1 and 3 MiB+123 (the last two take the parallel path) from a source pattern and asserts byte-for-byte equality and a clear unreadable flag. ## Testing - [x] `cargo test -p victory-hle -p victory -p victory-gpu -p xtask` (host arm64) — all pass, incl. `read_into_parallel_chunks_match_the_source_byte_for_byte` - [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/read-par-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:11 +00:00 (Migrated from github.com)

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


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

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7238983471 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/605#issuecomment-7238983471). Originally posted by [AnastasisKon](https://github.com/AnastasisKon) on 2026-11-28T12:05:11Z. --- CI green (check + macos-scripts SUCCESS), marked ready for review.
AnastasisKon commented 2026-11-28 12:49:15 +00:00 (Migrated from github.com)

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


Note for review: #603, #604, #605, #608, #610 and #609 were cherry-picked together onto a local integration branch off main; host 4-crate tests, x86_64-apple-darwin tests (victory-gpu/victory-loader/victory-hle), windows-target clippy --locked -D warnings and cargo xtask policy all pass on the composed result (the scan_round hunks of #603/#605/#608 resolve to: par_iter scan_one, big textures via read_into + hash_of). Happy to rebase any of these onto another once it merges.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7239489388 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/605#issuecomment-7239489388). Originally posted by [AnastasisKon](https://github.com/AnastasisKon) on 2026-11-28T12:49:15Z. --- Note for review: #603, #604, #605, #608, #610 and #609 were cherry-picked together onto a local integration branch off main; host 4-crate tests, x86_64-apple-darwin tests (victory-gpu/victory-loader/victory-hle), windows-target clippy --locked -D warnings and cargo xtask policy all pass on the composed result (the scan_round hunks of #603/#605/#608 resolve to: par_iter scan_one, big textures via read_into + hash_of). Happy to rebase any of these onto another once it merges.
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/605:upstream-pr/605'
git switch 'upstream-pr/605'

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