fix(gpu): expire hot textures by submission serial instead of probe count #252
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/252"
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 LakshanSivakumar/Native-Victory-macOS. Originally posted by Sheffy007 on 2026-11-27T05:18:46Z.
Summary
Title::sync_serialandTracked::hot_until = sync_serial + HOT) instead of decrementingTracked::hotonly whenprobe_roundvisits a texture (#179,#15). When world streaming puts ~18,900 textures intohot_keysandPROBE_BUDGETvisits ~60 per submission, unchanged streamed textures previously stayed hot for600 * (18900 / 60)submissions (> 1 hour) instead of 600 submissions.hot_until < sync_serialinprobe_roundwithout callingprobe_hash(mach_vm_read_overwrite) or consumingMIN_SYNC_HOT/PROBE_BUDGETprobes.probe_round's wraparound removal (wrappedprefix swap beforeswap_remove) so removing an entry after wrapping fromcursor..leninto0..startnever pulls an already-visited suffix entry back into the unvisited prefix or skips an unvisited entry.native::texture_tests::hot_textures_cool_by_submissions_even_when_probe_round_is_cappedand document the change indocs/native-host.md.Verification
cargo test -p victory-hle -p victory -p victory-gpu -p victory-metal -p victory-shader -p xtaskcargo clippy --workspace --all-targets --target x86_64-pc-windows-gnullvm -- -D warningscargo clippy --workspace --all-targets --all-features --target x86_64-pc-windows-gnullvm -- -D warningscargo xtask policyImported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T10:32:10Z.
I had not reviewed this one yet. Before it can merge:
start, thenswap_remove) is the delicate part and has one test. Please add a test where an entry is removed after the wrap, and say what keeps an entry that was already visited from being skipped or visited twice.I have not run it.
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Sheffy007 on 2026-11-27T11:53:07Z.
Addressed all three points:
main(e2f211a8): Updated cleanly onto currentmain.--releasebenchmark vs world run):hot_keysfigure came fromVICTORY_TRACE_TEXTURE_SYNC=1world logs in #179).native::textures::tests::bench_hot_texture_serial_cooling_under_probe_budget(--release -- --ignored --nocaptureon Apple M5 Pro, 48 GB, macOS 27.2.1) over5,000hot64 KiBtextures across800submissions under the2 msPROBE_BUDGET:1..=600:2.003 ms/submission(~200–250 probes/submission, capped byPROBE_BUDGET).HOT = 600submissions (601..=800): expired entries are evicted in a single pass without reading memory, droppinghot_keysto0and hot-probe lock hold time from2.003 ms/submissionto0.0004 ms/submission(at ~30 submissions per world frame, ~60 ms/frameof host-lock time freed once a streamed wave ages past 600 submissions, whereas per-visit decrement kepthot_keysat5,000for ~15,000submissions).probe_round_wraparound_removals_visit_each_live_entry_once):probe_roundmaintains a 3-way partition ofkeys:!wrapped,start <= idx <= keys.len()):keys[0..start]is unvisited,keys[start..idx]was visited and kept, andkeys[idx..keys.len()]is unvisited (swap_remove(idx)pulls an unvisited tail element intoidx, keepingkeys.len() >= start).wrapped,0 <= idx <= start <= keys.len()):keys[0..idx]was visited after wrap,keys[idx..start]is unvisited, andkeys[start..keys.len()]was visited before wrap. Whenkeys[idx](idx < start) is removed,*start -= 1names the last unvisited slot (idx <= *start),keys.swap(idx, *start)moves that unvisited entry intoidx(or hitsidx == *startand exits atidx >= start) while placing the removed entry at*start, andkeys.swap_remove(*start)fills*startfromkeys.len() - 1(an already-visited pre-wrap survivor, or pops*startitself when*start == keys.len() - 1). Both visited slices[0..idx]and[*start..keys.len()]remain strictly disjoint fromkeys[idx..*start].native::textures::tests::probe_round_wraparound_removals_visit_each_live_entry_once, testing both an explicit post-wrap removal trace (cursor = 4on[0..6], removing entries at indices0and2after wraparound) and an exhaustive sweep of all6start cursors across all3^6 = 729combinations of(already expired, expires after probe, stays hot)(4,374schedules), asserting viaTracked::skippedthat every live entry is visited once and only once and every expired entry is evicted with 0 probes.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Olima34 on 2026-11-27T13:06:06Z.
Check on
a2cd4625merged onto mainc5d7f4d0(M5 Pro 48 GB, arm64, with the converter): clippy, policy and victory-shader pass. In victory-gpu, the newnative::tests::texture_tests::hot_textures_cool_by_submissions_even_when_probe_round_is_cappedfailed once in three full runs of the lib tests, attexture_tests.rs:349(uploads_of(refreshed) == 4, 'still-hot texture is probed on the next submission'). It passes alone, and the other two full runs passed (330 passed). That looks like the order-or-timing flake of #307: with a zero budget the round stops afterMIN_SYNC_HOTprobes, so whetherrefreshedis among them depends on the cursor and on other tests' hot textures. @Sheffy007, could you make that assertion independent of the cursor, e.g. by giving the last sync no deadline or by checking the textures probed? I'm holding the merge until then. I'm also including this PR in a game run of the GPU PRs and will post that result here.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Sheffy007 on 2026-11-27T13:43:38Z.
Rebased onto
main(60baf130->09448b26) and replaced the two post-loopDuration::ZEROchecks inhot_textures_cool_by_submissions_even_when_probe_round_is_cappedwithsync_dirty_without_probe_deadline()(keeping theHOTloop steps capped atDuration::ZERO), soWATCHdirty entries from earlier tests can never stopprobe_roundatMIN_SYNC_HOTbefore reachingkeys/refreshed. Verified across 3 consecutive fullvictory-gputest runs + Windows clippy + policy. @Olima34Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Olima34 on 2026-11-27T13:48:48Z.
@Sheffy007 thanks. The maintainer had already merged this (
329d0f8f) with his own fix of the test's last syncs (c8bdf4dc), so I checked mainb639c175instead:cargo test -p victory-gpu --libpasses in 3 runs out of 3 (357 passed each), and Windows clippy andcargo xtask policypass. The flake is gone. No game run: world runs currently hang the GPU on this Mac (#79).