D3D12.X: check lazy texture level texels without detiling #3255
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3255"
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 Lakanya on 2026-11-29T01:28:28Z.
With
XCL_TEXTURE_LEVEL_PAGES=1,title_textures::upload_allcalledmap_levels_with_texels(&d.res, &subresources_in(d.src, &d.tex, d.pages.as_deref()))on every uploaded texture with lazy levels.subresources_inallocated heapVec<u8>buffers and single-threadedly detiled every mip level solely somap_levels_with_texelscould test!all_zero(&s.data)per level, then immediately discarded the detiled buffers beforetexture_upload::submitdetiled the same texture again.In a retail title (
2c508222) streaming into the 3D world, that single line accounted for ~13.6 s out of 16.6 s of texture upload time across 1,024 submits (~10.5 GB of redundant single-threaded detiling).What is in it
crates/xcl/src/gpu/tiling.rs: addChain::level_has_nonzeroandChain::volume_has_nonzero(word-at-a-time zero scan on the level's raw byte range, immediate return on full-block standalone levels with no padding, and zero-allocation in-place element scan for mip-tail, odd-sized, and 3D volume levels), plus unit testslevel_has_nonzero_matches_detile_across_mips_tails_and_paddingandvolume_has_nonzero_matches_detile_volume.crates/xcl/src/hle/d3d12x/title_textures.rs: addmap_levels_with_texels_inusinglevel_has_nonzero/volume_has_nonzeroand call it fromupload_allinstead ofmap_levels_with_texels(&d.res, &subresources_in(...)).Tested
cargo test --release -p xcl --lib -- level_has_nonzero volume_has_nonzero --nocapture: 2 passed, 0 failed, 0 ignored.cargo test --release -p xcl --lib -- gpu::tiling::tests --nocapture: 21 passed, 0 failed, 0 ignored.2c508222,XCL_DEVICE_TYPE=lockhart,XCL_TEXTURE_LEVEL_PAGES=1, 210 s in-world A/B):other active work(texture upload look time) dropped ~48% (19,713 ms->10,274 msover 48 s of 3D world;submit costtextures16.23->11.00 ms/submit, early streaming8.46->4.78 ms/submit), and sustained 3D FPS rose from1.48to2.27 FPS(0crashes,0device removals).Regression run
Base (
fa204595):PR head (
da008306):Not tested
cargo test --workspace(pre-existingend_title(0x80004005)inhle::lib tests).AI use
submit_cost/upload_all, implementedChain::level_has_nonzero,Chain::volume_has_nonzero,map_levels_with_texels_in, and unit tests, ran tests and smoke runs, and drafted this PR description.Imported from ivall/xcl. Originally posted by andrewDoing on 2026-11-29T01:36:31Z.
Paired native lazy-mip check on parent
fa204595a488c60c6c5f905244f0172072c9c2a9and headda008306ccefa1e79b8c2a58a037e6f8b749a2e1: a 1023×1021 RGBA8 texture with ten mip levels, swizzle mode 0x109, on GeForce RTX 5070 driver 616.92. Both revisions gave the same mapping decisions and byte-for-byte GPU readbacks through production refresh/upload.I identified padding by tiling an all-valid-texel bitmap over every level. D3D12 reported 64 tiles for mip 0: the padding marker alone did not allocate them, while the edge texel did. The second update also checks that one tiny mip can clear as a neighboring packed mip becomes nonzero.
One focused test passed per revision, zero skips. The synthetic allocation was manually marked pending for its second refresh. These are resource mapping counts and fenced texture readbacks; I did not measure detile CPU time, physical VRAM residency or title performance.
AI use: OpenAI Codex adapted the test fixture, ran the paired native checks and drafted this report.
Imported from ivall/xcl. Originally posted by Kalmarv on 2026-11-29T02:32:16Z.
merge-check
base:
fa204595a4head:
da008306ccmerge: clean (fast-forward: the head sits on main
fa204595; tested atda008306)build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 (XCL_DXC_DIR = DXC 1.9.2609) -> 2610 passed, 0 failed, 49 ignored; SKIPPED: 26, the usual set (21 no wave64 on this 32-lane GPU, 3 per-lane f16/f32 forms refused (#1426 semantics), 2 no heap windows). Both new tests ran and passed:
gpu::tiling::tests::level_has_nonzero_matches_detile_across_mips_tails_and_paddingandvolume_has_nonzero_matches_detile_volume.review: none blocking; whole diff read (
tiling.rs,title_textures.rs).Chain::level_has_nonzero/volume_has_nonzeroscan a level's tiled bytes in place, and they give the same answer as detiling it and then checking for all zeros. Tails, padding and thick-volume layers are covered, and the slice argument picks the same bytessubresources_inwould. The 1:1 fast path (a level whose tiled span is its texels) is correct.map_levels_with_texels_inis now the production path and only builds apresentlist; the oldmap_levels_with_texelsis test-only. Nits: (1) intiling.rs,all_zero_byteswas inserted under the tail ofChain's doc comment, so the last four lines of that doc (/// to mip 0; slices follow each other ...through... 909 of its 912 textures.) attach toall_zero_bytesand are missing fromChain; (2) intitle_textures.rsthe doc above the newmap_levels_from_presentstill talks about "its levels with texels insubs", but the function takespresent: Vec<u32>, and the now#[cfg(test)]map_levels_with_texelshas no doc of its own.performance: removes a detile into a fresh buffer for every lazy level checked before an upload; nothing measured beyond the title runs below. Title runs (release build of the head, scratch/fast-world.py fast profile, which runs with
XCL_TEXTURE_LEVEL_PAGES=1, so the lazy level path ran in all four; about 85 s in world each), PR against mainfa204595: exit 0 / 0 crashes / 0 device removals in all four; world entry 114.2 s and 92.6 s (PR) against 76.8 s and 99.7 s (main); peak commit 31,757 and 31,515 MB against 33,027 and 31,295 MB; 93 and 75 WARN lines against 86 and 90;failed_pipelines0 and no translation errors in all four. The level-pages counters match: 32,768 levels given pages in each run, with about 54,000 textures standing for about 22.4 GB holding 2,208-2,221 MB of pages (PR) against 2,016-2,364 MB (main), so the in-place check is not calling non-zero levels empty or the other way round. WARN kinds are the same apart from load-dependent ones ("running out of commit" in one main run, "ExecuteCommandLists took N ms in the driver" in one PR run, "waited N ms for a compute pipeline being built" in one main run). All runs show 0 fps in the world because the cache doesn't match the translator identity; world-entry and commit spread comes from cache contents and machine load.verdict: safe to merge
hardware / tool and model: NVIDIA GeForce RTX 5070 Ti 16 GB (driver 610.74, wave32 only), AMD Ryzen 9 9950X, Windows 11 build 26200; rustc 1.99.0, debug test profile, release build for the title runs, DXC 1.9.2609 via XCL_DXC_DIR. Claude Code, Claude Opus 5.5: build, suite, title runs and full-diff review; this report.
Imported from ivall/xcl. Originally posted by throny on 2026-11-29T09:01:23Z.
merge-check claim
head:
da008306ccImported from ivall/xcl. Originally posted by throny on 2026-11-29T09:20:33Z.
merge-check
base:
d8bd9a38head:
da008306ccmerge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2620 passed, 0 failed, 49 ignored (27 SKIPPED lines). Base alone at
d8bd9a38: 2618 passed, 0 failed, 49 ignored.review: no blocking finding. Which lazy levels get pages is now decided by scanning the tiled bytes in place instead of detiling every subresource; the argument that a zero byte range in the tiled form means zero texels holds from reading, and the new tiling tests compare the scan against detile across mip levels, the mip tail, padding and 3D. Small things: the new
all_zero_bytessits betweenChain's doc comment and its#[derive], so that long comment now documents the helper; main already hastitle_textures::all_zero, which does the same; and the production callermap_levels_with_texels_inhas no test of its own (the existing vram test still calls the old function, now test-only).performance: not measured here.
verdict: safe to merge
hardware / tool and model: RTX 4080 16 GB (621.40), i9-12900K, Windows 11 26300, Rust 1.100.0, debug. Claude Code; merge, build and suite run by Claude Fable 5.2, diff review by Claude Opus 5.5 (every hunk read; nothing run on the GPU beyond the suite).