perf(victory-gpu): direct BVH arena staging, partial updates, and fence-safe reclamation #477

Open
github-bot wants to merge 4 commits from github-bot/gh-477 into main AGit
Owner

@⁠mauroalvare on GitHub · 2026-11-27 01:33 UTC · original
mauroalvare:rt/bvh/arena-direct-upload-residency → main · +1375 −109 · 4 files · 4 commits · open

Change

  • Stage the 16 MiB BVH directory and 64 MiB arenas directly in CPU-cached D3D12 buffers. This removes the extra write-watched mirror. A streaming update that lands after command recording marks the ranges for upload before that submission reads them.
  • Reuse arena pages for resident geometry. Use write-watch masks and changed dwords for in-place updates. Releasing a packed BVH clears its directory entries and retires its arena pages until earlier submissions complete.
  • Keep staging separate from the GPU-visible buffer when the local VRAM budget runs out. The same dirty-range copies then update the shared-memory allocation in submission order.

Synthetic verification

The fixture builds box and triangle nodes from source and compares the translated RDNA 2 ray instruction against victory_shader::bvh::intersect bit for bit. It checks the old and new ray results after a move, the miss after removal, and both sets of results across consecutive asynchronous submissions. A queue fence holds the first submission until after the CPU removes its BVH.

  • Current main b62053f returns [0, 0, 0, 0] for a late-streamed box whose expected child is 48, with VICTORY_REFRESH_FRONT=1 and VICTORY_JOIN_PARTS=8.
  • With the forced queue wait and VICTORY_MEMORY_CARD_MB=0, the single-buffer fallback on the earlier PR revision returns a miss from the first submission. It should still hit child 64. The ordered shared-memory copy in a58deb9 passes this check on RTX and WARP.
  • The focused memory:: tests passed with the 0 MiB limit on both adapters (4 passed, 1 ignored on each). The lifetime fixture also passed with the 4096 MiB limit on both and with the 16 MiB limit on RTX. cargo run --offline --locked --quiet --package xtask -- policy from third_party/victory reported 290 files OK.

Sustained benchmark

Release with diagnostics on RTX 5070 Ti, driver 621.40. Both builds used VICTORY_REFRESH_FRONT=0 and VICTORY_JOIN_PARTS=1 for the timed comparison. Base b62053f contains the same test-only fixture and submission helpers. Head a58deb9 includes that main revision. One warm-up run per build preceded the order base/head/head/base. Each run used 20 warm-up frames and 120 measured frames per scene and checked all measured frames against the CPU oracle. The static scene streams 128 meshes (16 MiB). The dynamic scene moves 16 meshes each frame and replaces a 256 KiB packed BVH every eighth frame.

Metric Main b62053f PR a58deb9
Initial static stream, wall time 70.061–70.205 ms 26.331–26.622 ms
Initial bytes copied to GPU-visible buffers 83,886,080 B 16,779,264 B
Static frame p50 / p95 1.256–1.311 / 1.600–1.694 ms 0.800–0.831 / 1.166–1.193 ms
Dynamic frame p50 / p95 0.330 / 0.495–0.523 ms 0.181–0.191 / 0.334–0.351 ms
Move-only frame p50 0.321–0.324 ms 0.180–0.188 ms
Replacement frame p50 / p95 (15 samples per run) 0.477–0.487 / 0.612–0.651 ms 0.291–0.294 / 0.462–0.612 ms
Dynamic CPU prep p50 0.091 ms 0.059 ms
Sustained static / dynamic bytes copied per frame 0 / 33,093.7 B 0 / 33,096.0 B
Process private commit growth 589.8–590.5 MiB 348.7–348.8 MiB
Tracked BVH VRAM 144 MiB 144 MiB

A second pair with a 0 MiB local BVH limit and the same settings measured dynamic p50/p95 of 0.332/0.523 ms on main and 0.181/0.343 ms on the PR. Process private commit grew by 590.1 vs 348.3 MiB. Both tracked 0 MiB of local BVH VRAM.

From the repository root, set the same environment on both builds and run the benchmark.

$env:VICTORY_REFRESH_FRONT = '0'
$env:VICTORY_JOIN_PARTS = '1'
$env:VICTORY_MEMORY_CARD_MB = '4096'
cargo test --manifest-path third_party/victory/Cargo.toml --offline --locked --release -p victory-gpu --features diagnostics --lib memory::gpu_tests::bench_bvh_static_and_dynamic_sustained -- --exact --ignored --nocapture --test-threads=1

