Skip to content

Textures: detile big subresources in bands on several threads - #92

Open
marquezinii wants to merge 2 commits into
fxceless:mainfrom
marquezinii:perf/detile
Open

marquezinii wants to merge 2 commits into
fxceless:mainfrom
marquezinii:perf/detile

Conversation

@marquezinii

Copy link
Copy Markdown
Contributor

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 textures time (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_run already keeps:

  • victory-formats: Layout::detile_rows detiles rows y0..y1 of a subresource one slice deep into a buffer that starts at row y0. It goes through the same walk as detile, with an optional row range, so the runs and their fixed-length copies are the same.
  • victory-gpu: Staging::detile calls detile_wide, which cuts a subresource of 8 MiB or more into bands of about 4 MiB and hands them to wide_run. Smaller subresources, and 3D ones, are detiled whole as before.

Render targets in the _X modes are not detiled on the CPU (the layout has no pattern for them), so this only affects sampled textures in the S/D modes, 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 as detile. Bad bands (past the mip, empty, too small, 3D) are refused.
  • a_texture_detiled_in_bands_is_the_one_detiled_whole (gpu): detile_wide against detile on big and small textures and their mips.
  • Benchmarks, Ryzen 5 5600X, DDR4-3600 (wide_run has three threads plus the caller here), release, best of 7:
texture whole in bands
3840x2160 RGBA8, SW_4KB_S (33 MB) 7.3-8.6 ms 4.1-4.2 ms
4096x4096 RGBA8, SW_64KB_S (67 MB) 16.9-19.2 ms 8.3-11.0 ms
2048x2048 16 B, SW_64KB_D (67 MB) 16.6-17.1 ms 7.4-8.5 ms

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-gpu and cargo xtask policy pass. 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 textures time 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, the textures N ms M MB part of the frame line before and after is the number to compare.

cargo test --release -p victory-gpu detile_in_bands -- --ignored --nocapture
cargo test --release -p victory-formats detile_threads -- --ignored --nocapture

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).
@ryotdev

ryotdev commented Nov 24, 2026

Copy link
Copy Markdown

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.

Synthetic texture Linear output Base PR
3840 × 2160, RGBA8 33.2 MB 3.55 ms 1.25 ms
4096 × 4096, RGBA8 67.1 MB 10.72 ms 4.03 ms
2048 × 2048, 16 bytes per element 67.1 MB 8.83 ms 3.80 ms
4096 × 2048, 16 bytes per 4 × 4 block 8 MiB 0.294 ms 0.169 ms
1024 × 1024, RGBA8 4 MiB 0.234 ms 0.249 ms
777 × 427, 8 bytes per element, padded rows 2.7 MB 0.164 ms 0.175 ms

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 a_texture_detiled_in_bands_is_the_one_detiled_whole passed. The two cases below 8 MiB stayed on the serial path. I haven't measured this PR's effect on in-game frame times.

AI-assisted test and report.

@adriaespii

Copy link
Copy Markdown

Independent test run on commit 02c2743 (AMD RDNA4):

  • Hardware: AMD Radeon RX 9070 (driver 32.0.32015.7029), AMD Ryzen 5 7600, Windows 11 Pro, Rust 1.98.1 (x86_64-pc-windows-msvc)
  • cargo clippy --workspace --all-targets -- -D warnings: 0 warnings
  • cargo test --workspace: 498 passed, 0 failed, 9 ignored (victory-formats: 25 passed, 0 failed, 5 ignored; victory-gpu: 111 passed, 0 failed, 2 ignored; victory-shader: 210 passed, 0 failed, 2 ignored)
  • Not tested: --ignored benchmarks and live game run (no game files on this machine)

AI use: Antigravity (Gemini 4 Neon) ran clippy/tests locally and wrote this report.

@BitWuehler

Copy link
Copy Markdown

Tested on CachyOS Linux (Ryzen 7 9800X3D, RTX 5080 620.73.04, GE-Proton11-14, release build) bundled with #95, #108, #159 on top of 4e17478 + #454/#127/#154:

  • victory-formats: 25 passed, 0 failed, 5 ignored under GE-Proton11-14 (wine).
  • victory-gpu: 114 passed, 1 failed, 3 ignored (only the known CreatePipelineLibrary stub in vkd3d-proton fails; a_texture_detiled_in_bands_is_the_one_detiled_whole passes).
  • In a 353 s world session (0 crashes/device removals), combined preparing: textures dropped from 596.55 ms median (892.66 ms mean) to 91.30 ms median (122.55 ms mean; 10.5 ms in the final 5,426-draw frame).

(AI-assisted build/log analysis.)

@LastThylacine

Copy link
Copy Markdown

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):

C: without #92 D: with #92
frame, median / mean 517 / 646 ms 561 / 671 ms
textures 36 ms for 110 MB 45 ms for 138 MB
texture time per MB 0.33 ms 0.33 ms
device removed no no

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 × BAND_BYTES). The cost there is many smaller textures, not a few big ones. This is not a regression: it merges cleanly with #95 and #108, the formats and gpu tests pass on the combination, and nothing went wrong in 8 minutes. A counter of the subresources that take the band path would show which scenes it helps. Streamed 4K textures later in the game are probably where it pays.

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.
@marquezinii

Copy link
Copy Markdown
Contributor Author

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, f31ad94 adds the counter. In a diagnostics build the frame account line now reads N subresources detiled X MB, M of them in bands Y MB, per frame, so a run shows how much of a scene's texture work the band path even reaches. It is two copystat counters around the existing branch in detile_wide; nothing changes outside diagnostics builds. Both clippy runs and the detile tests pass with and without --features diagnostics.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants