Title textures: detile and hash the title's memory in place, not a copy #602

Manually merged
github merged 1 commit from gh-pr/602/head into gh-pr/602/base 2026-11-26 04:26:49 +00:00
Owner

@⁠dns54 on GitHub · 2026-11-24 02:19 UTC · original
dns54:perf/title-bytes-in-place → main · +37 −3 · 1 files · 1 commits · merged 2026-11-24 02:41 UTC

Before a title texture is hashed (unchanged_skip, #486) and detiled for an upload, title_textures copied its memory into a new zeroed buffer of its size (read_committed): a fresh allocation, its page faults and the copy, for every texture each time. The retail title's intro video re-uploads its 3840×2160 and 1920×1080 R8 planes several times a presented frame, and with #451 the copy was still the larger part of the time the render thread spends there. title_bytes now hands out the title's memory where it is when the whole range is readable (gpu::shader::readable), and the page-by-page copy as before when it is not.

What is in it

  • Title textures: detile and hash the title's memory in place, not a copy – crates/xcl/src/hle/d3d12x/title_textures.rs: title_bytes, used by the unchanged-content hash, the 2D slices and 3D textures in subresources; test title_bytes_are_used_in_place_when_all_are_readable (a committed page is used in place; a range with a reserved page is read, with the same bytes as read_committed).

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 --no-fail-fast -- --test-threads=4 at 3984bf1: 681 passed, 4 failed, 41 ignored. On main 9ce2070 on this card: 680 passed, the same 4 failed, 41 ignored: 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)
  • Retail title intro video, release, a local counter around the upload batches (not in the PR), main 9ce2070 → this PR: 39–41 → 60 presents per 2 s; hash + read + detile ~1.25 s for ~850 MB → ~0.6 s for ~1430 MB of every 2 s (1.47 → 0.42 ms per MB)

Regression run

xcl-smoke v1
commit: 9ce2070eccf436d7bd38601c90407da447df34f3
gpu: AMD Radeon RX 5700 XT
title: 2c508222
seconds: 60
exit: 0x0
frames shown: 1074 (PresentX 1074)
presents per 2 s (last 3): 48 54 60
device removals: 0
crashes: 0
peak commit: 15982 MB
xcl-smoke v1
commit: 3984bf1671233d03bfd7c92eaa01c2a443fdaf6f
gpu: AMD Radeon RX 5700 XT
title: 2c508222
seconds: 60
exit: 0x0
frames shown: 1258 (PresentX 1258)
presents per 2 s (last 3): 56 57 38
device removals: 0
crashes: 0
peak commit: 16755 MB

The last window of the PR's run (38) is the title loading its world after the video, which the main run reaches later.

Not tested

  • NVIDIA, Intel, RDNA2/3/4, wave32-only GPUs
  • 3D textures and array slices in a real title (the unit test only)
  • A title releasing a texture's memory while it is detiled: the detile now reads the memory for as long as the detile takes, where the copy read it for as long as the copy took
  • After the video, the world load on this 16 GB machine commits over 22 GB and pages; not looked at here

AI use

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

🤖 Generated with Claude Code

