GPU: parallelize large tiled texture uploads on bounded workers #154

Open
syrrath-creator wants to merge 3 commits from upstream-pr/154 into main
syrrath-creator commented 2026-11-25 16:13:04 +00:00 (Migrated from github.com)
First-time contributor

Imported from Zettrox/ztrx. Originally posted by syrrath-creator on 2026-11-25T15:31:48Z.


Large tiled textures are detiled on the CPU into mapped D3D12 upload memory. Split eligible 2D mips (at least 4 MiB of active data) into disjoint row bands. Up to four persistent workers serve two concurrent uploads. Further callers copy locally so several submission threads can still make progress. The ordinary row walker handles small mips, linear textures, volumes, and machines with fewer than four available logical processors.

The Windows renderer enables the optional Rayon dependency. The copy validates the destination before starting workers and respects the exact size of the final D3D12 footprint. Tests cover array slices, partial last rows, untouched padding, mip tails, and invalid or undersized buffers.

Hardware timings

Ryzen 7 7800X3D, physical GeForce RTX 4090, driver 621.40. Both sides built the actual Rust crate as an external Cargo dependency with the same wrapper. Three fresh A/B processes provided 72 balanced pairs per case, and all 1,680 warm GPU readbacks matched an independently addressed reference.

Changed synthetic texture CPU detile before → after Faster pairs
4096×4096 RGBA8, 64 MiB 7.582 → 3.207 ms 72/72
2048×2048 RGBA8, 16 MiB 1.413 → 0.688 ms 72/72
4096×4096 BC7, 16 MiB 1.425 → 0.644 ms 72/72
1920×1080 RGBA8 with mip chain 0.781 → 0.594 ms 72/72

For the 64 MiB case, CPU p95 was 8.254 → 3.563 ms. Wall time through the GPU upload and validation readback was 12.950 → 8.754 ms. The GPU upload itself took 2.498 ms on both revisions. Separate fresh-process first calls took 8.060 → 3.861 ms. Below-threshold R8 cases moved by +0.68% to +2.11% in the paired CPU comparison.

In a separate scaling experiment on the two-slot design, two simultaneous 64 MiB uploads completed in 7.33 → 5.36 ms; four in 11.65 → 11.88 ms; eight in 22.46 → 22.11 ms. Each group had 105 paired samples. Gains depend on size, concurrency, and available CPU capacity. A complete title scene is required to measure the effect on FPS.

The branch also merges cleanly with the current heads of #125, #129 and #131. Native staging test and reproduction instructions.

Complete texture refresh and content detection

The follow-up commit also uses the existing four texture-staging workers for full BLAKE3 content checks at 2 MiB and above. Hashing and detiling share the same two admission slots. Smaller inputs and callers that find both slots busy continue on their own thread.

Compared with the detile-only commit 48ef697, an RTX 4090 test calling the real staging refresh produced these median CPU wall times. Each cell has 16 samples per revision, with the process order reversed for the second run.

RGBA8 staging case Detile only With parallel content hash
8 MiB unchanged, direct 1.066 ms 0.365 ms
8 MiB changed, direct 1.450 ms 0.662 ms
64 MiB unchanged, direct 10.425 ms 3.255 ms
64 MiB changed, direct 13.546 ms 6.288 ms
64 MiB changed, including forced GPU readback and fence 19.765 ms 12.565 ms

For 8 MiB, copy-through, a partially committed allocation and the no-wait remapping path also reduced median refresh time by 37–43% on changes and 50–53% on unchanged checks. Each of 560 synthetic refresh decisions matched the serial 32-byte digest, dirty state and expected image. Source bytes, mappings and GPU readback all come from the fixture.

Eight concurrent callers each hashing a private 16 MiB input eight times took 29.24 → 22.19 ms per batch. With 2 MiB inputs the difference was smaller at 2.85 → 2.77 ms. Separate hash-only process cycle measurements on a rotating 256 MiB working set rose from 0.61 to 0.73 cycles per byte at 2 MiB and 0.61 to 0.65 at 64 MiB. Parallel hashing trades aggregate processor work for lower latency. These measurements cover the indicated staging paths and fixtures. No retail title FPS was measured.

The ignored tests, baseline/candidate runner and reproduction instructions are available on the hardware validation branch.

On the integrated preview, 28,672 physical RTX 4090 texture submissions spanning 282,624 subresources matched the independent row reference. Integrated RTX 4090 validation.

