Performance recipe: run the title's BVH builder for correct lighting #20

Manually merged
github merged 3 commits from github-bot/gh-20 into main 2026-11-28 00:49:49 +00:00 AGit
Owner

@⁠jgrizon on GitHub · 2026-11-27 18:57 UTC · original
jgrizon:perf/bvh-builder → main · +3589 −2 · 21 files · 3 commits · merged 2026-11-28 00:47 UTC

Summary

This PR builds on #15: it contains #15's two commits plus one new one. Merge #15 first, or take this PR alone.

lighting probes resolve
  before: builder held back (opens = !halves && all_made)
          -> probes trace an empty BVH -> faces and shade nearly black
  after:  builder runs when all 53 of its programs translate exactly
          (VICTORY_BUILDER_EXACT=1, needs VICTORY_WAVE64_REDUCE=1)
          -> the title's own ray-traced lighting, VICTORY_AMBIENT=0

The new commit adds patches 0014 to 0029 to perf/patches/series:

  • 0014 to 0024: ports the checkpoint wave64 work: LDS flag regions, lane-alike branches, wave64 reductions and lane reads across halves. It also adds diagnostics and two AGX shader prototypes. All of these are off by default.
  • 0025 to 0028: adds VICTORY_BUILDER_EXACT. A translation records whether its 32-lane halves are exact, and the builder opens only when they are. It is off by default.
  • 0029: play-main-mac.sh sets VICTORY_WAVE64_REDUCE=1, VICTORY_BUILDER_EXACT=1 and VICTORY_AMBIENT=0. This replaces #15's VICTORY_AMBIENT=1.0 default.

Why

The constant stand-in from #15 made faces visible but flat, and dropped draws stayed at about 1,400 a frame. Nearly all of them were "dispatch: the BVH builder held back". The builder was held back because it was run in 32-lane halves while its programs exchange data across the halves; upstream VIctory PR #2711 found that run this way it hung an RTX 4070 SUPER within two minutes. With exact wave64 reductions and lane reads, every one of its programs translates exactly, so the builder can run. I rejected the alternative, estimating the light (VICTORY_AMBIENT=estimate with or without FLOOR): faces stayed black.

Evidence

Hardware: Apple M5 Pro, 24 GB, macOS 27.3, CrossOver 26.3.0.39832 with patched Wine, D3DMetal 3.0. Series S intro, release builds, same launcher switches otherwise.

World frames, first 120 s Slowest 5% of frames Most dropped draws in a frame Faces
#15 (VICTORY_AMBIENT=1.0) 519 0.40 s ~1,400 lit, flat
this PR 424, 464, 443, 421 0.75 to 1.07 s 1 to 2 the title's own lighting
  • Builder log: BVH builder runs ... 53 made, 0 refused. No GPU hang in any run, the longest 10 minutes.
  • Captured frames from a diagnostics run show the cinematic correctly lit: face, skin, hair, street and background. Without the builder they were black.
  • Cost: about 15% fewer frames and slower worst-case frames. In release the builder adds about 10 ms of GPU time and about 55 MB of copies per frame.
  • ./build.sh --perf --prepare DIR on a clean directory: the whole series applies. The prepared tree is identical to the tree I benchmarked, except for the 0002 display-name patch.
  • Tests in Wine: victory-gpu 592 passed, 0 failed, 22 ignored. victory-hle 166 passed, 1 failed; the failure is the existing xpackage function-pointer test, which fails without these patches too.

Not tested: D3DMetal 4.0 beta 3, other Macs, and anything past the intro.

Risk

Can we undo it? Yes, easily.

What could break: the frame rate drops about 15% with the new default. A GPU hang is possible on hardware where the builder's programs do not translate exactly. The builder stays held back in that case, which gives the old black faces rather than a hang.

How to undo: export VICTORY_WAVE64_REDUCE=0 VICTORY_BUILDER_EXACT=0 VICTORY_AMBIENT=1.0, or drop patch 0029 from the series. VICTORY_WAVE64_REDUCE=1 without the builder leaves green speckles, so turn the two off together.

Also tried and not adopted: lighting the builder only every 3rd or 4th frame (VICTORY_BUILDER_EVERY), and VICTORY_FLIGHTS_RANGES. Neither gained anything over run-to-run noise.

Panel

Not run.

