D3D12.X: check lazy texture level texels without detiling #3255

Merged
Lakanya merged 1 commit from upstream-pr/3255 into main 2026-11-29 12:20:46 +00:00
Lakanya commented 2026-11-29 01:28:28 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Lakanya on 2026-11-29T01:28:28Z.


With XCL_TEXTURE_LEVEL_PAGES=1, title_textures::upload_all called map_levels_with_texels(&d.res, &subresources_in(d.src, &d.tex, d.pages.as_deref())) on every uploaded texture with lazy levels. subresources_in allocated heap Vec<u8> buffers and single-threadedly detiled every mip level solely so map_levels_with_texels could test !all_zero(&s.data) per level, then immediately discarded the detiled buffers before texture_upload::submit detiled 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: add Chain::level_has_nonzero and Chain::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 tests level_has_nonzero_matches_detile_across_mips_tails_and_padding and volume_has_nonzero_matches_detile_volume.
  • crates/xcl/src/hle/d3d12x/title_textures.rs: add map_levels_with_texels_in using level_has_nonzero / volume_has_nonzero and call it from upload_all instead of map_levels_with_texels(&d.res, &subresources_in(...)).

Tested

  • Hardware: Windows 11 Pro 26300 x64, NVIDIA GeForce RTX 5070 Laptop GPU (8 GB, driver 617.71).
  • 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.
  • Retail title (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 ms over 48 s of 3D world; submit cost textures 16.23 -> 11.00 ms/submit, early streaming 8.46 -> 4.78 ms/submit), and sustained 3D FPS rose from 1.48 to 2.27 FPS (0 crashes, 0 device removals).

Regression run

Base (fa204595):

xcl-smoke v1
commit: fa204595a488c60c6c5f905244f0172072c9c2a9
gpu: NVIDIA GeForce RTX 5070 Laptop GPU
title: 2c508222
seconds: 60
exit: 0x0
frames shown: 1576 (PresentX 1576)
presents per 2 s (last 3): 60 60 61
device removals: 0
crashes: 0
peak commit: 12877 MB

PR head (da008306):

xcl-smoke v1
commit: da008306ccefa1e79b8c2a58a037e6f8b749a2e1
gpu: NVIDIA GeForce RTX 5070 Laptop GPU
title: 2c508222
seconds: 60
exit: 0x0
frames shown: 1516 (PresentX 1516)
presents per 2 s (last 3): 61 60 60
device removals: 0
crashes: 0
peak commit: 13126 MB

Not tested

  • macOS / Linux (crate does not build on non-Windows).
  • AMD / Intel GPUs.
  • Full single-process cargo test --workspace (pre-existing end_title(0x80004005) in hle:: lib tests).

AI use

  • Antigravity, Gemini 4 Neon: profiled submit_cost / upload_all, implemented Chain::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.
