perf(victory-gpu): tile ambient gather in groupshared, cache coarse depth in raise, and scope UAV barriers #475

Open
github-bot wants to merge 1 commit from github-bot/gh-475 into main AGit
Owner

@⁠mauroalvare on GitHub · 2026-11-27 01:19 UTC · original
mauroalvare:rt/passes/resolve-lighting-perf → main · +707 −45 · 2 files · 1 commits · open

Change

Eliminates overly broad global UAV barriers and repeated per-pixel/per-point work in the lighting resolve pass (third_party/victory/crates/victory-gpu/src/ambient.rs and draw.rs, active both without RT and with RT under VICTORY_AMBIENT_RT) while preserving bit-for-bit identical R9G9B9E5 output:

  1. Cooperative groupshared cell tiling + full-warp occupancy in gather (ambient.rs):
    • Previously, gather used [numthreads(8, 2, 1)] (16 threads/group — half a 32-lane NVIDIA warp) and every one of the 160x90 = 14,400 threads looped over all 2,304 cells directly from global UAV memory (66.35M global float4 loads / frame).
    • Now uses [numthreads(8, 8, 1)] (64 threads/group, Dispatch(20, 12, 1)) with cooperative 64-cell groupshared tiling in the exact 0..2304 accumulation order (64x fewer global UAV loads, full warp occupancy).
  2. Cache coarse point depth p.z from gather to eliminate 4 redundant full-res depth.Load + seen() calls per pixel in raise (ambient.rs):
    • Aligns each points record to 4 float4s (64 bytes, one cache line) and stores p.z in points[at0 + 3].x.
    • raise reads points[at0 + 3].x directly instead of calling seen(...) / depth.Load(...) 4 extra times per full-resolution pixel (8.3M fewer depth loads at 1080p, 33.2M fewer at 4K).
  3. Resource-scoped UAV barriers & pass overlap (ambient.rs, draw.rs):
    • draw.rs passes the host target ID3D12Resource in ambient::Views (already resolved in table_view).
    • ambient::after replaces global NULL UAV barriers (pResource = None) with resource-scoped UAV barriers (target, &pass.cells, &pass.points).
    • In Role::Resolve, runs place and gather (which only read depth SRV + cells) before waiting on the title's light UAV write, batching [UAV(&pass.points), UAV(light)] right before raise.
    • Removes the unnecessary trailing global UAV barrier after Role::Radiance's mean (which writes only ambient's private cells buffer).

Verification

Tested locally on Windows x64 with NVIDIA GeForce RTX 5070 Ti (driver 621.40, Wave32, SM 6.6):

cargo test -p victory-gpu --lib ambient::
  -> 5 passed; 0 failed; 1 ignored (optimized_resolve_matches_original_bit_for_bit ... ok)
cargo test -p victory-gpu --features diagnostics --lib ambient::
  -> 5 passed; 0 failed; 1 ignored
cargo xtask policy
  -> asset policy: 289 files ok

RTX 5070 Ti Hardware Timestamp Benchmark (equal resolution, sample count, and bit-exact output: 0 differing pixels out of 2,073,600 at 1080p and 8,294,400 at 4K; 30 FPS budget = 33.333 ms)

cargo test -p victory-gpu --release --lib ambient::tests::ambient_resolve_perf_bench -- --ignored --nocapture --test-threads=1
Resolution Configuration Median Total GPU (ms) % of 33.3 ms place (ms) gather (ms) raise (ms) Pixel Diffs
1920x1080 Before (main) 0.4717 1.42% 0.0016 0.2145 0.2549 —
1920x1080 After (this PR) 0.3375 1.01% 0.0009 0.0938 0.2388 0 / 2,073,600
1920x1080 Delta -0.1343 (-28.5%) -0.41% -0.0007 -0.1207 (2.29x) -0.0161 bit-exact
3840x2160 Before (main) 1.8451 5.54% 0.0022 0.2364 1.6033 —
3840x2160 After (this PR) 1.6462 4.94% 0.0015 0.0943 1.4187 0 / 8,294,400
3840x2160 Delta -0.1989 (-10.8%) -0.60% -0.0007 -0.1421 (2.51x) -0.1846 bit-exact

Oracle and test data

  • Oracle: exact original gather and raise HLSL (LEGACY_SOURCE) executed on the same GPU over synthetic depth (with occluder step), radiance cells, and R9G9B9E5 light target; no game files or assets.
  • ambient::tests::optimized_resolve_matches_original_bit_for_bit asserts 0 differing R9G9B9E5 texels across the full target.

