Skip to content

Fix render layer change propagation for GPU-culled meshes - #1

Merged
CodingDaniel1 merged 2 commits into
CodingDaniel1:fix-camera-is-activefrom
beicause:review-25690-suggestions
Sep 8, 2026
Merged

Fix render layer change propagation for GPU-culled meshes#1
CodingDaniel1 merged 2 commits into
CodingDaniel1:fix-camera-is-activefrom
beicause:review-25690-suggestions

Conversation

@beicause

@beicause beicause commented Sep 8, 2026

Copy link
Copy Markdown

Objective

Follow-up to #25690, based on an AI code review against main.

⚠️ Disclaimer: authored entirely by AI, no human review, and not tested at runtime — only cargo check / clippy / fmt / existing unit tests were run. Please scrutinize; every hunk is independently droppable.

Changes

  1. Propagate render-layer changes of GPU-culled meshes (bug fix). RenderGpuCulledEntities::update() now records layer changes, but it only runs for meshes that extraction picked up that frame, and the extraction filter had no Changed<RenderLayers> / RemovedComponents<RenderLayers>. A static mesh whose only change is its render layers would never propagate. Adds both to extract_meshes_for_gpu_building.

  2. API cleanup. Removed RenderVisibleEntitiesClass::add_entity() — its only two callers on main are exactly the lines rewritten here, so it would be dead code; sort_added_entities' doc updated. (Its removal was deferred to a follow-up in the #25670 review — happy to drop this hunk.) Plus != over .ne() and a doc note on update().

Remaining known limitations

  • New shadow-map subviews: the light-side flush trigger is component-level (RenderShadowMapVisibleEntities::is_added()), but shadow subviews live in a per-RetainedViewEntity map. A fresh subview under an existing light component (new camera → new directional-light cascades, or a cascade count change) starts empty, misses all previously registered GPU-culled meshes, and never catches up. Pre-existing on main.
  • Minimized-window restore: while the render target is zero-sized, ExtractedView is removed and the view's GPU-culling table stops receiving the per-frame diffs; meshes registered/deregistered meanwhile are missing/stale after restore. Pre-existing on main; this is also why RenderVisibleEntities deliberately persists in the zero-size path per #25670.

Testing

  • cargo check -p bevy_pbr, cargo clippy -p bevy_render -p bevy_pbr, cargo fmt --check, bevy_render visibility unit tests.
  • Runtime — not done (AI, untested). Suggested: toggle Camera::is_active and delayed camera spawn with NoCpuCulling meshes (repro from #25690); change RenderLayers on a static NoCpuCulling mesh with two cameras on disjoint layers.

@beicause beicause left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

AI-generated follow-up to bevyengine#25690 — authored entirely by AI, no human review; not tested at runtime (static checks only). Rationale per hunk in the inline comments; overall description in the PR description.

Comment thread crates/bevy_pbr/src/render/mesh.rs
///
/// You must call this after adding entities to the list via
/// [`Self::add_entity`].
/// You must call this after pushing entities onto the list, as the

@beicause beicause Sep 8, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Removed add_entity() as well: its only callers on main were exactly the lines rewritten in collect_gpu_culled_meshes_for_subview, so it would be dead code after this PR. (During the bevyengine#25670 review its removal was suggested to be deferred to a follow-up PR — happy to drop this hunk if maintainers prefer that. AI-authored; untested.)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This is good, i was worried people are using this public api, dont know if this requires a migration guide?

Pure render-layer changes on a mesh never reached
`RenderGpuCulledEntities::update()` because `extract_meshes_for_gpu_building`
only iterates entities it considers changed, and `RenderLayers` wasn't part
of its change filter. A static mesh whose only change is its render layers
would therefore keep a stale layer relevance in all views forever, and the
`changed_layers` list would only be populated when a mesh happened to be
re-extracted for some other reason. Add `Changed<RenderLayers>` and
`RemovedComponents<RenderLayers>` to the change detection.
@beicause
beicause force-pushed the review-25690-suggestions branch from d46880d to 3f15240 Compare September 8, 2026 12:19
Its only callers were already converted to direct `added_entities`
pushes, leaving it as dead code; update `sort_added_entities`' doc
accordingly. (Its removal was deferred to a follow-up PR during the
bevyengine#25670 review.)
@beicause
beicause force-pushed the review-25690-suggestions branch from 3f15240 to 672fa54 Compare September 8, 2026 12:28
@beicause beicause changed the title Fix render layer change propagation and view-appear flush for GPU-culled meshes Fix render layer change propagation for GPU-culled meshes Sep 8, 2026
@CodingDaniel1

Copy link
Copy Markdown
Owner

"New shadow-map subviews"

I would like to fix this in another PR to not increase the complexity here. The reason this still works right now is due to how view can trigger change detection for each mesh via cpu culling ViewVisiblity change.

@CodingDaniel1

Copy link
Copy Markdown
Owner

Ive ran a live test against this, and changing layers is working, but found another issue and will commit that fix as well

@CodingDaniel1
CodingDaniel1 merged commit ae06d70 into CodingDaniel1:fix-camera-is-active Sep 8, 2026
@beicause
beicause deleted the review-25690-suggestions branch September 9, 2026 01:09
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.

2 participants