gpu: parallelize texture detiling across subresources and textures #184
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!184
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/184/head"
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?
@lucastol3do on GitHub · 2026-11-24 01:15 UTC · original
lucastol3do:parallel-texture-detiling→main· +129 −29 · 3 files · 1 commits · closed without mergingProblem
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.Three classes of shader translation failures are made non-fatal so the pipeline translates and its draws render, incorrectly, rather than dropping all its draws: 1. Lane masks read as data from another block (lower.rs:1160): instead of erroring, use the current block's entry as the ballot context. Fixes 'a lane mask holding lanes elsewhere read as data', 'a select on an untracked mask', 'a carry-in from an untracked mask', 'a wave reduction's untracked mask', and 'a lane-mask join of an untracked mask'. 2. Lane masks whose origin block has no DXIL block yet (lower.rs:1170): fall back to the current block instead of erroring. 3. Structured buffer accesses with unknown stride (lower.rs:5907, 5990, 6051): default to 4 bytes when the descriptor's stride is not tracked. Incorrect for buffers with larger strides but allows translation. Also parallelize Staging::detile across subresources when a texture has >4, using std:🧵:scope. Only the subresource loop is parallelized; the run_deferred ordering is unchanged from main.@DaviTostes on GitHub · 2026-11-24 01:21 UTC · original
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.
@Sunkiller-qc on GitHub · 2026-11-24 01:29 UTC · original
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.
@lucastol3do on GitHub · 2026-11-24 01:36 UTC · original
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.
@r4tedx on GitHub · 2026-11-24 03:29 UTC · original
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.
@ghost on GitHub · 2026-11-24 05:50 UTC · original
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