D3D12.X: faster title texture uploads (reused upload memory, faster detiling) #451
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!451
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/451/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@1984742628 on GitHub · 2026-11-24 00:31 UTC · original
1984742628:perf/reuse-upload-memory→main· +365 −28 · 3 files · 4 commits · merged 2026-11-24 01:56 UTCA 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 #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. #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 #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); #440 alone 231 / 295 (0 – 5); this PR before #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
@emirduran707 on GitHub · 2026-11-24 00:37 UTC · original
This overlaps #440 in
Chain::detile_level(they conflict textually), but the two speed up different layouts, so they combine rather than compete.detile_levelalone, single thread, release, on a Ryzen 5 5600 (local timing test, not committed; same harness on both heads):main2cefc88)be722a7)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.
@thehollowedone on GitHub · 2026-11-24 00:40 UTC · original
Tested
Windows 11 build 26300, Ryzen 7 9800X3D, RTX 3080 Ti (NVIDIA 621.35), Rust 1.99.1 MSVC, debug. Commit 2cefc889
cargo test --locked -p xcl --lib -- detile_level_matches_element_by_element gpu_upload_batches_reuse_the_queues_upload_buffer a_batch_detiled_on_several_threads_matches_one_thread --test-threads=1 --nocapture: 3 passed, 0 failed, 0 ignored, zero reported skips. The GPU check matched the readbacks from both batches and confirmed the second batch reused the staging buffer. The two CPU checks matched the element-by-element detiler and the single-threaded batch output.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.
@1984742628 on GitHub · 2026-11-24 00:41 UTC · original
Do you want to merge our PRs?
@PHeitor1 on GitHub · 2026-11-24 00:44 UTC · original
Tested
2cefc88merged ontomain2997c9a.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, noXCL_SAMPLE_*.Pass: 679 passed, 0 failed, 41 ignored. SKIPPED: only the 2
no wave64tests (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).
@TheHoracio on GitHub · 2026-11-24 00:46 UTC · original
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
2cefc88as it is (on its basea6f5f7a).cargo build --workspace, thencargo test --workspace --no-fail-fast -- --test-threads=4: 679 passed, 0 failed, 41 ignored, no SKIPPED tests (the twono wave64tests run here).gpu_upload_batches_reuse_the_queues_upload_buffer(GPU),detile_level_matches_element_by_elementanda_batch_detiled_on_several_threads_matches_one_thread.Not tested: a regression run on a title, a release build, the head merged onto current
main.AI use: Claude Code ran the commands and drafted this comment; the runs are real runs on the hardware above.
@1984742628 on GitHub · 2026-11-24 01:03 UTC · original
Thanks @emirduran707, good catch. The two changes fit together: your linear fast path is now the 4th commit of this PR (
1f282c7, with you as author), placed in front of the per-row loop, so linear levels take your row copy and swizzled ones take the per-row form. Yourlinear_levels_detile_by_rows_as_by_elementstest came along unchanged, and the whole suite passes at1f282c7(680 passed, 0 failed, 41 ignored).Combined numbers, measured on an RTX 3070 Ti and a Ryzen 9 7950X:
detile_levelalone (release, best of 7, the levels you timed):2997c9abe722a72cefc881f282c7The retail title,
scripts/smoke.ps160 s, two runs per build back to back in one session: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.)
@grahamster2 on GitHub · 2026-11-24 01:10 UTC · original
Tested on an RTX 3080 against
mainand the two other PRs for the same fix (#455, #465). #451 is the only one that speeds up the intro video here: about 4.5 → 20 fps (it takes 21 s instead of ~100 s), and world streaming starts at 60 s instead of 140 s. There were no device removals. The local patch from the #283 comment, ondb1ddb2, gave 30 fps in the earlier test, so this head is slower than that patch was.Setup: RTX 3080 10 GB, driver 610.88, 32 GB RAM with ~15–17 GB used by other programs. Release builds of
main2997c9a(code-identical toa6f5f7a) and of #4512cefc88, #455 07e6199 and #4651152852. Each PR was tested on its own. The retail title ran 180 s per run withXCL_NETWORK=0 XCL_ACTIVITY=1 XCL_PRESS_A_AT=14,17,21on a warm cache. Numbers are from theactivity (2 s)lines; the earlier patch test ondb1ddb2is here.0x887a0006(DEVICE_HUNG), at 13.5 s and 11.0 s, before the intro video. The log line isD3D12 device removed: 0x887a0006 … – the title is stopped, and then the process ends with status 0x887a0006.mainand the other PRs had no removals in their runs.smoke.ps1, 60 s: it presses nothing, so every build stays on the menu, and all four look the same there.2997c9a2cefc881152852All smoke runs reported
exit: 0x0andgpu: NVIDIA GeForce RTX 3080. I left the title line out of the table.Not tested:
The same numbers are posted on the other PRs: #455, #465.
Test runs and this report: Claude Code (Claude Opus 5.5).
@Chrysana on GitHub · 2026-11-24 01:05 UTC · original · edited 2026-11-24 01:11 UTC
Test report for #451 at
2cefc88on 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 (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
x86_64-pc-windows-msvc, DXC 1.9.2602.17 (SDK 10.0.26100). 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=4at2cefc88: 679 passed, 0 failed, 41 ignored.SKIPPED:test_title_draws_with_a_root_signature_under_the_debug_layeranduploads_start_from_each_subresources_state, both because the D3D12 debug layer isn't installed here.Title runs:
scripts/smoke.ps1 -Game <folder> -Seconds 60withXCL_PRESS_A_AT=14,17,21. Every run reaches the Bink intro (21 kept-in-step textures in each run's log). The picture was checked by eye only on main, where the video plays. Two rounds of main, #451, #440 and #458, interleaved, same machine, same saved state:a6f5f7a2cefc88be722a7a173fe0No 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.
@1bugproof on GitHub · 2026-11-24 01:21 UTC · original
please review @ivall / @theaustinayers / @Mavixot
@grahamster2 on GitHub · 2026-11-24 01:29 UTC · original
Follow-up on the RTX 3080 now that #486 is merged: yes, #451 still helps on top of #486. With
mainalone the intro video plays at ~6 fps. Withmain+ #451 it plays at 30 fps, and world streaming starts ~60 s earlier.Builds:
main7ebf1b8, which includes #486.main7ebf1b8with this PR's head1f282c7merged locally (not pushed). It merges without conflicts.The setup is the same as in my comment above: the retail title, 180 s,
XCL_NETWORK=0 XCL_ACTIVITY=1, warm cache, and a watchdog that stops the run when free RAM falls below 1.5 GB.7ebf1b8(#486)7ebf1b8+ #4511f282c7For comparison, on
2997c9a(before #486)mainplayed the video at ~4.5 fps and #4512cefc88at ~20 fps. #486 alone raises it to only ~6 fps on this card, not 30.Two extra #451 runs aren't in the table. I ran them with the same
XCL_PRESS_A_AT=14,17,21asmain. In both, the title read the gamepad for the first time only at ~21 s, so the press before the video came too early. The title then sat on that screen for the rest of the 180 s, at 60 presents per 2 s and 14.7 GB commit. Neither run had a crash or a removal. The two runs in the table used21,25,31and14,17,21,25,31; the extra presses didn't cut the video short.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).
mainreaches on Windows; the obstacle is replaced vtables — proposal: proxies #175@Alpha325 on GitHub · 2026-11-24 01:51 UTC · original
I tested PR head
1f282c737b5637b58de4847cacde208d23504ed7on Radeon RX 9060 XT with a local test-only fixture. The existing reuse test covers two batches that fit the same buffer. This fixture forces the buffer to grow and checks that a rejected item doesn't disturb the other uploads.1as failed.Results: 17 focused upload and detiling tests passed, with 0 failures, 0 ignored, and no skips. Windows 11, Radeon driver
32.0.32029.2010, Rust 1.100.0 MSVC x64, release. Synthetic fixtures only. This covers buffer growth, reuse, and per-item error handling. I did not measure performance or test GPU timeouts.AI use: OpenAI Codex (GPT-6.2 Sol) wrote the fixture, ran the tests, and drafted this report.
@tiagonleal on GitHub · 2026-11-24 01:57 UTC · original
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 (
title_textures::refresh→Chain::detile_level). I measured them against each other on the retail title (one machine, one procedure) before this was merged; the numbers agree with the choice, and #458 (still open) is below #451 here.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),
cargo build --release -p xcl. Title 1.0.2.1, unpacked, learned coherent window and warm DXIL cache (same for every build).Builds:
main2997c9a; #440be722a7; #4511f282c7; #458a173fe0as it is and merged ontomain2997c9a. #440 and #451 are ona6f5f7a, which differs from2997c9aonly in the README.Procedure:
xcl runfor 100 s withXCL_NETWORK=0,XCL_ACTIVITY=1,XCL_PRESS_AT=30:A(A on the account picker; the intro video starts right after). Intro fps = presents per second in the activity windows from 38 to 48 s. Two rounds, builds alternated (main, #440, #451, #458, #458 on main, then again).mainmainmain, in the threeXCL_THREAD_DUMP_ATdumps taken during the intro (45, 50, 55 s), the same title thread is the only one running, and it is inChain::detile_levelundertitle_textures::refresh: inLayout::offset_zin two dumps, in the copy in the third (frames named from the release PDB's public symbols).XCL_FRAME_DUMP=60shows the intro, then the loading screen art at 103–123 s; it then stops presenting at ~140 s and ends at 168.9 s in the #232 watchdog write (+0x23cf683,+0x2215c35on the stack). That is #232, not this PR (posted there).Not tested: AMD, other CPUs, the PRs' unit tests on this machine (only the title runs above), debug builds, a full
cargo test --workspaceon each head.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.
@ArturoWolff on GitHub · 2026-11-24 14:01 UTC · original
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
47efa2ecea0a12934719ae69b81930cf02a4b1c3: four batches needing 4, 8, 8 and 4 MiB, same destination textures on both builds. At the 4 → 8 MiB step: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
upload_batchpath: release only a completed cached buffer that is too small, and drop the batch-local reference before publishing the uploader back to the pool. No change to in-flight or timed-out work.gpu/texture.rsis unchanged between that tested revision and930e8b4(source comparison only). Not a measured retail saving, a reduction in final footprint, or a Windows smoke result. If investigating this on a title, the useful measurement is the old/new capacity of the same completed uploader at growth; matching allocation sizes in a driver log alone don't identify the owner.AI use: Hermes Agent (gpt-6.2-astra) built the private fixture and candidate, ran the tests, and checked the driver logs and readbacks.