Send memory: use the buffers of finished submissions again, let idle ones go (from #306, alone on main) #458

Manually merged
github merged 1 commit from github-bot/gh-458 into main 2026-12-04 17:31:56 +00:00 AGit
Owner

@⁠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 UTC

One commit from #306 (20547ee), taken out of the hardware ray-tracing stack and put on main by itself. It touches host/send.rs and a report line in host.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 0fd7614

  • The commit applies with no conflict.
  • cargo clippy --release -p victory-gpu --all-targets for x86_64-pc-windows-msvc: 40 warnings, as on main; none in host/send.rs.
  • host::send tests 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

**@⁠LOCKhart07** on GitHub · 2026-12-04 12:32 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/458) `LOCKhart07:send-buffers-on-main` → `main` · +340 −27 · 2 files · 1 commits · merged 2026-12-04 17:30 UTC One commit from #306 (`20547ee`), taken out of the hardware ray-tracing stack and put on main by itself. It touches `host/send.rs` and a report line in `host.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 `0fd7614` - The commit applies with no conflict. - `cargo clippy --release -p victory-gpu --all-targets` for `x86_64-pc-windows-msvc`: 40 warnings, as on main; none in `host/send.rs`. - `host::send` tests 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](https://claude.ai/code)_
Every submission in flight made an upload buffer of its own for what it sends up, sized to what was asked, and kept it until the submission was done. A buffer given back was used again only by a request of the same size, so most were made new: about 570 MB of them stood on the card at the end of a six minute run.

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, as other memory the card may still read.

Measured on an RX 9070 XT (RADV), 2560x1440, six minutes with the camera turning, hardware ray tracing on: 3 buffers alive (0.9 MB), 6 made in the whole run, 3 let go by the trim, none for the cap. Three runs, no error line, no device loss.

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.

Tests: host::send, 6 passed.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-04 12:33:29 +00:00
Author
Owner

@⁠Kal0s-design on GitHub · 2026-12-04 13:59 UTC · original

Checked d7ee411 natively on Windows, on one NVIDIA desktop card plus WARP, against the merge base 0fd7614.

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_back has 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, since landable stops at the first flight with f > completed (host.rs:2471, used at 3486-3491). On the direct path it runs after WaitForSingleObject on the submission's fence (host.rs:4723, then 4787). The sends list is executed on self.queue right 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 call fail (host.rs:4125, 4776) before card_done, and fail does not return (host.rs:709). While its submission runs, a Memory belongs to that submission's CardPlan (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 Signal or SetEventOnCompletion fails, the code logs a warning (host.rs:4727) and still calls card_done. The buffer can then be reused while the card may still be reading it. Main does the same thing, and the bury call 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 inside give_back (send.rs:294), at most every 10 s by now_ms, which is elapsed time and not a frame count. When nothing is dirty, card_before returns 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. memory and give_back run under the host's submission lock on the direct path (taken at host.rs:4452) and without it on the relay. SPARE is never held while another lock is taken. memory drops it before making a new buffer (send.rs:254 against 262). give_back retires after dropping it (send.rs:310), and nothing is dropped while it is held. Under the submission lock retire takes a part of RETIRED, which bury at host.rs:4739 already does there, so no new lock order comes in.

When a buffer can't be made, memory returns None (send.rs:262). take then returns None and card_before falls 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's Drop (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_resource with the debug layer on.

  • On NVIDIA the PR got 345 passed and 5 failed, and the base 340 passed and 4 failed. The extra six passes are the new host::send tests. The extra failure is watch::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 two indirect::tests::host_list_* tests and the two pipeline::host library loads) fail on the base too.
  • On WARP with --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 plus descriptor::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::memory on 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 Kept that 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

**@⁠Kal0s-design** on GitHub · 2026-12-04 13:59 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/458#issuecomment-7413653812) Checked d7ee411 natively on Windows, on one NVIDIA desktop card plus WARP, against the merge base 0fd7614. 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_back` has 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, since `landable` stops at the first flight with `f > completed` (host.rs:2471, used at 3486-3491). On the direct path it runs after `WaitForSingleObject` on the submission's fence (host.rs:4723, then 4787). The sends list is executed on `self.queue` right 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 call `fail` (host.rs:4125, 4776) before `card_done`, and `fail` does not return (host.rs:709). While its submission runs, a `Memory` belongs to that submission's `CardPlan` (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 `Signal` or `SetEventOnCompletion` fails, the code logs a warning (host.rs:4727) and still calls `card_done`. The buffer can then be reused while the card may still be reading it. Main does the same thing, and the `bury` call 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 inside `give_back` (send.rs:294), at most every 10 s by `now_ms`, which is elapsed time and not a frame count. When nothing is dirty, `card_before` returns 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. `memory` and `give_back` run under the host's submission lock on the direct path (taken at host.rs:4452) and without it on the relay. `SPARE` is never held while another lock is taken. `memory` drops it before making a new buffer (send.rs:254 against 262). `give_back` retires after dropping it (send.rs:310), and nothing is dropped while it is held. Under the submission lock `retire` takes a part of `RETIRED`, which `bury` at host.rs:4739 already does there, so no new lock order comes in. When a buffer can't be made, `memory` returns `None` (send.rs:262). `take` then returns `None` and `card_before` falls 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`'s `Drop` (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_resource` with the debug layer on. - On NVIDIA the PR got 345 passed and 5 failed, and the base 340 passed and 4 failed. The extra six passes are the new `host::send` tests. The extra failure is `watch::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 two `indirect::tests::host_list_*` tests and the two `pipeline::host` library loads) fail on the base too. - On WARP with `--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 plus `descriptor::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::memory` on 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 `Kept` that 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 manually merged commit 44c4a5e2b8 into main 2026-12-04 17:31:56 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.