[formats] bcpack: reuse thread-local history rings across decodes #661

Open
Nyutt wants to merge 1 commit from nyutt/merge-bcpack-tls-rings into post-merge AGit
Contributor

Contributor role (optional)

  • Fluxer ID:

What it changes

  • The problem on Merge: read from crates/darner-formats/src/bcpack.rs. plain(), bc7(), and bc6() allocate a fresh 256-entry Vec (vec![...; HISTORY]) on the heap on every decoded BCPack block stream during DirectStorage texture streaming.

Reuse thread_local! RefCell<Vec<_>> rings (PLAIN_HISTORY, BC7_HISTORY, BC6_HISTORY) per decoder thread instead of allocating per call. pick() only reads slots i - r where 1 <= r <= i (already written during the current stream), so reusing the ring buffer is exact.

How it was tested

  • Tested revision: d143979 (based on origin/Merge 28a9b42)
  • Commands and results: Not yet A/B benchmarked in the game on Merge.
  • Changes a default: yes (removes per-call heap allocations in BCPack decoding; identical decoded output).
  • A/B result: not yet measured in-game on Merge.
  • Checks run on that revision:
    • cargo test -p darner-formats --lib --locked -> 19 passed, 0 failed
    • cargo clippy -p darner-formats --all-targets --locked -> 0 warnings
  • Hardware dependence: general (benefits DirectStorage CPU texture decode threads).
  • Coverage gaps: darner-formats --lib currently has tests in gfx; in-game texture decode run needed to confirm streaming speedup.

Checklist

  • I ran this change in the game, or say below why it can't be (unit tests + clippy verified; not yet benchmarked in-game).
  • This PR contains one change based on Merge.
  • The diff contains no game files, code or assets.
  • I recorded this PR's dependencies below.
    • Depends on: none

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches.
  • Related PRs: #604 (adds BC2 tests)
  • Replaces or overlaps: none found
## Contributor role (optional) - Fluxer ID: <!-- paste your !myid here if wanted --> ## What it changes - The problem on `Merge`: read from `crates/darner-formats/src/bcpack.rs`. `plain()`, `bc7()`, and `bc6()` allocate a fresh 256-entry `Vec` (`vec![...; HISTORY]`) on the heap on every decoded BCPack block stream during DirectStorage texture streaming. Reuse `thread_local!` `RefCell<Vec<_>>` rings (`PLAIN_HISTORY`, `BC7_HISTORY`, `BC6_HISTORY`) per decoder thread instead of allocating per call. `pick()` only reads slots `i - r` where `1 <= r <= i` (already written during the current stream), so reusing the ring buffer is exact. ## How it was tested - Tested revision: `d143979` (based on `origin/Merge` `28a9b42`) - Commands and results: Not yet A/B benchmarked in the game on `Merge`. - Changes a default: yes (removes per-call heap allocations in BCPack decoding; identical decoded output). - A/B result: not yet measured in-game on `Merge`. - Checks run on that revision: - `cargo test -p darner-formats --lib --locked` -> 19 passed, 0 failed - `cargo clippy -p darner-formats --all-targets --locked` -> 0 warnings - Hardware dependence: general (benefits DirectStorage CPU texture decode threads). - Coverage gaps: `darner-formats --lib` currently has tests in `gfx`; in-game texture decode run needed to confirm streaming speedup. ## Checklist - [ ] I ran this change in the game, or say below why it can't be (unit tests + clippy verified; not yet benchmarked in-game). - [x] This PR contains one change based on `Merge`. - [x] The diff contains no game files, code or assets. - [x] I recorded this PR's dependencies below. - Depends on: none ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. - Related PRs: #604 (adds BC2 tests) - Replaces or overlaps: none found
TrustNo1 changed title from [pr-performance][formats] bcpack: reuse thread-local history rings across decodes to [formats] bcpack: reuse thread-local history rings across decodes 2026-12-06 03:25:25 +00:00
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/661/head:nyutt/merge-bcpack-tls-rings'
git switch 'nyutt/merge-bcpack-tls-rings'

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 'post-merge'
git merge --no-ff 'nyutt/merge-bcpack-tls-rings'
git switch 'nyutt/merge-bcpack-tls-rings'
git rebase 'post-merge'
git switch 'post-merge'
git merge --ff-only 'nyutt/merge-bcpack-tls-rings'
git switch 'nyutt/merge-bcpack-tls-rings'
git rebase 'post-merge'
git switch 'post-merge'
git merge --no-ff 'nyutt/merge-bcpack-tls-rings'
git switch 'post-merge'
git merge --squash 'nyutt/merge-bcpack-tls-rings'
git switch 'post-merge'
git merge --ff-only 'nyutt/merge-bcpack-tls-rings'
git switch 'post-merge'
git merge 'nyutt/merge-bcpack-tls-rings'
git push origin 'post-merge'
Sign in to join this conversation.
No reviewers
No milestone
No project
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.

Dependencies

No dependencies set

Reference
TrustNo1/Darner!661
No description provided.