gpu: parallelize texture detiling across subresources and textures #184
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/184"
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 lucastol3do on 2026-11-24T01:15:12Z.
Problem
Texture detiling — converting the console's tiled memory layouts into linear staging buffers — runs on a single thread at submission time. When the title loads a batch of new textures (~12.7 MB), the detiling costs ~22 ms, enough to drop the frame rate from 30 fps to 25-28 fps on a multi-core CPU that is otherwise idle.
Fix
Two levels of parallelism, both via
std::thread::scope(no new dependencies):Within a texture (
Staging::detile): spawns one thread per subresource (mip level / array slice). Each writes to a non-overlapping region of the mapped staging buffer, so the slices are independent.Across textures (
run_deferred): collects allStep::Hostclosures and runs them in a scope instead of one by one.Step::Hostdoes not interact with the shadow-buffer batch, so reordering relative toCopy/Run/Refreshsteps is safe.Test hardware
Result
On the hardware above, with the title running in Xbox Series X mode at 4K:
The remaining ~16 ms is dominated by a single large mip 0 that cannot be split at the subresource level; parallelizing inside
Layout::walk(row-level, invictory-formats) would close the rest of the gap.Imported from Marvisak/VIctory. Originally posted by DaviTostes on 2026-11-24T01:21:43Z.
Tested
c9dbb6aunder Wine 11.22 + vkd3d-proton 3.1 on Arch Linux x86_64 (AMD RX 9060 XT, RADV 26.3.1), Windows build withcargo xwin ... --target x86_64-pc-windows-msvcand a native Microsoftd3dcompiler_47: pass, no regression.victory_gpu: 37 passed, 2 failed.a_rejected_blob_gives_an_empty_library(vkd3d needs a non-empty blob) and #128.No game data used.
Imported from Marvisak/VIctory. Originally posted by Sunkiller-qc on 2026-11-24T01:29:26Z.
Two problems in
run_deferred(crates/victory-gpu/src/host.rs:1183):Step::Hostwork is collected (host.rs:1231) and only run after the whole loop (host.rs:1246). On main it runs in order with the list's copies (host.rs:1199). The rectangle expansion indraw.rs:871is adefer_hoststep that reads title vertex memory, so aCopyorRunstep recorded after the draw that writes that buffer now lands before the expansion reads it.for step in &self.deferred().copiesonly holds the guard for the loop, so theSyncFnRefpointers are used after theMutexGuardis dropped. Binding the guard (let deferred = self.deferred();) until the host work is done would make the SAFETY comment true.Also, one OS thread per host step and per subresource (
texture.rs:258) can mean dozens of spawns per submission for a mip chain. A bounded pool, or only splitting above a size threshold, would be safer for frame time. Withoutdiagnostics, the secondstartedis unused and will warn.Static review, not built or run.
Imported from Marvisak/VIctory. Originally posted by lucastol3do on 2026-11-24T01:36:29Z.
Thanks for the review and the Wine test.
All four points are addressed in
9ddeffe(force-pushed):1. Ordering.
run_deferrednow matches main exactly —Step::Hostruns in order withCopy/Run, not collected and deferred. TheSyncFnRefwrapper and the post-loop parallel section are gone. OnlyStaging::detileis parallelized (subresource loop), which is safe: each subresource writes to a non-overlapping region of the mapped staging buffer and does not interact with the shadow-buffer batch.2. Lifetime. Moot —
SyncFnRefis removed. There is no cross-texture parallelism inrun_deferredanymore, so no pointer-outliving-guard issue.3. Thread spawn.
Staging::detilenow only spawns whenitems.len() > 4(texture.rs:258). A texture with 1–4 subresources detiles on the calling thread; only larger mip chains or arrays split. Thestd::thread::scopestill creates one thread per subresource above the threshold, but the threshold keeps the common case (a single large mip 0) single-threaded and caps the spawn count for the rest.4. Unused
started. Moot — the secondstartedand its#[cfg(feature = "diagnostics")]block are gone with the post-loop section.The shader fallbacks in
lower.rs(untracked masks → use current block; unknown stride → default 4) are unchanged in this push.@daviTostes — thanks for the cross-platform check. You're right that the diff adds no test for the parallel detiling; I'll add one if this approach is kept.
Imported from Marvisak/VIctory. Originally posted by r4tedx on 2026-11-24T03:29:44Z.
Review note: this merges cleanly onto current
main(d2a4bae) but the result does not compile, becausemaingained a deferred step since the branch was cut:mainalone builds here, so it needs a rebase with an arm forStep::Texture. The shader-crate half passes its tests on its own (RTX 5070).From building only; I have no copy of the title.
Imported from Marvisak/VIctory. Originally posted by TrashTalker3460 on 2026-11-24T05:50:43Z.
Review note on head
9ddeffe: besides the parallel detile, this PR changescrates/victory-shader/src/emit/lower.rs. It removes six refusals:Three sites now fall back to
unwrap_or(Bool::TRUE)(lines 726, 746, 3922).A mask the translator cannot track is then treated as "all lanes active". A shader that used to be refused with a reason now translates, possibly wrong, with no error or log. Could these hunks move to their own PR with tests showing the
TRUEfallback is correct, or be dropped from this one? The detile change doesn't depend on them.Read-only review, nothing built. AI-assisted (Claude Code); the claim above was checked against this head and
mainatd2a4bae. Context: the triage in #366.Pull request closed