Formats/coalesce linear texture copies #3477
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!3477
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@nothanger on GitHub · 2026-11-27 06:33 UTC · original
nothanger:formats/coalesce-linear-texture-copies→main· +315 −0 · 2 files · 3 commits · openDense 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.
@oni-swr on GitHub · 2026-11-27 07:03 UTC · original
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.
@AurumCarlos on GitHub · 2026-11-27 11:06 UTC · original · requested changes
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: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.