Skip to content

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

Merged
Mavixot merged 1 commit into
xcl-dev:mainfrom
dns54:perf/title-bytes-in-place
Nov 24, 2026
Merged

Mavixot merged 1 commit into
xcl-dev:mainfrom
dns54:perf/title-bytes-in-place

Conversation

@dns54

@dns54 dns54 commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

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

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 xcl-dev#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 <noreply@anthropic.com>
@dns54
dns54 marked this pull request as ready for review November 24, 2026 02:22
@ryosen0

ryosen0 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

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 D3D12.X: show live FPS in the game window title #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.

@Mavixot
Mavixot merged commit bdab194 into xcl-dev:main Nov 24, 2026
2 checks passed
@MonkeyPython

MonkeyPython commented Nov 24, 2026 •

Copy link
Copy Markdown

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

@grahamster2

Copy link
Copy Markdown
Collaborator

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 added a commit to grahamster2/xcl that referenced this pull request Nov 24, 2026
… copy

The unchanged-content hash, the detile of title textures and the
frame-trace sampler read the title's memory in place once it looked
readable (xcl-dev#602). That bypasses the ReadProcessMemory copy of
read_committed (xcl-dev#484): the title can decommit or unmap those pages from
another thread at any moment, and the read then faults with 0xC0000005.

with_title_bytes replaces title_bytes. A range inside the coherent
committed window is still read in place: XCL's VirtualFree never
decommits that window (MEM_DECOMMIT there zeroes the block in place).
Everything else is read as read_committed reads it, into a buffer kept
per thread and dropped after a read that grew it past 64 MiB.
read_committed_into now writes every byte (copied, or zero for a page
that is not readable), so the reused buffer needs no memset and nothing
of an earlier read shows through a hole. Only long-lived threads reuse
the buffer: the scoped workers of a parallel batch detile allocate one
per batch.

title_bytes_survive_concurrent_decommit hashes 1 MiB while another
thread decommits and recommits its 64 KiB pages.
grahamster2 added a commit to grahamster2/xcl that referenced this pull request Nov 24, 2026
… copy

The unchanged-content hash, the detile of title textures and the
frame-trace sampler read the title's memory in place once it looked
readable (xcl-dev#602). That bypasses the ReadProcessMemory copy of
read_committed (xcl-dev#484): the title can decommit or unmap those pages from
another thread at any moment, and the read then faults with 0xC0000005.

with_title_bytes replaces title_bytes. A range inside the coherent
committed window is still read in place: XCL's VirtualFree never
decommits that window (MEM_DECOMMIT there zeroes the block in place).
Everything else is read as read_committed reads it, into a buffer kept
per thread and dropped after a read that grew it past 64 MiB.
read_committed_into now writes every byte (copied, or zero for a page
that is not readable), so the reused buffer needs no memset and nothing
of an earlier read shows through a hole. Only long-lived threads reuse
the buffer: the scoped workers of a parallel batch detile allocate one
per batch.

title_bytes_survive_concurrent_decommit hashes 1 MiB while another
thread decommits and recommits its 64 KiB pages.
grahamster2 added a commit to grahamster2/xcl that referenced this pull request Nov 24, 2026
… copy

The unchanged-content hash, the detile of title textures and the
frame-trace sampler read the title's memory in place once it looked
readable (xcl-dev#602). That bypasses the ReadProcessMemory copy of
read_committed (xcl-dev#484): the title can decommit or unmap those pages from
another thread at any moment, and the read then faults with 0xC0000005.

with_title_bytes replaces title_bytes. A range inside the coherent
committed window is still read in place: XCL's VirtualFree never
decommits that window (MEM_DECOMMIT there zeroes the block in place).
Everything else is read as read_committed reads it, into a buffer kept
per thread and dropped after a read that grew it past 64 MiB.
read_committed_into now writes every byte (copied, or zero for a page
that is not readable), so the reused buffer needs no memset and nothing
of an earlier read shows through a hole. Only long-lived threads reuse
the buffer: the scoped workers of a parallel batch detile allocate one
per batch.

title_bytes_survive_concurrent_decommit hashes 1 MiB while another
thread decommits and recommits its 64 KiB pages.
theaustinayers added a commit to theaustinayers/xcl that referenced this pull request Nov 24, 2026
…l#486, ivall#574, ivall#602, ivall#634, ivall#636

Upstream's texture detiling and uploads replace the fork's (ivall#440 and the threaded detile); its disk cache of driver blobs (ivall#634) replaces the fork's first version.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
mastrr9 added a commit to mastrr9/xcl that referenced this pull request Nov 24, 2026
Check every tiling mode, element size and pipe configuration: offsets
one-to-one and in bounds, equal to addrlib's swizzle equations across
the full coordinate range (guarding xcl-dev#435), tile / detile round trips,
the detile fast paths from xcl-dev#451 and xcl-dev#602 against a texel-by-texel
reader, mip chains and volumes without overlaps, and invalid input
giving None.

Assisted-by: Claude Code (Claude Opus 5.5)
wondercrash pushed a commit to wondercrash/xcl that referenced this pull request Nov 24, 2026
… copy

The unchanged-content hash, the detile of title textures and the
frame-trace sampler read the title's memory in place once it looked
readable (xcl-dev#602). That bypasses the ReadProcessMemory copy of
read_committed (xcl-dev#484): the title can decommit or unmap those pages from
another thread at any moment, and the read then faults with 0xC0000005.

with_title_bytes replaces title_bytes. A range inside the coherent
committed window is still read in place: XCL's VirtualFree never
decommits that window (MEM_DECOMMIT there zeroes the block in place).
Everything else is read as read_committed reads it, into a buffer kept
per thread and dropped after a read that grew it past 64 MiB.
read_committed_into now writes every byte (copied, or zero for a page
that is not readable), so the reused buffer needs no memset and nothing
of an earlier read shows through a hole. Only long-lived threads reuse
the buffer: the scoped workers of a parallel batch detile allocate one
per batch.

title_bytes_survive_concurrent_decommit hashes 1 MiB while another
thread decommits and recommits its 64 KiB pages.

(cherry picked from commit 4e101fc)
themaoci pushed a commit to themaoci/xcl that referenced this pull request Nov 24, 2026
… copy

The unchanged-content hash, the detile of title textures and the
frame-trace sampler read the title's memory in place once it looked
readable (xcl-dev#602). That bypasses the ReadProcessMemory copy of
read_committed (xcl-dev#484): the title can decommit or unmap those pages from
another thread at any moment, and the read then faults with 0xC0000005.

with_title_bytes replaces title_bytes. A range inside the coherent
committed window is still read in place: XCL's VirtualFree never
decommits that window (MEM_DECOMMIT there zeroes the block in place).
Everything else is read as read_committed reads it, into a buffer kept
per thread and dropped after a read that grew it past 64 MiB.
read_committed_into now writes every byte (copied, or zero for a page
that is not readable), so the reused buffer needs no memset and nothing
of an earlier read shows through a hole. Only long-lived threads reuse
the buffer: the scoped workers of a parallel batch detile allocate one
per batch.

title_bytes_survive_concurrent_decommit hashes 1 MiB while another
thread decommits and recommits its 64 KiB pages.

(cherry picked from commit 4e101fc)
grahamster2 added a commit to grahamster2/xcl that referenced this pull request Nov 24, 2026
… copy

The unchanged-content hash, the detile of title textures and the
frame-trace sampler read the title's memory in place once it looked
readable (xcl-dev#602). That bypasses the ReadProcessMemory copy of
read_committed (xcl-dev#484): the title can decommit or unmap those pages from
another thread at any moment, and the read then faults with 0xC0000005.

with_title_bytes replaces title_bytes. A range inside the coherent
committed window is still read in place: XCL's VirtualFree never
decommits that window (MEM_DECOMMIT there zeroes the block in place).
Everything else is read as read_committed reads it, into a buffer kept
per thread and dropped after a read that grew it past 64 MiB.
read_committed_into now writes every byte (copied, or zero for a page
that is not readable), so the reused buffer needs no memset and nothing
of an earlier read shows through a hole. Only long-lived threads reuse
the buffer: the scoped workers of a parallel batch detile allocate one
per batch.

title_bytes_survive_concurrent_decommit hashes 1 MiB while another
thread decommits and recommits its 64 KiB pages; it checks that every
decommit and recommit succeeded, that some happened during the hashing and
that each read holds the title's bytes or zeros.
title_bytes_leave_guard_pages_alone reads a guard and a no-access page
as zeros and checks that the guard stays.

read_committed_into first copies the whole range with one
ReadProcessMemory and walks it region by region with VirtualQuery only
when that is refused (a page not committed, no-access or a guard page;
the guard stays). VirtualQuery scans from the page asked about to the
end of its run of like pages, and the title's memory is a few runs of
hundreds of MiB: in a release
microbenchmark (7600X), reading 16 KiB / 256 KiB / 4 MiB of a
fully committed 64 MiB region took 128 / 125 / 280 us with the walk and
1.3 / 6.9 / 156 us now (512 MiB region: 1629 / 1179 / 1753 us, now
1.4 / 7.5 / 128 us). A range with holes pays one refused copy on top
of the walk (4 MiB with one hole: ~158 us before, ~230 us now).
grahamster2 added a commit to grahamster2/xcl that referenced this pull request Nov 25, 2026
… copy

The unchanged-content hash, the detile of title textures and the
frame-trace sampler read the title's memory in place once it looked
readable (xcl-dev#602). That bypasses the ReadProcessMemory copy of
read_committed (xcl-dev#484): the title can decommit or unmap those pages from
another thread at any moment, and the read then faults with 0xC0000005.

with_title_bytes replaces title_bytes. A range inside the coherent
committed window is still read in place: XCL's VirtualFree never
decommits that window (MEM_DECOMMIT there zeroes the block in place).
Everything else is read as read_committed reads it, into a buffer kept
per thread and dropped after a read that grew it past 64 MiB.
read_committed_into now writes every byte (copied, or zero for a page
that is not readable), so the reused buffer needs no memset and nothing
of an earlier read shows through a hole. Only long-lived threads reuse
the buffer: the scoped workers of a parallel batch detile allocate one
per batch.

title_bytes_survive_concurrent_decommit hashes 1 MiB while another
thread decommits and recommits its 64 KiB pages; it checks that every
decommit and recommit succeeded, that some happened during the hashing and
that each read holds the title's bytes or zeros.
title_bytes_leave_guard_pages_alone reads a guard and a no-access page
as zeros and checks that the guard stays.

read_committed_into first copies the whole range with one
ReadProcessMemory and walks it region by region with VirtualQuery only
when that is refused (a page not committed, no-access or a guard page;
the guard stays). VirtualQuery scans from the page asked about to the
end of its run of like pages, and the title's memory is a few runs of
hundreds of MiB: in a release
microbenchmark (7600X), reading 16 KiB / 256 KiB / 4 MiB of a
fully committed 64 MiB region took 128 / 125 / 280 us with the walk and
1.3 / 6.9 / 156 us now (512 MiB region: 1629 / 1179 / 1753 us, now
1.4 / 7.5 / 128 us). A range with holes pays one refused copy on top
of the walk (4 MiB with one hole: ~158 us before, ~230 us now).
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