Skip to content

Title textures: detile levels a row at a time, not element by element - #458

Closed
dns54 wants to merge 1 commit into
xcl-dev:mainfrom
dns54:perf/row-detile
Closed

dns54 wants to merge 1 commit into
xcl-dev:mainfrom
dns54:perf/row-detile

Conversation

@dns54

@dns54 dns54 commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Every upload of a title texture kept in step with its memory detiles each level on the CPU (title_textures::refresh → subresources → Chain::detile_level), and detile_level computed offset_z for every element: about a dozen divisions and remainders, six table lookups and a bounds-checked copy of a runtime-sized element. The retail title's intro video rewrites 3840×2160 R8 linear planes every frame; each took ~255 ms to detile, so the render thread spent ~2 s of every 2 s there and the video ran at ~1 fps (found with XCL_THREAD_DUMP_AT: the render thread was in Layout::offset_z in every dump).

offset_z(x, y, z) now splits into what x gives (block column + in-block bits, a table per level) and what y and z give (once per row); the two cannot overlap, so an element is a lookup and an XOR. The copy is monomorphized by element size, and a row whose columns follow each other (linear) is one copy. Mip-tail levels and 3D textures take the same path. All callers of detile_level / detile_volume get it (title_textures, gpu/texture.rs, hle/xg.rs); the tile direction and offset_z are unchanged.

The same bottleneck was measured in the profiling comment on #283 (RX 7800 XT); #334 did the linear case and was closed by its author. This is a separate implementation that also covers tiled, tail and 3D levels.

What is in it

  • Title textures: detile levels a row at a time, not element by element – crates/xcl/src/gpu/tiling.rs (Layout::columns / row / copy_row, Chain::detile_level / detile_volume), and a test that compares both with the element-by-element address (element_at, element_at_z) for every 2D mode including linear, every element size, 3 pipe configurations, with and without a base swizzle, a source cut short, two array slices, every level (tail included), and the 3D modes.

Tested

  • AMD Radeon RX 5700 XT 8 GB (RDNA1, no mesh shaders), driver 32.0.21045.29003; Ryzen 5 2600, 16 GB; Windows 11 Pro 10.0.26300; rustc 1.100.0 MSVC; debug for tests, release for the game
  • cargo test --workspace -- --test-threads=4: 627 passed, 4 failed, 21 ignored. The 4 failures fail on main 2b4bb43 on this card too (the change stashed): gpu_nonfused_mad_and_mac_prevent_fma_contraction, placed_title_textures_share_vram_and_preserve_pixels, transitions_apply_when_their_list_is_submitted, d32s8_targets_take_their_own_size_of_video_memory
  • SKIPPED: gpu_geometry_mode_es_gs_strip, gpu_mesh_mode_two_passes (no mesh shaders)
  • cargo test -p xcl --lib tiling: 12 passed
  • Retail title, release, a local timer around subresources (not in the PR): 3840×2160 R8 linear 255 → 5 ms; 1280×720 4-byte SW_256B_D, 5 mips 40 → 4 ms; 75 s run 379 → 1442 frames

Regression run

xcl-smoke v1
commit: 2b4bb431e4f44803bc1d2937fdf1cfbdb1b03bea
gpu: AMD Radeon RX 5700 XT
title: 2c508222
seconds: 60
exit: 0x0
frames shown: 339 (PresentX 339)
presents per 2 s (last 3): 3 2 2
device removals: 0
crashes: 0
peak commit: 15627 MB
xcl-smoke v1
commit: a173fe0775bae4b48e7c83df6326a4ca4bb59cc7
gpu: AMD Radeon RX 5700 XT
title: 2c508222
seconds: 60
exit: 0x0
frames shown: 1019 (PresentX 1019)
presents per 2 s (last 3): 40 39 40
device removals: 0
crashes: 0
peak commit: 15665 MB

Not tested

  • NVIDIA, Intel, RDNA2/3/4, wave32-only GPUs, mesh-shader paths
  • 3D textures and array slices in a real title (unit test only)
  • Audio/video sync of the intro video: it now plays at speed, and audio drifts against it; not looked at here

