perf(rt): prioritize VRAM for BVH arenas and use GPU-ordered single-buffer PC-RAM spill #290
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/TaynanGT--Vice-Tay!290
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-290"
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?
@Vladimir-Human on GitHub · 2026-11-27 13:48 UTC · original
Vladimir-Human:perf/rt-vram-arenas-and-port-rt→main· +815 −55 · 4 files · 1 commits · openNarrowed strictly to VRAM BVH arena budgeting/reclamation and GPU-ordered single-buffer PC-RAM spill per review feedback. The opt-in
VICTORY_PORT_RT=1forward-fill path andVICTORY_RT_STAMPS=1diagnostics have been split out into standalone PR #299.Summary (4 files in
crates/victory-gpu)crates/victory-gpu/src/host.rs:host::drain_retired()to flush matured retired COM resources whose fence has completed before checking VRAM headroom.shadow::direct_dirty()insideHost::card_before()via a transient upload buffer and GPU-orderedCopyBufferRegion, keeping_syncedand_direct_uploadsalive inCardPlanuntil GPU completion (no unsynchronized CPU overwrites into in-flight GPU reads).drain_retired_releases_matured_com_resource_after_fenceverifying actual COM resource release after fence completion while retaining in-flight entries.crates/victory-gpu/src/resource.rs:request_vram_eviction(bytes)consumed on the submitting thread inlet_go_idle(), avoidingMEMORY -> TEXTURESlock nesting and avoiding any phantom VRAM budget credit before eviction actually releases resources.crates/victory-gpu/src/shadow.rs:stagingbuffer when a by-address arena spills to PC RAM (by_address_pc_ram_fallback_uses_single_buffer_without_staging).Shadow::stage_direct(),coalesce_direct_runs()(sorted, disjoint, newest-wins coalescing for overlapping CPU writes), anddirect_dirty(), verified bycoalesce_direct_runs_is_disjoint_and_newest_winsand GPUCopyBufferRegionupload tests.BY_ADDRESS_CARD_BYTES) with allocation/drop coverage (by_address_vram_arena_tracks_and_releases_card_bytes).crates/victory-gpu/src/memory.rs:host::drain_retired()before evaluating realhas_room(host.video_memory())for by-address arenas; when VRAM is still tight, signalsresource::request_vram_eviction(len * 2)for the submitting thread and falls back cleanly to single-buffer PC RAM.delayed_freemonotonicallybury_lag-aware viacompute_delayed_until(...)(delayed_free_holds_pc_ram_slot_until_flight_completes).is_in_pcPC-RAM arena telemetry inMemory::report.Verification
Run with
VICTORY_D3D12_DEBUG=1(0D3D12 debug layer errors):cargo clippy -p victory-gpu --all-targets --locked -- -D warnings(default &--features diagnostics): 0 warningsmemory::tests,by_address,coalesce_direct_runs,drain_retired_releases): 10/10--features diagnostics(same suite): 11/11--features diagnosticsparallel stress (descriptor::host::tests+drain_retired_releasesconcurrently without--test-threads=1): 49/49VICTORY_D3D12_WARP=1,--features diagnostics): 11/11xtask policyclean (315 files ok);cargo test -p xtask --locked: 11/11Same-Route A/B Measurement Plan (Local VRAM + Private Bytes + Frame Times)
No live title capture is present in this automated test environment; to evaluate on hardware against
main(withVICTORY_PORT_RTunset):mainand on this branch.Host::video_memory()/BY_ADDRESS_CARD_BYTESand DXGI localCurrentUsage)stagingallocations on PC-RAM spilled arenas)Memory::reportPC-RAM arena count (is_in_pc)Keeps ray-tracing BVH arenas in local VRAM longer, removes duplicate 64 MiB staging allocations on PC-RAM spill with GPU-ordered uploads, adds residency telemetry, and ports the opt-in `VICTORY_PORT_RT=1` submission-stall fix and `VICTORY_RT_STAMPS=1` dispatch profiler: 1. VRAM priority & single-buffer PC-RAM spill (`resource.rs`, `shadow.rs`, `memory.rs`, `host.rs`): - Adds `host::drain_retired()` (drops already-matured retired resources safely without holding `TEXTURES` or waiting on the GPU) before re-checking real DXGI `video_memory()` headroom; when VRAM is still full, signals `resource::request_vram_eviction(len * 2)` consumed on the single submitting thread inside `resource::let_go_idle()` (preserving its >= 5 s idle window and avoiding `MEMORY -> TEXTURES` lock nesting) without crediting unfreed `RETIRED` bytes against real DXGI budget. - Decouples `BY_ADDRESS_CARD_BYTES` from `WINDOW_CARD_BYTES` (preventing 64 MiB RT arenas from starving loose non-RT windows under `VICTORY_CARD_WINDOWS_MB`) and rolls back/decrements `BY_ADDRESS_USED` cleanly across error paths and `Drop`. - When spilled to PC RAM, allocates a single mapped `shared_buffer` with no duplicate 64 MiB `staging` buffer; stages only changed dword runs via `Shadow::stage_direct()` (and coalesces overlapping writes into strictly disjoint runs) to be uploaded via GPU-ordered `CopyBufferRegion` in `Host::card_before` using a tiny transient upload buffer, so CPU writes never race live GPU-readable shared memory and adjacent GPU-written dwords stay intact. - Defers recycled single-buffer PC-RAM slots in `Memory::gone()` via `delayed_free` using a strictly monotonic target incorporating `bury_lag()` (minimum 1) and `cut_for` headroom so recording and split submissions never read overwritten slots. Frees reserved virtual memory if `Memory::another()` fails to back an arena. - Adds `is_in_pc()` telemetry logging PC-RAM copy and arena counts in `Memory::report()` (adapted from avatarmanz). 2. Opt-in `VICTORY_PORT_RT=1` & `VICTORY_RT_STAMPS=1` (`port_rt.rs`, `host/rtstamps.rs`, `host/card_steps.rs`, `host/place.rs`, `host.rs`, `draw.rs`): - Ports `avatarmanz`'s `VICTORY_PORT_RT=1` placed-copy ordering (rejecting upload-backed placed copies whose source was written by an earlier card-taken copy), list-cut counters, and same-list `HostList::forward_fill`, plus diagnostics-gated `VICTORY_RT_STAMPS=1` per-dispatch GPU timestamps (with zero-frequency guard).@TaynanGT on GitHub · 2026-11-27 13:51 UTC · original
@Vladimir-Human Separate the arena budget and RAM-spill comparison from the submission-stall switch. The critical checks are actual budget reclamation after the fence, newest-wins upload ordering, and a same-route A/B with local VRAM, private bytes and frame times recorded together.
github-bot referenced this pull request2026-11-27 14:42:53 +00:00
perf(rt): prioritize VRAM for BVH arenas, avoid duplicate PC-RAM staging, and port VICTORY_PORT_RTto perf(rt): prioritize VRAM for BVH arenas and use GPU-ordered single-buffer PC-RAM spillc6ce32bd96to46d7a3ebdc@Vladimir-Human on GitHub · 2026-11-27 14:40 UTC · original
@TaynanGT Split and narrowed as requested:
VICTORY_PORT_RT=1(forward_fill,Does::Placed.from_uploadordering guard) and diagnostics-gatedVICTORY_RT_STAMPS=1into standalone PR #299.#290is now strictly the 4 files for VRAM BVH arena budgeting/reclamation and GPU-ordered single-buffer PC-RAM spill (host.rs,memory.rs,resource.rs,shadow.rs).by_address_inner()drains matured retired COM resources viahost::drain_retired()before checking realhas_room(host.video_memory())(no phantom VRAM credit; eviction requests go lock-free viaresource::request_vram_eviction()tolet_go_idle()on the submitting thread).host::batch::drain_retired_releases_matured_com_resource_after_fence(actual COMReleaseof matured entries while retaining in-flight entries; also verified under parallel stress withdescriptor::host::tests49/49),by_address_vram_arena_tracks_and_releases_card_bytes(decoupledBY_ADDRESS_CARD_BYTESaccounting on alloc/drop), andmemory::tests::delayed_free_holds_pc_ram_slot_until_flight_completes(monotonicbury_lag-aware deferral).stagingbuffer and instead queue writes throughShadow::stage_direct(), merged bycoalesce_direct_runs()into sorted, disjoint, newest-wins byte ranges, then uploaded inHost::card_before()via transient upload buffer + GPU-orderedCopyBufferRegion(keeping_syncedand_direct_uploadsalive inCardPlanuntil GPU completion).VICTORY_D3D12_DEBUG=1, 0 debug errors) bycoalesce_direct_runs_is_disjoint_and_newest_winsandby_address_pc_ram_fallback_uses_single_buffer_without_staging.video_memory/BY_ADDRESS_CARD_BYTES), process private bytes,Memory::reportis_in_pccounts, and frame times together onmainvs#290independently of#299.@TaynanGT on GitHub · 2026-11-27 14:49 UTC · original
@Vladimir-Human The fence release test and newest-wins checks cover the two hazards in the spill path. For the game run, log local VRAM, private bytes, spill count and p10 frame time together. Keep #299 disabled for that pair so the change in allocation policy is the only variable.
46d7a3ebdcto315c946d8d@hamdanpor-ctrl on GitHub · 2026-11-27 23:24 UTC · original
The new test
shadow::copied_and_take_tests::by_address_pc_ram_fallback_uses_single_buffer_without_stagingfails every time on my laptop: 5 of 5 parallel runs ofcargo test -p victory-gpu --locked.Line 7925 on that tree is
assert_eq!(BY_ADDRESS_USED.load(Ordering::Relaxed), before_used);, so the 64 KiB PC-RAM fallback arena was counted inBY_ADDRESS_USED, which the test expects to stay unchanged. The other counter checks before it passed.315c946against its merge base) applied onmainatfe7c6e5--all-features: clean; the other 533victory-gputests passedNot tried with the PR's own base alone; happy to run anything that helps.
AI-assisted (Claude Code).
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.