Formats/coalesce linear texture copies #3477
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3477"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from Marvisak/VIctory. Originally posted by nothanger on 2026-11-27T06:33:39Z.
Dense LINEAR textures are currently copied row by row. This change copies contiguous rows as a whole plane, and adjacent volume planes as one span, reducing CPU copy overhead.
Changes
Validation
Tested on Linux x86-64 with Rust 1.98.1:
-D warnings: passed.The five ignored tests are two existing benchmarks and three external-data tests.
Performance
In synthetic CPU measurements, dense-volume detile improved from 28.67 µs to 23.06 µs, approximately 1.24x throughput. Padded rows remained stable; unaligned-width controls were approximately 1–2% slower. Tiled controls remained close to baseline.
No game-FPS improvement is claimed.
Related work
This partially overlaps #3450's GPU staging shortcut. This implementation operates in
victory-formats, covers both tile and detile, and also benefits XG callers.Limitations
Native Windows execution, physical GPUs, retail titles and the complete workspace suite were not tested. Linux performance results do not establish Windows performance.
AI assistance
OpenAI Codex (GPT-6 family reported in this session) assisted with investigation, implementation, independent review, tests, measurements and this description. All reported test and benchmark results were actually executed.
Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-27T07:03:37Z.
Independent CPU verification (claimed on #1633). AI-assisted (Claude Sonnet 5.5). CPU only: no GPU, no title, no game data.
Environment: AMD Ryzen 7 5700X3D, Windows 11 build 10.0.26200, rustc 1.98.1,
-j 4, own target dir.Base: origin/main
63bcca43c6a00a758510398fa43096ce7e4f7df0. Head:e65fb626e9c484c58cbaf37dbc98599fd6c889ad.Tests (
cargo test -p victory-formats -j 4)texture::tests::linear_copies_match_element_addresses(7680 cases against the element-wise oracle) passes.Benchmark (
linear_copy_bench, release, median of 3 runs; each run is itself a median of 9 samples). The example uses only the public API, so I ran the same file against base. Base and head runs were interleaved. Ratio is base/head, so above 1 means head is faster.The slowdowns reproduced in both measurement sets, with head's dense 256x256 detile at 87.7 and 88.8 us. On this CPU the single large copy is slower than the per-row copies it replaces for the dense cases (up to about 12x for 256x256 detile, about 1.6x for 1080p and the dense volume). I did not find the cause. Possibly the large
copy_from_slicehits a slow memcpy path here, for example 4K aliasing between the two same-sized buffers, but that is a guess. It would be worth checking on other CPUs before relying on the speedup claim. Only the mip-chain volume and 1D cases improved.Review (diff read in full, only
crates/victory-formatstouched)row_pitch == bytes,m.pitch * n == bytes(tiled row has no padding) andSwizzle::LINEAR. Planes merge only whenslice_size == slice_bytesanddepth_pitch == slice_bytes. A mip chain correctly falls back to the per-plane loop, becauseslice_sizespans the chain.slice_bytesandneedare stillchecked_*, and the length checks run before the fast path.base + z * slice_sizeis the same arithmetic as the old path. I found no off-by-one and no correctness bug.No game files, dumps, paths, shader names or hashes were used or are included here.
Imported from Marvisak/VIctory. Originally posted by AurumCarlos on 2026-11-27T11:06:20Z.
Review: CHANGES_REQUESTED
The fast path is correct: for
LINEAR,split(z)is(z, 0), sobase + z * slice_sizematches the general path, and the 47 formats tests pass one65fb62. But it makes large dense copies much slower with the MSVC CRT that VIctory links against. Requesting changes for that; the fix is small.Reproduced: one large
copy_from_slicehits the MSVCmemcpy's large-copy path. I built the PR's ownlinear_copy_benchwith-C target-feature=+crt-static, so the binary carries Microsoft'smemcpyfromlibvcruntime.lib, and ran it under Wine on a Ryzen 5 9600X (base, head and fix interleaved, median of 3 runs each):mainWith Wine's own
memcpythe 1080p case doesn't slow down (0.96x–1.11x), which fits the gains measured on Linux. oni-swr's native Windows run on Zen 3 (0.61x at 1080p, 0.08x at 256x256) is the same effect, stronger on that CPU.Suggested fix: cap each copy at 64 KiB (
texture.rs:685). 16 KiB and 4 KiB chunks were no better at 1080p and gave back part of the 256x256 and BC7 gain.On Zen 3, oni-swr's "padded depth" case was slower even with 64 KiB copies, so a native rerun there would be worth it.
No test case exceeds 64 KiB, so the 7,680 cases don't reach the chunking. This test does. It passes with the fix and fails if the chunk's tiled offset is dropped (
copy(t, l + at, n)), whilelinear_copies_match_element_addressesstill passes in that case:Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-28T09:54:52Z.
I combined this PR at
e65fb62with #3706 at92b2f83in 59ebeb5. The two exact heads merged cleanly.The combined Windows build matched all copy offsets and lengths from this head across 3,360 generated subresources with tight and padded pitches, including 1,108 mip tails and 120 volume cases. The release suite passed with 47 passed and five ignored, with your differential linear-copy test among the passes. Strict Clippy and the asset policy passed.
The 256×256 dense linear control stayed around 20 µs. Both benchmark setups showed a gain on the 1,920×1 and 1,920×8 tiled cases. Results for 640×360 and 32×8 varied between the same-binary comparison and separate release builds, so the timings support the narrow cases most clearly.
@nothanger, the combined tree is available for review if both changes are considered together. Please retain the Git authors on cherry-pick or rebase, or add
Co-authored-by: andrewpozdnakov7-jpg <[email protected]>if folding the changes into another commit.AI-assisted with OpenAI Codex.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.