WIP: hwrt: empty the emptiest BLAS heap into the others and give it back (DARNER_HW_RT_HEAP_EVACUATE, off by default) #453
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
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
TrustNo1/Darner!453
Loading…
Reference in a new issue
No description provided.
Delete branch "Layne/Darner:pr/hwrt-heap-evacuate"
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. It is a port, onto
main, of a change that ran for one hour on a fork with other local changes. The port differs from that version in ways that matter (see "Differences from the fork's version"). The switch is off by default, and nothing changes while it is unset.Depends on #452 (
DARNER_HW_RT_COMPACT). It reuses that PR's per-structure address list (HostAs::keys), its buildgenerationcounter and its per-frame share (compact_pick). The two switches work independently at run time, but the code is stacked. Keep this PR in draft until that one is merged.Contributor role (optional)
What it changes
With
DARNER_HW_RT_HEAP_EVACUATE=1(and the BLAS heaps on, as by default), once a frame inblas_work, after the compaction:COPY_MODE_CLONE) into buffers of the same size in other heaps that already hold something. No new heap and no committed buffer is made for them. At most 16 BLASes (8 MB) move per frame, largest first. A BLAS waiting for compaction is left to the compaction.shown, so the list that built or copied it has been submitted and runs before the copy on the one queue), and nothing but the table holds it. The holder count is read before thegenerationcounter, behind an Acquire fence, so a build recorded into it since the look is caught.hardware RT BLAS heaps emptied (...), giving heaps chosen, emptied, let go and given up, BLASes moved (count and MB), BLASes with no room elsewhere, BLASes built into since the look, and the CPU time per frame.create_blas_buffernow also returns the heap the buffer was placed in, andtake_unitsgets agrowflag (false for a moved structure: only non-empty, non-draining heaps).Why updatable BLASes are not moved
On
maina refit reads its source from the lookup table at record time, and lists are recorded on several threads. After a move, the table points at the new buffer before the copying list is submitted, so a refit in a list submitted earlier would read a buffer that has not been written yet. The fork's version moved updatable BLASes too, but it was safe only because of a local "refit only from a submitted source" guard. #446 (DARNER_HW_RT_REFIT_BUILT) is that guard upstream. If #446 lands, updatable BLASes could be moved as well: the newHostAswould getbuilt = false, set when the copying list is submitted. With #445 (DARNER_HW_RT_REFIT_COMMITTED, on by default) updatable BLASes are in committed buffers and never in the heaps, so this restriction costs nothing there.Relation to other pull requests
take_units/place_blas_buffer. #318 releases heaps that empty by themselves. This PR empties one on purpose and releases it. If #318 is merged first, this PR should be rebased onto it: choose the victim within a size class, use #318's release, and keep only the moving and the draining mark. Not meant to go in before #318 is decided.create_blas_buffer(both change its signature): it would take both therefittableargument and the returned heap.HostAsfields and constructors: the movedHostAsgetsbuilt: true(its source was already submitted, asshownproves).generationcounter is used instead of lists holdingArc<HostAs>).Differences from the fork's version
evacuate_victim). The fork relied on a separate local heap-packing change that is not upstream.take_units(the fork timed every placement: 115-750 us/frame of measuring overhead in its log).How it was tested
Tested revision:
df1b41b98(on7d95441b6, #452, onmain47d21cd3b).Commands and results:
cargo check --release -p darner-gpu: finished, no warningscargo clippy -p darner-gpu --all-targets --locked -- -D warnings: cleancargo test --release -p darner-gpu --lib hwrt: 36 passed, 0 failed (5 new)Changes a default: no (off unless
DARNER_HW_RT_HEAP_EVACUATE=1).How the switch was checked: the fork's version ran for one hour on an RTX 4070 Ti 12 GB (Series X profile, 1440p, DLSS Quality, frame generation x2, hardware RT, 33.3 ms frame interval, with
DARNER_HW_RT_COMPACT=1and other local memory changes). At the end of the hour: heaps chosen 668, emptied 644, given up 23; BLASes moved 41,234 (7,458 MB); no room elsewhere 586; 645 heaps given back, but 677 made, ending at 32 heaps (2,048 MB) for 1,358 MB of units in use (66 %) and 1,054 MB live. The card ledger showedaccel2,068 MB. There is no device-removed line in that log. That run did not show a smaller steady-state heap count than the 18-minute run without evacuation (24-26 heaps), and heaps were made and released about every 5.5 s. An A/B on the same route is needed before any claim of saving.Gates run on that revision: none of the three full gates. Only the narrower checks above.
Hardware dependence: may depend on VRAM size and driver (heap creation cost, release timing).
Coverage gaps: the GPU path (
evacuate_work, heap release) has no unit test. Not run on this branch, and not with the D3D12 debug layer.Risks
CreateHeap.shownwhen the copying list is submitted. The fork measured roughly 0.1-1 ms per frame for the evacuation work in total.shown), and it is never refitted. The next full build replaces it.How to test
DARNER_HW_RT=1 DARNER_HW_RT_HEAP_EVACUATE=1, with and withoutDARNER_HW_RT_COMPACT=1.hardware RT BLAS heaps emptied(let go,BLASes moved) andhardware RT BLAS buffers(heaps, MB in use).card ledger kindsaccelvalue, and the frame times. Watch for device loss, TDRs, and missing or flickering geometry in ray-traced shadows and reflections.Checklist
main. Stacked on #452.docs/asset-policy.md.DARNER_HW_RT_COMPACT): sharesHostAs::keys,generationandcompact_pick.Checked for overlap
🤖 Generated with Claude Code
WIP: [pr-feature][memory][RAYTRACING] hwrt: empty the emptiest BLAS heap into the others and give it back (DARNER_HW_RT_HEAP_EVACUATE, off by default)to WIP: hwrt: empty the emptiest BLAS heap into the others and give it back (DARNER_HW_RT_HEAP_EVACUATE, off by default)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.