Checklist

  • The PR covers a single reviewable behaviour.
  • A test fails without this change and passes with it.
  • The commands and results of each check are given above.
  • An unimplemented function returns an error (E_NOTIMPL), never a fake success.
  • README: unchanged (test count did not cross a hundred).
  • No game, console or SDK file, no key, no dump, no download link.
  • Findings drawn from a title: none beyond existing ambient.rs shader slots.
  • Code taken from another project: none.

Made with AI assistance (Antigravity / Gemini).

**@⁠mauroalvare** on GitHub · 2026-11-27 01:19 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/475) `mauroalvare:rt/passes/resolve-lighting-perf` → `main` · +707 −45 · 2 files · 1 commits · open ## Change Eliminates overly broad global UAV barriers and repeated per-pixel/per-point work in the lighting resolve pass (`third_party/victory/crates/victory-gpu/src/ambient.rs` and `draw.rs`, active both without RT and with RT under `VICTORY_AMBIENT_RT`) while preserving **bit-for-bit identical** `R9G9B9E5` output: 1. **Cooperative `groupshared` cell tiling + full-warp occupancy in `gather` (`ambient.rs`):** - Previously, `gather` used `[numthreads(8, 2, 1)]` (16 threads/group — half a 32-lane NVIDIA warp) and every one of the `160x90 = 14,400` threads looped over all `2,304` cells directly from global UAV memory (`66.35M` global `float4` loads / frame). - Now uses `[numthreads(8, 8, 1)]` (64 threads/group, `Dispatch(20, 12, 1)`) with cooperative 64-cell `groupshared` tiling in the exact `0..2304` accumulation order (`64x` fewer global UAV loads, full warp occupancy). 2. **Cache coarse point depth `p.z` from `gather` to eliminate 4 redundant full-res `depth.Load` + `seen()` calls per pixel in `raise` (`ambient.rs`):** - Aligns each `points` record to 4 `float4`s (64 bytes, one cache line) and stores `p.z` in `points[at0 + 3].x`. - `raise` reads `points[at0 + 3].x` directly instead of calling `seen(...)` / `depth.Load(...)` 4 extra times per full-resolution pixel (`8.3M` fewer depth loads at 1080p, `33.2M` fewer at 4K). 3. **Resource-scoped UAV barriers & pass overlap (`ambient.rs`, `draw.rs`):** - `draw.rs` passes the host target `ID3D12Resource` in `ambient::Views` (already resolved in `table_view`). - `ambient::after` replaces global NULL UAV barriers (`pResource = None`) with resource-scoped UAV barriers (`target`, `&pass.cells`, `&pass.points`). - In `Role::Resolve`, runs `place` and `gather` (which only read `depth` SRV + `cells`) before waiting on the title's `light` UAV write, batching `[UAV(&pass.points), UAV(light)]` right before `raise`. - Removes the unnecessary trailing global UAV barrier after `Role::Radiance`'s `mean` (which writes only `ambient`'s private `cells` buffer). ## Verification Tested locally on Windows x64 with **NVIDIA GeForce RTX 5070 Ti** (driver 621.40, Wave32, SM 6.6): ``` cargo test -p victory-gpu --lib ambient:: -> 5 passed; 0 failed; 1 ignored (optimized_resolve_matches_original_bit_for_bit ... ok) cargo test -p victory-gpu --features diagnostics --lib ambient:: -> 5 passed; 0 failed; 1 ignored cargo xtask policy -> asset policy: 289 files ok ``` ### RTX 5070 Ti Hardware Timestamp Benchmark (equal resolution, sample count, and **bit-exact** output: 0 differing pixels out of 2,073,600 at 1080p and 8,294,400 at 4K; 30 FPS budget = 33.333 ms) ``` cargo test -p victory-gpu --release --lib ambient::tests::ambient_resolve_perf_bench -- --ignored --nocapture --test-threads=1 ``` | Resolution | Configuration | Median Total GPU (ms) | % of 33.3 ms | `place` (ms) | `gather` (ms) | `raise` (ms) | Pixel Diffs | | --- | --- | ---: | ---: | ---: | ---: | ---: | ---: | | 1920x1080 | Before (main) | 0.4717 | 1.42% | 0.0016 | 0.2145 | 0.2549 | — | | 1920x1080 | After (this PR) | 0.3375 | 1.01% | 0.0009 | 0.0938 | 0.2388 | **0 / 2,073,600** | | **1920x1080** | **Delta** | **-0.1343 (-28.5%)** | **-0.41%** | -0.0007 | **-0.1207 (2.29x)** | -0.0161 | **bit-exact** | | 3840x2160 | Before (main) | 1.8451 | 5.54% | 0.0022 | 0.2364 | 1.6033 | — | | 3840x2160 | After (this PR) | 1.6462 | 4.94% | 0.0015 | 0.0943 | 1.4187 | **0 / 8,294,400** | | **3840x2160** | **Delta** | **-0.1989 (-10.8%)** | **-0.60%** | -0.0007 | **-0.1421 (2.51x)** | **-0.1846** | **bit-exact** | ## Oracle and test data - Oracle: exact original `gather` and `raise` HLSL (`LEGACY_SOURCE`) executed on the same GPU over synthetic depth (with occluder step), radiance cells, and `R9G9B9E5` light target; no game files or assets. - `ambient::tests::optimized_resolve_matches_original_bit_for_bit` asserts 0 differing `R9G9B9E5` texels across the full target. ## Checklist - [x] The PR covers a single reviewable behaviour. - [x] A test fails without this change and passes with it. - [x] The commands and results of each check are given above. - [x] An unimplemented function returns an error (`E_NOTIMPL`), never a fake success. - [x] README: unchanged (test count did not cross a hundred). - [x] No game, console or SDK file, no key, no dump, no download link. - [x] Findings drawn from a title: none beyond existing `ambient.rs` shader slots. - [x] Code taken from another project: none. Made with AI assistance (Antigravity / Gemini).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 01:26:09 +00:00
Author
Owner

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