<!-- greyfinch-sync:ivall/xcl:issue:5546433436 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3255). Originally posted by [Lakanya](https://github.com/Lakanya) on 2026-11-29T01:28:28Z. --- With `XCL_TEXTURE_LEVEL_PAGES=1`, `title_textures::upload_all` called `map_levels_with_texels(&d.res, &subresources_in(d.src, &d.tex, d.pages.as_deref()))` on every uploaded texture with lazy levels. `subresources_in` allocated heap `Vec<u8>` buffers and single-threadedly detiled every mip level solely so `map_levels_with_texels` could test `!all_zero(&s.data)` per level, then immediately discarded the detiled buffers before `texture_upload::submit` detiled 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`: add `Chain::level_has_nonzero` and `Chain::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 tests `level_has_nonzero_matches_detile_across_mips_tails_and_padding` and `volume_has_nonzero_matches_detile_volume`. - `crates/xcl/src/hle/d3d12x/title_textures.rs`: add `map_levels_with_texels_in` using `level_has_nonzero` / `volume_has_nonzero` and call it from `upload_all` instead of `map_levels_with_texels(&d.res, &subresources_in(...))`. **Tested** - Hardware: Windows 11 Pro 26300 x64, NVIDIA GeForce RTX 5070 Laptop GPU (8 GB, driver 617.71). - `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. - Retail title (`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 ms` over 48 s of 3D world; `submit cost` `textures` `16.23` -> `11.00 ms/submit`, early streaming `8.46` -> `4.78 ms/submit`), and sustained 3D FPS rose from `1.48` to `2.27 FPS` (`0` crashes, `0` device removals). **Regression run** Base (`fa204595`): ``` xcl-smoke v1 commit: fa204595a488c60c6c5f905244f0172072c9c2a9 gpu: NVIDIA GeForce RTX 5070 Laptop GPU title: 2c508222 seconds: 60 exit: 0x0 frames shown: 1576 (PresentX 1576) presents per 2 s (last 3): 60 60 61 device removals: 0 crashes: 0 peak commit: 12877 MB ``` PR head (`da008306`): ``` xcl-smoke v1 commit: da008306ccefa1e79b8c2a58a037e6f8b749a2e1 gpu: NVIDIA GeForce RTX 5070 Laptop GPU title: 2c508222 seconds: 60 exit: 0x0 frames shown: 1516 (PresentX 1516) presents per 2 s (last 3): 61 60 60 device removals: 0 crashes: 0 peak commit: 13126 MB ``` **Not tested** - macOS / Linux (crate does not build on non-Windows). - AMD / Intel GPUs. - Full single-process `cargo test --workspace` (pre-existing `end_title(0x80004005)` in `hle::` lib tests). **AI use** - Antigravity, Gemini 4 Neon: profiled `submit_cost` / `upload_all`, implemented `Chain::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.
andrewDoing commented 2026-11-29 01:36:31 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by andrewDoing on 2026-11-29T01:36:31Z.


Paired native lazy-mip check on parent fa204595a488c60c6c5f905244f0172072c9c2a9 and head da008306ccefa1e79b8c2a58a037e6f8b749a2e1: 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.

Guest memory when refreshed Mapped D3D12 64 KiB tiles GPU readback on both revisions
Nonzero byte only in top-level padding; mip 9 has one RGBA texel 2 Mip 0 all zero; mip 9 = 01 02 03 04; mip 8 all zero
Keep padding; set bottom-right valid texel of mip 0; clear mip 9; set bottom-right texel of mip 8 66 Mip 0 entirely zero except its last texel 0b 16 21 2c; mip 8 entirely zero except its last texel 09 08 07 06; mip 9 zero

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.

<!-- greyfinch-sync:ivall/xcl:comment:7248895339 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3255#issuecomment-7248895339). Originally posted by [andrewDoing](https://github.com/andrewDoing) on 2026-11-29T01:36:31Z. --- Paired native lazy-mip check on parent `fa204595a488c60c6c5f905244f0172072c9c2a9` and head `da008306ccefa1e79b8c2a58a037e6f8b749a2e1`: 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. | Guest memory when refreshed | Mapped D3D12 64 KiB tiles | GPU readback on both revisions | |---|---:|---| | Nonzero byte only in top-level padding; mip 9 has one RGBA texel | 2 | Mip 0 all zero; mip 9 = 01 02 03 04; mip 8 all zero | | Keep padding; set bottom-right valid texel of mip 0; clear mip 9; set bottom-right texel of mip 8 | 66 | Mip 0 entirely zero except its last texel 0b 16 21 2c; mip 8 entirely zero except its last texel 09 08 07 06; mip 9 zero | 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.
Kalmarv commented 2026-11-29 02:32:16 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Kalmarv on 2026-11-29T02:32:16Z.


merge-check
base: fa204595a4
head: da008306cc
merge: clean (fast-forward: the head sits on main fa204595; tested at da008306)
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_padding and volume_has_nonzero_matches_detile_volume.
review: none blocking; whole diff read (tiling.rs, title_textures.rs). Chain::level_has_nonzero / volume_has_nonzero scan 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 bytes subresources_in would. The 1:1 fast path (a level whose tiled span is its texels) is correct. map_levels_with_texels_in is now the production path and only builds a present list; the old map_levels_with_texels is test-only. Nits: (1) in tiling.rs, all_zero_bytes was inserted under the tail of Chain'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 to all_zero_bytes and are missing from Chain; (2) in title_textures.rs the doc above the new map_levels_from_present still talks about "its levels with texels in subs", but the function takes present: Vec<u32>, and the now #[cfg(test)] map_levels_with_texels has 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 main fa204595: 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_pipelines 0 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.

<!-- greyfinch-sync:ivall/xcl:comment:7249489719 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3255#issuecomment-7249489719). Originally posted by [Kalmarv](https://github.com/Kalmarv) on 2026-11-29T02:32:16Z. --- merge-check base: fa204595a488c60c6c5f905244f0172072c9c2a9 head: da008306ccefa1e79b8c2a58a037e6f8b749a2e1 merge: clean (fast-forward: the head sits on main fa204595; tested at da008306) 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_padding` and `volume_has_nonzero_matches_detile_volume`. review: none blocking; whole diff read (`tiling.rs`, `title_textures.rs`). `Chain::level_has_nonzero` / `volume_has_nonzero` scan 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 bytes `subresources_in` would. The 1:1 fast path (a level whose tiled span is its texels) is correct. `map_levels_with_texels_in` is now the production path and only builds a `present` list; the old `map_levels_with_texels` is test-only. Nits: (1) in `tiling.rs`, `all_zero_bytes` was inserted under the tail of `Chain`'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 to `all_zero_bytes` and are missing from `Chain`; (2) in `title_textures.rs` the doc above the new `map_levels_from_present` still talks about "its levels with texels in `subs`", but the function takes `present: Vec<u32>`, and the now `#[cfg(test)]` `map_levels_with_texels` has 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 main fa204595: 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_pipelines` 0 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.
throny commented 2026-11-29 09:01:23 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by throny on 2026-11-29T09:01:23Z.


merge-check claim
head: da008306cc

<!-- greyfinch-sync:ivall/xcl:comment:7253483389 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3255#issuecomment-7253483389). Originally posted by [throny](https://github.com/throny) on 2026-11-29T09:01:23Z. --- merge-check claim head: da008306ccefa1e79b8c2a58a037e6f8b749a2e1
throny commented 2026-11-29 09:20:33 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by throny on 2026-11-29T09:20:33Z.


merge-check
base: d8bd9a38
head: da008306cc
merge: 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_bytes sits between Chain's doc comment and its #[derive], so that long comment now documents the helper; main already has title_textures::all_zero, which does the same; and the production caller map_levels_with_texels_in has 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).

<!-- greyfinch-sync:ivall/xcl:comment:7253698360 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3255#issuecomment-7253698360). Originally posted by [throny](https://github.com/throny) on 2026-11-29T09:20:33Z. --- merge-check base: d8bd9a38 head: da008306ccefa1e79b8c2a58a037e6f8b749a2e1 merge: 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_bytes` sits between `Chain`'s doc comment and its `#[derive]`, so that long comment now documents the helper; main already has `title_textures::all_zero`, which does the same; and the production caller `map_levels_with_texels_in` has 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).
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!3255
No description provided.