AI use

  • Claude Code with Claude Opus 5.5: profiled the run (thread dumps, timers), wrote the code, the test, the commit message and this description, and ran the tests and smoke runs above.

🤖 Generated with Claude Code

Every upload of a title texture kept in step with its memory detiles each
level on the CPU (title_textures::refresh -> subresources ->
Chain::detile_level). That computed offset_z for every element: about a
dozen divisions and remainders by the block size and table lengths, six
table lookups and a bounds-checked copy of a runtime-sized element. A title that writes a texture every frame
pays it every frame: GTA VI's intro video writes 3840x2160 R8 linear
planes, and each one took ~255 ms to detile (~32 MB/s), so the render
thread spent ~2 s of every 2 s in it and the video ran at ~1 fps.

offset_z(x, y, z) splits into a part x gives (block column and in-block
bits, one table per level) and a part y and z give (once per row); the
two never overlap, so an element costs a lookup and an XOR. The copy is
monomorphized by element size, and a row whose columns follow each other
(linear layouts) is one copy. Levels in the mip tail and 3D textures go
the same way.

Measured on an RX 5700 XT / Ryzen 5 2600 (release, local timer around
subresources): 3840x2160 R8 linear 255 -> 5 ms, 1280x720 4-byte
SW_256B_D 5 mips 40 -> 4 ms; GTA VI frames in 75 s 379 -> 1442, the video at
40-60 presents per 2 s instead of 2.

The same idea was measured in the profiling comment on xcl-dev#283 (RX 7800 XT,
8 -> 60 presents per 2 s during the video); xcl-dev#334 did the linear case and
was closed by its author.

Assisted-by: Claude Code (Claude Opus 5.5)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014iLwwhKe7L6XShVmjgRRDr
@PHeitor1

Copy link
Copy Markdown

Tested a173fe0 merged onto main 2997c9a.

RTX 5060 Ti 8 GB (Blackwell, 32-lane waves), NVIDIA 621.24, Ryzen 5 5600X, Windows 11 Pro 26300 (native, Graphics Tools + XGameRuntime installed, so the debug-layer tests run), rustc 1.100.0 MSVC, debug, cargo test --workspace --no-fail-fast -- --test-threads=4, no XCL_SAMPLE_*.

Pass: 677 passed, 0 failed, 41 ignored. SKIPPED: only the 2 no wave64 tests (gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware). Build clean.

Run and written with Claude Code (Claude Opus 5.5).

@Chrysana

Chrysana commented Nov 24, 2026 •

Copy link
Copy Markdown

Test report for #458 at a173fe0 on AMD RDNA4 (the "Not tested" item), with the retail title reaching the intro video.

Setup: AMD Radeon RX 9070 XT 16 GB, driver 32.0.32015.2008, Ryzen 7 9800X3D, 31 GB RAM, Windows 11 25H2 build 26200.9974, rustc 1.100.0 x86_64-pc-windows-msvc, DXC 1.9.2602.17. Retail title 1.0.2.1. Debug build for the tests, release build for the runs.

Tests: cargo test --workspace --no-fail-fast -- --test-threads=4 at a173fe0: 679 passed, 0 failed, 41 ignored. The 4 failures listed for the RX 5700 XT don't occur here. SKIPPED: the two debug-layer tests (the D3D12 debug layer isn't installed here).

Title runs: scripts/smoke.ps1 -Game <folder> -Seconds 60 with XCL_PRESS_A_AT=14,17,21, two rounds each, interleaved with main, #451 and #440, same saved state. Every run reaches the Bink intro.

build frames, round 1 / round 2 last 20 s
main a6f5f7a 489 / 497 ~5.5 fps
#458 at a173fe0 (base 2b4bb43) 1082 / 1085 ~12 fps; 30 fps until ~38 s, then 12
#458 merged onto a6f5f7a (local merge 66d0ca5, not pushed) 1418 / 1470 30 fps

The drop at ~38 s happens on the PR's own base and goes away when it's merged onto current main. So it comes from one of the 15 commits main gained since 2b4bb43, not from this change. A rebase onto main should be enough. Peak commit was 15868 / 15747 MB at the head and 15920 MB merged onto main (main: 15824 / 15815 MB). No device removal or crash in any run.

