Detile title textures faster: copy contiguous runs on the CPU, detile on the GPU #1511

Open
opened 2026-11-26 04:55:59 +00:00 by github-bot · 1 comment
Owner

@⁠oishigeso on GitHub · 2026-11-24 17:09 UTC · original

Problem. A retail title creates thousands of tiled textures during loading, and XCL detiles each one on the CPU (tiling::detile_level), element by element, on the thread that uploads them. On the console pipe config an RGBA8 2048×2048 texture takes ~22 ms.

Plan, two PRs:

  1. detile_level copies contiguous runs at once (16 B in the swizzled modes) instead of one element at a time: 22 ms → 10 ms for that texture, ~10 % for BC. Small, CPU only.
  2. A compute shader detiles on the GPU: the tiled bytes and the layout's tables go to the upload buffer as they are, a cs_6_0 program writes each subresource's rows into the uploader's scratch buffer at its GetCopyableFootprints place, and the copies into the texture read from there. Same formula as Layout::offset_z. The CPU path stays for XCL_GPU_DETILE=0, no DXC or pipeline, a texture the plan cannot take, and frame tracing. A test reads 78 textures (every 2D mode × element size, mips, slices, cut-short bytes, 3D) back byte-identical against the CPU path.

Earlier detile work: #451 and #602 (merged) sped up other parts; #474 (closed). I found no open PR doing either of these. Does this fit, or would you rather take only the first? The PRs are open as drafts (PRLIST).

Written with Claude Code (Claude Opus 5.5).

