Prefill nearby guest BVH directory entries after demand faults #240

Manually merged
github merged 2 commits from github-bot/gh-240 into main 2026-12-03 17:29:34 +00:00 AGit
Owner

@⁠tommiehansen on GitHub · 2026-12-02 20:24 UTC · original
tommiehansen:experiment/bvh-fault-lookahead → main · +58 −0 · 2 files · 2 commits · merged 2026-12-03 17:28 UTC

Bottleneck and change

A missing guest directory entry can cost the first shader read or write, even when title memory already has in-place backing. The demand handler reveals a 4 MiB cell only after a miss. With VICTORY_BVH_LOOKAHEAD=1, it tries up to four following cells after all observed demand has been handled. An off run uses the original demand policy.

This is a narrower follow-up to #25. That experiment reported a roughly 4–5 ms improvement in its own run and revealed much larger ranges. This patch makes no assumption that its smaller policy will reproduce that result.

Correctness and cost

Candidates stay in the demand's already-created 128 MiB mirror, stop before the empty directory sentinel, and require covered pages at the cell boundary. Existing entries are preserved. Each new entry goes through the normal put_in_place eligibility, alias checks, lazy reveal request, and publication path under the memory lock. The normal submission path still publishes the directory and reveals backing before use. Demand budgets, resource ownership, shaders, queue ordering and fence waits are unchanged. Extra entries can create extra reveal work and change the timing at which shader accesses succeed, so the experiment defaults to off.

Evidence from the earlier eager-mapping experiment

PR #25 reported the following on RX 9070 XT, Series X, 2560×1440, RT enabled. The frame-time and VRAM figures come from its scripted eight-minute benchmark; the fault-category counts come from a separate four-minute diagnostic run.

