GPU: copies of single views reuse the buffers of dead ones #1979
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!1979
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1979/head"
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?
@0xkn0wh3r3 on GitHub · 2026-11-25 02:15 UTC · original
0xkn0wh3r3:gpu/reuse-view-copy-buffers→main· +209 −5 · 2 files · 2 commits · closed without mergingThe problem
Every frame, hundreds of small host buffers are made and dropped for the title's buffer views. Each one is a new committed buffer, so this costs frame time.
A buffer view that does not start on an element of its title buffer's copy gets a copy of just its own bytes (
shadow::exact). The title places such views at ring positions that move every frame:So these copies die and are made by the hundred each frame. Each one was a new committed buffer, created and mapped under the global
EXACTlock.Measured on an RTX 5070 Ti (driver 621.24), 20 frames of 300 new 456-byte view copies at moving positions, 300 live at a time:
The fix
A dead copy's buffer is kept for the next copy of the same width:
Shadow::drop), its buffer goes to a pool by width (SPARE, 256 MiB at most in all).exact) takes it, and zeroes it over the view's bytes, as a new buffer would be.Copies of whole buffers and of loose windows are unchanged, as are the copies' widths. The cost is up to 256 MiB of spare buffers held.
Testing
shadow::tests::view_copies_reuse_the_buffers_of_dead_ones_nothing_holds: checks that a copy takes a dead one's buffer, zeroed, and that a buffer a list still holds is not handed on.cargo test -p victory-gpuon an RTX 5070 Ti (driver 621.24): all pass exceptdescriptor::host::tests::dynamic_slots_are_held_until_releasedandmemory::tests::lists_share_a_table_and_copies_keep_their_views. Those fail the same way onmain(the NVIDIA 1,000,000-descriptor heap cap, #1835).cargo clippy -p victory-gpu --all-targets, with and without--features diagnostics: clean.@DesertGamer on GitHub · 2026-11-25 02:16 UTC · original
VIctory V2: community PRs, merged and tested
Open PRs sitting in the queue? V2 pulls them into one build, screens each one (binaries, build scripts, hooks, new deps) and runs tests after every batch.
Where it stands today: launches, runs the menu at 30 fps, plays the intro video, reaches the start screen and loads the world (~50 s). Entering the world is the current blocker: rendering fails with a GPU "device removed" error (tracked in issue #1).
⚠️ Entering the world on a real GPU can hang it and make Windows reset the driver. Try it at your own risk.
Not playable yet, but every batch of merged fixes moves it closer. If you have a PR that's stuck, or a GPU to test on, I'd love your help:
https://DesertGamer/VIctory-V2
Unofficial community fork of Marvisak/VIctory, GPL-3.0.
@jeremygold02 on GitHub · 2026-11-25 03:43 UTC · original
Triage verdict — Keep the allocation win; use an explicit retirement condition (
0a690f2)Evidence
Shadow::dropuses the value returned byIUnknown::Releaseto decide whether the mapped buffer can be zeroed and reused. Microsoft documents that return value as test-only. D3D12 command lists do not take references to recorded objects, so the reuse condition needs to follow VIctory’s own command-list ownership and completion rules.Checks and limits
Next step
Shadow, and checks contents before and after the buffer becomes eligible for reuse.This verification was AI-assisted.
@0xkn0wh3r3 on GitHub · 2026-11-25 06:07 UTC · original
Thanks @jeremygold02, that's a fair point.
4efedc7makes the rule explicit:mainrelies on to avoid freeing a buffer still in use. That covers lists (what theykeep, and the copies their steps name) until they're reset, view heap slots, and slots rewritten mid-submission (host::retire). A buffer is only given back when no other reference exists. Once that count reads zero it can't go back up, because taking a reference needs one, so the race COM's documentation warns about can't happen here.host::release_retired, which already ends retired resources' lives after a submission, now also settles the pool.Tests:
spare_buffers_wait_for_a_submission: runs on a pool instance of its own. Nothing given back is taken before a settle. After that, buffers come back by width, last given first, within the byte limit. It fails if buffers are made reusable straight away.a_dead_copy_a_list_holds_is_not_handed_on: the test you asked for. A list records a GPU read of a copy and keeps its buffer, then the copy dies. The buffer isn't given back, and the submitted read sees the copy's original bytes.I replaced the old reuse test. It depended on which buffer a new copy got from the process-wide pool, and other tests running in parallel could change that.
@Marvisak on GitHub · 2026-11-25 08:24 UTC · original · edited 2026-11-25 16:05 UTC
Automated triage for the maintainers.
This pull request no longer merges cleanly into
main(conflicts incrates/victory-gpu/src/host.rs,crates/victory-gpu/src/shadow.rs). It will be reviewed once it is rebased onto the currentmain. The earlier verdict (needs work) was for an older state ofmain.Generated by Claude Code
@0xkn0wh3r3 on GitHub · 2026-11-25 18:50 UTC · original
Closing: upstream
6cc6aa3(copies of single views share large buffers) covers this. Single-view copies now take runs of shared 16 MiB arenas, and larger ones get an arena chunk that is reused too, so no committed buffer is made per copy for a pool to reuse. Lists and heap slots hold theArc<Shadow>, so a run given back on drop is safe without this PR's after-a-submission rule.Pull request closed