**@⁠oishigeso** on GitHub · 2026-11-24 17:09 UTC · [original](https://github.com/xcl-dev/xcl/issues/1511) **Problem.** A retail title creates thousands of tiled textures during loading, and XCL detiles each one on the CPU (`tiling::detile_level`), element by element, on the thread that uploads them. On the console pipe config an RGBA8 2048×2048 texture takes ~22 ms. **Plan**, two PRs: 1. `detile_level` copies contiguous runs at once (16 B in the swizzled modes) instead of one element at a time: 22 ms → 10 ms for that texture, ~10 % for BC. Small, CPU only. 2. A compute shader detiles on the GPU: the tiled bytes and the layout's tables go to the upload buffer as they are, a `cs_6_0` program writes each subresource's rows into the uploader's scratch buffer at its `GetCopyableFootprints` place, and the copies into the texture read from there. Same formula as `Layout::offset_z`. The CPU path stays for `XCL_GPU_DETILE=0`, no DXC or pipeline, a texture the plan cannot take, and frame tracing. A test reads 78 textures (every 2D mode × element size, mips, slices, cut-short bytes, 3D) back byte-identical against the CPU path. Earlier detile work: #451 and #602 (merged) sped up other parts; #474 (closed). I found no open PR doing either of these. Does this fit, or would you rather take only the first? The PRs are open as drafts (PRLIST). Written with Claude Code (Claude Opus 5.5).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:56:00 +00:00
Author
Owner

@⁠humsterbumster on GitHub · 2026-11-26 14:26 UTC · original

A detile of a title texture read unmapped console memory and ended a run, with the fault inside the copy rather than at a bounds check.

unhandled exception 0xc0000005 in msvcrt.dll+0xa4fb (read at address 0x769000000)
rax=0x1e4c85e70 rbx=0x0 rcx=0x1e4c85e70 rdx=0x769000000 rsi=0x769000000 rdi=0x1e4c85e70 rbp=0x0
r8=0x0 r9=0x0 r10=0x680 r11=0x10 r12=0x0 r13=0x68 r14=0x1e2957208 r15=0x1000 rsp=0x1e5eafa88
on the stack: xcl.exe+0x304bb7, xcl.exe+0x8b50f0, xcl.exe+0x250997, xcl.exe+0x19bf30, xcl.exe+0xec84e, xcl.exe+0x880500

addr2line on the same build (main b49be18 plus local changes, x86_64-pc-windows-gnu, release with debuginfo) resolves it to

<[u8]>::copy_from_slice
  <xcl::gpu::tiling::Chain>::detile_level            crates/xcl/src/gpu/tiling.rs:464
  xcl::hle::d3d12x::title_textures::subresources     crates/xcl/src/hle/d3d12x/title_textures.rs:1480

so the source of the copy - the title's own memory - was not mapped, and the address is page-aligned (0x769000000, r15=0x1000), i.e. it faulted on the first page. The read reaches detile_level through title_bytes, which borrows the title's memory when gpu::shader::readable(at, len) holds and otherwise copies page by page with read_committed. Both have a shortcut that skips a per-region walk:

  • shader::readable first asks resident_and_readable, which uses K32QueryWorkingSetEx for up to 16 pages and checks the working set rather than the commit state;
  • read_committed first asks Uma::in_committed_window(p, len), which is is_committed(p) && window_of(p + len - 1) == window_of(p) - both ends in one committed window, not every page between them committed.

Environment: Arch kernel 7.3.5, Wine 11, vkd3d-proton 3.2.0 ec20719, RTX 5090, XCL_DEVICE_TYPE=lockhart XCL_TEXTURE_LEVEL_PAGES=1, 1080p, retail title 1.0.2.1. It happened at 148 s, on the start screen (60 presents, 660 draws a frame), right after a texture at 0xb87a07000 lies in a GPU view of the title's CPU memory: kept in step with 0x787a07000 (512 so far); a run of the same binary and environment went on to 12 minutes of world loading without it and then lost the device, which is #1452. One occurrence, so I am not claiming a definite defect of the level pages - but if in_committed_window is what lets read_committed skip VirtualQuery, a texel range of a level-mapped texture is exactly the case where "both ends in one window" and "every page committed" differ.

**@⁠humsterbumster** on GitHub · 2026-11-26 14:26 UTC · [original](https://github.com/xcl-dev/xcl/issues/1511#issuecomment-7194830909) A detile of a title texture read unmapped console memory and ended a run, with the fault inside the copy rather than at a bounds check. ``` unhandled exception 0xc0000005 in msvcrt.dll+0xa4fb (read at address 0x769000000) rax=0x1e4c85e70 rbx=0x0 rcx=0x1e4c85e70 rdx=0x769000000 rsi=0x769000000 rdi=0x1e4c85e70 rbp=0x0 r8=0x0 r9=0x0 r10=0x680 r11=0x10 r12=0x0 r13=0x68 r14=0x1e2957208 r15=0x1000 rsp=0x1e5eafa88 on the stack: xcl.exe+0x304bb7, xcl.exe+0x8b50f0, xcl.exe+0x250997, xcl.exe+0x19bf30, xcl.exe+0xec84e, xcl.exe+0x880500 ``` `addr2line` on the same build (`main` `b49be18` plus local changes, x86_64-pc-windows-gnu, release with debuginfo) resolves it to ``` <[u8]>::copy_from_slice <xcl::gpu::tiling::Chain>::detile_level crates/xcl/src/gpu/tiling.rs:464 xcl::hle::d3d12x::title_textures::subresources crates/xcl/src/hle/d3d12x/title_textures.rs:1480 ``` so the source of the copy - the title's own memory - was not mapped, and the address is page-aligned (`0x769000000`, `r15=0x1000`), i.e. it faulted on the first page. The read reaches `detile_level` through `title_bytes`, which borrows the title's memory when `gpu::shader::readable(at, len)` holds and otherwise copies page by page with `read_committed`. Both have a shortcut that skips a per-region walk: - `shader::readable` first asks `resident_and_readable`, which uses `K32QueryWorkingSetEx` for up to 16 pages and checks the working set rather than the commit state; - `read_committed` first asks `Uma::in_committed_window(p, len)`, which is `is_committed(p) && window_of(p + len - 1) == window_of(p)` - both ends in one committed window, not every page between them committed. Environment: Arch kernel 7.3.5, Wine 11, vkd3d-proton 3.2.0 `ec20719`, RTX 5090, `XCL_DEVICE_TYPE=lockhart XCL_TEXTURE_LEVEL_PAGES=1`, 1080p, retail title 1.0.2.1. It happened at 148 s, on the start screen (60 presents, 660 draws a frame), right after `a texture at 0xb87a07000 lies in a GPU view of the title's CPU memory: kept in step with 0x787a07000 (512 so far)`; a run of the same binary and environment went on to 12 minutes of world loading without it and then lost the device, which is #1452. One occurrence, so I am not claiming a definite defect of the level pages - but if `in_committed_window` is what lets `read_committed` skip `VirtualQuery`, a texel range of a level-mapped texture is exactly the case where "both ends in one window" and "every page committed" differ.
This discussion has been locked. Commenting is limited to contributors.
No description provided.