Skip to content

allocate 1x1 shadow map textures when no shadow-casting lights - #25820

Merged
alice-i-cecile merged 1 commit into
bevyengine:mainfrom
issam3105:allocate_1x1_shadow_map_textures
Sep 20, 2026
Merged

alice-i-cecile merged 1 commit into
bevyengine:mainfrom
issam3105:allocate_1x1_shadow_map_textures

Conversation

@issam3105

@issam3105 issam3105 commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

Objective

point_light_shadow_map_texture and directional_light_shadow_map_texture are always allocated at their full configured size (default: 1024×1024×6 = 24 MB and 2048×2048 = 16 MB) even when no shadow-casting lights are present in the scene.

Solution

When no shadow-casting lights are present, allocate a 1×1 texture instead of a full-size one. The binding remains valid (no shader changes required), and TextureCache will reallocate at the correct size as soon as a shadow-casting light appears.

Testing

Tested with a scene containing no lights, then toggling point and directional lights with shadows on/off at runtime. The GPU memory inspector confirms:

  • Before: ~40 MB allocated at startup regardless of lights
  • After: ~0 MB for shadow maps at startup; full allocation only when a shadow-casting light is active

@alice-i-cecile alice-i-cecile added A-Rendering Drawing game state to the screen C-Performance A change motivated by improving speed, memory usage or compile times X-Uncontroversial This work is generally agreed upon D-Straightforward Simple bug fixes and API improvements, docs, test and examples labels Sep 17, 2026
@github-project-automation github-project-automation Bot moved this to Needs SME Triage in Rendering Sep 17, 2026
@alice-i-cecile alice-i-cecile added the S-Needs-Review Needs reviewer attention (from anyone!) to move forward label Sep 17, 2026

@alice-i-cecile alice-i-cecile left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, the logic makes sense here, and I can see the value for 2D or UI-only scenes in projects that still want to pull in bevy_pbr. Or cases where you're rolling your own shadows / rendering pipeline.

Is there a noticeable hitch for reallocation when toggling shadows on? I think it'll probably be dwarfed by asset loading in most realistic cases but it's something I worry a bit about.

@issam3105

issam3105 commented Sep 18, 2026

Copy link
Copy Markdown
Contributor Author

I tested on native (Windows Vulkan), WebGPU (Chrome desktop), and WebGPU (Chrome) on a mid-range Android device (Redmi Note 14). In all cases, toggling shadows on/off caused no perceptible hitch. The reallocation is fast enough to be invisible even on mobile hardware.

Also toggling shadow casting at runtime is not a common pattern in production apps, it's mostly a concern for tooling and debug workflows, where a one-frame hitch (even if exists) is entirely acceptable.

@Zeophlite Zeophlite added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Sep 19, 2026
@alice-i-cecile
alice-i-cecile added this pull request to the merge queue Sep 20, 2026
Merged via the queue into bevyengine:main with commit d126db0 Sep 20, 2026
51 checks passed
@github-project-automation github-project-automation Bot moved this from Needs SME Triage to Done in Rendering Sep 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Rendering Drawing game state to the screen C-Performance A change motivated by improving speed, memory usage or compile times D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it X-Uncontroversial This work is generally agreed upon

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants