gpu: deduplicate per-list ambient gather, scope UAV barriers, and widen mean/gather warps #2359

Open
nidea1 wants to merge 2 commits from upstream-pr/2359 into main
nidea1 commented 2026-11-29 12:21:26 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by nidea1 on 2026-11-29T12:21:26Z.


What it changes

Reduces GPU and barrier overhead in the ambient indirect-light stand-in (crates/victory-gpu/src/ambient.rs, crates/victory-gpu/src/host.rs):

  • Parallel mean reduction: replaces [numthreads(1, 1, 1)] looping over all 2,304 cells on a single thread with a [numthreads(64, 1, 1)] groupshared tree reduction.
  • Full-warp gather: widens gather from [numthreads(8, 2, 1)] (half-warp on 32-lane NVIDIA GPUs, Dispatch(20, 45, 1)) to [numthreads(16, 2, 1)] (Dispatch(10, 45, 1)), covering the same 160x90 point grid at full warp utilization.
  • Resource-scoped UAV barriers: adds uav_barrier_for (routed through crate::barstat::rb) so keep, mean, place, and gather synchronize only pass.cells or pass.points instead of issuing global NULL UAV barriers.
  • Per-list place + gather deduplication: tracks the last gathered (depth_gpu_handle, depth_size) on HostList, skipping redundant place + gather dispatches when multiple Resolve/Miss dispatches on the same command list share the same depth and cells, and invalidating on list reset, Role::Radiance, or depth/copy-dest transitions (0x10 | 0x400).

