Textures: Detile volume mips directly into pitched upload memory #3701
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3701"
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 ivall/xcl. Originally posted by bmjask on 2026-12-02T15:38:24Z.
What is in it
Volume mips now write directly into the mapped row layout. This removes a temporary allocation and a second CPU pass over the mip. Row padding stays untouched, missing whole elements are zeroed, and the GPU upload still occurs.
Tested
cargo test --release --locked -p xcl --lib bench_volume_detile_pitched_upload -- --ignored --nocapture --test-threads=1.Mapped D3D12 upload benchmark
A 129 × 97 × 19 RGBA8 mip took 2.443 ms with a reconstruction of the previous per-element detile plus row copy, 1.281 ms with contiguous-run detiling plus row copy, and 1.213 ms with contiguous-run detiling directly into the pitched upload allocation. Direct writes reduced time by 50.4% against the first path and 5.4% against the second. Most of the gain came from copying contiguous runs. The direct path beat the contiguous-run temporary path in all five runs. Warm-up verifies all output bytes and padding against the reference.
Release build on an i9-12900K and RTX 4090 (610.88). Each value is the median of five independent process medians, with 30 timed samples per method and run, with the order and destination region varied. XCL allocated a native D3D12 upload buffer. The device reported WRITE_COMBINE and Windows reported PAGE_READWRITE | PAGE_WRITECOMBINE (0x404). Both focused checks passed in each process on the combined development checkout. These are CPU staging times.
Reproduce with
cargo test --release --locked -p xcl --lib bench_volume_detile_pitched_upload_mapped -- --ignored --test-threads=1 --nocapture.Regression run
Main
PR head
The mapped benchmark and pitched-output oracle cover the zero pipe/packer configuration. Thick layouts with single-element runs, nonzero console pipe configurations, and eight-byte elements remain unmeasured on the mapped heap. AMD hardware was unavailable. The benchmark helper in runner.rs is byte-identical on #3701 and #3702; a three-way merge of these heads reported no conflict.
Not tested
The full GPU workspace suite and a matched in-world frame-time comparison for this individual PR.
AI use
OpenAI Codex (GPT-6) implemented and reviewed the change, ran the focused tests and benchmark, and prepared this PR.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T18:19:59Z.
merge-check
base:
5eaadb54c1head:
4aac1176b7merge: clean
build: ok
tests: 2975 passed, 0 failed, 53 ignored; 28 skipped, the same as on main
review: 2 high, 3 medium (below)
performance: 60 s smoke run: 1422 → 1681 frames (118 % of main), peak commit 17184 → 16434 MB, no device removal, no crash
title run: not run
verdict: not yet: it is a draft,
PR descriptionis red, and 2 high findings (below): a default-path change with no smoke runs or suite run yet, and the speed-up measured on ordinary RAM, not the write-combined upload heaphardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5
In short: Adds
Chain::detile_volume_into, which detiles one volume mip straight into rows of a given pitch, copying runs of elements that sit together in memory;detile_volumeuses it, and the D3D12.X volume upload writes into the mapped upload buffer instead of a temporary Vec. By reading, the output matches the old path byte for byte, and the suite and smoke run below are clean. It changes every volume upload, though, and the speed-up was measured on ordinary RAM.High
texture_upload.rs~683-692) and every otherdetile_volumecaller (texture.rs:99,title_textures.rs:3455,xg.rs:740) takes the new path, but the smoke runs and the GPU suite are "pending". Add both smoke blocks and the suite counts.tiling.rs~1386) writes to ordinary RAM, but the real target is a write-combinedD3D12_HEAP_TYPE_UPLOADbuffer (~815). The old path wrote whole rows; the new one writes run by run, which can be a single element on thick layouts, so the 12.7 % figure says nothing about the real path. Measure into an upload heap.Medium
pitched_volume_matches_element_addresses_and_preserves_padding(~1347) is a sound element-by-element oracle (padding, guard bytes, a source truncated mid-element, an empty source), but it uses onlyPipeConfig {0,0}and neverelem_log2 = 3. With the real pipe configs (texture.rs:22-23) thehx/hy/hzXOR terms are non-zero, and run contiguity depends on them. Add those configs.detile_volume/tile_volumeas block runs, and #1624 changes thebase_xormasking inoffset_z, whicheffective_runrelies on.Checked and fine
bpe == 1<<e.base_xorboundary, and tail mips that start partway into a run are handled.plan_itemreserved for that piece.How this was tested
5eaadb54, thencargo build --workspaceandcargo test --workspace --no-fail-fast -- --test-threads=4.scripts/smoke.ps1: 60 s of a retail title on main5eaadb54and on this merge; presents per 2 s at the end: 60 60 60.Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by capy-ai[bot] on 2026-12-02T20:10:08Z.
Code review (head
a276a5617b, diff read only — not built or tested on Windows/GPU, not a merge-check)No code or memory-safety bugs found; merges cleanly onto
origin/main(5ad98adb).Chain::detile_volume_intohandles zero dimensions, validates destination bounds, respectseffective_run()and tail-mip run origins ((run - (x + l.origin.0) % run)), zeroes missing/partial trailing elements in reused upload buffers, and leaves row padding intact. Intexture_upload.rs,plan_itemreservespitch * l.height * l.depthbytes per volume piece, so thefrom_raw_parts_mutslice stays in bounds and disjoint across workers.pitched_volume_matches_element_addresses_and_preserves_paddingand the new mapped WC upload benchmark only exercisePipeConfig { pipes_log2: 0, pkrs_log2: 0 }(and notelem_log2 = 3), so real console pipe configs and thickeffective_run() == 1layouts aren't covered against write-combined memory.#3701and#3702both add the identicalwith_upload_pairhelper atcrates/xcl/src/gpu/recomp/runner.rs:566(whichever lands second will need a quick rebase/dedup), andtiling.rsalso overlaps with open#901.D3D12.X:/Textures:),AI usenamesOpenAI Codexwithout the exact model name, and the two#[ignore]timing tests live inmod testsrather thancrates/xcl/benches/.gpu:both), and a real title run past loading on heada276a5617b.AI use: Capy, Google Gemini 4 Neon (static code review only; not built or tested on Windows/GPU).
Imported from ivall/xcl. Originally posted by Kalmarv on 2026-12-02T20:42:29Z.
merge-check
base:
5ad98adbc3(current main)head:
a276a5617bmerge: clean (aacfe7c7c; runner.rs auto-merged)
build: cargo check -p xcl --all-targets -> ok (39 lib / 19 lib-test warnings, same as main
5ad98adbc); git diff --check cleantests: cargo test -p xcl --lib -- --test-threads=1 gpu::tiling:: -> 22 passed, 0 failed, 2 ignored (the two manual benches); includes pitched_volume_matches_element_addresses_and_preserves_padding. Full workspace suite and GPU tests not run here; Foniass's full suite on
4aac1176b(this code without the bench commit) passed 2975/0.review:
mainby reading.tiling.rs:657ff), asmain's per-elementmem.get(o..o+e)did.detile_volumecallers (texture.rs,title_textures.rs,xg.rs) go throughdetile_volume_intowithpitch == row, so their output is the same.from_raw_parts_mut(to + p.at, pitch * l.height * l.depth)(texture_upload.rs:689-691) is exactly whatplan_itemreserves for the piece (*at += pitch * h * depth,:485), andl.heightis checked againstGetCopyableFootprints' row count (:462).run_elems(tiling.rs:174-188) only grows while none ofoy/oz/hx/hy/hztouches the run's low address bits and whileoxis linear within it, capped atblock_w.effective_run()run aligned onx + origin.0is contiguous for any layout, including depth and pipe XOR terms. The 2D detiler already relies on the same primitive.:1347) still only usesPipeConfig{0,0}. Looping it over a real config, asparts_of_some_bytes_are_the_blocks_they_are_indoes with{5,3}(:1101), would pin that for 3D at no cost.effective_run() == 1, the upload buffer gets onee-byte store per element (sequential within a row). The mapped benchmark covers only mode 5 RGBA8, a long-run case; one short-run mode would show the default path doesn't regress there.detile_volume/tile_volume: whichever lands second needs a rebase.performance: not run here; no GPU work in this check. The description's smoke pair shares a disturbed
mainblock with #3702/#3703 (presents 51/16/48). Foniass's 5070 Ti pair on4aac1176b(the same code without the bench commit), 1,422 -> 1,681 frames, 0 removals, is the usable one.verdict: safe to merge: correct by reading and its tests pass on current main; a real PipeConfig in the 3D oracle test would be a good addition.
hardware / tool and model: NVIDIA GeForce RTX 5070 Ti, driver 32.0.16.1074, AMD Ryzen 9 9950X, Windows 11 Pro 26200 / Claude Code (claude-opus-5-5)
Imported from ivall/xcl. Originally posted by lucsoft on 2026-12-02T20:43:31Z.
merge-check claim
head:
a276a5617bImported from ivall/xcl. Originally posted by lucsoft on 2026-12-02T23:13:26Z.
merge-check
base:
5ad98adbc3head:
a276a5617bmerge: clean (merge commit 69f5c95f, auto-merge in runner.rs, git diff --check clean)
build: cargo build --release -p xcl && cargo test --workspace --release --no-run (x86_64-pc-windows-gnu) -> ok
tests: lib 2798 passed, 17 failed, 15 ignored, 31 died; integration 134 passed, 6 failed, 20 ignored, 2 exes died (main
5ad98adb: lib 2797 / 17 / 13 / 31; +1 passed = pitched_volume_matches_element_addresses_and_preserves_padding, +2 ignored = the manual benches). The one extra integration death is d3d12_resource_and_sync: glibc "free(): corrupted unsorted chunks" right after its GetGPUVirtualAddress-of-a-committed-texture line, the same message at the same point as an earlier main run here. Over all runs here (2 threads) it died in 4 of 10 on this PR (suite 1/1, rerun 2/3, alternating A/B 1/6) and in 0 of 6 on main5ad98adbin that A/B. The test creates no 3D texture, so detile_volume / detile_volume_into (volume textures only) do not run in it; I read it as the known Linux-side abort, but the rate here was higher than on main. Under Wine, one test module per process with --test-threads=2, not 4. Skipped: 8 tests, the same set as on main (no dxc.exe, no D3D12 debug layer, heap windows opt-in, driver cache cannot be disabled, stale-blob probe refused, Close does not refuse an open pipeline-statistics query x2, SetPredication ignored for copies). failing: every failure also fails on main5ad98adbin the same setup (suite-diff by test name: 0 only on this PR): 31 died = 29 split-wave/DXIL GPU tests that abort in dxil-spirv without #3707 (module::split 10, mask_exchange 5, lower_dxil 5, recomp 4, robustness 2, idioms 2, lower 1), hle::netoff 1, and the known serialize_root_signature hang (not run), 17 failed = Wine/RADV-specific (title_textures group 4, list_x 3, recomp 2, lower_dxil 2, and single ones in root_signature, driver_cache, descriptor_heap, device_x, round, fuzz); integration: gpu_compute_e2e died, e2e x2, frame_clock, gpu_two_pass_cache_e2e, pls_quota, tls_slot_zero fail on main tootitle run: retail title, RX 7800 XT (RADV, Wine), 480 s run, past the loading screen into the in-engine intro cutscenes / prologue (world rendering from 131 s: first 2 s window with >= 1000 draws), 350 s there, no crash, no device removal, 0 amdgpu page faults or ring timeouts, 0.80 presents/s there (2724 frames in total). Run on this merge result + #3707 (
912ff558) on top: main5ad98adbalone aborts ~3 s in under vkd3d-proton (dxil-spirv, the helper functions #3707 inlines), so did this merge without it (exit 0x3 at ~3.3 s). main5ad98adb+ #3707 the same way: 359 s there, no crash, 0.59 presents/s, 2182 frames.review: read the whole diff (+200/-10). detile_volume_into writes each row straight into the upload footprint in runs of effective_run() elements, shortened for tail-mip origins ((x + origin.0) % run), instead of detiling into a temporary Vec and copying rows. In fill_hashed the destination slice is pitch * height * depth, which is exactly what plan_item reserved for a volume piece (rect = 0..width, row_bytes = width * bpe checked against GetCopyableFootprints), and the asserts (pitch >= row, last row fits) hold for it. Short sources: a run that runs past mem copies the whole elements left and zero-fills the rest, same bytes as the old per-element path (old: fresh zeroed Vec), and row padding stays untouched. The new test compares against per-element addressing for modes 0, 5, 9, 24 (with base_xor) and truncated/empty sources; other 3D swizzle modes rely on element_at_z being contiguous within effective_run() and are not covered by the test. with_upload_pair is #[cfg(test)]. No findings.
performance: removes a temporary allocation + one full copy per uploaded volume mip; cannot cost frame time or memory. Title run 0.80 presents/s vs 0.59 on the base (noise at this rate).
verdict: safe to merge
hardware / tool and model: AMD Radeon RX 7800 XT (RADV NAVI32, Mesa 26.3.1), Ryzen 7 7800X3D, NixOS (Linux 7.3.5) with Wine staging 11.21 + vkd3d-proton 3.1 / Claude Code, claude-opus-5-5
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-03T02:19:41Z.
merge-check
base:
078358a058head:
a276a5617bmerge: clean
build: ok
tests: 3007 passed, 0 failed, 54 ignored; 28 skipped, the same as on main
review: 4 medium, 1 nit (below)
performance: 60 s smoke run: 1669 → 1681 frames (100 % of main), peak commit 17577 → 18074 MB, no device removal, no crash
title run: retail title on the RTX 5070 Ti (driver 621.14), into the world by scripted presses: 228 s there, 0 device removals, 0 crashes, 3 presents/s; run with
XCL_SKIP_CS=95cc13288a27a96e(the NVIDIA hang at the end of loading, #3541) and NVIDIA's 2048 MB shader heap (#2590)verdict: safe to merge: no blocking finding (the points below are medium or nits), the suite passes and the smoke run is clean
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5
In short: Detiles each volume mip straight into the pitched upload memory, copying runs of contiguous elements, instead of building a Vec and copying it row by row. Since the earlier merge-check it has added smoke blocks and a benchmark on a real write-combined upload heap, and by reading the output still matches the old path element for element. Nothing blocks; the oracle test still uses only the zero pipe config.
Medium
Nit
Checked and fine
How this was tested
078358a0, thencargo build --workspaceandcargo test --workspace --no-fail-fast -- --test-threads=4.scripts/smoke.ps1: 60 s of a retail title on main078358a0and on this merge; presents per 2 s at the end: 60 60 60.XCL_RUN_SECONDS=300and scripted A presses counted from the first frame (XCL_PRESS_BASE=frame, #3712) into the world from an existing save; time in the world is counted from the first in-world draw call to the end of the run.Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.