Repository navigation
D3D12.X: faster title texture uploads (reused upload memory, faster detiling) - #451
Conversation
`gpu::texture::upload_batch` made a new upload buffer for every texture and a new command allocator, command list and fence for every batch, and released them all again. Each of these D3D12 calls waits for the video memory manager. While a retail title streamed textures the CPU writes, they took 200 - 650 ms apiece (timed in the title's runs), and its frames fell to 1 - 3 a second. Each upload queue now keeps an `Uploader`: one persistently mapped upload buffer that the batch's textures share (each at a 512-byte aligned offset; it grows only when a batch needs more room), an allocator and list that are reset, and a fence whose value counts up. When the wait for a batch times out, the uploader is retired and kept alive instead of released: the GPU may still read the buffer and run the list, and releasing them under it removed the device. `record_upload_states` is split into `layout` and `record_into`; it keeps its behaviour (a buffer of its own) for its other callers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`Chain::detile_level` called `element_at` / `Layout::offset_z` for every element: a `div_ceil`, several divisions and modulos and six table lookups each. Once the upload buffers were reused, it was most of a retail title's render thread while the title streamed textures the CPU writes (thread samples, frames named from a symbol build). The parts of the offset that depend on x alone (block column and the x and high-x pattern bits) are now computed once per level, those that depend on y and the slice once per row, leaving two lookups and an XOR per element. The result is the same: a new test compares it with `element_at` for every mode, element size, pipe configuration and level (mip tails too), with a base swizzle, two slices and a source cut short. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…eads `title_textures::upload_all` read and detiled each texture of a batch one after another, inside the title's own submit and present. Batches of 1 MB or more are now detiled on up to 8 threads (half the cores), each taking the next texture; the results keep the batch's order. Smaller batches stay on the calling thread. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
This overlaps #440 in
A linear level's rows are contiguous, so #440 copies them whole; your per-row form is what the swizzled modes need. Whichever lands first, I'll rebase #440 onto it as a linear fast path in front of your loop (a few lines plus its equivalence test) – or feel free to fold it into this PR if you prefer, and I'll close #440. AI use: Claude Code with Claude Opus 5.5 ran the timings and wrote this comment. |
|
Tested Windows 11 build 26300, Ryzen 7 9800X3D, RTX 3080 Ti (NVIDIA 621.35), Rust 1.99.1 MSVC, debug. Commit 2cefc889
Not tested Full workspace suite, AMD, retail titles, and performance. AI use Codex with GPT-6.2 Sol ran the tests and drafted this report. |
Do you want to merge our PRs? |
Chain::detile_level computed the address of every element and copied it on its own. A linear level (mode 0) keeps each row's elements contiguous, so its rows are now copied whole; which elements are copied when the source is cut short is unchanged. Swizzled modes, a base swizzle and levels in a mip tail keep the per-row form of the previous commit. A retail title's intro video is three linear R8 planes per frame (3840x2160 and two 1920x1080), uploaded on every frame through the kept-in-step title textures: release, one plane 56.9 ms -> 1.2 ms and 14.4 ms -> 0.3 ms, about 85 ms -> 2 ms a frame. The video played at 3.5 fps on an RX 9060 XT with the element-by-element form. Test: linear levels give the same bytes by rows as by elements, for every element size, padded rows, every mip and a cut-short source. From xcl-dev#440 (be722a7), placed in front of the per-row loop of this PR. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Tested 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, Pass: 679 passed, 0 failed, 41 ignored. SKIPPED: only the 2 Run and written with Claude Code (Claude Opus 5.5). |
|
Test report on AMD RDNA3: RX 7800 XT (16 GB, wave32 and wave64), driver 32.0.32015.7029, Ryzen 7 9800X3D, Windows 11 Pro 10.0.26300, Rust 1.100.0 MSVC, DXC 1.9.2602.17, debug build. No retail data was used. The PR's own runs are all on NVIDIA, so this adds an AMD GPU with 64-lane waves. Tested: the PR head
Not tested: a regression run on a title, a release build, the head merged onto current AI use: Claude Code ran the commands and drafted this comment; the runs are real runs on the hardware above. |
|
Thanks @emirduran707, good catch. The two changes fit together: your linear fast path is now the 4th commit of this PR ( Combined numbers, measured on an RTX 3070 Ti and a Ryzen 9 7950X:
The retail title,
None of the runs crashed or removed the device. Frame counts vary a lot from run to run, so only runs from the same session are compared. I didn't start the title's intro video by hand, so your video case was measured only through the timings above. If this lands, #440 can be closed. The PR description is updated to match. (Written with Claude Code, Claude Opus 5.5; I checked the numbers against the runs.) |
|
Test report for #451 at Setup: AMD Radeon RX 9070 XT 16 GB, driver 32.0.32015.2008 (the CPU's integrated Radeon is also present; XCL ran on the RX 9070 XT), Ryzen 7 9800X3D, 31 GB RAM, Windows 11 25H2 build 26200.9974, rustc 1.100.0 Tests: Title runs:
No device removal or crash in any run. Peak commit was 16150 / 16023 MB with this PR against 15824 / 15815 MB on main (+2 %). Regression run (round 1): main: PR: Not tested: gameplay past the video; picture correctness beyond what the person watching saw; any title other than this one. AI use: Claude Code with Claude Opus 5.5 built the commits, ran the tests and the title runs, and wrote this report. The runs were made on my machine. |
|
Tested on an RTX 3080 against Setup: RTX 3080 10 GB, driver 610.88, 32 GB RAM with ~15–17 GB used by other programs. Release builds of
All smoke runs reported Not tested:
The same numbers are posted on the other PRs: #455, #465. Test runs and this report: Claude Code (Claude Opus 5.5). |
|
please review @ivall / @theaustinayers / @Mavixot |
|
Follow-up on the RTX 3080 now that #486 is merged: yes, #451 still helps on top of #486. With Builds:
The setup is the same as in my comment above: the retail title, 180 s,
For comparison, on 2997c9a (before #486) Two extra #451 runs aren't in the table. I ran them with the same Not tested: picture correctness (I can't see the screen), and anything past the first ~20 s of world streaming, because of the RAM limit. Test runs and this report: Claude Code (Claude Opus 5.5). |
|
I tested PR head
Results: 17 focused upload and detiling tests passed, with 0 failures, 0 ignored, and no skips. Windows 11, Radeon driver AI use: OpenAI Codex (GPT-6.2 Sol) wrote the fixture, ran the tests, and drafted this report. |
|
After the merge, for the record: #440, #451 and #458 side by side on the retail title's intro video (RTX 5070 Ti) The three PRs sped up the same path ( Setup: NVIDIA GeForce RTX 5070 Ti 16 GB (driver 32.0.16.1742, 32-lane waves), Ryzen 7 9800X3D, 31 GB RAM, Windows 11 Pro build 26300, rustc 1.100.0 MSVC, DXC 1.8.2502.11 (SDK 10.0.26100), Builds: Procedure:
Not tested: AMD, other CPUs, the PRs' unit tests on this machine (only the title runs above), debug builds, a full AI use: Claude Code (Claude Opus 5.5) built the five binaries, ran the title and the thread dumps on my machine, computed the numbers from the logs and wrote this comment. |
Upstream rewrote the title texture system the fork had also changed (ivall#248 shared VRAM pages, retire_overlapping, ivall#451 reused upload memory, ivall#486 unchanged textures not uploaded, detiling on several threads): its title_textures.rs, vram.rs, device_x.rs and texture.rs are taken as they are, and the fork's own versions of those (streamed textures on pages and own tiles, dead-texture eviction, async uploads, release counters) and their XCL_ACTIVITY lines are dropped. - kernelx/lazy.rs: upstream's `allows` retry replaces the fork's retry of a lazily mapped page another thread committed; `state` stays (diagnostics) - dstorage.rs: the fork keeps holding a request whose page entry is still 0 (up to HOLD_MAX) instead of upstream's single re-read when it runs; upstream's test of it waits out the hold - present.rs: upstream's FPS in the title with the fork's count of the pipelines waiting to be built cargo test --release -p xcl --lib -- --test-threads=4 (RTX 4090): 645 passed, 0 failed, 24 ignored; SKIPPED (no wave64): 2. Assisted-by: Claude Code (Claude Opus 5.5) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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 <noreply@anthropic.com>
…upload reuse, ivall#300 timer)
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)
|
Follow-up to the AMD growth/reuse test: reuse worked here too. The remaining cost I could isolate was temporary overlap when a completed upload buffer grows, not retained memory after the batch. On a Linux RTX 4060 (8 GB, NVIDIA 620.73.04, GE-Proton11-14), I ran a game-free RGBA8 fixture on
The later equal/smaller batches made no new type-2 allocations. All six 4 MiB texture readbacks per build matched the expected bytes. A separate destruction-notifier test confirmed the old resource was gone before replacement creation only on the changed build. The change is limited to the synchronous
AI use: Hermes Agent (gpt-6.2-astra) built the private fixture and candidate, ran the tests, and checked the driver logs and readbacks. |
A retail title that rewrites textures with the CPU (kept in step with its memory by
title_textures) fell to 1 – 3 frames a second on an NVIDIA RTX 3070 Ti once it streamed them. The time went to uploading those textures inside the title's own submit and present: D3D12 objects made and released for every upload, then detiling every texel through a full offset computation, one texture after another. This PR makes the uploads reuse their D3D12 objects and detiles faster and in parallel, and now also carries #440's linear fast path (by @emirduran707, see the 4th commit), which speeds up the linear levels this PR's per-row form only helped 3×. In back-to-back runs of the title the combined change is the only build that reaches the title's 30 fps cap at the end of a 60 s run.What is in it
D3D12.X: title texture uploads reuse their queue's buffer and list(gpu/texture.rs):upload_batchmade an upload buffer per texture and an allocator, a list and a fence per batch – each a call that waits for the video memory manager, 200 – 650 ms apiece while the title streamed (timed in its runs). Each upload queue now keeps one persistently mapped upload buffer (grown only when a batch needs more; textures at 512-byte aligned offsets), its allocator and list (reset) and a fence. When a batch's wait times out, the set is retired and kept alive instead of released under the GPU, which removed the device.record_upload_stateskeeps its behaviour for its other callers.Textures: detiling a mip level computes column and row parts once(gpu/tiling.rs):Chain::detile_levelcomputedLayout::offset_zfor every element (divisions, modulos, six lookups). The x-only parts are now computed once per level and the y/slice parts once per row: two lookups and an XOR per element, byte for byte the same result.D3D12.X: the title textures of a big batch are detiled on several threads(hle/d3d12x/title_textures.rs): batches of 1 MB or more are detiled on up to 8 threads (half the cores), in order; smaller batches stay on the calling thread.Textures: linear levels are detiled a row at a time(gpu/tiling.rs, authored by @emirduran707, from Textures: linear levels are detiled a row at a time #440be722a7): a linear level (mode 0, no base swizzle, not in a mip tail) has contiguous rows, so they are copied whole, in front of the per-row loop above; which elements are copied from a source cut short is unchanged. Textures: linear levels are detiled a row at a time #440 can be closed if this lands.detile_level_matches_element_by_element(every swizzled mode, element size, pipe configuration and level including mip tails, a base swizzle, two slices, a source cut short),linear_levels_detile_by_rows_as_by_elements(from Textures: linear levels are detiled a row at a time #440: every element size, padded rows, every mip, a source cut short inside a row and inside an element),gpu_upload_batches_reuse_the_queues_upload_buffer(two batches of three textures – mips, an odd size, BC7 – read back exactly, and the second batch made no new upload buffer),a_batch_detiled_on_several_threads_matches_one_thread(2, 3 and 8 threads against one).Tested
cargo test --workspace -- --test-threads=4at1f282c7with no uncommitted changes: 680 passed, 0 failed, 41 ignored (SKIPPED GPU tests: 2, both "no wave64":gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware). TheXCL_SAMPLE_*variables were not set, so the tests on game data did nothing.detile_levelalone (a local timing test, not committed; best of 7, release, the levels @emirduran707 timed):2997c9abe722a72cefc881f282c7scripts/smoke.ps160 s, two runs per build one after another (same session, no input): main 260 / 292 frames (last 6 s: 3 – 5 presents per 2 s); Textures: linear levels are detiled a row at a time #440 alone 231 / 295 (0 – 5); this PR before Textures: linear levels are detiled a row at a time #440 552 / 553 (1); this PR 670 / 1011 (60, the title's 30 fps cap). No crash or device removal in any of them. The frame counts vary from run to run and between sessions (main showed 720 in the regression run below, in an earlier session), so only runs of one session are compared.Regression run
scripts/smoke.ps1 -Game <the title's folder> -Xcl target\release\xcl.exe(60 s), built from main and from this PR's head with no uncommitted changes. (Windows PowerShell 5.1 does not set$PSScriptRootin the parameter default, hence-Xcl.)main:
PR:
Not tested
tests/texture_states.rs(upload barriers checked by the D3D12 debug layer) skips here: the debug layer is not installed.BATCH_BYTES, 256 MB, plus one texture); it is not shrunk.AI use