perf(victory-gpu): reuse capped thread-local scratch buffer in texback::land_tiled #418

Merged
Lewandox merged 2 commits from upstream-pr/418 into main 2026-11-26 18:41:39 +00:00
Lewandox commented 2026-11-26 18:01:03 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by Lewandox on 2026-11-26T18:01:03Z.


Summary

Reuses a capped thread-local scratch buffer for tiled texture readbacks in third_party/victory/crates/victory-gpu/src/texback.rs:

  1. Eliminate per-frame scratch allocation in land_tiled:
    • Previously land_tiled allocated and zeroed a fresh vec![0u8; back.size] on every non-packed texture readback (e.g. padded linear or swizzled ocean readbacks).
    • Now reuses a thread-local TILED_SCRATCH buffer (TILED_SCRATCH_CAP = 4 MiB), dropping oversized buffers immediately on return so idle threads never retain large allocations.
  2. Test:
    • Adds padded_linear_readback_reuses_capped_cpu_scratch verifying consecutive padded readbacks preserve row padding and reuse the same thread-local scratch allocation.

Verification

  • cargo test -p victory-gpu --lib texback::tests (default and --features diagnostics)
  • cargo xtask policy inside third_party/victory
<!-- greyfinch-sync:LooperSalty/AnyXboxX:issue:6632451771 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/418). Originally posted by [Lewandox](https://github.com/Lewandox) on 2026-11-26T18:01:03Z. --- ## Summary Reuses a capped thread-local scratch buffer for tiled texture readbacks in `third_party/victory/crates/victory-gpu/src/texback.rs`: 1. **Eliminate per-frame scratch allocation in `land_tiled`**: - Previously `land_tiled` allocated and zeroed a fresh `vec![0u8; back.size]` on every non-packed texture readback (e.g. padded linear or swizzled ocean readbacks). - Now reuses a thread-local `TILED_SCRATCH` buffer (`TILED_SCRATCH_CAP = 4 MiB`), dropping oversized buffers immediately on return so idle threads never retain large allocations. 2. **Test**: - Adds `padded_linear_readback_reuses_capped_cpu_scratch` verifying consecutive padded readbacks preserve row padding and reuse the same thread-local scratch allocation. ## Verification - `cargo test -p victory-gpu --lib texback::tests` (default and `--features diagnostics`) - `cargo xtask policy` inside `third_party/victory`
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
LooperSalty/AnyXboxX!418
No description provided.