hwrt: compact the BLASes built without update on the host (DARNER_HW_RT_COMPACT, off by default) #452
No reviewers
Labels
No labels
AMD
audio
bug
confirmed
crash
cutscene
dlss
documentation
duplicate
enhancement
fixed-on-main
frame-generation
hle
input
INTEL
lighting
linux-proton
memory
MULDER
needs-info
needs-logs
needs-rebase
NVIDIA
performance
post-merge
pr-diagnostics
pr-docs
pre-merge
pr-feature
pr-fix
pr-performance
pr-refactor
pr-tests
question
RAYTRACING
relevance
high
relevance
low
relevance
medium
relevance
very-high
rendering
report
roadmap-proposal
saves
series-s
shaders
startup
status
blocked-by-rework
status
needs-test-report
status
needs-triage
status
ready-for-review
status
stale
status
superseded
status
wip
tools
ui
upstream
wontfix
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
TrustNo1/Darner!452
Loading…
Reference in a new issue
No description provided.
Delete branch "Layne/Darner:pr/hwrt-blas-compact"
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?
Not run in the game on this branch. The numbers below come from a one-hour session on a fork of this tree that carried the same compaction together with other local changes (see "How it was tested"). The switch is off by default, and nothing changes while it is unset.
Contributor role (optional)
What it changes
ResultDataMaxSizeInBytes), and the title's own compaction (its copy, mode 1) only makes a second console address point at the same host buffer (execute_copy). So no structure ever gets smaller. On an RTX 4070 Ti (12 GB), the compacted size the card reports for the BLASes built without update is about half of what they hold (numbers below).With
DARNER_HW_RT_COMPACT=1:ALLOW_UPDATEnorPERFORM_UPDATE(static and rehydrated geometry, mostly) is built withALLOW_COMPACTION. Unless its buffer is a single 64 KiB unit (it could not shrink), the list that builds it asks the card for its compacted size withEmitRaytracingAccelerationStructurePostbuildInfo. The size is copied to a readback buffer and read when that list is reset after its last execution, the same way as the TLAS marks (Feedback).blas_workahead of that list's builds, it is compacted, but only if all of these still hold under the lookup table's write lock: the table still points at its buffer, nothing has been built into that buffer since (a per-structuregenerationcounter, bumped inemit_blas_wave), and nothing but the table holds it. A smaller buffer is made,CopyRaytracingAccelerationStructure(..., COPY_MODE_COMPACT)is recorded, and every console address that pointed at the old buffer points at the new one.shown, the existing path that already keeps TLASes from naming structures whose build was not submitted). A TLAS built before keeps the old buffer throughBlasRefsuntil it is built again. The old buffer is released past the fences when its last holder goes, and its heap units go with it.addresses built again after compaction).HostAs::keys, written under the table's write lock). That way the compaction does not walk the whole lookup table under its write lock: it checks only the addresses that may name the structure. An address missing from that list makes the holder count larger than expected, so that structure is skipped rather than compacted.hardware RT BLAS compaction (...), giving the candidates, the sizes read, how many were compacted (MB before and after, and 64 KB units given back), and why the others were dropped.Only structures that are never refitted and never serve as a refit's source are compacted. So no refit ever reads a buffer whose copy is recorded but not yet submitted. Unset, nothing of this runs: no extra flag, no postbuild query, no work per frame.
Relation to other pull requests
main, heaps are kept for the whole run, so freed units only go to later BLASes, which means fewer new heaps but no heap given back. With #318, heaps that the compaction empties can be released. The new buffers come fromcreate_blas_buffer, whose signature #318 keeps. Expect at most a trivial rebase in thetestsmodule.generationcounter rather than relying on lists holdingArc<HostAs>. If #268 lands, lists hold the structures they build until reset, and the "held by nothing but the table" check simply gets stricter.DARNER_HW_RT_REFIT_BUILT): compatible. The compaction never reads a source whose build is not finished. It copies only after the compacted size of that very build has been read back, which happens when the building list is reset after its last execution, and only if thegenerationcounter shows no build into the buffer since. Compacted copies are never refit sources (noALLOW_UPDATE). Expect a textual conflict: both add a field toHostAsand initialise it in the same constructors. On rebase, the compactedHostAsshould getbuilt: true(or be set at the copying list's submission; it is never a refit source either way).DARNER_HW_RT_REFIT_COMMITTED): compatible. Compaction only takes BLASes built without update, which stay in the shared heaps under #445 too. Textual conflict: #445 adds arefittableargument tocreate_blas_buffer, and this PR calls it once more for the compacted buffer. On rebase, passfalsethere.DARNER_HW_RT_HEAP_EVACUATE, branchpr/hwrt-heap-evacuate).How it was tested
Tested revision: 15498a839, on top of
main47d21cd3b.Commands and results:
cargo check --release -p darner-gpu: finished, no warningscargo test --release -p darner-gpu --lib hwrt: 31 passed, 0 failed (6 of them new)compact_candidate), when a compaction is worth it (a whole 64 KiB unit saved), that a buffer of one unit or less is never asked its compacted size, the per-frame share (count and bytes, at least one), and the wait/retry queue (120-frame wait, once a frame, retries, give up after 8 tries).Changes a default: no (off unless
DARNER_HW_RT_COMPACT=1).How the switch was checked: in a one-hour session on an RTX 4070 Ti 12 GB, Series X profile, hardware RT on (
DARNER_HW_RT=1), 30 fps cap (33.4 ms/frame median at the end of the run, 0 frames over 50 ms in the last interval). This was on a fork that also carried other memory changes, including a BLAS heap packing and release thatmaindoes not have. The compaction line at the end of the hour:No A/B (off and on, same route) has been run on this branch yet:
accel, MBGates run on that revision: none of the three full gates. Only the narrower checks: the two above and
cargo clippy -p darner-gpu --all-targets --locked -- -D warnings(clean).Gameplay: RTX 4070 Ti 12 GB, Series X profile, 1440p, DLSS Quality, frame generation x2, hardware RT, frame interval 33.3 ms (fork session above). The log has no device-removed line.
Hardware dependence: compacted sizes are the driver's. The saving may differ on AMD or Intel cards, and on other NVIDIA drivers.
Coverage gaps: the GPU path (
ask_compacted_sizes,compact_work) has no unit test, since it needs a device. It has not been run with the D3D12 debug layer or GPU-based validation on this branch.Risks
ALLOW_COMPACTIONadded may build slightly slower, and the driver may report a differentResultDataMaxSizeInBytesfor them. The flag is added only with the switch on.shownwhen the copying list is submitted.shown, which is swapped only on submission), and it is never refitted or compacted again. The next full build at that address replaces it. The only cost is memory until then.How to test
DARNER_HW_RT=1 DARNER_HW_RT_COMPACT=1.hardware RT BLAS compactionline every five seconds:compactedshould grow after the first 120 frames of a scene with static geometry.card ledger kindsline (accel), thehardware RT BLAS buffersline (MB in use) and the frame times. Watch for device loss, TDRs, or missing or flickering geometry in ray-traced shadows and reflections.Checklist
main.docs/asset-policy.md.Checked for overlap
🤖 Generated with Claude Code
[pr-feature][memory][RAYTRACING] hwrt: compact the BLASes built without update on the host (DARNER_HW_RT_COMPACT, off by default)to hwrt: compact the BLASes built without update on the host (DARNER_HW_RT_COMPACT, off by default)Test needed — commit
7d95441b; what to check:DARNER_HW_RT=1 DARNER_HW_RT_COMPACT=1.hardware RT BLAS compactionline every five seconds:compactedshould grow after the first 120 frames of a scene with static geometry.card ledger kindsline (accel), thehardware RT BLAS buffersline (MB in use) and the frame times. Watch for device loss, TDRs, or missing or flickering geometry in ray-traced shadows and reflections.Evidence to post: card + driver, settings, commit tested, before/after (switch off vs on, two runs each), fps median and p99, and one line saying you looked at the picture.
Reply
testingto take this run; it's free again after 24 h with no results.View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
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.