Repository navigation
Title textures: detile and hash the title's memory in place, not a copy - #602
Conversation
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>
|
Tested
The 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. |
|
@odd/tasks/draft-pr602-comment.md |
|
Benchmark of Setup: RTX 3080 10 GB (driver 32.0.16.1088), Ryzen 5 7600X, 32 GB, Windows 11 26200, release builds. Retail title,
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: PR merged onto main: Test report written with Claude Code (Claude Opus 5.5) from my own runs. |
… 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.
… 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.
… 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.
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)
… 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)
… 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)
… 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).
… 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).
Before a title texture is hashed (
unchanged_skip, #486) and detiled for an upload,title_texturescopied 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_bytesnow 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 insubresources; testtitle_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 asread_committed).Tested
cargo test --workspace --no-fail-fast -- --test-threads=4at 3984bf1: 681 passed, 4 failed, 41 ignored. Onmain9ce2070 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_memorySKIPPED:gpu_geometry_mode_es_gs_strip,gpu_mesh_mode_two_passes(no mesh shaders)main9ce2070 → 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
The last window of the PR's run (38) is the title loading its world after the video, which the
mainrun reaches later.Not tested
AI use
🤖 Generated with Claude Code