Regression run (round 1). The PR's block is from its head, whose base is older than this main:

main:

xcl-smoke v1
commit: a6f5f7a74cc620c1f88a9e3669a633d10c3c8212
gpu: AMD Radeon RX 9070 XT
title: retail-title
seconds: 60
exit: 0x0
frames shown: 489 (PresentX 490)
presents per 2 s (last 3): 10 12 10
device removals: 0
crashes: 0
peak commit: 15824 MB

PR:

xcl-smoke v1
commit: a173fe0775bae4b48e7c83df6326a4ca4bb59cc7
gpu: AMD Radeon RX 9070 XT
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1082 (PresentX 1082)
presents per 2 s (last 3): 24 24 25
device removals: 0
crashes: 0
peak commit: 15868 MB

Not tested: which of the 15 commits makes the difference; audio/video sync; gameplay past the video.

AI use: Claude Code with Claude Opus 5.5 built the commits, made the local merge, ran the tests and the title runs, and wrote this report. The runs were made on my machine.

@xstraok

xstraok commented Nov 24, 2026

Copy link
Copy Markdown

Test report for a173fe0, on Linux (Wine), RDNA4: the stretch of slow frames after the first menus is gone.

Setup: main a6f5f7a + #257 (Linux kit, merged locally), release, x86_64-pc-windows-gnu; with and without this PR's diff. RX 9060 XT (RADV, Mesa 26.2.6), Ryzen 5 7600, 32 GB, Arch Linux, kernel 7.2.15, Proton Experimental 11.0 Wine, vkd3d-proton v3.1 + #257's patch. GTA VI 1.0.2.1, XCL_NETWORK=0 XCL_ACTIVITY=1 XCL_COHERENT_MB=512, A pressed by hand at the first prompt (settings already saved, so the title goes straight to its loading screen).

without with a173fe0
A pressed ~38 s 38.9 s
presents per 2 s, 46–74 s 10–13 44–60
world loading starts ~162 s ~74 s

Unit tests under Wine: cargo test --release --target x86_64-pc-windows-gnu -p xcl --lib tiling: 12 passed, 0 failed, 0 ignored.

Not this PR: both runs end in a GPU page fault (SQC (data), permission fault) and 0x887a0005 about 65–75 s after world loading starts; the same happens without the PR, it only gets there sooner.

Not tested: Windows, the whole workspace suite, NVIDIA.

Measured and written with Claude Code (Claude Opus 5.5).

@dns54

dns54 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Closing: superseded by #451 (merged), which detiles 2D levels a row at a time and copies linear rows whole, the same change as this PR's first commit. The in-place read from this branch's second commit will come as its own PR, rebased onto main, once it is re-measured there.

@crosettiremi

Copy link
Copy Markdown

Tested a173fe0 on an RX 7900 XT (driver 32.0.32029.2010), Ryzen 5 5600X, Windows 11 build 26100 and Rust 1.100.0. The release build used DXC from Windows SDK 10.0.26100.0. I applied the PR to a local a6f5f7a-based stack containing #150, #208, #273, #473, the sparse scan change from #203, #486 and #508, along with local startup and test-input fixes.

  • cargo test --locked --workspace -- --test-threads=4 passed 690 tests with 41 ignored, including row_detile_matches_the_element_address.
  • Offline retail 1.0.2.1, warm caches and a saved setup profile. A at 37 seconds advanced Player 1. The intro averaged 28.5 FPS over 300 presents and world streaming began around 54 seconds. An earlier run before this PR showed about 4–5 FPS during the intro with a first-run profile, so the timings are from different startup routes.
  • The game stayed on the world-loading screen and exited at 172.887 seconds on 0xc0000005 in a VCRUNTIME140.dll read called by title_textures::refresh. There were 1,847 presents, zero failed pipelines and zero device removals. Dumps at 95 and 145 seconds also showed the title thread constructing coordinate tables in Layout::from_bits, the path addressed by Textures: a layout's high-coordinate tables hold one period, not 65536 entries #435.

AI disclosure: Codex ran the diagnostics and prepared this report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants