perf(gpu): add opt-in GPU compute prelude texture detiling (VICTORY_GPU_DETILE) #249
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/249"
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 TaynanGT/Vice-Tay. Originally posted by Vladimir-Human on 2026-11-27T12:12:26Z.
Summary
Adds an opt-in GPU compute texture detiler (
VICTORY_GPU_DETILE=1, off by default;VICTORY_GPU_DETILE=alttoggles 20 s off/on) that offloads compatible texture detiling from CPU threads to a D3D12cs_5_1compute pass recorded inHostList::prelude.Instead of detiling element runs on the CPU into the upload buffer, enabled stagings copy raw tiled bytes sequentially into upload memory (alongside the held-level bitmask and the layout's pattern tables), dispatch the compute detiler in the list's prelude into a device-local UAV buffer (
COMMON -> UNORDERED_ACCESS -> COMMON), and let the list's existingCopyTextureRegioncommands copy from that linear buffer into the host texture. Unsupported layouts (all XOR modes_T/_X), background copy-queue uploads (ahead), movie planes, and allocation-pressured stagings automatically fall back to the existing CPU AVX2/SSE2DetilePoolpath (#191).Design adapted from
fxceless/victory-forkcommit3461f52(VICTORY_GPU_DETILE), withVice-Tay-specific extensions:Staging::base): bindsbuffer.GetGPUVirtualAddress() + self.baseas Root SRV and uses(&gpu.linear, 0)vs(&self.buffer, self.base)forCopyTextureRegion.first/level0): sizes raw staging fromlayout.bytes_from(first), validateslayout.bytes_from(mip) <= raw.tiled_bytes, and maps each subresource to its exact console mip index.Plan::linear_bytes): guarantees 32-bitRWByteAddressBuffer::Storestays strictly in bounds even on 1-byte / 2-byte last rows whose D3D12totalsize is not 4-byte aligned.bw_log2,bh_log2,slab_log2,n_log2,pitch / block_w) and table offsets into 24 root constants (0 integer divides in the shader).aheadsafety:ahead::claimrequests CPU-only staging (allow_gpu = false+!s.is_gpu()) soD3D12_COMMAND_LIST_TYPE_COPYlists never receive a GPU-detiled staging.SPARE_LINEARpool: tracksafter <= finishedagainsthost::submissions()before reusing device-local linear buffers, respectsresidencygrowth gates, and trims spares inlet_go_idle().#211): deduplicates compute passes across multiple lists in the same submission (needs_detile/record_detile), skips empty preludes when an earlier list already detiled the texture, and records insideprelude_pool::Slot::record.Files changed
crates/victory-formats/src/texture.rs:Swizzle::name(),Layout::detile_params(),Layout::pattern_tables(),DetileParams::address(), and exhaustive addressing/XOR-refusal unit test (detile_params_address_every_element_as_offset_does).crates/victory-gpu/src/gpudetile.rs: self-containedcs_5_1compute detiler, staging layout helpers, dispatch planner (jobs), prelude recorder (record), per-frame meter line (meter_line), and HW + WARP + prelude integration tests.crates/victory-gpu/src/texture.rs:Staging::gpu,SPARE_LINEARpool, raw copy path inStaging::detile,copy_source(),needs_detile()/record_detile(), and automatic CPU fallback.crates/victory-gpu/src/texture/ahead.rs: keep background copy-queue uploads CPU-detiled.crates/victory-gpu/src/host.rs:Deferred::detiles,HostList::detile_first,HostList::prelude(this_submission),HostList::untouched, andgpudetile::meter_line(frames).crates/victory-gpu/src/lib.rs: registermod gpudetile;.Verification (
rustc 1.98.1,VICTORY_D3D12_DEBUG=1)cargo run -p xtask --locked -- policy(asset policy: 313 files ok) &cargo test -p xtask --locked: 11/11 passedcargo clippy -p victory-formats -p victory-gpu --all-targets --locked -- -D warnings: 0 warningscargo clippy -p victory-formats -p victory-gpu --all-targets --all-features --locked -- -D warnings: 0 warningscargo test -p victory-formats --locked: 48 passed, 0 failed, 6 ignoredVICTORY_D3D12_DEBUG=1):gpudetile::: 5/5 passed (25-case + 2 on-demand mask byte-exact matrix across RGBA8, BC1, BC3, BC5, BC7, R8, R16, R16G16B16A16F, R32G32B32A32F, POT + NPOT, 256B/4KB/64KB S+D, LINEAR, mip tails, arrays, 3D thick/linear,level0/firstmip-clamping, pooledraw_baseoffset; 9 XOR mode fallbacks; end-to-endHostList::preludeupload + multi-list dedup + mip 0 & tail readback + dynamic v2 update;aheadCPU-only check)gpudetile::withVICTORY_PRELUDE_POOL=1: 5/5 passedgpudetile::withVICTORY_D3D12_GBV=1: 5/5 passedgpudetile::&texture::(--features diagnostics): 5/5 & 8/8 passedtexture::(VICTORY_GPU_DETILE=0&VICTORY_GPU_DETILE=1): 8/8 passedVICTORY_D3D12_WARP=1,VICTORY_D3D12_DEBUG=1):gpudetile::: 5/5 passedtexture::(VICTORY_GPU_DETILE=1): 8/8 passedImported from TaynanGT/Vice-Tay. Originally posted by TaynanGT on 2026-11-27T12:19:47Z.
@Vladimir-Human The copy-queue fallback and fence-gated reuse are the critical boundaries for this opt-in path. I’ll start with the CPU-versus-GPU byte checks at held mip levels and at the last narrow row, then keep the in-game comparison as a separate measurement with the same textures and camera.
Imported from TaynanGT/Vice-Tay. Originally posted by Vladimir-Human on 2026-11-27T12:59:19Z.
@TaynanGT Thanks — here are the exact checkpoints for those four boundaries:
level0/first):crates/victory-gpu/src/texture.rs:2252-2255(first = read_from(&layout, first).max(level0).min(mips - 1),read = layout.bytes_from(first)) andcrates/victory-gpu/src/gpudetile.rs:361(layout.bytes_from(mip) <= raw.tiled_bytes), covered byte-exactly on HW and WARP bygpudetile::tests::gpu_detile_matches_cpu_on_hardware(gpudetile.rs:923),gpu_detile_matches_cpu_on_warp(gpudetile.rs:917), andprelude_uploads_detiled_textures_byte_exact(gpudetile.rs:980, includinglevel0 == first == 2andlevel0 == 0, first == 2).crates/victory-gpu/src/gpudetile.rs:369-386, 445(words = row_bytes.div_ceil(4),written_end = last_row + words * 4,Plan::linear_bytes = max_written_end.next_multiple_of(4)) andcrates/victory-gpu/src/texture.rs:2294(total.max(p.linear_bytes).next_multiple_of(4)), keeping 1B/2B last-row UAV writes strictly in bounds.crates/victory-gpu/src/texture/ahead.rs:125-129(super::staging(..., false)+!s.is_gpu()filter) andcrates/victory-gpu/src/texture.rs:2232, 2289(allow_gpu), verified bygpudetile::tests::ahead_copy_queue_never_uses_gpu_staging(gpudetile.rs:1170).SPARE_LINEARreuse:crates/victory-gpu/src/texture.rs:175-195(entry.after <= finishedagainsthost::submissions()),texture.rs:607-622(returns toSPARE_LINEARtagged withstartedunderspare_linear_limit()), andtexture.rs:656-659(let_go_idle->trim_spare_linear).Imported from TaynanGT/Vice-Tay. Originally posted by TaynanGT on 2026-11-27T13:08:54Z.
@Vladimir-Human The byte-exact held-mip checks on hardware and WARP cover the rounding case. The copy-queue fallback and
after <= finishedcondition are the right boundaries for the next runtime comparison. Use the same scene and compare upload time and bytes along with the rendered frame times.Imported from TaynanGT/Vice-Tay. Originally posted by TaynanGT on 2026-11-30T17:15:01Z.
mainhas moved to a new line of the code and everything is now named Vice-Tay, so this PR no longer applies as it is (details in #468). If you'd like this change in, please rebuild it on the currentmainand open a new PR; I'll review it there.Pull request closed