Independent release validation at b38e40ad2fb3e2d74f9ad4caa20def050cba83ef on RTX 5070 Ti, driver 621.40. ambient:: passed 5 tests. The published benchmark matched all pixels at 1080p and 4K and reproduced GPU median improvements from 0.4609 to 0.3341 ms and 1.7084 to 1.5217 ms, respectively.

I also ran the same fixture in two binaries, a40ed684341fbd2cc6d27c171af9ae27bbc56018 (whose resolve code matches the PR parent) and b38e40ad2fb3e2d74f9ad4caa20def050cba83ef. Each used the production place, gather and raise pipelines with ambient band constants 0.75 / 2.5 / 0.8 over the same synthetic lighting input. The fixture restored that input before each frame. GPU timestamps exclude the reset. Each build used 24 warmups and 120 samples per resolution and ran twice in base/head/head/base order.

Resolution Frame base → head p50 / p95 (ms), run A GPU base → head p50 / p95 (ms), run A
1080p 0.545 / 0.666 → 0.400 / 0.551 0.4556 / 0.4591 → 0.3301 / 0.3311
4K 1.957 / 2.174 → 1.736 / 1.928 1.7036 / 2.0142 → 1.4952 / 1.6548

Repeat GPU medians were 0.4559 → 0.3303 ms and 1.7043 → 1.4949 ms. gather accounted for most of the reduction, 0.202 → 0.092 ms at 1080p and 0.252 → 0.093 ms at 4K. raise remained the largest 4K phase at 1.400 ms. Sampled process-local DXGI usage rose by 0.25 MiB. The full R9G9B9E5 output matched across all four runs at both resolutions.

cargo test --manifest-path third_party/victory/Cargo.toml --offline --locked --release -p victory-gpu --lib ambient::tests::ambient_resolve_perf_bench -- --exact --ignored --nocapture --test-threads=1

The local registry has pr475-ambient-probe.rs and the pr475-ambient-{base,head}.patch overlays. Copy the shared probe to src/ambient_rt_validation.rs, apply the matching overlay and use the filter ambient::validation::ambient_rt_two_builds with the same flags. The pr475-band-{base,head}-{a,b} logs include phase samples, memory and image hashes. These numbers cover the synthetic ambient resolve stage with the RT-band settings.

**@⁠mauroalvare** on GitHub · 2026-11-27 01:31 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/475#issuecomment-7207355074) Independent release validation at `b38e40ad2fb3e2d74f9ad4caa20def050cba83ef` on RTX 5070 Ti, driver 621.40. `ambient::` passed 5 tests. The published benchmark matched all pixels at 1080p and 4K and reproduced GPU median improvements from 0.4609 to 0.3341 ms and 1.7084 to 1.5217 ms, respectively. I also ran the same fixture in two binaries, `a40ed684341fbd2cc6d27c171af9ae27bbc56018` (whose resolve code matches the PR parent) and `b38e40ad2fb3e2d74f9ad4caa20def050cba83ef`. Each used the production `place`, `gather` and `raise` pipelines with ambient band constants 0.75 / 2.5 / 0.8 over the same synthetic lighting input. The fixture restored that input before each frame. GPU timestamps exclude the reset. Each build used 24 warmups and 120 samples per resolution and ran twice in base/head/head/base order. | Resolution | Frame base → head p50 / p95 (ms), run A | GPU base → head p50 / p95 (ms), run A | | --- | ---: | ---: | | 1080p | 0.545 / 0.666 → 0.400 / 0.551 | 0.4556 / 0.4591 → 0.3301 / 0.3311 | | 4K | 1.957 / 2.174 → 1.736 / 1.928 | 1.7036 / 2.0142 → 1.4952 / 1.6548 | Repeat GPU medians were 0.4559 → 0.3303 ms and 1.7043 → 1.4949 ms. `gather` accounted for most of the reduction, 0.202 → 0.092 ms at 1080p and 0.252 → 0.093 ms at 4K. `raise` remained the largest 4K phase at 1.400 ms. Sampled process-local DXGI usage rose by 0.25 MiB. The full `R9G9B9E5` output matched across all four runs at both resolutions. ```powershell cargo test --manifest-path third_party/victory/Cargo.toml --offline --locked --release -p victory-gpu --lib ambient::tests::ambient_resolve_perf_bench -- --exact --ignored --nocapture --test-threads=1 ``` The local registry has `pr475-ambient-probe.rs` and the `pr475-ambient-{base,head}.patch` overlays. Copy the shared probe to `src/ambient_rt_validation.rs`, apply the matching overlay and use the filter `ambient::validation::ambient_rt_two_builds` with the same flags. The `pr475-band-{base,head}-{a,b}` logs include phase samples, memory and image hashes. These numbers cover the synthetic ambient resolve stage with the RT-band settings.
Author
Owner

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

Integration verification on the same RTX 5070 Ti and driver 621.40. I reapplied the saved ambient probe to base 28fd0a746bd1e9170cca57e0a942a356b3e290af and integrated stack 8e0f6d9ce7e693bf9745f36f6c9ad73b980e8e2e (main b62053f, #472, #474–477 and revised #451). Each build ran twice in base/stack/stack/base order, 24 warmup and 120 measured frames per resolution per process. The fixed RT-band scene restored the same input lighting before each frame.

Resolution Base GPU p50 / p95 (ms) Stack GPU p50 / p95 (ms)
1080p 0.4570 / 0.4602 0.3307 / 0.3316
4K 1.7083 / 2.0302 1.5013 / 1.6801

The 27.6% and 12.1% GPU median reductions retain the earlier isolated gains. Full output hashes match at both resolutions. The 4K raise stage now uses 1.405 ms of the 1.501 ms median GPU time. Sampled local memory for the 4K workload was 143.1 MiB base and 143.3 MiB integrated.

Reproduction uses the pr475-ambient-probe.rs fixture from the earlier review with the local integration overlays. The exact test filter is ambient::validation::ambient_rt_two_builds with --release --exact --ignored --nocapture --test-threads=1. The common registry contains the four rtint-ambient logs and integration-8e0f6d9/summary.json.

**@⁠mauroalvare** on GitHub · 2026-11-27 02:11 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/475#issuecomment-7207904555) Integration verification on the same RTX 5070 Ti and driver 621.40. I reapplied the saved ambient probe to base `28fd0a746bd1e9170cca57e0a942a356b3e290af` and integrated stack `8e0f6d9ce7e693bf9745f36f6c9ad73b980e8e2e` (main `b62053f`, #472, #474–477 and revised #451). Each build ran twice in base/stack/stack/base order, 24 warmup and 120 measured frames per resolution per process. The fixed RT-band scene restored the same input lighting before each frame. | Resolution | Base GPU p50 / p95 (ms) | Stack GPU p50 / p95 (ms) | | --- | ---: | ---: | | 1080p | 0.4570 / 0.4602 | 0.3307 / 0.3316 | | 4K | 1.7083 / 2.0302 | 1.5013 / 1.6801 | The 27.6% and 12.1% GPU median reductions retain the earlier isolated gains. Full output hashes match at both resolutions. The 4K `raise` stage now uses 1.405 ms of the 1.501 ms median GPU time. Sampled local memory for the 4K workload was 143.1 MiB base and 143.3 MiB integrated. Reproduction uses the `pr475-ambient-probe.rs` fixture from the earlier review with the local integration overlays. The exact test filter is `ambient::validation::ambient_rt_two_builds` with `--release --exact --ignored --nocapture --test-threads=1`. The common registry contains the four `rtint-ambient` logs and `integration-8e0f6d9/summary.json`.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
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/475/head:github-bot/gh-475'
git switch 'github-bot/gh-475'

Merge

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