How it was tested

  • GPU and profile (Series X or S, resolution, DLSS, frame generation, ray tracing): RTX 3060 Ti 8 GB (plus WARP software adapter), Series S profile, 1440p, FSR 3 2x FG, RT off
  • Before: mean ran 2,304 iterations on 1 lane, gather ran half-warps, every internal pass issued global NULL UAV barriers, and repeated Miss/Resolve dispatches on a list re-ran place + gather
  • After: parallel_mean_and_full_warp_gather_match_cpu_reference verifies exact match against CPU reference on both RTX 3060 Ti and WARP with 0 D3D12 debug layer errors; live session confirmed identical lighting with reduced GPU barrier overhead
  • For shader changes, the wave sizes tested (32 and/or 64 lanes): N/A (host HLSL compute passes; tested on NVIDIA 32-lane hardware and WARP)
  • cargo test passed for the crates it touches: yes (cargo test -p victory-gpu --lib --locked ambient::tests:: — 15 passed, 0 failed)

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches. Related: #1736 (opt-in tiled ambient GI variant), #2336 (reuses weighted terms inside gather's inner loop; complementary to this PR's parallel mean, full-warp gather threadgroup size, scoped UAV barriers, and per-list gather deduplication)
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5550651177 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2359). Originally posted by [nidea1](https://github.com/nidea1) on 2026-11-29T12:21:26Z. --- ## What it changes Reduces GPU and barrier overhead in the ambient indirect-light stand-in (`crates/victory-gpu/src/ambient.rs`, `crates/victory-gpu/src/host.rs`): - **Parallel `mean` reduction:** replaces `[numthreads(1, 1, 1)]` looping over all 2,304 cells on a single thread with a `[numthreads(64, 1, 1)]` groupshared tree reduction. - **Full-warp `gather`:** widens `gather` from `[numthreads(8, 2, 1)]` (half-warp on 32-lane NVIDIA GPUs, `Dispatch(20, 45, 1)`) to `[numthreads(16, 2, 1)]` (`Dispatch(10, 45, 1)`), covering the same `160x90` point grid at full warp utilization. - **Resource-scoped UAV barriers:** adds `uav_barrier_for` (routed through `crate::barstat::rb`) so `keep`, `mean`, `place`, and `gather` synchronize only `pass.cells` or `pass.points` instead of issuing global `NULL` UAV barriers. - **Per-list `place` + `gather` deduplication:** tracks the last gathered `(depth_gpu_handle, depth_size)` on `HostList`, skipping redundant `place` + `gather` dispatches when multiple `Resolve`/`Miss` dispatches on the same command list share the same depth and cells, and invalidating on list reset, `Role::Radiance`, or depth/copy-dest transitions (`0x10 | 0x400`). ## How it was tested - GPU and profile (Series X or S, resolution, DLSS, frame generation, ray tracing): RTX 3060 Ti 8 GB (plus WARP software adapter), Series S profile, 1440p, FSR 3 2x FG, RT off - Before: `mean` ran 2,304 iterations on 1 lane, `gather` ran half-warps, every internal pass issued global `NULL` UAV barriers, and repeated `Miss`/`Resolve` dispatches on a list re-ran `place` + `gather` - After: `parallel_mean_and_full_warp_gather_match_cpu_reference` verifies exact match against CPU reference on both RTX 3060 Ti and WARP with 0 D3D12 debug layer errors; live session confirmed identical lighting with reduced GPU barrier overhead - For shader changes, the wave sizes tested (32 and/or 64 lanes): N/A (host HLSL compute passes; tested on NVIDIA 32-lane hardware and WARP) - `cargo test` passed for the crates it touches: yes (`cargo test -p victory-gpu --lib --locked ambient::tests::` — 15 passed, 0 failed) ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. Related: #1736 (opt-in tiled ambient GI variant), #2336 (reuses weighted terms inside `gather`'s inner loop; complementary to this PR's parallel `mean`, full-warp `gather` threadgroup size, scoped UAV barriers, and per-list gather deduplication)
CLHelper commented 2026-11-30 17:59:09 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by CLHelper on 2026-11-30T17:59:09Z.


Data point for this PR from an 8 GB laptop card, in case it helps review. Closed #961 made the same three changes
behind a switch (16x2 gather, a tree for the mean, the second gather of a list reused when the depth and cells are
unchanged); since this PR covers them and more, I will not reopen #961.

RTX 4060 Laptop GPU (8 GB), Series S profile, DLSS quality, no hardware ray tracing, on an earlier main (63b902fe1),
150 s runs through the opening, two sets of three runs, card time from GPU timestamps:

stand-in's card time a frame (median) card busy a frame (median)
plain 2.38 ms / 2.38 ms 43.04 ms / 43.01 ms
wide gather only 1.45 ms / 1.43 ms 42.20 ms / 42.04 ms
all three 1.43 ms / 1.42 ms 42.10 ms / 41.87 ms

Bench on the same card without the title: gather 0.814 -> 0.416 ms, mean 0.045 -> 0.003 ms; the 16x2 gather's points
buffer was byte-for-byte equal to the 8x2 one's at 1280x720 and 640x360, the tree mean within 1e-5 relative.

Most of the saving is the wider gather: adding the tree mean and the reuse on top of it took another 0.01-0.02 ms
(the two were not measured apart). The frame rate did not move on that
laptop (the CPU side of submissions held the frame there), so the gain shows where the card is the limit. Not run
with this PR's code itself.

AI-assisted.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7287142066 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2359#issuecomment-7287142066). Originally posted by [CLHelper](https://github.com/CLHelper) on 2026-11-30T17:59:09Z. --- Data point for this PR from an 8 GB laptop card, in case it helps review. Closed #961 made the same three changes behind a switch (16x2 gather, a tree for the mean, the second gather of a list reused when the depth and cells are unchanged); since this PR covers them and more, I will not reopen #961. RTX 4060 Laptop GPU (8 GB), Series S profile, DLSS quality, no hardware ray tracing, on an earlier main (63b902fe1), 150 s runs through the opening, two sets of three runs, card time from GPU timestamps: | | stand-in's card time a frame (median) | card busy a frame (median) | |---|---|---| | plain | 2.38 ms / 2.38 ms | 43.04 ms / 43.01 ms | | wide gather only | 1.45 ms / 1.43 ms | 42.20 ms / 42.04 ms | | all three | 1.43 ms / 1.42 ms | 42.10 ms / 41.87 ms | Bench on the same card without the title: gather 0.814 -> 0.416 ms, mean 0.045 -> 0.003 ms; the 16x2 gather's points buffer was byte-for-byte equal to the 8x2 one's at 1280x720 and 640x360, the tree mean within 1e-5 relative. Most of the saving is the wider gather: adding the tree mean and the reuse on top of it took another 0.01-0.02 ms (the two were not measured apart). The frame rate did not move on that laptop (the CPU side of submissions held the frame there), so the gain shows where the card is the limit. Not run with this PR's code itself. AI-assisted.
nidea1 commented 2026-12-01 03:14:16 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by nidea1 on 2026-12-01T03:14:16Z.


@CLHelper Thanks for the RTX 4060 Laptop 8 GB measurements (2.38 -> 1.42 ms stand-in GPU time) and closing #961 in favour of this PR! #2359 is now rebased cleanly onto current main (6f957fbb, MERGEABLE).

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7299491405 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2359#issuecomment-7299491405). Originally posted by [nidea1](https://github.com/nidea1) on 2026-12-01T03:14:16Z. --- @CLHelper Thanks for the RTX 4060 Laptop 8 GB measurements (`2.38 -> 1.42 ms` stand-in GPU time) and closing #961 in favour of this PR! #2359 is now rebased cleanly onto current `main` (`6f957fbb`, `MERGEABLE`).
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/2359:upstream-pr/2359'
git switch 'upstream-pr/2359'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/2359'
git switch 'upstream-pr/2359'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2359'
git switch 'upstream-pr/2359'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2359'
git switch 'main'
git merge --squash 'upstream-pr/2359'
git switch 'main'
git merge --ff-only 'upstream-pr/2359'
git switch 'main'
git merge 'upstream-pr/2359'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
trustno1-coder/VIctory-NVIDIA!2359
No description provided.