Repository navigation
Textures: detile big subresources in bands on several threads - #92
marquezinii wants to merge 2 commits into
Conversation
A sampled texture that changed is detiled into its staging buffer on the submitting thread, one subresource after another, at about 4.5 GB/s: 7-17 ms for a single 33-67 MB texture, and part of the frame line's "textures" time. Layout::detile_rows detiles one band of a subresource's rows, and a subresource of 8 MiB or more is now cut into bands of about 4 MiB that the kept threads (shadow::wide_run) detile at once. Smaller ones, and 3D ones, are detiled whole as before. Bands give the rows of the whole detile byte for byte (tests over every mode, mips, odd sizes, block compression and array slices). On a Ryzen 5 5600X with DDR4-3600 (three kept threads and the caller): 33 MB 7.3 -> 4.2 ms, 67 MB 16.6-17.1 -> 7.4-8.5 ms (detile_in_bands, detile_threads).
|
I tested 02c2743 on Windows x64 with a Ryzen 7 7800X3D (8 cores, 16 logical processors). The large-texture speedup reproduced here. I compared the serial implementation from base 4e17478 with the PR's banded implementation and worker pool. The native release microbenchmark alternated which version ran first, warmed both paths for four rounds, then measured 22 rounds per case. The table shows median CPU time per conversion, rounded. The machine had a game session open during measurement.
All six outputs matched base byte-for-byte, including row padding. The formats suite passed 25 tests with 5 ignored, and the GPU crate's CPU test AI-assisted test and report. |
|
Independent test run on commit
AI use: Antigravity (Gemini 4 Neon) ran clippy/tests locally and wrote this report. |
|
Tested on CachyOS Linux (
(AI-assisted build/log analysis.) |
|
An in-game data point on an RTX 5070 Ti, measured together with #95 and #108. Full table and setup: #108 (comment). On one exe with a warm cache, a local switch turned the band detile on and off (D vs C: #95 + #108 with and without this PR):
In the opening scenes the texture time per megabyte is the same with and without bands. The frame difference is within run-to-run noise: two runs of the same configuration differ by 14% in median. My reading is that few refreshed subresources here reach the 8 MiB the band path needs (2 × AI use: measured and written with Claude Code (Claude Opus 5.5); posted with my approval. |
The diagnostics frame account now says how many texture subresources were detiled per frame and their megabytes, and how many of them took the band path (8 MiB or more). A scene's texture time can so be read against how much of it the bands could have helped: in the opening scenes most refreshed subresources are smaller than that.
|
Thanks to both of you for the in-game runs. @LastThylacine, I agree with your reading. The A/B isolates this PR, and the same 0.33 ms per MB with and without bands means the opening scenes' texture time comes from many subresources under the 8 MiB threshold, plus the read of title memory before the detile, which stays on one thread. @BitWuehler, your drop from 597 to 91 ms comes with #95 in the same build, and #95 takes the texture refresh's waits for remappings away. That fits the A/B: most of that drop is likely #95's. As suggested, |
A sampled texture whose memory changed is detiled into its staging buffer on the submitting thread, subresource by subresource, at about 4.5 GB/s. That is 7-17 ms for one 33-67 MB texture, and it is part of the frame line's
texturestime (44-51 ms a frame in the 4060 Ti numbers in #10).This cuts the detile of a big subresource into bands of rows and runs them on the threads
shadow::wide_runalready keeps:victory-formats:Layout::detile_rowsdetiles rowsy0..y1of a subresource one slice deep into a buffer that starts at rowy0. It goes through the samewalkasdetile, with an optional row range, so the runs and their fixed-length copies are the same.victory-gpu:Staging::detilecallsdetile_wide, which cuts a subresource of 8 MiB or more into bands of about 4 MiB and hands them towide_run. Smaller subresources, and 3D ones, are detiled whole as before.Render targets in the
_Xmodes are not detiled on the CPU (the layout has no pattern for them), so this only affects sampled textures in theS/Dmodes, such as streamed textures and the ones the title rewrites.Checked
bands_detile_as_the_whole(formats): for every mode, mip and array slice, with block compression, odd sizes and padded rows, any band split gives the same bytes asdetile. Bad bands (past the mip, empty, too small, 3D) are refused.a_texture_detiled_in_bands_is_the_one_detiled_whole(gpu):detile_wideagainstdetileon big and small textures and their mips.wide_runhas three threads plus the caller here), release, best of 7:SW_4KB_S(33 MB)SW_64KB_S(67 MB)SW_64KB_D(67 MB)It levels off at about 8 GB/s from four threads, which looks like this machine's memory bandwidth.
cargo clippy --workspace --all-targets -- -D warnings(default and--all-features),cargo test -p victory-formats -p victory-gpuandcargo xtask policypass. Only my own lines were run through rustfmt; both files had older unformatted parts, which I left alone.Not checked: a run of the title, since I don't have the files here. How much of the
texturestime this removes depends on how big the changed textures are in a given scene: the read of title memory before the detile is still on one thread, and many small textures gain nothing. If someone runs it, thetextures N ms M MBpart of the frame line before and after is the number to compare.