fix(victory-gpu): track exact upload block spans and move zeroing/alloc outside ARENAS lock #451
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/451"
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?
Imported from LooperSalty/AnyXboxX. Originally posted by Lewandox on 2026-11-26T20:08:50Z.
Summary
Fixes two issues in
victory-gpu/src/upload.rs(used bylist::allocate_uploadandmemory::named_in_uploadfor ray-tracing top-level structure builds):Exact allocation boundaries in
upload::block(address)(fixes cross-list bleed / over-scan):Arenastored onlytaken: Vec<bool>, soupload::block(address)counted all consecutivetrueblocks starting at(address - arena.at) / BLOCK.memory::named_in_uploadscanned across unrelated command lists' upload buffers (risking concurrent data races with other recording threads and wasting CPU scanning up to 4 MiB instead of the caller's own block). And whenaddressfell inside a later block of a multi-block allocation,block()returned a truncated tail instead of the allocation's true start.(first, count)(Slot::FREEwhen free), soupload::block(address)returns the exact(start, len)of the owning allocation in O(1).Reduced
ARENASmutex contention and unnecessaryMEM_WRITE_WATCHdirtying inUpload::new(len):Arena::freeto skip full arenas in O(1).write_byteszeroing of reused blocks outside the globalARENASlock.VirtualAlloc2(reserve) andshadow::registeroutside theARENASlock (eliminating lock nesting withshadow's global table and stalls on parallel recording threads).write_bytes(0)on freshlyVirtualAlloc2(MEM_COMMIT)arenas (Windows guarantees zero-initialized pages), avoiding prematurely dirtying untouched pages inMEM_WRITE_WATCH.Verification
cargo test -p victory-gpu --lib upload::tests(default and--features diagnostics)upload::tests::block_returns_exact_allocation_bounds_without_bleeding_into_neighborsverifies adjacent allocations, multi-block queries from non-zero offsets, and clean release.Imported from LooperSalty/AnyXboxX. Originally posted by mauroalvare on 2026-11-27T01:13:22Z.
Independent Windows x64 release verification at
ef0113b6585249f8e5fbe7652f9319d7dfa42ba7and parent37d4686711bbb04c2cc3825f3f13bbff7c140fb0.upload::testspassed at the head, both with default features and with--features diagnostics.block_returns_exact_allocation_bounds_without_bleeding_into_neighborstest copied over, the first assertion returned 256 KiB for a 64 KiB allocation.Reproduce the cold case by appending this test to
third_party/victory/crates/victory-gpu/src/upload.rson each revision and running the command in a fresh process for each sample.Sharing a pending arena reservation among simultaneous misses would retain the exact-span fix while limiting committed memory growth. Builder frame timings would need a fixture that exercises
memory::named_in_upload.Imported from LooperSalty/AnyXboxX. Originally posted by Lewandox on 2026-11-27T01:28:02Z.
Great catch — thank you for the independent release verification and the cold-start repro!
Pushed a follow-up commit adding a dedicated slow-path
ARENA_GROWmutex with a double-checkedARENASre-probe before callingreserve():ARENA_GROWand still zero outsideARENAS.VirtualAlloc2andshadow::registerstay outsideARENAS, while simultaneous cold-start misses now serialize growth and share one 4 MiB arena.upload::tests::cold_parallel_uploads_share_a_single_arena(fresh subprocess, 16 concurrent threads on a barrier, assertingARENAS.len() == 1); all 4upload::testspass locally (4 passed, 0 failed).Imported from LooperSalty/AnyXboxX. Originally posted by mauroalvare on 2026-11-27T01:56:18Z.
Retested the follow-up
c9aadb7684e86f2f8e3afb4258d3a701027cce8bon Windows x64, Rust 1.98.1, release.upload::testspassed with the default features and with--features diagnostics.ef0113bbuild used 8–16 arenas. This reproduces the correction with the original workload.The last command uses the test in my earlier comment and was run eight times in fresh processes.