**@⁠jgrizon** on GitHub · 2026-11-27 18:57 UTC · [original](https://github.com/paveledits/ScarlettMac/pull/20) `jgrizon:perf/bvh-builder` → `main` · +3589 −2 · 21 files · 3 commits · merged 2026-11-28 00:47 UTC ## Summary This PR builds on #15: it contains #15's two commits plus one new one. Merge #15 first, or take this PR alone. ```text lighting probes resolve before: builder held back (opens = !halves && all_made) -> probes trace an empty BVH -> faces and shade nearly black after: builder runs when all 53 of its programs translate exactly (VICTORY_BUILDER_EXACT=1, needs VICTORY_WAVE64_REDUCE=1) -> the title's own ray-traced lighting, VICTORY_AMBIENT=0 ``` The new commit adds patches 0014 to 0029 to `perf/patches/series`: - **0014 to 0024:** ports the checkpoint wave64 work: LDS flag regions, lane-alike branches, wave64 reductions and lane reads across halves. It also adds diagnostics and two AGX shader prototypes. All of these are off by default. - **0025 to 0028:** adds `VICTORY_BUILDER_EXACT`. A translation records whether its 32-lane halves are exact, and the builder opens only when they are. It is off by default. - **0029:** `play-main-mac.sh` sets `VICTORY_WAVE64_REDUCE=1`, `VICTORY_BUILDER_EXACT=1` and `VICTORY_AMBIENT=0`. This replaces #15's `VICTORY_AMBIENT=1.0` default. ## Why The constant stand-in from #15 made faces visible but flat, and dropped draws stayed at about 1,400 a frame. Nearly all of them were "dispatch: the BVH builder held back". The builder was held back because it was run in 32-lane halves while its programs exchange data across the halves; upstream VIctory PR #2711 found that run this way it hung an RTX 4070 SUPER within two minutes. With exact wave64 reductions and lane reads, every one of its programs translates exactly, so the builder can run. I rejected the alternative, estimating the light (`VICTORY_AMBIENT=estimate` with or without `FLOOR`): faces stayed black. ## Evidence Hardware: Apple M5 Pro, 24 GB, macOS 27.3, CrossOver 26.3.0.39832 with patched Wine, D3DMetal 3.0. Series S intro, release builds, same launcher switches otherwise. | | World frames, first 120 s | Slowest 5% of frames | Most dropped draws in a frame | Faces | | --- | ---: | ---: | ---: | --- | | #15 (`VICTORY_AMBIENT=1.0`) | 519 | 0.40 s | ~1,400 | lit, flat | | this PR | 424, 464, 443, 421 | 0.75 to 1.07 s | 1 to 2 | the title's own lighting | - Builder log: `BVH builder runs ... 53 made, 0 refused`. No GPU hang in any run, the longest 10 minutes. - Captured frames from a diagnostics run show the cinematic correctly lit: face, skin, hair, street and background. Without the builder they were black. - Cost: about 15% fewer frames and slower worst-case frames. In release the builder adds about 10 ms of GPU time and about 55 MB of copies per frame. - `./build.sh --perf --prepare DIR` on a clean directory: the whole series applies. The prepared tree is identical to the tree I benchmarked, except for the 0002 display-name patch. - Tests in Wine: victory-gpu `592 passed, 0 failed, 22 ignored`. victory-hle `166 passed, 1 failed`; the failure is the existing xpackage function-pointer test, which fails without these patches too. Not tested: D3DMetal 4.0 beta 3, other Macs, and anything past the intro. ## Risk **Can we undo it?** Yes, easily. **What could break:** the frame rate drops about 15% with the new default. A GPU hang is possible on hardware where the builder's programs do not translate exactly. The builder stays held back in that case, which gives the old black faces rather than a hang. **How to undo:** export `VICTORY_WAVE64_REDUCE=0 VICTORY_BUILDER_EXACT=0 VICTORY_AMBIENT=1.0`, or drop patch 0029 from the series. `VICTORY_WAVE64_REDUCE=1` without the builder leaves green speckles, so turn the two off together. Also tried and not adopted: lighting the builder only every 3rd or 4th frame (`VICTORY_BUILDER_EVERY`), and `VICTORY_FLIGHTS_RANGES`. Neither gained anything over run-to-run noise. ## Panel Not run.
victory-gpu's maps keyed by its own addresses use a multiply-and-fold hash
instead of SipHash. World frames in the first 120 s on a 24 GB M5 Pro:
520 and 523, against 488 to 516 before.
With VICTORY_HALVES_LOCAL the title's compute BVH builder never runs, so the
estimate left faces and unlit surfaces nearly black. VICTORY_AMBIENT=1.0
lights them at no measurable cost.
With VICTORY_HALVES_LOCAL the title's compute BVH builder was held back, so
its lighting probes traced against nothing and faces came out nearly black.
The recipe now carries the wave64 reduction and lane-read patches and
VICTORY_BUILDER_EXACT, which lets the builder run when its programs
translate exactly. play-main-mac.sh sets VICTORY_WAVE64_REDUCE=1,
VICTORY_BUILDER_EXACT=1 and VICTORY_AMBIENT=0.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 19:00:45 +00:00
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-11-27 18:57 UTC · original · reviewed

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

**@⁠copilot-pull-request-reviewer[bot]** on GitHub · 2026-11-27 18:57 UTC · [original](https://github.com/paveledits/ScarlettMac/pull/20#pullrequestreview-6092325718) · **reviewed** Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
github manually merged commit 7b86dadc93 into main 2026-11-28 00:49:49 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.