Skip to content

Create mesh view bind group layout on demand to remove unused bindings#23982

Merged
alice-i-cecile merged 17 commits intobevyengine:mainfrom
beicause:mesh-view-rm-unused-binding
May 1, 2026
Merged

Create mesh view bind group layout on demand to remove unused bindings#23982
alice-i-cecile merged 17 commits intobevyengine:mainfrom
beicause:mesh-view-rm-unused-binding

Conversation

@beicause
Copy link
Copy Markdown
Member

@beicause beicause commented Apr 25, 2026

Objective

Fixes #23627.

MeshPipelineViewLayoutKey uses too many bindings even if features like ssr, environment map are unused.

Solution

Don't pre-allocate every combination that grows exponentially. Instead, create mesh view bind group layout on demand so that we can add more view keys to reduce unused bindings.

MeshPipelineViewLayouts::get_view_layout will be slower, but I'm not sure how slow it is. My feeling is that the overhead is not high, compared to when we clone it before.

Testing

WGPU_SETTINGS_PRIO=webgl2 cargo r --example 3d_scene
cargo r --example ssr --features bluenoise_texture
cargo r --example ssao
cargo r --example irradiance_volumes

Comment thread crates/bevy_pbr/src/render/mesh_view_bindings.rs Outdated
Copy link
Copy Markdown
Contributor

@IceSentry IceSentry left a comment

Choose a reason for hiding this comment

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

Could the logic to create the offsets array be pulled out to a separate system that runs before the various render commands and stores it in as a component on the view? That way it doesn't need to be copy pasted everywhere.

@kfc35 kfc35 added this to the 0.19 milestone Apr 25, 2026
@kfc35 kfc35 added C-Bug An unexpected or incorrect behavior A-Rendering Drawing game state to the screen S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Apr 25, 2026
@github-project-automation github-project-automation Bot moved this to Needs SME Triage in Rendering Apr 25, 2026
@kfc35 kfc35 added the P-Regression Functionality that used to work but no longer does. Add a test for this! label Apr 25, 2026
@kfc35 kfc35 self-requested a review April 25, 2026 18:14
Copy link
Copy Markdown
Contributor

@kfc35 kfc35 left a comment

Choose a reason for hiding this comment

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

Thank you for doing this!

I tested it with the 3d_scene example as described and it is no longer broken for me.

This does not fix #23975 but that’s a separate issue. (This PR reduces the sampled textures to 17. I also get some other validation error about dynamic offsets: BindGroup with 'mesh_view_bind_group' label 0 expects 4 dynamic offsets. However 5 dynamic offsets were provided.) That can be a separate PR (and probably should be separate to keep this PR less complicated).

Comment thread crates/bevy_pbr/src/deferred/mod.rs Outdated
Comment thread crates/bevy_dev_tools/src/render_debug.rs Outdated
Comment thread crates/bevy_pbr/src/render/fog.rs Outdated
Comment thread crates/bevy_pbr/src/render/mesh_view_bindings.rs
Comment thread crates/bevy_pbr/src/render/mesh_view_bindings.rs
@beicause beicause force-pushed the mesh-view-rm-unused-binding branch 2 times, most recently from 8331905 to 059affa Compare April 26, 2026 11:58
@beicause beicause force-pushed the mesh-view-rm-unused-binding branch from 059affa to b3e7359 Compare April 26, 2026 12:07
@alice-i-cecile alice-i-cecile added the D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes label Apr 26, 2026
Copy link
Copy Markdown
Contributor

@kfc35 kfc35 left a comment

Choose a reason for hiding this comment

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

Thank you for consolidating! It feels cleaner

Comment thread crates/bevy_pbr/src/render/mesh_view_bindings.rs
Comment thread _release-content/migration-guides/mesh_pipeline_view_layout.md Outdated
@kfc35 kfc35 requested a review from IceSentry April 26, 2026 16:25
Co-authored-by: Kevin Chen <chen.kevin.f@gmail.com>
@HackerFoo
Copy link
Copy Markdown
Contributor

This looks good and cleans up a lot of the code I've been working with.

@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 Apr 29, 2026
@alice-i-cecile alice-i-cecile added this pull request to the merge queue May 1, 2026
Merged via the queue into bevyengine:main with commit 6fcf9a6 May 1, 2026
40 checks passed
@github-project-automation github-project-automation Bot moved this from Needs SME Triage to Done in Rendering May 1, 2026
jvastola pushed a commit to jvastola/bevy that referenced this pull request May 3, 2026
…g `MeshPipelineViewLayoutKey` (bevyengine#24090)

# Objective

- Related bevyengine#24084
- Fixes `atmosphere` example after merging bevyengine#23982

## Solution

- As @beicause mentioned, volumetric frog was calculating
`MeshPipelineViewLayoutKey` manually when it could just rely on the
`ViewKeyCache` instead, which has centralized logic for calculating it
in `check_views_need_specialization` (`STBN` is added in `impl
From<MeshPipelineKey> for MeshPipelineViewLayoutKey`)

## Testing

- `cargo run --example atmosphere` works now, no strobing!
- `cargo run --example volumetric_fog` also works
- `cargo run --example scrolling_fog` works
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-Bug An unexpected or incorrect behavior D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes P-Regression Functionality that used to work but no longer does. Add a test for this! S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Bevy 3d_scene not working in WebGL2 on windows

6 participants