Add opt-in tiled ambient GI passes #1736

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

@⁠Gauss999 on GitHub · 2026-11-28 23:48 UTC · original
Gauss999:patch-8 → main · +532 −5 · 1 files · 1 commits · open

What it changes

  • Add VICTORY_AMBIENT_TILED=1 as an opt-in; it does not enable the ambient stand-in by itself.
  • Keep the existing scalar mean and gather PSOs as the default and as independent fallbacks if either tiled PSO cannot be created.
  • Add a 64-thread groupshared tree reduction for mean_tiled.
  • Add a 16x8-thread, 128-cell tiled gather_tiled; both barriers are reached by padding lanes, and only valid 160x90 points write output.
  • Dispatch tiled gather as 10x12 groups (160x96 threads), in both Resolve and Miss. Scalar dispatch remains 20x45.
  • Cover both new HLSL entries in the existing FXC compile test and add opt-in/layout tests.

Adapted only for mean/gather from ToLIManl/VIctory-Hydra@a7bfab0. The unrelated raise changes are deliberately excluded.

The Hydra author reports roughly 1.7-2.1 ms to 0.21-0.24 ms, but that is third-party, unreproduced data, and the source item also includes other work; it is not an isolated or guaranteed gain here. The reduction order, rsqrt and reciprocal multiplies mean scalar/tiled output should be compared with a numerical tolerance, not bit-for-bit.

How it was tested

  • GPU and profile: not run locally; this patch was prepared through the GitHub editor.
  • Before/after: no local timing is claimed. The figures above belong to the Hydra author.
  • Tests added: FXC compilation coverage for both entries, opt-in parsing and dispatch/cell bounds. None has been run in this environment.
  • Required before leaving Draft: run the victory-gpu tests and clippy; add/run a WARP scalar-versus-tiled differential with tolerance and output sentinels, especially at y=89/90; then compare temporal stability and separate mean/gather GPU timestamps on NVIDIA with the option off/on.

Checked for overlap

  • Checked the current main implementation and the Hydra source. Existing root signatures, reflection/bound passes, GATHERED handling and UAV barriers are preserved.
**@⁠Gauss999** on GitHub · 2026-11-28 23:48 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1736) `Gauss999:patch-8` → `main` · +532 −5 · 1 files · 1 commits · open ## What it changes - Add `VICTORY_AMBIENT_TILED=1` as an opt-in; it does not enable the ambient stand-in by itself. - Keep the existing scalar `mean` and `gather` PSOs as the default and as independent fallbacks if either tiled PSO cannot be created. - Add a 64-thread groupshared tree reduction for `mean_tiled`. - Add a 16x8-thread, 128-cell tiled `gather_tiled`; both barriers are reached by padding lanes, and only valid 160x90 points write output. - Dispatch tiled gather as 10x12 groups (160x96 threads), in both Resolve and Miss. Scalar dispatch remains 20x45. - Cover both new HLSL entries in the existing FXC compile test and add opt-in/layout tests. Adapted only for mean/gather from [ToLIManl/VIctory-Hydra@a7bfab0](https://github.com/ToLIManl/VIctory-Hydra/commit/a7bfab0). The unrelated `raise` changes are deliberately excluded. The Hydra author reports roughly 1.7-2.1 ms to 0.21-0.24 ms, but that is **third-party, unreproduced data**, and the source item also includes other work; it is not an isolated or guaranteed gain here. The reduction order, `rsqrt` and reciprocal multiplies mean scalar/tiled output should be compared with a numerical tolerance, not bit-for-bit. ## How it was tested - GPU and profile: not run locally; this patch was prepared through the GitHub editor. - Before/after: no local timing is claimed. The figures above belong to the Hydra author. - Tests added: FXC compilation coverage for both entries, opt-in parsing and dispatch/cell bounds. **None has been run in this environment.** - Required before leaving Draft: run the victory-gpu tests and clippy; add/run a WARP scalar-versus-tiled differential with tolerance and output sentinels, especially at y=89/90; then compare temporal stability and separate mean/gather GPU timestamps on NVIDIA with the option off/on. ## Checked for overlap - [x] Checked the current main implementation and the Hydra source. Existing root signatures, reflection/bound passes, `GATHERED` handling and UAV barriers are preserved.
Add VICTORY_AMBIENT_TILED=1 with groupshared mean/gather kernels, scalar fallback, dispatch/layout tests and FXC compile coverage. Adapted from ToLIManl/VIctory-Hydra a7bfab0 without the unrelated raise changes.
Clarify test documentation regarding shader compilation behavior.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-28 23:52:57 +00:00
Author
Owner

@⁠nick0451 on GitHub · 2026-11-29 01:26 UTC · original

Tested, since the PR says nothing has been run yet. RTX 3090 24 GB (driver 610.88), i9-14900K, Windows 11, release build of this PR merged onto main f9dfb76, Series S, DLSS performance, no frame generation, VICTORY_AMBIENT=0.8 (the launcher's default).

Tests: cargo test -p victory-gpu --lib passes 552, including the 13 ambient tests (both new HLSL entries compile, and the layout check at rows 89/90 holds). Clippy has nothing in ambient.rs.

In game: the same executable, tiled unset against VICTORY_AMBIENT_TILED=1, alternating, 3 rounds each after a warm-up, the same frozen save (a balcony, about 5,800 draws a frame), a 60 s window each:

fps (runs) frame ms card busy
scalar (default) 26.4 (26.2, 26.4, 26.6) 37.8 88%
tiled 26.8 (26.9, 26.8, 25.9) 37.5 85%
  • The tiled pipelines were made: no tiled ambient … unavailable warning in any run, so no fallback.
  • +1.5% is inside this bench's run-to-run noise (2-3%). On a card this busy, the claimed 1.5-1.9 ms would be about 5%, so if the gain exists here it's smaller than that. The bench measures whole frames, not the passes' own GPU timestamps.
  • Picture: the indirect light matches by eye: walls, the character's shading and the shaded side of the house look the same in all six screenshots. The only difference I found, specks of the water's reflection in a dark window, comes and goes between runs of either variant (it shows in 2 of 3 scalar runs), so it isn't the tiled pass.
  • 8 of 8 starts reached the world with no crash or new ERROR line.

Not done: the WARP scalar-against-tiled differential and per-pass timestamps that the PR lists before leaving draft.

🤖 Generated with Claude Code

**@⁠nick0451** on GitHub · 2026-11-29 01:26 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1736#issuecomment-7248788355) Tested, since the PR says nothing has been run yet. RTX 3090 24 GB (driver 610.88), i9-14900K, Windows 11, release build of this PR merged onto main `f9dfb76`, Series S, DLSS performance, no frame generation, `VICTORY_AMBIENT=0.8` (the launcher's default). **Tests:** `cargo test -p victory-gpu --lib` passes 552, including the 13 ambient tests (both new HLSL entries compile, and the layout check at rows 89/90 holds). Clippy has nothing in `ambient.rs`. **In game:** the same executable, tiled unset against `VICTORY_AMBIENT_TILED=1`, alternating, 3 rounds each after a warm-up, the same frozen save (a balcony, about 5,800 draws a frame), a 60 s window each: | | fps (runs) | frame ms | card busy | |---|---|---|---| | scalar (default) | **26.4** (26.2, 26.4, 26.6) | 37.8 | 88% | | tiled | **26.8** (26.9, 26.8, 25.9) | 37.5 | 85% | - The tiled pipelines were made: no `tiled ambient … unavailable` warning in any run, so no fallback. - +1.5% is inside this bench's run-to-run noise (2-3%). On a card this busy, the claimed 1.5-1.9 ms would be about 5%, so if the gain exists here it's smaller than that. The bench measures whole frames, not the passes' own GPU timestamps. - **Picture:** the indirect light matches by eye: walls, the character's shading and the shaded side of the house look the same in all six screenshots. The only difference I found, specks of the water's reflection in a dark window, comes and goes between runs of either variant (it shows in 2 of 3 scalar runs), so it isn't the tiled pass. - 8 of 8 starts reached the world with no crash or new `ERROR` line. Not done: the WARP scalar-against-tiled differential and per-pass timestamps that the PR lists before leaving draft. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
@ -332,0 +372,4 @@
g_col[gi] = cells[base + gi];
GroupMemoryBarrierWithGroupSync();
if (valid) {
[unroll(8)]
Author
Owner

@⁠Yoshi-233 on GitHub · 2026-11-29 06:21 UTC · original

On Windows, the system FXC (D3DCompile, cs_5_1, flags 0) at 369af03b compiles the tile accumulation to eight constant-index reads of each groupshared array (indices 0 through 7). The only remaining loop advances the tile base by 128. That uses 144 of the 2,304 cell contributions in the scalar gather.

I checked the production gather and gather_tiled entries with a D3D12 readback on an RTX 4070 Ti SUPER. All cells had the same position, radius and weight. In each tile the first eight cells were red (1,0,0) and the other 120 were (0,1,0.25). From the same query point the scalar entry returned (0.062502,0.937503,0.234376) and the tiled entry returned (1,0,0).

With this one-line change, the compiler emits an inner loop bounded by 128. The hardware and WARP both return the scalar RGB for the tiled entry. This gives a fixed-workload baseline for pricing the optimization. A two-colour fixture like this would also catch a future compiler regression that a layout/compile-only test misses.

            [loop]
**@⁠Yoshi-233** on GitHub · 2026-11-29 06:21 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1736#discussion_r4730317870) On Windows, the system FXC (`D3DCompile`, `cs_5_1`, flags 0) at `369af03b` compiles the tile accumulation to eight constant-index reads of each groupshared array (indices 0 through 7). The only remaining loop advances the tile base by 128. That uses 144 of the 2,304 cell contributions in the scalar gather. I checked the production `gather` and `gather_tiled` entries with a D3D12 readback on an RTX 4070 Ti SUPER. All cells had the same position, radius and weight. In each tile the first eight cells were red `(1,0,0)` and the other 120 were `(0,1,0.25)`. From the same query point the scalar entry returned `(0.062502,0.937503,0.234376)` and the tiled entry returned `(1,0,0)`. With this one-line change, the compiler emits an inner loop bounded by 128. The hardware and WARP both return the scalar RGB for the tiled entry. This gives a fixed-workload baseline for pricing the optimization. A two-colour fixture like this would also catch a future compiler regression that a layout/compile-only test misses. ```suggestion [loop] ```
FXC compiled the [unroll(8)] inner loop of gather_tiled into eight
constant-index groupshared reads (j = 0..7), so each tile processed
only its first eight cells: 144 of 2,304 contributions. A plain
[loop] keeps the full 128-iteration loop (FXC rejects [unroll] and
[loop] together), matching the scalar result on hardware and WARP.

The new two-colour differential fixture (first 8 cells of each tile
red, the other 120 green-blue, all with equal weight) fails if only
the first elements are read, compares scalar vs tiled by tolerance,
and covers sentinel writes and the y=89/90 boundary.
Author
Owner

@⁠Gauss999 on GitHub · 2026-11-29 18:33 UTC · original

Fixed with one adjustment to the suggestion: the system FXC (D3DCompile, cs_5_1, flags 0) rejects [unroll(8)] and [loop] on the same loop — compilation fails with E_FAIL, so the suggested change as shown does not build. A plain [loop] compiles, emits the inner loop bounded by 128, and makes the tiled entry return the scalar RGB, on hardware and on WARP.

Added the two-colour differential regression along these lines: gather and gather_tiled run on the same buffers, all cells with equal position/radius/weight, the first eight cells of each 128-cell tile red (1,0,0) and the other 120 (0,1,0.25), so the expected light is analytic — (0.0625, 0.9375, 0.234375). It fails if only the first elements of each tile are read. Scalar and tiled outputs are compared with a documented tolerance (2e-3; no bit equality), the points buffer is NaN-filled as a sentinel so any texel the shader leaves unwritten fails the test, and the probes cover the boundary row y=89 and column x=159 (the tiled dispatch's y=90+ padding lanes must not write them).

Validation run locally: the 14 ambient tests pass, including the new differential on hardware and WARP, and the full victory-gpu lib suite passes (553 tests). Default behaviour is unchanged — the tiled passes remain opt-in via VICTORY_AMBIENT_TILED=1, with the scalar fallbacks intact.

**@⁠Gauss999** on GitHub · 2026-11-29 18:33 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1736#issuecomment-7260577973) Fixed with one adjustment to the suggestion: the system FXC (D3DCompile, cs_5_1, flags 0) rejects [unroll(8)] and [loop] on the same loop — compilation fails with E_FAIL, so the suggested change as shown does not build. A plain [loop] compiles, emits the inner loop bounded by 128, and makes the tiled entry return the scalar RGB, on hardware and on WARP. Added the two-colour differential regression along these lines: gather and gather_tiled run on the same buffers, all cells with equal position/radius/weight, the first eight cells of each 128-cell tile red (1,0,0) and the other 120 (0,1,0.25), so the expected light is analytic — (0.0625, 0.9375, 0.234375). It fails if only the first elements of each tile are read. Scalar and tiled outputs are compared with a documented tolerance (2e-3; no bit equality), the points buffer is NaN-filled as a sentinel so any texel the shader leaves unwritten fails the test, and the probes cover the boundary row y=89 and column x=159 (the tiled dispatch's y=90+ padding lanes must not write them). Validation run locally: the 14 ambient tests pass, including the new differential on hardware and WARP, and the full victory-gpu lib suite passes (553 tests). Default behaviour is unchanged — the tiled passes remain opt-in via VICTORY_AMBIENT_TILED=1, with the scalar fallbacks intact.
github-bot force-pushed github-bot/gh-1736 from 4f30610cb2 to 46b0cbc7a6 2026-11-30 00:23:03 +00:00 Compare
Author
Owner

@⁠Yoshi-233 on GitHub · 2026-11-30 01:09 UTC · original

@⁠Gauss999 Thanks for checking the exact FXC behaviour and correcting my suggestion. I checked the updated diff: the inner loop now has just [loop], and putting the red cells in the first eight positions makes the previous eight-read result distinguishable from the expected full-tile colour. That addresses the issue I raised in review. The hardware and WARP runs are yours; I’ve only checked the updated source here.

**@⁠Yoshi-233** on GitHub · 2026-11-30 01:09 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1736#issuecomment-7265895104) @⁠Gauss999 Thanks for checking the exact FXC behaviour and correcting my suggestion. I checked the updated diff: the inner loop now has just `[loop]`, and putting the red cells in the first eight positions makes the previous eight-read result distinguishable from the expected full-tile colour. That addresses the issue I raised in review. The hardware and WARP runs are yours; I’ve only checked the updated source here.
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/1736/head:github-bot/gh-1736'
git switch 'github-bot/gh-1736'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1736'
git switch 'github-bot/gh-1736'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1736'
git switch 'github-bot/gh-1736'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1736'
git switch 'main'
git merge --squash 'github-bot/gh-1736'
git switch 'main'
git merge --ff-only 'github-bot/gh-1736'
git switch 'main'
git merge 'github-bot/gh-1736'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

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