perf(gpu): leaner passes for the stand-in of the indirect light (VICTORY_AMBIENT_LEAN, off by default) #961

Closed
CLHelper wants to merge 1 commit from upstream-pr/961 into main
CLHelper commented 2026-11-28 10:11:00 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by CLHelper on 2026-11-28T10:11:00Z.


What

VICTORY_AMBIENT_LEAN=<bits> (off by default; unset, every pass of the indirect-light stand-in runs as before):

  • 1 - the gather (each of the 160x90 points sums the light of all 2,304 cells) runs in groups of 32 threads
    (numthreads(16, 2, 1), dispatched 10x45) instead of 16 (8, 2, 1, 20x45). On a 32-lane card a group of 16
    leaves half of every wave idle. Each point is worked out by the same code from the same inputs, so the points
    buffer holds the same bytes. The gather runs three times a frame (after both CS_RayMiss dispatches and after
    the diffuse resolve), so it was the largest of the stand-in's passes.
  • 2 - the mean of the cells' light by one group of 256 threads in a fixed tree instead of one thread adding
    2,304 values in turn. The sum is rounded in another order (the bench checks it to 1e-5 relative).
  • 4 - a gather is left out when the last gather was recorded into the same host list since its reset, of the
    same depth view and size, with no keep of the cells' light recorded since: its points are what this one would
    write. (In practice: the second CS_RayMiss dispatch of a frame reuses the first one's points.)

The default HLSL is unchanged (GATHER_X defaults to 8; the mean's lean form is behind its own define), so with the
switch unset the same bytecode is compiled. Lean pipelines are compiled only for the bits asked for; one that does
not compile is logged once and the plain pass runs.

New files: ambient/lean.rs (switch, the lean mean's HLSL, the reuse decision, 2 tests) and ambient/bench.rs
(ignored on-device bench); ambient.rs +48/-10.

Measured

RTX 4060 Laptop GPU (8 GB), Series S profile, DLSS quality; 150 s runs through the opening into the first scenes,
card time from GPU timestamps around each run of commands (a diagnostic of ours, not part of this PR).

run stand-in's card time a frame (median of 27-28 windows) card busy a frame (median)
off 2.38 ms 43.04 ms
=1 1.45 ms 42.20 ms
=7 1.43 ms 42.10 ms
off (second pair) 2.38 ms 43.01 ms
=1 1.43 ms 42.04 ms
=7 1.42 ms 41.87 ms

Bench on the same card, no title (cargo test -p victory-gpu --release --features diagnostics --lib -- ambient::bench --ignored --nocapture --test-threads=1): gather 0.814 -> 0.416 ms, mean 0.045 -> 0.003 ms; the wide
gather's output is byte-for-byte equal to the plain one's at 1280x720 and 640x360. Picture scores of the captured
frames (noise, dark, luma; world and cutscene) are equal within run-to-run spread.

The frame rate did not move on this laptop (world median 56.0 / 54.8 / 55.8 ms in the first set, 55.9 / 56.2 /
54.4 ms in the second): here the frame is held by the CPU side of submissions, not by the card, and the card's idle
time grew by what was saved. The saving is card time (~0.9 ms of the stand-in's 2.4), so it shows where the card is
the limit. The worst cutscene frame varies from run to run on this machine with and without the switch, so no claim
is made about it.

Tests

  • ambient::lean::tests::bits_are_read_as_asked, a_gather_is_left_out_only_after_the_same_one_in_the_same_list.
  • ambient::tests::the_passes_build now also builds the lean pipelines (on a machine with a card).
  • ambient::bench::bench_the_stand_ins_passes (ignored): times each pass plain and lean, asserts the wide gather's
    bytes equal the plain gather's and the lean mean within 1e-5.

AI-assisted.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5539065636 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/961). Originally posted by [CLHelper](https://github.com/CLHelper) on 2026-11-28T10:11:00Z. --- ## What `VICTORY_AMBIENT_LEAN=<bits>` (off by default; unset, every pass of the indirect-light stand-in runs as before): - `1` - the **gather** (each of the 160x90 points sums the light of all 2,304 cells) runs in groups of 32 threads (`numthreads(16, 2, 1)`, dispatched 10x45) instead of 16 (`8, 2, 1`, 20x45). On a 32-lane card a group of 16 leaves half of every wave idle. Each point is worked out by the same code from the same inputs, so the points buffer holds the same bytes. The gather runs three times a frame (after both `CS_RayMiss` dispatches and after the diffuse resolve), so it was the largest of the stand-in's passes. - `2` - the **mean** of the cells' light by one group of 256 threads in a fixed tree instead of one thread adding 2,304 values in turn. The sum is rounded in another order (the bench checks it to 1e-5 relative). - `4` - a gather is **left out** when the last gather was recorded into the same host list since its reset, of the same depth view and size, with no keep of the cells' light recorded since: its points are what this one would write. (In practice: the second `CS_RayMiss` dispatch of a frame reuses the first one's points.) The default HLSL is unchanged (`GATHER_X` defaults to 8; the mean's lean form is behind its own define), so with the switch unset the same bytecode is compiled. Lean pipelines are compiled only for the bits asked for; one that does not compile is logged once and the plain pass runs. New files: `ambient/lean.rs` (switch, the lean mean's HLSL, the reuse decision, 2 tests) and `ambient/bench.rs` (ignored on-device bench); `ambient.rs` +48/-10. ## Measured RTX 4060 Laptop GPU (8 GB), Series S profile, DLSS quality; 150 s runs through the opening into the first scenes, card time from GPU timestamps around each run of commands (a diagnostic of ours, not part of this PR). | run | stand-in's card time a frame (median of 27-28 windows) | card busy a frame (median) | |---|---|---| | off | 2.38 ms | 43.04 ms | | `=1` | 1.45 ms | 42.20 ms | | `=7` | 1.43 ms | 42.10 ms | | off (second pair) | 2.38 ms | 43.01 ms | | `=1` | 1.43 ms | 42.04 ms | | `=7` | 1.42 ms | 41.87 ms | Bench on the same card, no title (`cargo test -p victory-gpu --release --features diagnostics --lib -- ambient::bench --ignored --nocapture --test-threads=1`): gather 0.814 -> 0.416 ms, mean 0.045 -> 0.003 ms; the wide gather's output is byte-for-byte equal to the plain one's at 1280x720 and 640x360. Picture scores of the captured frames (noise, dark, luma; world and cutscene) are equal within run-to-run spread. **The frame rate did not move on this laptop** (world median 56.0 / 54.8 / 55.8 ms in the first set, 55.9 / 56.2 / 54.4 ms in the second): here the frame is held by the CPU side of submissions, not by the card, and the card's idle time grew by what was saved. The saving is card time (~0.9 ms of the stand-in's 2.4), so it shows where the card is the limit. The worst cutscene frame varies from run to run on this machine with and without the switch, so no claim is made about it. ## Tests - `ambient::lean::tests::bits_are_read_as_asked`, `a_gather_is_left_out_only_after_the_same_one_in_the_same_list`. - `ambient::tests::the_passes_build` now also builds the lean pipelines (on a machine with a card). - `ambient::bench::bench_the_stand_ins_passes` (ignored): times each pass plain and lean, asserts the wide gather's bytes equal the plain gather's and the lean mean within 1e-5. AI-assisted.
trustno1-coder commented 2026-11-28 19:23:04 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by trustno1-coder on 2026-11-28T19:23:04Z.


Thanks for this. I'm closing it without merging because it conflicts with the current main in several places (main has moved a lot since it was opened, with about 100 pull requests merged today), and I can't resolve that safely on your behalf. If you'd still like it in, please rebase it on the current main and open a new pull request.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7244503225 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/961#issuecomment-7244503225). Originally posted by [trustno1-coder](https://github.com/trustno1-coder) on 2026-11-28T19:23:04Z. --- Thanks for this. I'm closing it without merging because it conflicts with the current main in several places (main has moved a lot since it was opened, with about 100 pull requests merged today), and I can't resolve that safely on your behalf. If you'd still like it in, please rebase it on the current main and open a new pull request.

Pull request closed

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!961
No description provided.