For the baseline overlay, copy the PR's memory_tests.rs and the #[cfg(test)] hooks in memory.rs and host.rs. Omit the two inspections of the PR's retirement queue from the lifetime test when compiling on main. The benchmark code is the same on both builds.

For the lifetime regression, set VICTORY_REFRESH_FRONT=1, VICTORY_JOIN_PARTS=8, and VICTORY_MEMORY_CARD_MB=0 and run the exact test memory::gpu_tests::synthetic_bvh_static_dynamic_move_remove_and_lifetime_on_gpu with --nocapture --test-threads=1. Set VICTORY_D3D12_WARP=1 with diagnostics for the WARP run.

In-game validation remaining

Measure world-streaming frame times and peak residency, and check for lighting flicker with the title's builder active. Compacted-size readback and overlapping dynamic allocations remain open as documented in the ray-tracing notes.

This pull request was prepared with AI assistance.

**@⁠mauroalvare** on GitHub · 2026-11-27 01:33 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/477) `mauroalvare:rt/bvh/arena-direct-upload-residency` → `main` · +1375 −109 · 4 files · 4 commits · open ## Change - Stage the 16 MiB BVH directory and 64 MiB arenas directly in CPU-cached D3D12 buffers. This removes the extra write-watched mirror. A streaming update that lands after command recording marks the ranges for upload before that submission reads them. - Reuse arena pages for resident geometry. Use write-watch masks and changed dwords for in-place updates. Releasing a packed BVH clears its directory entries and retires its arena pages until earlier submissions complete. - Keep staging separate from the GPU-visible buffer when the local VRAM budget runs out. The same dirty-range copies then update the shared-memory allocation in submission order. ## Synthetic verification The fixture builds box and triangle nodes from source and compares the translated RDNA 2 ray instruction against `victory_shader::bvh::intersect` bit for bit. It checks the old and new ray results after a move, the miss after removal, and both sets of results across consecutive asynchronous submissions. A queue fence holds the first submission until after the CPU removes its BVH. - Current main `b62053f` returns `[0, 0, 0, 0]` for a late-streamed box whose expected child is `48`, with `VICTORY_REFRESH_FRONT=1` and `VICTORY_JOIN_PARTS=8`. - With the forced queue wait and `VICTORY_MEMORY_CARD_MB=0`, the single-buffer fallback on the earlier PR revision returns a miss from the first submission. It should still hit child `64`. The ordered shared-memory copy in `a58deb9` passes this check on RTX and WARP. - The focused `memory::` tests passed with the 0 MiB limit on both adapters (4 passed, 1 ignored on each). The lifetime fixture also passed with the 4096 MiB limit on both and with the 16 MiB limit on RTX. `cargo run --offline --locked --quiet --package xtask -- policy` from `third_party/victory` reported 290 files OK. ## Sustained benchmark Release with diagnostics on RTX 5070 Ti, driver 621.40. Both builds used `VICTORY_REFRESH_FRONT=0` and `VICTORY_JOIN_PARTS=1` for the timed comparison. Base `b62053f` contains the same test-only fixture and submission helpers. Head `a58deb9` includes that main revision. One warm-up run per build preceded the order base/head/head/base. Each run used 20 warm-up frames and 120 measured frames per scene and checked all measured frames against the CPU oracle. The static scene streams 128 meshes (16 MiB). The dynamic scene moves 16 meshes each frame and replaces a 256 KiB packed BVH every eighth frame. | Metric | Main `b62053f` | PR `a58deb9` | | --- | ---: | ---: | | Initial static stream, wall time | 70.061–70.205 ms | 26.331–26.622 ms | | Initial bytes copied to GPU-visible buffers | 83,886,080 B | 16,779,264 B | | Static frame p50 / p95 | 1.256–1.311 / 1.600–1.694 ms | 0.800–0.831 / 1.166–1.193 ms | | Dynamic frame p50 / p95 | 0.330 / 0.495–0.523 ms | 0.181–0.191 / 0.334–0.351 ms | | Move-only frame p50 | 0.321–0.324 ms | 0.180–0.188 ms | | Replacement frame p50 / p95 (15 samples per run) | 0.477–0.487 / 0.612–0.651 ms | 0.291–0.294 / 0.462–0.612 ms | | Dynamic CPU prep p50 | 0.091 ms | 0.059 ms | | Sustained static / dynamic bytes copied per frame | 0 / 33,093.7 B | 0 / 33,096.0 B | | Process private commit growth | 589.8–590.5 MiB | 348.7–348.8 MiB | | Tracked BVH VRAM | 144 MiB | 144 MiB | A second pair with a 0 MiB local BVH limit and the same settings measured dynamic p50/p95 of 0.332/0.523 ms on main and 0.181/0.343 ms on the PR. Process private commit grew by 590.1 vs 348.3 MiB. Both tracked 0 MiB of local BVH VRAM. From the repository root, set the same environment on both builds and run the benchmark. ```powershell $env:VICTORY_REFRESH_FRONT = '0' $env:VICTORY_JOIN_PARTS = '1' $env:VICTORY_MEMORY_CARD_MB = '4096' cargo test --manifest-path third_party/victory/Cargo.toml --offline --locked --release -p victory-gpu --features diagnostics --lib memory::gpu_tests::bench_bvh_static_and_dynamic_sustained -- --exact --ignored --nocapture --test-threads=1 ``` For the baseline overlay, copy the PR's `memory_tests.rs` and the `#[cfg(test)]` hooks in `memory.rs` and `host.rs`. Omit the two inspections of the PR's retirement queue from the lifetime test when compiling on main. The benchmark code is the same on both builds. For the lifetime regression, set `VICTORY_REFRESH_FRONT=1`, `VICTORY_JOIN_PARTS=8`, and `VICTORY_MEMORY_CARD_MB=0` and run the exact test `memory::gpu_tests::synthetic_bvh_static_dynamic_move_remove_and_lifetime_on_gpu` with `--nocapture --test-threads=1`. Set `VICTORY_D3D12_WARP=1` with diagnostics for the WARP run. ## In-game validation remaining Measure world-streaming frame times and peak residency, and check for lighting flicker with the title's builder active. Compacted-size readback and overlapping dynamic allocations remain open as documented in [the ray-tracing notes](third_party/victory/docs/fork-ray-tracing.md). *This pull request was prepared with AI assistance.*
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 02:08:19 +00:00
Author
Owner

