Skip to content

perf: the world and its VOBs are SRP batched again (SetPass 3100 -> 190 with shadows) - #558

Open
BoroBongo wants to merge 1 commit into
developfrom
fix/world-srp-batcher
Open

BoroBongo wants to merge 1 commit into
developfrom
fix/world-srp-batcher

Conversation

@BoroBongo

Copy link
Copy Markdown
Contributor

What

The world and its VOBs are drawn with Unity's SRP batcher again. Fewer CPU draw costs on every platform (Quest too).

  • Lit/World wasn't SRP batcher compatible: _FocusBrightness was a material property outside the UnityPerMaterial buffer (ShaderUtil.GetSRPBatcherCompatibilityCode reported it). It's inside now.
  • VOBs standing in light mapped areas (houses, caves) got their lightmap tint through a MaterialPropertyBlock. The SRP batcher skips every renderer with one: ~1900 VOBs in Khorinis. The tint now goes into the renderer's own materials. Every renderer has its own materials already, because StationaryLightsService.UpdateRenderer writes its light indices there too (measured: 4762 materials for 4771 renderers).

Measured in the editor in Khorinis with the shadows of #555 on: SetPass calls went from 3100 to 190, and the opaque pass from 86 ms CPU / 44 ms GPU to 5 / 9.5 ms (sum of 4 profiler blocks). Without shadows the gain is smaller, but it's the same mistake.

Why

Found while chasing the frame rate drop of the PC shadows (#555). Every shadow pass draws the world again, and unbatched that tanked the frame rate. It's a fix on its own, independent of the shadows, so it goes first.

How to test manually

  • G2, Khorinis: VOBs in houses (Abuyin's carpets, Coragon's tavern) are lit like before, neither black nor bright
  • G1, Old Mine: the scaffolds and stairs are as dark as the walls around them (the lightmap tint still applies)
  • Point at an item or NPC: the highlight still brightens it (_FocusBrightness)
  • Optional: Frame Debugger / Profiler shows "SRP Batch" for the world, far fewer SetPass calls

Tested in the editor (G2 Khorinis, quality High) and in a PC build with the keyboard/mouse VR simulator. Not tested with a headset yet, and nothing on Quest 2 or 3.

Save/load

Nothing saved. The tint is set when a VOB loads, like before.

Known gaps / follow-ups

…htness was outside UnityPerMaterial and ~1900 VOBs had a MaterialPropertyBlock

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant