VRAM: allocate the projector shadow atlas (and sun cascades) only when shadow maps are actually used -- ~320 MB back for ray-traced shadows #600

Closed
opened 2026-10-09 09:20:39 +00:00 by sky_line · 2 comments
Owner

Shadow maps are allocated at startup whether or not they're used. With ray-traced shadows active they're unused memory, so ray tracing only ever adds VRAM instead of replacing the shadow-map cost.

Measured (4K, RTX 5090, RT sun + projector shadows on):

  • Projector shadow atlas + static cache: 320 MB (8192x4096 D32 atlas + same-size static cache + half-size translucency pair; cell size picked at startup by vramPick, initProjShadows in llcleanrenderervk.cpp). Unused while projector shadows are ray traced.
  • Sun shadow cascades: 96 MB at 2048 (4 cascades); only used while RT warms up (BLAS rebuild) or when RT is off.

On an 8 GB card the startup pick sees an empty card, so it takes the full 1024-cell atlas; that's ~320 MB of an often 5-6 GB OS budget, wasted while RT is on (see #595 / #597 / #599 for 6-8 GB cards hitting the wall).

Do:

  • Allocate the projector atlas + static cache lazily: only when projectors actually render through shadow maps (RT off, RT projector shadows off, TLAS invalid / warming up, or a per-frame fallback). Free it after a grace period (e.g. 30-60 s) of not being used.
  • Size it at allocation time against the current budget (not at startup), soft-fail, and fall back to a smaller cell size or to no projector shadows for that frame -- never fatal.
  • Same idea for the sun cascades if the warm-up fallback can tolerate a frame or two without them (or keep a small low-res fallback cascade set instead of the full resolution).
  • Log the allocate/free events and show the category in the VKMem breakdown.

Expected win: ~320 MB back for every RT user (more than the RT shadow mask itself at 1440p), plus up to ~96 MB from cascades.

Part of #282 (8 GB fit).

Shadow maps are allocated at startup whether or not they're used. With ray-traced shadows active they're unused memory, so ray tracing only ever *adds* VRAM instead of replacing the shadow-map cost. **Measured (4K, RTX 5090, RT sun + projector shadows on):** - Projector shadow atlas + static cache: **320 MB** (8192x4096 D32 atlas + same-size static cache + half-size translucency pair; cell size picked at startup by `vramPick`, `initProjShadows` in `llcleanrenderervk.cpp`). Unused while projector shadows are ray traced. - Sun shadow cascades: 96 MB at 2048 (4 cascades); only used while RT warms up (BLAS rebuild) or when RT is off. On an 8 GB card the startup pick sees an empty card, so it takes the full 1024-cell atlas; that's ~320 MB of an often 5-6 GB OS budget, wasted while RT is on (see #595 / #597 / #599 for 6-8 GB cards hitting the wall). **Do:** - Allocate the projector atlas + static cache lazily: only when projectors actually render through shadow maps (RT off, RT projector shadows off, TLAS invalid / warming up, or a per-frame fallback). Free it after a grace period (e.g. 30-60 s) of not being used. - Size it at allocation time against the *current* budget (not at startup), soft-fail, and fall back to a smaller cell size or to no projector shadows for that frame -- never fatal. - Same idea for the sun cascades if the warm-up fallback can tolerate a frame or two without them (or keep a small low-res fallback cascade set instead of the full resolution). - Log the allocate/free events and show the category in the VKMem breakdown. **Expected win:** ~320 MB back for every RT user (more than the RT shadow mask itself at 1440p), plus up to ~96 MB from cascades. Part of #282 (8 GB fit).
sky_line added this to the Slipstream project 2026-10-09 09:20:39 +00:00
Author
Owner

808bb1cdd4: the projector shadow atlas is allocated only while projectors are shadow-mapped (sized against the current budget, soft-fail) and freed after 45 s unused; the sun cascades drop to 512 while the sun is ray traced. Verified: with RT the atlas is never allocated (shadow VRAM 6 MB, was ~416 MB); switching projectors to shadow maps allocated it (320 MB, 17 ms one-time hitch). Lands in 1.2.0 Beta 8.

808bb1cdd4: the projector shadow atlas is allocated only while projectors are shadow-mapped (sized against the current budget, soft-fail) and freed after 45 s unused; the sun cascades drop to 512 while the sun is ray traced. Verified: with RT the atlas is never allocated (shadow VRAM 6 MB, was ~416 MB); switching projectors to shadow maps allocated it (320 MB, 17 ms one-time hitch). Lands in 1.2.0 Beta 8.
Author
Owner

Verified end to end: switching projectors back to ray traced freed the atlas after the grace period ("projector shadow atlas FREED ... 320 MB"), shadow VRAM back to 6 MB. Lands in 1.2.0 Beta 8.

Verified end to end: switching projectors back to ray traced freed the atlas after the grace period ("projector shadow atlas FREED ... 320 MB"), shadow VRAM back to 6 MB. Lands in 1.2.0 Beta 8.
sky_line 2026-10-09 22:37:11 +00:00
Sign in to join this conversation.
No milestone
No project
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
sky_line/Slipstream#600
No description provided.