**@⁠dns54** on GitHub · 2026-11-24 02:19 UTC · [original](https://github.com/xcl-dev/xcl/pull/602) `dns54:perf/title-bytes-in-place` → `main` · +37 −3 · 1 files · 1 commits · merged 2026-11-24 02:41 UTC Before a title texture is hashed (`unchanged_skip`, #486) and detiled for an upload, `title_textures` copied its memory into a new zeroed buffer of its size (`read_committed`): a fresh allocation, its page faults and the copy, for every texture each time. The retail title's intro video re-uploads its 3840×2160 and 1920×1080 R8 planes several times a presented frame, and with #451 the copy was still the larger part of the time the render thread spends there. `title_bytes` now hands out the title's memory where it is when the whole range is readable (`gpu::shader::readable`), and the page-by-page copy as before when it is not. **What is in it** - `Title textures: detile and hash the title's memory in place, not a copy` – `crates/xcl/src/hle/d3d12x/title_textures.rs`: `title_bytes`, used by the unchanged-content hash, the 2D slices and 3D textures in `subresources`; test `title_bytes_are_used_in_place_when_all_are_readable` (a committed page is used in place; a range with a reserved page is read, with the same bytes as `read_committed`). **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 --no-fail-fast -- --test-threads=4` at 3984bf1: 681 passed, 4 failed, 41 ignored. On `main` 9ce2070 on this card: 680 passed, the same 4 failed, 41 ignored: `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) - Retail title intro video, release, a local counter around the upload batches (not in the PR), `main` 9ce2070 → this PR: 39–41 → 60 presents per 2 s; hash + read + detile ~1.25 s for ~850 MB → ~0.6 s for ~1430 MB of every 2 s (1.47 → 0.42 ms per MB) **Regression run** ``` xcl-smoke v1 commit: 9ce2070eccf436d7bd38601c90407da447df34f3 gpu: AMD Radeon RX 5700 XT title: 2c508222 seconds: 60 exit: 0x0 frames shown: 1074 (PresentX 1074) presents per 2 s (last 3): 48 54 60 device removals: 0 crashes: 0 peak commit: 15982 MB ``` ``` xcl-smoke v1 commit: 3984bf1671233d03bfd7c92eaa01c2a443fdaf6f gpu: AMD Radeon RX 5700 XT title: 2c508222 seconds: 60 exit: 0x0 frames shown: 1258 (PresentX 1258) presents per 2 s (last 3): 56 57 38 device removals: 0 crashes: 0 peak commit: 16755 MB ``` The last window of the PR's run (38) is the title loading its world after the video, which the `main` run reaches later. **Not tested** - NVIDIA, Intel, RDNA2/3/4, wave32-only GPUs - 3D textures and array slices in a real title (the unit test only) - A title releasing a texture's memory while it is detiled: the detile now reads the memory for as long as the detile takes, where the copy read it for as long as the copy took - After the video, the world load on this 16 GB machine commits over 22 GB and pages; not looked at here **AI use** - Claude Code with Claude Opus 5.5: profiled the run (thread dumps, counters), wrote the code, the test, the commit message and this description, and ran the tests and smoke runs above. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Before each upload of a title texture, and before hashing it to see whether
it changed, its memory was copied into a new zeroed buffer of its size
(read_committed). The copy, a fresh allocation and its page faults every
time, cost as much as the detile itself: GTA VI's intro video re-uploads
its 3840x2160 and 1920x1080 R8 planes several times a frame.

title_bytes now hands out the title's memory where it is when the whole
range is readable (gpu::shader::readable), and the page-by-page copy as
before when it is not. The 2D slices, 3D textures and the unchanged-content
hash take it.

Measured on an RX 5700 XT / Ryzen 5 2600 during the video (release, a
local counter around the upload batches, with a row-at-a-time detile like
the one #451 merged): reading and detiling 0.9 -> 0.4 s of every 2 s,
36 -> 54 presents per 2 s.

Assisted-by: Claude Code (Claude Opus 5.5)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:26:49 +00:00
github manually merged commit 3984bf1671 into gh-pr/602/base 2026-11-26 04:26:49 +00:00
Author
Owner

@⁠ryosen0 on GitHub · 2026-11-24 02:37 UTC · original

Tested 3984bf1 (on 9ce2070) on NVIDIA: RTX 3060 Ti 8 GB (wave32), Ryzen 7 9800X3D, driver 32.0.16.1742, Windows 11, release build.

  • cargo test -p xcl --lib -- --test-threads=1 title_textures: 10 passed, 0 failed — including title_bytes_are_used_in_place... and the GPU mirror/placement tests (serial; under --test-threads=4 that set hits the poisoned-lock contention documented on main in #516's report).
  • Retail run (GTA VI 1.0.2.1, XCL_NETWORK=0 XCL_ACTIVITY=1 XCL_RUN_SECONDS=120): clean exit, 3262 frames, steady 60 presents / 2 s at every 30 s sample through t=118 s — the intro's 4K/1080p R8 re-upload path this PR targets ran the whole window with no dip, no device removal.

The readable whole-range check before handing out the title's memory reads right: the page-by-page fallback keeps the old behaviour for a range with an unreadable page, so the fast path can't fault where the copy wouldn't.

Not tested: a range that straddles an unreadable page in a retail run (fallback exercised by the unit test only); no timing comparison against the copy path on this machine.

AI use: GPT-6.2 Astra (API model selector) in DSH ran the tests and the run and wrote this comment; the human contributor reviewed it.

**@⁠ryosen0** on GitHub · 2026-11-24 02:37 UTC · [original](https://github.com/xcl-dev/xcl/pull/602#issuecomment-7120327845) Tested `3984bf1` (on `9ce2070`) on NVIDIA: RTX 3060 Ti 8 GB (wave32), Ryzen 7 9800X3D, driver 32.0.16.1742, Windows 11, release build. - `cargo test -p xcl --lib -- --test-threads=1 title_textures`: **10 passed, 0 failed** — including `title_bytes_are_used_in_place...` and the GPU mirror/placement tests (serial; under `--test-threads=4` that set hits the poisoned-lock contention documented on main in #516's report). - Retail run (GTA VI 1.0.2.1, `XCL_NETWORK=0 XCL_ACTIVITY=1 XCL_RUN_SECONDS=120`): clean exit, **3262 frames, steady 60 presents / 2 s at every 30 s sample through t=118 s** — the intro's 4K/1080p R8 re-upload path this PR targets ran the whole window with no dip, no device removal. The `readable` whole-range check before handing out the title's memory reads right: the page-by-page fallback keeps the old behaviour for a range with an unreadable page, so the fast path can't fault where the copy wouldn't. Not tested: a range that straddles an unreadable page in a retail run (fallback exercised by the unit test only); no timing comparison against the copy path on this machine. AI use: GPT-6.2 Astra (API model selector) in DSH ran the tests and the run and wrote this comment; the human contributor reviewed it.
Author
Owner

@⁠grahamster2 on GitHub · 2026-11-24 03:08 UTC · original

Benchmark of 3984bf1 merged onto main 3db536e (clean merge). Result: no measurable difference on this machine, neither better nor worse.

Setup: RTX 3080 10 GB (driver 32.0.16.1088), Ryzen 5 7600X, 32 GB, Windows 11 26200, release builds. Retail title, XCL_NETWORK=0, A at 14/17/21/25/31 s, 180 s runs. Both caches were warmed with one run per build first (not counted); then 2 measured runs per build. main = 3db536e (#451 and #435 in).

main run 1 / 2 main + #602 run 1 / 2
presents/s, intro video (4–16 s) 22.5 / 22.5 22.5 / 22.0
presents/s, menus + loading (16–44 s) 30.0 / 29.9 30.0 / 29.9
streaming starts 44.0 s / 44.1 s 44.0 s / 44.0 s
presents/s while streaming (44–84 s) 6.0 / 5.5 5.5 / 5.2
peak commit 30.1 / 30.3 GB 30.2 / 30.0 GB
peak local video memory 14.3 / 14.1 GB 14.3 / 14.0 GB
end #232 watchdog (+0x23cf683) at 100.4 / 97.4 s the same at 98.4 / 96.4 s

The intro already runs at ~22.5 fps on main here, so on this CPU the copy this PR removes is not what limits it. The end-of-run crash is the #232 / #505 stop, the same on both builds.

Regression run (no presses, 60 s; the title folder is a neutrally named junction)

main:

xcl-smoke v1
commit: 3db536ebe231418d76e8d6e52ccee0b47330a522
gpu: NVIDIA GeForce RTX 3080
title: xcl-title
seconds: 60
exit: 0x0
frames shown: 1625 (PresentX 1625)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14737 MB

PR merged onto main:

xcl-smoke v1
commit: 71d0ad9783c71e58caea91051c4b8521c97ae008
gpu: NVIDIA GeForce RTX 3080
title: xcl-title
seconds: 60
exit: 0x0
frames shown: 1642 (PresentX 1642)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14746 MB

Test report written with Claude Code (Claude Opus 5.5) from my own runs.

**@⁠grahamster2** on GitHub · 2026-11-24 03:08 UTC · [original](https://github.com/xcl-dev/xcl/pull/602#issuecomment-7120802147) Benchmark of `3984bf1` merged onto `main` 3db536e (clean merge). **Result: no measurable difference on this machine**, neither better nor worse. **Setup**: RTX 3080 10 GB (driver 32.0.16.1088), Ryzen 5 7600X, 32 GB, Windows 11 26200, release builds. Retail title, `XCL_NETWORK=0`, A at 14/17/21/25/31 s, 180 s runs. Both caches were warmed with one run per build first (not counted); then 2 measured runs per build. `main` = 3db536e (#451 and #435 in). | | main run 1 / 2 | main + #602 run 1 / 2 | |---|---|---| | presents/s, intro video (4–16 s) | 22.5 / 22.5 | 22.5 / 22.0 | | presents/s, menus + loading (16–44 s) | 30.0 / 29.9 | 30.0 / 29.9 | | streaming starts | 44.0 s / 44.1 s | 44.0 s / 44.0 s | | presents/s while streaming (44–84 s) | 6.0 / 5.5 | 5.5 / 5.2 | | peak commit | 30.1 / 30.3 GB | 30.2 / 30.0 GB | | peak local video memory | 14.3 / 14.1 GB | 14.3 / 14.0 GB | | end | #232 watchdog (`+0x23cf683`) at 100.4 / 97.4 s | the same at 98.4 / 96.4 s | The intro already runs at ~22.5 fps on main here, so on this CPU the copy this PR removes is not what limits it. The end-of-run crash is the #232 / #505 stop, the same on both builds. **Regression run** (no presses, 60 s; the title folder is a neutrally named junction) main: ``` xcl-smoke v1 commit: 3db536ebe231418d76e8d6e52ccee0b47330a522 gpu: NVIDIA GeForce RTX 3080 title: xcl-title seconds: 60 exit: 0x0 frames shown: 1625 (PresentX 1625) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14737 MB ``` PR merged onto main: ``` xcl-smoke v1 commit: 71d0ad9783c71e58caea91051c4b8521c97ae008 gpu: NVIDIA GeForce RTX 3080 title: xcl-title seconds: 60 exit: 0x0 frames shown: 1642 (PresentX 1642) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14746 MB ``` _Test report written with Claude Code (Claude Opus 5.5) from my own runs._
Author
Owner

@⁠MonkeyPython on GitHub · 2026-11-24 03:01 UTC · original · edited 2026-11-24 03:17 UTC

@⁠odd/tasks/draft-pr602-comment.md

**@⁠MonkeyPython** on GitHub · 2026-11-24 03:01 UTC · [original](https://github.com/xcl-dev/xcl/pull/602#issuecomment-7120698326) · edited 2026-11-24 03:17 UTC @⁠odd/tasks/draft-pr602-comment.md
This discussion has been locked. Commenting is limited to contributors.
No description provided.