[pr-performance][RAYTRACING] Hardware RT: no host views made to read BLAS inputs; BLAS and meshlet buffers in shared memory (driving 12-17 -> 20-35 fps) #23
Loading…
Reference in a new issue
No description provided.
Delete branch "f41/Darner:pr-hwrt-soft-reads"
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?
Contributor role (optional)
What it changes
The problem
With hardware ray tracing on, driving a car drops the frame rate to 12-17 fps. It recovers within a few seconds of stopping. Walking is fine, and driving with ray tracing off is fine. The frames are CPU-bound: the log shows "0.0 on the GPU" and 35-60 ms of preparing per frame.
Unmodified build, 8 minutes with a long drive:
BLAS prep 61773 ms(about 13% of wall time across threads). While driving it reached 1.0-3.7 s per 5 s report.What the time was
I added timers that split BLAS prep. Driving, 42 s, before this PR:
I first assumed the cost was buffer creation. Placing the buffers in shared memory (parts 2 and 3 below) cut that to 13-15 us each, but driving fps did not change. A meshlet miss still took ~240 us with no buffer made. Quant24 decode ran about 10x slower than the same loop on plain memory (2.7 GB/s measured).
The cost was in reading title memory.
decode_title_meshlet_ib,decode_title_quant24_vb, the plain index range scan and the transform reads all go throughtitle_readable->readable_len->watch::materialize. WithDARNER_SOFT_VIEWS, that turns every view the runtime keeps in its books alone into a host mapping before the read. The xmem report line counts these as "asked for by the GPU side":The title keeps remapping those pages (about 20,000-25,000 page-mapping copies every 10 s), so the mappings are made over and over. One of these reads runs on the title's own thread for every geometry with a transform:
read_geometriescopies the transform for deferred builds (6a5f7ee). So it stalls the title directly.The fix
DARNER_HW_RT_SOFT_READS(on unless0), the part that fixes it. The BLAS inputs are copied out throughhost::read_into, the way the GPU side already reads title memory: soft views are read from their pages and no host view is made. That covers transforms (at recording and the unaligned fallback), quant24 vertices, meshlet indices and the plain index range scan. If a read fails, the old path is used. A unit test checks that both decoders give the same bytes on synthetic meshlet and quant24 data, including out-of-range triangles and winding flip.DARNER_HW_RT_BLAS_HEAPS(on unless0). BLAS buffers up to 16 MB are placed in 64 MB heaps instead of each being committed. On an RTX 5090,CreateCommittedResourceof a 64 KB-4 MB default buffer took 225-310 us and its release 135-160 us; a placed buffer took 2.6 us and 0.6 us. Units go back when the D3D12 object itself is destroyed: a smallIUnknownheld as the resource's private data, which the runtime releases on destruction. So list keeps, retirements and TLAS refs hold the memory exactly as long as a committed buffer. Written by hand rather than with#[implement], sodarner-gpuneeds nowindows-coredependency andCargo.lock(hashed into the translator) does not change.DARNER_HW_RT_MESHLET_ARENA(on unless0). Decoded meshlet index buffers go into 32 MB persistently mapped upload blocks in 4 KiB units, charged what they take. Before, each was a committed buffer charged a whole 64 KiB unit: the 256 MB cache held about 4,000 and thrashed while driving through traffic (about 320 misses/s). Units go back throughretirewhen the entry is dropped, so only past the submissions that may read it.DARNER_HW_RT_BLAS_BUDGET_MBsets it outright.Everything is in
crates/darner-gpu/src/hwrt.rs, and each part has its own switch for A/B.How it was tested
fa0b1fconmain4a92569. The game runs used the samehwrt.rschange applied toe6245bf(hwrt.rsis identical between the two), plus an unrelated local DLSS change.fa0b1fc):cargo clippy --workspace --all-targets --locked -- -D warnings: cleancargo clippy --workspace --all-targets --all-features --locked -- -D warnings: cleancargo test --workspace --locked: 2021 passed, 1 failed, 87 ignored. The failure ishost::watch_pipe::tests::finish_early_watch_fast_path_reasks_overlap_and_handles_settle_or_cancel: it passed 3 of 3 runs alone on this branch and 3 of 3 onmain, so it looks timing-dependent under the full parallel run and unrelated (this PR does not touchwatch_pipe.rs).cargo test -p darner-gpu --lib hwrt: 23 passed, including the newdecodes_from_copies_match_those_in_placeandfree_runs_are_found_across_words_and_given_back.Before (parts 2-5 only), driving:
After (this PR), driving:
Standing still: 37-41 fps in both.
Checklist
main. (It addresses one problem, the BLAS input cost while driving, in five parts in one file, each with its own switch. I can split parts 2-5 into their own PRs if you prefer.)docs/asset-policy.md.Checked for overlap
hwrt.rs(shows the running ray tracing mode in F1). It is unrelated, but the two may conflict textually.Driving with hardware RT dropped to 12-17 fps (RTX 5090, Series X, 4K DLSS Quality) and recovered within seconds of stopping; walking was fine and RT off was fine. BLAS prep took ~200 ms of CPU per second while driving. The new prep timers put it in reading title memory: decoding a meshlet index buffer took ~240 us and quant24 vertices ~10x what the decode itself costs, because `title_readable` ran `watch::materialize`, which makes every view the runtime keeps in its books alone (DARNER_SOFT_VIEWS) a mapping of the host's: 1,400-2,400 every 10 s while driving ("asked for by the GPU side"), none with RT off. One of them ran on the title's thread for every geometry with a transform (the deferred-build transform copy,6a5f7ee). - DARNER_HW_RT_SOFT_READS (on unless 0): transforms, quant24 vertices, meshlet indices and the plain index range scan are copied out through `host::read_into`, as the GPU side reads title memory; the old path stays as the fallback. A test checks both decodes give the same bytes. - DARNER_HW_RT_BLAS_HEAPS (on unless 0): BLAS buffers up to 16 MB are placed in 64 MB heaps (2.6 us to make vs 240 us committed on the same card); their units go back when the D3D12 object goes (a private-data object the runtime releases), so they live as long as before. - DARNER_HW_RT_MESHLET_ARENA (on unless 0): decoded meshlet index buffers go into 32 MB mapped upload blocks in 4 KiB units, charged what they take (the cache held ~4,000 at 64 KiB each and thrashed), units reused after the entry's retirement. - BLAS budget: on cards with 28 GB or more, a tenth of the budget up to 4 GB (1.5 GB filled with 6,064 evictions in 8 minutes on 32 GB); DARNER_HW_RT_BLAS_BUDGET_MB sets it. - Report lines: BLAS buffer making, BLAS prep split, meshlet cache misses and their time, the decoded meshlet blocks. Same route, same settings: 12.5-17.5 fps driving before the reads change, 20-35 after; BLAS prep ~200 -> ~25 ms per second; meshlet miss 240 -> 18 us; host views asked for by the GPU side 1,400-2,400 -> 0 per 10 s. Co-Authored-By: Claude Opus 5.5 <[email protected]>Test report from an RTX 5090, standing still (no driving yet).
Setup
mainat4a92569fagainst this PR'sfa0b1fc2(which sits directly on4a92569f). Both release builds also carry the 7-linerayquery.rschange from my callback-marks branch.scripts/play-nvidia.ps1 -NoMenu -PreloadwithDARNER_HW_RT=1: Series X profile, 1440p, DLSS Quality, frame generation off. Window off screen and without focus.Results
mainevery run had frames of 1.6 to 2.9 s; with the PR the longest frame of a run was 200 to 347 ms.mainmade up to 718 host views in 10 s, the PR 0 in the lines I looked at.Not tested
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.