Metric Baseline Eager mapping (#25)
Reported "no copy" pages 527–660 134
Median frame time 36.5–37.8 ms 31.5–33.1 ms
VRAM usage ~11.1 GB 11.2 GB
Late faults (diagnostic) 1,018 0
LeafRehydration faults (diagnostic) 292 0

Comparison with existing approaches

Policy Speculative mapping scope
Original demand mapping Requested 4 MiB cell
#25 eager mapping Initial whole-space reveal and full 128 MiB stretch after a demand hit
This PR At most four following 4 MiB cells in the already-created mirror, after observed demand

This PR deliberately limits additional work to at most 16 MiB of candidate cell ranges per qualifying demand, subject to eligibility and mirror boundaries. That is a mapping scope, not a promise of 16 MiB of new VRAM allocations.

Why this should be merged

The earlier experiment demonstrates that late directory publication can be a meaningful bottleneck. This narrower opt-in policy makes the trade-off between avoided late accesses and extra mapping work measurable while retaining the existing publication and eligibility rules. It does not repair out-of-range or otherwise invalid BVH pointers. The results from #25 cannot be attributed to this PR, and native RayQuery may reduce the relevant traversal workload.

Validation

The Windows target for victory and victory-gpu, including diagnostics and test compilation, passed from macOS with a check-only mimalloc override and the pure Rust BLAKE3 path. Portable tests passed for every cell boundary and 65,536 randomized page addresses against a byte-address reference. git diff --check passed. Hardware benchmarking was unavailable.

Could maintainers test RX 9060 XT 16 GB at native 1920×1080 and RX 9070 XT at native 2560×1440, with RT on and frame generation off? Compare VICTORY_BVH_LOOKAHEAD=0 and 1 on the same cold and warm routes. Record render frame-time percentiles, directory faults, pages shown ahead, and VRAM. Check image parity around scene cuts and shader-built structures. The expected benefit is fewer late accesses if faults cluster across cell boundaries. Extra directory and mapping work can offset it.

**@⁠tommiehansen** on GitHub · 2026-12-02 20:24 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/240) `tommiehansen:experiment/bvh-fault-lookahead` → `main` · +58 −0 · 2 files · 2 commits · merged 2026-12-03 17:28 UTC ### Bottleneck and change A missing guest directory entry can cost the first shader read or write, even when title memory already has in-place backing. The demand handler reveals a 4 MiB cell only after a miss. With `VICTORY_BVH_LOOKAHEAD=1`, it tries up to four following cells after all observed demand has been handled. An off run uses the original demand policy. This is a narrower follow-up to #25. That experiment reported a roughly 4–5 ms improvement in its own run and revealed much larger ranges. This patch makes no assumption that its smaller policy will reproduce that result. ### Correctness and cost Candidates stay in the demand's already-created 128 MiB mirror, stop before the empty directory sentinel, and require covered pages at the cell boundary. Existing entries are preserved. Each new entry goes through the normal `put_in_place` eligibility, alias checks, lazy reveal request, and publication path under the memory lock. The normal submission path still publishes the directory and reveals backing before use. Demand budgets, resource ownership, shaders, queue ordering and fence waits are unchanged. Extra entries can create extra reveal work and change the timing at which shader accesses succeed, so the experiment defaults to off. ## Evidence from the earlier eager-mapping experiment [PR #25](https://git.gtahub.st/github/lobomfz--VIctory-xmem/pulls/25) reported the following on RX 9070 XT, Series X, 2560×1440, RT enabled. The frame-time and VRAM figures come from its scripted eight-minute benchmark; the fault-category counts come from a separate four-minute diagnostic run. | Metric | Baseline | Eager mapping (#25) | |---|---:|---:| | Reported "no copy" pages | 527–660 | 134 | | Median frame time | 36.5–37.8 ms | 31.5–33.1 ms | | VRAM usage | ~11.1 GB | 11.2 GB | | Late faults (diagnostic) | 1,018 | 0 | | LeafRehydration faults (diagnostic) | 292 | 0 | ## Comparison with existing approaches | Policy | Speculative mapping scope | |---|---| | Original demand mapping | Requested 4 MiB cell | | #25 eager mapping | Initial whole-space reveal and full 128 MiB stretch after a demand hit | | This PR | At most four following 4 MiB cells in the already-created mirror, after observed demand | This PR deliberately limits additional work to at most 16 MiB of candidate cell ranges per qualifying demand, subject to eligibility and mirror boundaries. That is a mapping scope, not a promise of 16 MiB of new VRAM allocations. ## Why this should be merged The earlier experiment demonstrates that late directory publication can be a meaningful bottleneck. This narrower opt-in policy makes the trade-off between avoided late accesses and extra mapping work measurable while retaining the existing publication and eligibility rules. It does not repair out-of-range or otherwise invalid BVH pointers. The results from #25 cannot be attributed to this PR, and native RayQuery may reduce the relevant traversal workload. ### Validation The Windows target for `victory` and `victory-gpu`, including diagnostics and test compilation, passed from macOS with a check-only mimalloc override and the pure Rust BLAKE3 path. Portable tests passed for every cell boundary and 65,536 randomized page addresses against a byte-address reference. `git diff --check` passed. Hardware benchmarking was unavailable. Could maintainers test RX 9060 XT 16 GB at native 1920×1080 and RX 9070 XT at native 2560×1440, with RT on and frame generation off? Compare `VICTORY_BVH_LOOKAHEAD=0` and `1` on the same cold and warm routes. Record render frame-time percentiles, directory faults, pages shown ahead, and VRAM. Check image parity around scene cuts and shader-built structures. The expected benefit is fewer late accesses if faults cluster across cell boundaries. Extra directory and mapping work can offset it.
The first shader access to a missing guest directory entry is lost while the host services the fault. The current handler reveals the demanded 4 MiB cell, then waits for later faults even if the next cell is backed by the same mirror.

Add an opt-in pass after demand handling. Probe at most four distinct following cells per frame and require coverage at each cell boundary. Use the existing per-page placement checks and directory publication path. Leave existing entries intact and stop at mirror boundaries or the empty sentinel. Report the pages revealed ahead of faults. The original handler remains the default.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-02 20:29:54 +00:00
Keep the upstream README layout and move this branch’s setting to the corresponding documentation page.
github manually merged commit 4b9947e706 into main 2026-12-03 17:29:34 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.