@⁠mauroalvare on GitHub · 2026-11-27 01:40 UTC · original

Independent two-build check on RTX 5070 Ti, driver 621.40. I used release with --features diagnostics, VICTORY_REFRESH_FRONT=0, and VICTORY_JOIN_PARTS=1 in both builds. The base was a40ed684341fbd2cc6d27c171af9ae27bbc56018 (BVH code matches 4340aac1a494b9649c00e0e1ad2c6fbe6ea00e80) with the shared benchmark and test-only hooks. The head was b30bd612c9486e7825fd948f9cc41e2ed3ddd7c2. All four base/head/head/base runs passed the frame oracle at 120 samples per mode.

RTX workload Base A p50 / p95 (ms) Head A p50 / p95 (ms) Base B p50 / p95 (ms) Head B p50 / p95 (ms)
Static frame 1.466 / 2.569 1.004 / 2.225 1.504 / 2.623 1.045 / 2.030
Dynamic frame 0.351 / 0.681 0.195 / 0.542 0.385 / 0.903 0.260 / 0.460
Dynamic CPU prep 0.094 / 0.200 0.059 / 0.132 0.097 / 0.215 0.068 / 0.135

Initial upload was 80.0 → 16.0 MiB. Private commit growth fell from 590.0–607.3 MiB to 348.9–362.7 MiB, with the same 144 MiB of tracked BVH VRAM. That host figure is the before/after PrivateUsage delta.

With VICTORY_REFRESH_FRONT=1 and VICTORY_JOIN_PARTS=8, the lifetime/movement test passed on the RTX and on WARP with --features diagnostics and VICTORY_D3D12_WARP=1. The diagnostic run printed Microsoft Basic Render Driver and card_memory=true, so it exercised the GPU fixture. The WARP selector requires the diagnostics feature.

For the table I used nearest-rank p95 in both test overlays. In the committed stats_summary, v[v.len() * 95 / 100] selects the 115th of 120 samples. The nearest-rank index is (95 * v.len()).div_ceil(100) - 1, which selects the 114th sample.

cargo test --manifest-path third_party/victory/Cargo.toml --offline --locked --release -p victory-gpu --features diagnostics --lib memory::gpu_tests::bench_bvh_static_and_dynamic_sustained -- --exact --ignored --nocapture --test-threads=1

Reproduction files in the local registry are pr477-base-fixture.rs (copy to src/memory_tests.rs), pr477-base-test-hooks.patch, pr477-head-percentiles.patch, and the pr477-bvh-{base,head}-{a,b} logs.

