Send memory: use the buffers of finished submissions again, let idle ones go (from #306, alone on main) #458
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/lobomfz--VIctory-xmem!458
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-458"
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?
@LOCKhart07 on GitHub · 2026-12-04 12:32 UTC · original
LOCKhart07:send-buffers-on-main→main· +340 −27 · 2 files · 1 commits · merged 2026-12-04 17:30 UTCOne commit from #306 (
20547ee), taken out of the hardware ray-tracing stack and put on main by itself. It toucheshost/send.rsand a report line inhost.rs, nothing of hardware ray tracing, and adds no switch.What changes
Every submission in flight made an upload buffer of its own for what it sends up, sized to what was asked, and a buffer given back was used again only by a request of the same size, so most were made new.
Now a buffer is made at the next power of two (64 KiB at least) and, once its submission is done, kept spare for the next request of that size. Spare buffers not taken for 10 s are let go, and so is what passes 768 MB of spare; both go through
host::retire.Two report lines say it: what submissions send up (alive, in flight, spare, made, let go), and the host's buffers by who makes them.
Checked on main
0fd7614cargo clippy --release -p victory-gpu --all-targetsforx86_64-pc-windows-msvc: 40 warnings, as on main; none inhost/send.rs.host::sendtests under Wine 9.0: 6 passed, 0 failed.Measured, and what is not
The numbers in the commit message are from the stack, with hardware ray tracing on, on an RX 9070 XT (RADV), 2560x1440, six minutes: about 570 MB of these buffers on the card before; 3 alive (0.9 MB) and 6 made in the whole run after.
Not measured: a play of this branch alone on main, without hardware ray tracing. The machine that made this branch has no card.
Generated by Claude Code
@Kal0s-design on GitHub · 2026-12-04 13:59 UTC · original
Checked
d7ee411natively on Windows, on one NVIDIA desktop card plus WARP, against the merge base0fd7614.Reuse. The rule for when a buffer comes back is the same as on main. What changed is what happens to it after.
send::give_backhas one caller,card_done(host.rs:4099), which runs in two places. On the relay it runs for flights that have landed (host.rs:4155). A flight lands only once the fence's completed value has reached its number, sincelandablestops at the first flight withf > completed(host.rs:2471, used at 3486-3491). On the direct path it runs afterWaitForSingleObjecton the submission's fence (host.rs:4723, then 4787). The sends list is executed onself.queueright before the submission's lists (host.rs:4080), and the fence is signalled on that same queue after them, so it covers the sends too. Those buffers are not recorded anywhere else. When the device is removed, both paths callfail(host.rs:4125, 4776) beforecard_done, andfaildoes not return (host.rs:709). While its submission runs, aMemorybelongs to that submission'sCardPlan(host.rs:2283), so the pool can't hand it out or trim it.There is one older case this PR doesn't change. On the direct path, if
SignalorSetEventOnCompletionfails, the code logs a warning (host.rs:4727) and still callscard_done. The buffer can then be reused while the card may still be reading it. Main does the same thing, and theburycall right after (host.rs:4739) frees retired objects on the same assumption. I'm not asking for a fix in this PR.Letting go. Both the trim and the 768 MB cap now go through
host::retire(send.rs:310). That keeps a buffer until the newest started submission, plus the queued ones and 128 more, has finished. On main the cap dropped the buffer at once (main send.rs:130), so this is stricter. The trim runs only insidegive_back(send.rs:294), at most every 10 s bynow_ms, which is elapsed time and not a frame count. When nothing is dirty,card_beforereturns early (host.rs:4033) and no buffer comes back, so nothing gets trimmed either. Spare buffers, up to the cap, then stay until sends start again.Locks.
memoryandgive_backrun under the host's submission lock on the direct path (taken at host.rs:4452) and without it on the relay.SPAREis never held while another lock is taken.memorydrops it before making a new buffer (send.rs:254 against 262).give_backretires after dropping it (send.rs:310), and nothing is dropped while it is held. Under the submission lockretiretakes a part ofRETIRED, whichburyat host.rs:4739 already does there, so no new lock order comes in.When a buffer can't be made,
memoryreturnsNone(send.rs:262).takethen returnsNoneandcard_beforefalls back to copying from the staging side (host.rs:4062), as on main. Also as on main, there is no second try after letting the spare buffers go.One small thing in the report line.
Memory'sDrop(send.rs:91) runs when a retired buffer is buried, not when it is retired. So "in flight" (alive minus spare) also counts the buffers waiting out those 128 submissions.Tests. I ran
cargo test -p victory-gpu --lib -- --test-threads=2 --skip descriptor::tests::views_die_with_their_resourcewith the debug layer on.host::sendtests. The extra failure iswatch::tests::the_rest_of_the_one_asking_has_a_number_of_its_own, which passed 3 of 3 times on its own and also fails on the base under WARP. The other four (the twoindirect::tests::host_list_*tests and the twopipeline::hostlibrary loads) fail on the base too.--features diagnostics, the PR got 392 passed and 5 failed, and the base 386 passed and 6 failed. The base's sixth failure was the same watch test. The other five are the four above plusdescriptor::host::tests::views_are_made_beside_the_heap_and_copied_in, which fails on WARP on the base as well.No test in the suite reaches
send::memoryon either adapter. I checked with a print in it that I didn't commit. So the adapter runs only show nothing else broke, and the reuse timing above comes from reading the code.I also ran a local stress test on
Keptthat I'm not pushing. Eight threads take and give back under one lock, with simulated completion numbers, random trims and a small cap. It checked that nothing in flight is handed out or let go, that nothing is let go twice, and that the low count never goes above the number of buffers of that size. It passed.Looks right to me.
AI-assisted: yes
github-bot referenced this pull request2026-12-04 17:15:51 +00:00