Performance recipe: cheaper hash for victory-gpu's maps, constant indirect light by default #15

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

@⁠jgrizon on GitHub · 2026-11-27 13:59 UTC · original
jgrizon:perf/fold-hasher → main · +630 −1 · 4 files · 2 commits · merged 2026-11-28 00:47 UTC

Changes

Adds patch 0012 to the performance recipe. victory-gpu keeps about 19 hash maps keyed by its own addresses and slot numbers: twins, texture states, pending refreshes, bound pipelines, page-table views and so on. They used Rust's default hasher (SipHash), which protects against keys an attacker picks. These keys are addresses VIctory chooses, so that protection buys nothing. The patch switches those maps to the multiply-and-fold hash the descriptor census already uses.

census_maps.rs   + FoldHashing (zero-sized BuildHasher), FoldMap<K,V>, FoldSet<K>
host.rs, descriptor/host.rs, unwaited.rs, flights.rs, memory.rs, watch.rs,
replay/record.rs, resource.rs, descriptor.rs, shadow.rs, widened.rs, ...
                 HashMap<addr, _> -> FoldMap<addr, _>

There is no switch. The maps hold the same entries and give the same answers. Nothing depends on a map's iteration order; the one count that needs an order sorts its entries first.

A profile showed the submitting thread spending about 7 ms of each ~240 ms frame in SipHash.

Second patch: constant indirect light by default (0013)

play-main-mac.sh now sets VICTORY_AMBIENT=1.0 instead of estimate. With VICTORY_HALVES_LOCAL, the title's compute BVH builder (XboxBvhBuilder.dll) never runs, so the probe resolve traces against nothing and anything the sun does not reach directly is near black. The estimate's floor (about 0.04) leaves 99 to 100% of points under it. The constant stand-in lights faces, skin and clothing, with some small dotted artifacts on skin. Details are in #17. Exporting VICTORY_AMBIENT=estimate restores the old behavior.

Settings (release, same session) World frames in the first 120 s
VICTORY_AMBIENT=estimate (old default) 538
VICTORY_AMBIENT=1.0 503, 586

A diagnostics build gave 431 frames with 1.0 and 386 with estimate. Single runs on this Mac vary between about 450 and 600 frames, so these numbers show no cost, not a speed gain.

runtime-preview/build.sh --perf --prepare NEW_DIR applies all 13 patches from a fresh directory (exit 0).

Verification

Apple M5 Pro, 24 GB, macOS 27.3, CrossOver 26.3.0.39832, D3DMetal 3.0, patched CrossOver Wine from tools/macos/build-crossover-wine.sh.

  • runtime-preview/build.sh --perf --prepare NEW_DIR applies all 12 patches from a fresh directory (exit 0).
  • cargo check -p victory-gpu --target x86_64-pc-windows-gnullvm on that tree: clean.
  • victory-gpu Windows unit tests under that Wine, on our tree with this change: 587 passed; 0 failed; 21 ignored.
  • zsh -n scripts/build.sh && zsh -n scripts/run.sh && sh -n runtime-preview/build.sh: passed.
  • Series S intro, release build, play-main-mac.sh settings. World frames in the first 120 s:
Build Runs
Before (same day, same settings) 488, 506, 516
With this patch 520, 523, 521, 532, 516

The gain is about 3%. Runs vary by 10% to 30%, so this is a small, steady gain, not a big one.

Not verified: all game runs above used the November 27 recipe (0001) plus this change, without upstream's newer patches 0003 to 0011. Those patches and this one touch different files and apply cleanly together, but no game run of the exact 12-patch series has finished yet.

**@⁠jgrizon** on GitHub · 2026-11-27 13:59 UTC · [original](https://github.com/paveledits/ScarlettMac/pull/15) `jgrizon:perf/fold-hasher` → `main` · +630 −1 · 4 files · 2 commits · merged 2026-11-28 00:47 UTC ## Changes Adds patch 0012 to the performance recipe. victory-gpu keeps about 19 hash maps keyed by its own addresses and slot numbers: twins, texture states, pending refreshes, bound pipelines, page-table views and so on. They used Rust's default hasher (SipHash), which protects against keys an attacker picks. These keys are addresses VIctory chooses, so that protection buys nothing. The patch switches those maps to the multiply-and-fold hash the descriptor census already uses. ```text census_maps.rs + FoldHashing (zero-sized BuildHasher), FoldMap<K,V>, FoldSet<K> host.rs, descriptor/host.rs, unwaited.rs, flights.rs, memory.rs, watch.rs, replay/record.rs, resource.rs, descriptor.rs, shadow.rs, widened.rs, ... HashMap<addr, _> -> FoldMap<addr, _> ``` There is no switch. The maps hold the same entries and give the same answers. Nothing depends on a map's iteration order; the one count that needs an order sorts its entries first. A profile showed the submitting thread spending about 7 ms of each ~240 ms frame in SipHash. ## Second patch: constant indirect light by default (0013) `play-main-mac.sh` now sets `VICTORY_AMBIENT=1.0` instead of `estimate`. With `VICTORY_HALVES_LOCAL`, the title's compute BVH builder (`XboxBvhBuilder.dll`) never runs, so the probe resolve traces against nothing and anything the sun does not reach directly is near black. The estimate's floor (about 0.04) leaves 99 to 100% of points under it. The constant stand-in lights faces, skin and clothing, with some small dotted artifacts on skin. Details are in #17. Exporting `VICTORY_AMBIENT=estimate` restores the old behavior. | Settings (release, same session) | World frames in the first 120 s | | --- | --- | | `VICTORY_AMBIENT=estimate` (old default) | 538 | | `VICTORY_AMBIENT=1.0` | 503, 586 | A diagnostics build gave 431 frames with `1.0` and 386 with `estimate`. Single runs on this Mac vary between about 450 and 600 frames, so these numbers show no cost, not a speed gain. `runtime-preview/build.sh --perf --prepare NEW_DIR` applies all 13 patches from a fresh directory (exit 0). ## Verification Apple M5 Pro, 24 GB, macOS 27.3, CrossOver 26.3.0.39832, D3DMetal 3.0, patched CrossOver Wine from `tools/macos/build-crossover-wine.sh`. - `runtime-preview/build.sh --perf --prepare NEW_DIR` applies all 12 patches from a fresh directory (exit 0). - `cargo check -p victory-gpu --target x86_64-pc-windows-gnullvm` on that tree: clean. - victory-gpu Windows unit tests under that Wine, on our tree with this change: `587 passed; 0 failed; 21 ignored`. - `zsh -n scripts/build.sh && zsh -n scripts/run.sh && sh -n runtime-preview/build.sh`: passed. - Series S intro, release build, `play-main-mac.sh` settings. World frames in the first 120 s: | Build | Runs | | --- | --- | | Before (same day, same settings) | 488, 506, 516 | | With this patch | 520, 523, 521, 532, 516 | The gain is about 3%. Runs vary by 10% to 30%, so this is a small, steady gain, not a big one. Not verified: all game runs above used the November 27 recipe (0001) plus this change, without upstream's newer patches 0003 to 0011. Those patches and this one touch different files and apply cleanly together, but no game run of the exact 12-patch series has finished yet.
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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 14:01:21 +00:00
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-11-27 14:00 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 14:00 UTC · [original](https://github.com/paveledits/ScarlettMac/pull/15#pullrequestreview-6089257597) · **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-bot changed title from Performance recipe: cheaper hash for victory-gpu's address maps (+3%) to Performance recipe: cheaper hash for victory-gpu's maps, constant indirect light by default 2026-11-27 16:24:26 +00:00
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.
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.