**@⁠mauroalvare** on GitHub · 2026-11-27 01:40 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/477#issuecomment-7207479744) Independent two-build check on RTX 5070 Ti, driver 621.40. I used release with `--features diagnostics`, `VICTORY_REFRESH_FRONT=0`, and `VICTORY_JOIN_PARTS=1` in both builds. The base was `a40ed684341fbd2cc6d27c171af9ae27bbc56018` (BVH code matches `4340aac1a494b9649c00e0e1ad2c6fbe6ea00e80`) with the shared benchmark and test-only hooks. The head was `b30bd612c9486e7825fd948f9cc41e2ed3ddd7c2`. All four base/head/head/base runs passed the frame oracle at 120 samples per mode. | RTX workload | Base A p50 / p95 (ms) | Head A p50 / p95 (ms) | Base B p50 / p95 (ms) | Head B p50 / p95 (ms) | | --- | ---: | ---: | ---: | ---: | | Static frame | 1.466 / 2.569 | 1.004 / 2.225 | 1.504 / 2.623 | 1.045 / 2.030 | | Dynamic frame | 0.351 / 0.681 | 0.195 / 0.542 | 0.385 / 0.903 | 0.260 / 0.460 | | Dynamic CPU prep | 0.094 / 0.200 | 0.059 / 0.132 | 0.097 / 0.215 | 0.068 / 0.135 | Initial upload was 80.0 → 16.0 MiB. Private commit growth fell from 590.0–607.3 MiB to 348.9–362.7 MiB, with the same 144 MiB of tracked BVH VRAM. That host figure is the before/after `PrivateUsage` delta. With `VICTORY_REFRESH_FRONT=1` and `VICTORY_JOIN_PARTS=8`, the lifetime/movement test passed on the RTX and on WARP with `--features diagnostics` and `VICTORY_D3D12_WARP=1`. The diagnostic run printed `Microsoft Basic Render Driver` and `card_memory=true`, so it exercised the GPU fixture. The WARP selector requires the diagnostics feature. For the table I used nearest-rank p95 in both test overlays. In the committed `stats_summary`, `v[v.len() * 95 / 100]` selects the 115th of 120 samples. The nearest-rank index is `(95 * v.len()).div_ceil(100) - 1`, which selects the 114th sample. ```powershell cargo test --manifest-path third_party/victory/Cargo.toml --offline --locked --release -p victory-gpu --features diagnostics --lib memory::gpu_tests::bench_bvh_static_and_dynamic_sustained -- --exact --ignored --nocapture --test-threads=1 ``` Reproduction files in the local registry are `pr477-base-fixture.rs` (copy to `src/memory_tests.rs`), `pr477-base-test-hooks.patch`, `pr477-head-percentiles.patch`, and the `pr477-bvh-{base,head}-{a,b}` logs.
Author
Owner

@⁠mauroalvare on GitHub · 2026-11-27 02:15 UTC · original

Independent integration check on RTX 5070 Ti (driver 621.40), Windows x64, release diagnostics. The same queue-fenced test passed with a 4096 MiB local limit on both integrated revisions. At a 0 MiB limit, the previous stack 8e0f6d9ce7e693bf9745f36f6c9ad73b980e8e2e lost a hit that was queued before the CPU removed the BVH. Flight 1 returned four NONE values where it expected child 64. The integrated 0de11a1d06dca2e3174ed92133d03083fcd90051, including #477 at a58deb9, passed the same forced shared-memory test and the normal-budget control. This was the exact same test implementation on each integrated revision.

