GPU: reduce CPU time selecting indexed textures from a backlog #144

Open
syrrath-creator wants to merge 1 commit from upstream-pr/144 into main
syrrath-creator commented 2026-11-25 15:08:42 +00:00 (Migrated from github.com)
First-time contributor

Imported from Zettrox/ztrx. Originally posted by syrrath-creator on 2026-11-25T14:17:57Z.


The renderer can have 25,000–40,000 texture slots waiting for a host view. Each pass takes up to 4,096. The current implementation sorts all due slots, copies the retry candidates before truncating them, and walks the queue again for diagnostics, all while holding the queue mutex.

This change computes the five existing counters during selection and orders only the parts needed for the result. It preserves the retry-first rule and alternates newest and oldest fresh writes as before. The returned vector releases capacity used solely for discarded retries.

Synthetic queue Median CPU time per selection on Ryzen 7 7800X3D
25,000 slots, mixed 573.9 → 197.6 µs
40,000 slots, mixed 927.3 → 361.9 µs
40,000 slots, writes in reverse order 389.5 → 261.7 µs

The release-mode comparison ran in three processes, nine alternating A/B pairs per shape per process. 8,400 comparisons agreed on all returned (slot, generation) pairs and the complete census, including zero capacity, just over the cap, retries, partial uploads and future frames. The crate suite passed on Windows, as did Clippy with all targets and features. These timings cover queue selection and exclude uploads, GPU execution and game frame time.

Reproduce the comparison without game assets. Prepared and tested with Codex.

<!-- greyfinch-sync:Zettrox/ztrx:issue:6606563779 --> Imported from [Zettrox/ztrx](https://github.com/Zettrox/ztrx/pull/144). Originally posted by [syrrath-creator](https://github.com/syrrath-creator) on 2026-11-25T14:17:57Z. --- The renderer can have 25,000–40,000 texture slots waiting for a host view. Each pass takes up to 4,096. The current implementation sorts all due slots, copies the retry candidates before truncating them, and walks the queue again for diagnostics, all while holding the queue mutex. This change computes the five existing counters during selection and orders only the parts needed for the result. It preserves the retry-first rule and alternates newest and oldest fresh writes as before. The returned vector releases capacity used solely for discarded retries. | Synthetic queue | Median CPU time per selection on Ryzen 7 7800X3D | | --- | ---: | | 25,000 slots, mixed | 573.9 → 197.6 µs | | 40,000 slots, mixed | 927.3 → 361.9 µs | | 40,000 slots, writes in reverse order | 389.5 → 261.7 µs | The release-mode comparison ran in three processes, nine alternating A/B pairs per shape per process. 8,400 comparisons agreed on all returned (slot, generation) pairs and the complete census, including zero capacity, just over the cap, retries, partial uploads and future frames. The crate suite passed on Windows, as did Clippy with all targets and features. These timings cover queue selection and exclude uploads, GPU execution and game frame time. [Reproduce the comparison without game assets](https://github.com/syrrath-creator/ztrx/tree/2520e6d5cdb3dc04d316bf992bc50e0c8808bfe4/scripts/bench). Prepared and tested with Codex.
Artking175 commented 2026-11-25 15:08:46 +00:00 (Migrated from github.com)
Author
First-time contributor

Imported from Zettrox/ztrx. Originally posted by Artking175 on 2026-11-25T15:01:28Z.


Independent rerun on an Intel Core i7-9750H, Windows 10 22H2, Rust 1.98.1 MSVC. I used the pinned synthetic fixture and extracted the selector implementations from 90b529f and c459d07 as in the supplied build script. The three seeds matched every selected (slot, generation) sequence and all five census values in 8,400 comparisons.

Queue Main median PR median Speedup
25,000 mixed 875.86 µs 374.92 µs 2.34×
40,000 mixed 1,482.00 µs 579.12 µs 2.56×
40,000 reverse 664.76 µs 453.75 µs 1.47×

Each median covers 27 alternating A/B pairs across three processes. The timed region covers CPU queue selection. All inputs were synthetic.

<!-- greyfinch-sync:Zettrox/ztrx:comment:7166182538 --> Imported from [Zettrox/ztrx](https://github.com/Zettrox/ztrx/pull/144#issuecomment-7166182538). Originally posted by [Artking175](https://github.com/Artking175) on 2026-11-25T15:01:28Z. --- Independent rerun on an Intel Core i7-9750H, Windows 10 22H2, Rust 1.98.1 MSVC. I used the pinned synthetic fixture and extracted the selector implementations from `90b529f` and `c459d07` as in the supplied build script. The three seeds matched every selected `(slot, generation)` sequence and all five census values in **8,400 comparisons**. | Queue | Main median | PR median | Speedup | | --- | ---: | ---: | ---: | | 25,000 mixed | 875.86 µs | 374.92 µs | 2.34× | | 40,000 mixed | 1,482.00 µs | 579.12 µs | 2.56× | | 40,000 reverse | 664.76 µs | 453.75 µs | 1.47× | Each median covers 27 alternating A/B pairs across three processes. The timed region covers CPU queue selection. All inputs were synthetic.
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/144:upstream-pr/144'
git switch 'upstream-pr/144'

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