<!-- greyfinch-sync:Zettrox/ztrx:issue:6608027588 --> Imported from [Zettrox/ztrx](https://github.com/Zettrox/ztrx/pull/154). Originally posted by [syrrath-creator](https://github.com/syrrath-creator) on 2026-11-25T15:31:48Z. --- Large tiled textures are detiled on the CPU into mapped D3D12 upload memory. Split eligible 2D mips (at least 4 MiB of active data) into disjoint row bands. Up to four persistent workers serve two concurrent uploads. Further callers copy locally so several submission threads can still make progress. The ordinary row walker handles small mips, linear textures, volumes, and machines with fewer than four available logical processors. The Windows renderer enables the optional Rayon dependency. The copy validates the destination before starting workers and respects the exact size of the final D3D12 footprint. Tests cover array slices, partial last rows, untouched padding, mip tails, and invalid or undersized buffers. ### Hardware timings Ryzen 7 7800X3D, physical GeForce RTX 4090, driver 621.40. Both sides built the actual Rust crate as an external Cargo dependency with the same wrapper. Three fresh A/B processes provided 72 balanced pairs per case, and all 1,680 warm GPU readbacks matched an independently addressed reference. | Changed synthetic texture | CPU detile before → after | Faster pairs | | --- | ---: | ---: | | 4096×4096 RGBA8, 64 MiB | 7.582 → 3.207 ms | 72/72 | | 2048×2048 RGBA8, 16 MiB | 1.413 → 0.688 ms | 72/72 | | 4096×4096 BC7, 16 MiB | 1.425 → 0.644 ms | 72/72 | | 1920×1080 RGBA8 with mip chain | 0.781 → 0.594 ms | 72/72 | For the 64 MiB case, CPU p95 was 8.254 → 3.563 ms. Wall time through the GPU upload and validation readback was 12.950 → 8.754 ms. The GPU upload itself took 2.498 ms on both revisions. Separate fresh-process first calls took 8.060 → 3.861 ms. Below-threshold R8 cases moved by +0.68% to +2.11% in the paired CPU comparison. In a separate scaling experiment on the two-slot design, two simultaneous 64 MiB uploads completed in 7.33 → 5.36 ms; four in 11.65 → 11.88 ms; eight in 22.46 → 22.11 ms. Each group had 105 paired samples. Gains depend on size, concurrency, and available CPU capacity. A complete title scene is required to measure the effect on FPS. The branch also merges cleanly with the current heads of #125, #129 and #131. [Native staging test and reproduction instructions](https://github.com/syrrath-creator/ztrx/blob/validation/texture-upload-staging/docs/texture-upload-hardware.md). ### Complete texture refresh and content detection The follow-up commit also uses the existing four texture-staging workers for full BLAKE3 content checks at 2 MiB and above. Hashing and detiling share the same two admission slots. Smaller inputs and callers that find both slots busy continue on their own thread. Compared with the detile-only commit `48ef697`, an RTX 4090 test calling the real staging refresh produced these median CPU wall times. Each cell has 16 samples per revision, with the process order reversed for the second run. | RGBA8 staging case | Detile only | With parallel content hash | | --- | ---: | ---: | | 8 MiB unchanged, direct | 1.066 ms | 0.365 ms | | 8 MiB changed, direct | 1.450 ms | 0.662 ms | | 64 MiB unchanged, direct | 10.425 ms | 3.255 ms | | 64 MiB changed, direct | 13.546 ms | 6.288 ms | | 64 MiB changed, including forced GPU readback and fence | 19.765 ms | 12.565 ms | For 8 MiB, copy-through, a partially committed allocation and the no-wait remapping path also reduced median refresh time by 37–43% on changes and 50–53% on unchanged checks. Each of 560 synthetic refresh decisions matched the serial 32-byte digest, dirty state and expected image. Source bytes, mappings and GPU readback all come from the fixture. Eight concurrent callers each hashing a private 16 MiB input eight times took 29.24 → 22.19 ms per batch. With 2 MiB inputs the difference was smaller at 2.85 → 2.77 ms. Separate hash-only process cycle measurements on a rotating 256 MiB working set rose from 0.61 to 0.73 cycles per byte at 2 MiB and 0.61 to 0.65 at 64 MiB. Parallel hashing trades aggregate processor work for lower latency. These measurements cover the indicated staging paths and fixtures. No retail title FPS was measured. The ignored tests, baseline/candidate runner and reproduction instructions are available on the [hardware validation branch](https://github.com/syrrath-creator/ztrx/blob/validation/texture-content-hash/docs/texture-content-hash-hardware.md). On the integrated preview, 28,672 physical RTX 4090 texture submissions spanning 282,624 subresources matched the independent row reference. [Integrated RTX 4090 validation](https://github.com/syrrath-creator/ztrx/blob/f70020779f87ab936752637d129abe159fc3c930/docs/rtx-4090-integration.md).
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/154:upstream-pr/154'
git switch 'upstream-pr/154'

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