Repository navigation
D3D12.X: faster title texture uploads (reused upload memory, faster detiling) - #451
1984742628 wants to merge 3 commits into
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? |
|
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. |
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. The regression run below shows 1482 frames in 60 s against main's 720 (2.06×), and 30 frames a second at the end against about 14.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.detile_level_matches_element_by_element(every mode, element size, pipe configuration and level including mip tails, a base swizzle, two slices, a source cut short),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=4ona6f5f7awith these changes (the same code as2cefc88): 679 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.cargo check --release -p xcl --testsatc55783eand7d60a48).XCL_ACTIVITY=1, thread dumps at 25 / 45 / 60 s and per-thread CPU sampled every 5 s (the dumps pause the title, so these frame counts are lower than the regression run's), one run per step: main 355 frames, with the first commit 516, with the second 964, with all three 1352. In the streaming phase (after about 28 s) frames a second went from 1 – 3 to about 20, then 30. With all three, the busiest thread in that phase is one of the title's own workers in the title's code, not XCL.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