gpu: a texture placement reaps the pending ranges only when no heap has room #3478
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!3478
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3478"
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?
@borosf on GitHub · 2026-11-27 07:04 UTC · original
borosf:vibe/placement-reap-842ca5→main· +210 −6 · 1 files · 4 commits · openWhat
placement::place()calledHeaps::reap()on every placement, andfree()called it on every texture given back. A reap walks the whole pending list — two COM reference calls (AddRef/Release) per range, since a range is only reusable once nothing else holds its texture. A new shot places hundreds of textures while its own earlier textures keep ranges pending, so that is an O(n²) walk over the ranges the shot itself created.Now:
REAP_EVERY), bounding both the walk's share of a placement and how much free space waits unreclaimed;free_bytes()andstats()still reap, as they did (they run per frame for the statistics line).Nothing about when a range may be reused changes: a range still only returns to the free map once nothing but the pool holds its texture, and
unplaceis untouched. The change makes reclamation later, never earlier.Measured (Intel Arc B580, Windows 11, synthetic, new test)
With 512 pending ranges — a heap's worth of textures a shot gave back while they are still held:
place()did)27x on the placement path, and the test also asserts the reap runs exactly once when the heap is finally full. A shot placing 300 textures at a 512-range backlog is ~2.3 ms → ~0.09 ms; the cost scales with the backlog, which is what made it O(n²).
Verification
cargo test -p victory-gpu --lib --locked -- --test-threads=1: 230 passed / 2 failed / 1 ignored — the two being the known B580 heap-cap failures (#1744/#1829) that pristine main fails here too (main: 229 passed / 2 failed / 1 ignored; the extra pass is the new test).cargo clippy -p victory-gpu --all-targets -- -D warnings: clean, and clean with--all-features.rustfmt --edition 2024 --checkhunk parity with origin/main (10 = 10);cargo xtask policy: 191 files ok.No game data used; synthetic tests only.
claim: posted on #1633 (comment 7212062567)
@oni-swr on GitHub · 2026-11-27 07:30 UTC · original
WARP verification of #3478 (head
15004cad4e441d0edde8401ada07bdd88f3c1592, base63bcca43c6a00a758510398fa43096ce7e4f7df0= merge base with main = main tip at the time). No physical GPU used.Setup: Ryzen 7 5700X3D, Windows 11 Pro build 10.0.26200, rustc 1.98.1 (48a229cea 2026-09-01),
VICTORY_WARP=1+VICTORY_D3D12_WARP=1,dxil.dllfrom Windows SDK 10.0.26100.0 (VICTORY_DXIL). Command:cargo test -p victory-gpu --lib --locked --features diagnostics -j 4 -- --test-threads=1(thediagnosticsfeature is needed, otherwiseVICTORY_D3D12_WARPis ignored andhost()would pick the real adapter).Tests (victory-gpu lib):
63bcca415004cadThe new
a_placement_with_room_does_not_walk_the_pending_rangesactually runs on WARP (not skipped) and passes: 512 pending, placement with a reap 9.3 µs vs 329 ns without.Review:
allocate()order is right:take_room→reap→take_room→new_heap, so a reap always happens before a new heap is created.free_bytes()andstats()still reap unconditionally.since_reapis reset inreap(), all state sits under theHEAPSmutex, so no new thread-safety issue. No leak: unreclaimed ranges are bounded (at most 63 given-back ranges wait, plus anything still held) and are collected by the next reap fromplace/free_bytes/stats/a 64thfree.place()(placement.rs,heaps.reap(); heaps.allocate(...)) still callsheaps.reap()itself beforeallocate(), and the PR doesn't touch it. So every placement still walks all pending ranges, and the new "reap only when no heap has room" logic inallocate()is never reached without a prior reap. The new test callsallocate/take_roomdirectly, so it doesn't see this. Suggest removing thereap()inplace()(allocate already reaps when needed) and have the test go throughplace().free(): batching the reap by 64 removes the O(n²) walk when many textures are given back at once.after * 4 < beforeis wall-clock based and could be flaky on a loaded CI machine; the struct literal intake_roomwas also reflowed to multi-line unlike the surrounding style.Benchmark (not part of the PR; a throwaway in-crate test through the real
place/free, not committed, 512 placed 256x256 BC1 textures kept held so all 512 stay pending, release build, WARP, base and head interleaved, 3 runs, median):free()x512place()+unplace()with 512 pending63bcca415004cadSo
free()is about 29x cheaper, butplace()with a backlog is unchanged (within noise), consistent with the leftoverreap()inplace(). Numbers are WARP/CPU only, the real-GPU effect is not measured here.AI-assisted (Claude Code, Claude Sonnet 5.5). No game files, dumps, install paths, shader names or hashes were used. Claim is on #1633.
@AurumCarlos on GitHub · 2026-11-27 08:43 UTC · original · reviewed
The placement half doesn't reach the hot path yet:
place()still callsheaps.reap()beforeheaps.allocate(...)(placement.rs:220at15004ca). So every placement still walks the pending list, and when no heap has room it now walks it twice, once inplaceand again inallocate. Only thefree()batching takes effect as it stands.The new test calls
Heaps::take_room/allocatedirectly, so it passes without going throughplace(). Dropping thatreap()and checking thereapscounter across aplace()call would cover it.Smaller:
after * 4 < beforeis a wall-clock assertion that runs whereverhost()finds a device, and the "after" loop is 100 very short calls, so one preemption can fail it. Asserting onreapsand only printing the timings would keep the check without that risk.@borosf on GitHub · 2026-11-27 11:21 UTC · original
@AurumCarlos both points are in at
2e2d2a24.The outer
reap()is gone. It walked the pending ranges for every placement, including the common one that a heap already had room for.allocatenow goes through a newHeaps::reserved:So a placement pays the walk only when no heap holds the range, and then once, before the new heap.
reservedtakes no device, which is what the new test uses.New test
a_placement_into_a_heap_with_room_does_not_reap(no game files; it makes a 64 KiB range in a real heap, then drivesreserveddirectly): a placement into a heap with room leavesreapsunchanged, and the first one that finds no room reaps exactly once.Local verification on Windows 11 x64 (Intel Arc B580):
cargo test -p victory-gpu --lib placement:: --locked: 4 passed, 0 failed (the 3 existing tests plus the new one).cargo clippy -p victory-gpu --all-targets --locked -- -D warnings: clean.cargo xtask policy: 191 files ok.rustfmt --checkonplacement.rs: 10 hunks, same asorigin/main(the file's pre-existing ones).On the duplicate: #2955 (RVZO6) defers the same
free()reap, infree()rather than inplace(). The two are not exclusive but they overlap; if you would rather review one, this one is the smaller of the two and keeps the reap counted at the placement (since_reap/REAP_EVERY). I have not pushed anyone to close theirs.@oni-swr on GitHub · 2026-11-27 11:46 UTC · original
WARP/CPU re-check of #3478 at its new head
2e2d2a24dfe9f4e59d385d5b6f6695b9415b28ca(base63bcca43c6a00a758510398fa43096ce7e4f7df0= merge base = main tip). Earlier report: #3478 (head15004cad). No physical GPU used. Claim on #1633.Environment: Windows 11 Pro 10.0.26200, WARP
d3d10warp.dll10.0.26100.9818, rustc 1.98.1,VICTORY_WARP=1+VICTORY_D3D12_WARP=1,dxil.dllfrom Windows SDK 10.0.26100.0. Command:cargo test -p victory-gpu --lib --locked --features diagnostics -j 4 -- --test-threads=1.63bcca42e2d2a24New:
placement::tests::a_placement_into_a_heap_with_room_does_not_reappasses and runs on WARP (not skipped). The earliera_placement_with_room_does_not_walk_the_pending_rangesalso passes and prints, for 512 pending ranges, a placement with a reap of 15.1 µs against 541 ns without. No new failure, no flakes seen.Is our earlier note resolved? Yes. At
2e2d2a24place()isheaps.allocate(device, size, align)with theheaps.reap()line removed (read from the diff and the file). The only reap on the placement path is insidereserved(), aftertake_room()found no room, followed by a secondtake_room()and thennew_heap(). So a placement into a heap with room no longer walks the pending list, and when there is no room it reaps once rather than twice.free_bytes(),stats()and the batched reap infree()are unchanged and still reap as before. The new test drivesreserved()rather thanplace(), butplace()now has no reap of its own, so it covers the path.Still open from AurumCarlos's review: the older test keeps the wall-clock assertion
after * 4 < before(the margin was about 28x here, but it can still flap on a loaded machine); asserting onreapsand only printing timings would remove that risk. I did not re-run the through-place()benchmark from my earlier report.AI use: Claude Code (Claude Sonnet 5.5). No game files, dumps, install paths, shader names or hashes were used.
@borosf on GitHub · 2026-11-27 11:56 UTC · original
@oni-swr thanks — your re-check caught the last real item, and it is fixed at
52dcc55.The wall-clock assertion is gone. The test now asserts what it is actually about, the reap:
before/afterare still measured and still printed, so the 28× margin you saw can be read off a run without any build depending on it. That removes the flake you flagged without losing the number.Local verification here (Windows 11 x64, Intel Arc B580) at
52dcc55:cargo test -p victory-gpu --lib placement:: --locked: 4 passed, 0 failed (all three existing plusa_placement_into_a_heap_with_room_does_not_reap).cargo clippy -p victory-gpu --all-targets --locked -- -D warnings: clean.cargo xtask policy: 191 files ok.rustfmt --checkonplacement.rs: 10 hunks, the same asorigin/main(its pre-existing ones).For the record on your two findings: the through-
place()benchmark being flat was the symptom of the leftoverreap()inplace(), which is what your first report identified — that is why removing it (rather than only batching infree()) was the fix, andplace()now goes straight toallocate. Yourfree()number (1.136 ms → 38.6 µs for 512 given back) is the part this PR can claim on its own, and I have not tried to measure the real-GPU side of it either.@futurepro62 on GitHub · 2026-11-27 18:18 UTC · original
NVIDIA full-suite run, to go with the reports above by oni-swr, since none of them names a GPU run. Tested exact head
348a74b(on its base63bcca4).Tested
dxil.dllfrom Windows SDK 10.0.26100 (the loader's default), debug.cargo build --workspace --locked, thencargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware: 869 passed, 0 failed, 10 ignored.a_placement_with_room_does_not_walk_the_pending_ranges,a_placement_into_a_heap_with_room_does_not_reap,the_place_entry_into_a_heap_with_room_does_not_reap.--skipleaves out tests that fail on main63bcca4on this card too, not because of this PR:heap_direct_texture_reads_mark_their_heap_indexends thevictory-shadertest process with0xc0000005(#2571), so without the skip the rest of that crate never reports;dynamic_slots_are_held_until_released,lists_share_a_table_and_copies_keep_their_viewsand the twostride_testshit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317);gathers_at_a_level_match_the_hardwarefails on lane 0 (#1744).Not tested
AI use
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.