The warmed fixture used 128 static meshes and 16 moving meshes, with 20 warmups and 120 measured frames per scene in each process. Base (28fd0a7, main plus #472) and the updated stack ran in ABBA order per budget. Each cell pools 240 frames. The CPU oracle matched all measured frames.

Local BVH budget (MiB) Workload Base frame p50 / p95 (ms) Stack frame p50 / p95 (ms)
4096 Static frame 1.256 / 1.406 0.779 / 0.950
4096 Dynamic frame 0.327 / 0.503 0.186 / 0.287
0 Static frame 1.221 / 1.369 0.786 / 1.011
0 Dynamic frame 0.317 / 0.490 0.176 / 0.284

The dynamic median improves by 43.1% at the normal budget and 44.5% without local BVH VRAM. Peak process working set at the normal budget was 405.6 MiB base and 260.7 MiB integrated. Both tracked 144 MiB resident BVH VRAM. With forced shared memory, peak process working set was 549.5 and 404.5 MiB and both tracked 0 MiB BVH VRAM. Static CPU prep moved from about 91 to 95–96 µs while full static frame time fell. This stack comparison does not isolate the 4–5 µs prep difference to a single change. The normal-budget integrated diagnostics suite passed 511 tests (47 ignored).

$env:VICTORY_D3D12_ADAPTER = 'RTX 5070 Ti'
$env:VICTORY_WARP = '0'
$env:VICTORY_D3D12_WARP = '0'
$env:VICTORY_MEMORY_CARD_MB = '0'
$env:VICTORY_REFRESH_FRONT = '1'
$env:VICTORY_JOIN_PARTS = '8'
cargo test --manifest-path third_party/victory/Cargo.toml --offline --locked --release -p victory-gpu --features diagnostics --lib memory::gpu_tests::synthetic_bvh_static_dynamic_move_remove_and_lifetime_on_gpu -- --exact --nocapture --test-threads=1

Repeat with VICTORY_MEMORY_CARD_MB=4096 for the control. Timings use the exact ignored test memory::gpu_tests::bench_bvh_static_and_dynamic_sustained, VICTORY_REFRESH_FRONT=0, and VICTORY_JOIN_PARTS=1 at both budgets. The common registry entry integration-0de11a1/summary.json lists the raw sample logs and build identifiers. The same directory contains the test overlays.

**@⁠mauroalvare** on GitHub · 2026-11-27 02:15 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/477#issuecomment-7207971546) Independent integration check on RTX 5070 Ti (driver 621.40), Windows x64, release diagnostics. The same queue-fenced test passed with a 4096 MiB local limit on both integrated revisions. At a 0 MiB limit, the previous stack `8e0f6d9ce7e693bf9745f36f6c9ad73b980e8e2e` lost a hit that was queued before the CPU removed the BVH. Flight 1 returned four `NONE` values where it expected child `64`. The integrated `0de11a1d06dca2e3174ed92133d03083fcd90051`, including #477 at `a58deb9`, passed the same forced shared-memory test and the normal-budget control. This was the exact same test implementation on each integrated revision. The warmed fixture used 128 static meshes and 16 moving meshes, with 20 warmups and 120 measured frames per scene in each process. Base (`28fd0a7`, main plus #472) and the updated stack ran in ABBA order per budget. Each cell pools 240 frames. The CPU oracle matched all measured frames. | Local BVH budget (MiB) | Workload | Base frame p50 / p95 (ms) | Stack frame p50 / p95 (ms) | | ---: | --- | ---: | ---: | | 4096 | Static frame | 1.256 / 1.406 | 0.779 / 0.950 | | 4096 | Dynamic frame | 0.327 / 0.503 | 0.186 / 0.287 | | 0 | Static frame | 1.221 / 1.369 | 0.786 / 1.011 | | 0 | Dynamic frame | 0.317 / 0.490 | 0.176 / 0.284 | The dynamic median improves by 43.1% at the normal budget and 44.5% without local BVH VRAM. Peak process working set at the normal budget was 405.6 MiB base and 260.7 MiB integrated. Both tracked 144 MiB resident BVH VRAM. With forced shared memory, peak process working set was 549.5 and 404.5 MiB and both tracked 0 MiB BVH VRAM. Static CPU prep moved from about 91 to 95–96 µs while full static frame time fell. This stack comparison does not isolate the 4–5 µs prep difference to a single change. The normal-budget integrated diagnostics suite passed 511 tests (47 ignored). ```powershell $env:VICTORY_D3D12_ADAPTER = 'RTX 5070 Ti' $env:VICTORY_WARP = '0' $env:VICTORY_D3D12_WARP = '0' $env:VICTORY_MEMORY_CARD_MB = '0' $env:VICTORY_REFRESH_FRONT = '1' $env:VICTORY_JOIN_PARTS = '8' cargo test --manifest-path third_party/victory/Cargo.toml --offline --locked --release -p victory-gpu --features diagnostics --lib memory::gpu_tests::synthetic_bvh_static_dynamic_move_remove_and_lifetime_on_gpu -- --exact --nocapture --test-threads=1 ``` Repeat with `VICTORY_MEMORY_CARD_MB=4096` for the control. Timings use the exact ignored test `memory::gpu_tests::bench_bvh_static_and_dynamic_sustained`, `VICTORY_REFRESH_FRONT=0`, and `VICTORY_JOIN_PARTS=1` at both budgets. The common registry entry `integration-0de11a1/summary.json` lists the raw sample logs and build identifiers. The same directory contains the test overlays.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/477/head:github-bot/gh-477'
git switch 'github-bot/gh-477'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-477'
git switch 'github-bot/gh-477'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-477'
git switch 'github-bot/gh-477'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-477'
git switch 'main'
git merge --squash 'github-bot/gh-477'
git switch 'main'
git merge --ff-only 'github-bot/gh-477'
git switch 'main'
git merge 'github-bot/gh-477'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.