bevy/crates/bevy_pbr/src/meshlet
Patrick Walton 40df1ea4b6
Remove the type parameter from check_visibility, and only invoke it once. (#16812)
Currently, `check_visibility` is parameterized over a query filter that
specifies the type of potentially-visible object. This has the
unfortunate side effect that we need a separate system,
`mark_view_visibility_as_changed_if_necessary`, to trigger view
visibility change detection. That system is quite slow because it must
iterate sequentially over all entities in the scene.

This PR moves the query filter from `check_visibility` to a new
component, `VisibilityClass`. `VisibilityClass` stores a list of type
IDs, each corresponding to one of the query filters we used to use.
Because `check_visibility` is no longer specialized to the query filter
at the type level, Bevy now only needs to invoke it once, leading to
better performance as `check_visibility` can do change detection on the
fly rather than delegating it to a separate system.

This commit also has ergonomic improvements, as there's no need for
applications that want to add their own custom renderable components to
add specializations of the `check_visibility` system to the schedule.
Instead, they only need to ensure that the `ViewVisibility` component is
properly kept up to date. The recommended way to do this, and the way
that's demonstrated in the `custom_phase_item` and
`specialized_mesh_pipeline` examples, is to make `ViewVisibility` a
required component and to add the type ID to it in a component add hook.
This patch does this for `Mesh3d`, `Mesh2d`, `Sprite`, `Light`, and
`Node`, which means that most app code doesn't need to change at all.

Note that, although this patch has a large impact on the performance of
visibility determination, it doesn't actually improve the end-to-end
frame time of `many_cubes`. That's because the render world was already
effectively hiding the latency from
`mark_view_visibility_as_changed_if_necessary`. This patch is, however,
necessary for *further* improvements to `many_cubes` performance.

`many_cubes` trace before:
![Screenshot 2024-12-13
015318](https://github.com/user-attachments/assets/d0b1881b-fb75-4a39-b05d-1a16eabfa2c5)

`many_cubes` trace after:
![Screenshot 2024-12-13
145735](https://github.com/user-attachments/assets/0a364289-e942-41bb-9cc2-b05d07e3722d)

## Migration Guide

* `check_visibility` no longer takes a `QueryFilter`, and there's no
need to add it manually to your app schedule anymore for custom
rendering items. Instead, entities with custom renderable components
should add the appropriate type IDs to `VisibilityClass`. See
`custom_phase_item` for an example.
2024-12-17 04:43:45 +00:00
..
asset.rs Deny derive_more error feature and replace it with thiserror (#16684) 2024-12-06 17:03:55 +00:00
cull_clusters.wgsl Meshlet fill cluster buffers rewritten (#15955) 2024-10-23 19:18:49 +00:00
downsample_depth.wgsl Meshlet software raster + start of cleanup (#14623) 2024-08-26 17:54:34 +00:00
dummy_visibility_buffer_resolve.wgsl Meshlet rendering (initial feature) (#10164) 2024-03-25 19:08:27 +00:00
fill_cluster_buffers.wgsl Meshlet fill cluster buffers rewritten (#15955) 2024-10-23 19:18:49 +00:00
from_mesh.rs Update hashbrown to 0.15 (#15801) 2024-12-10 19:45:50 +00:00
instance_manager.rs Update hashbrown to 0.15 (#15801) 2024-12-10 19:45:50 +00:00
material_pipeline_prepare.rs Add a bindless mode to AsBindGroup. (#16368) 2024-12-03 18:00:34 +00:00
material_shade_nodes.rs Meshlet software raster + start of cleanup (#14623) 2024-08-26 17:54:34 +00:00
meshlet_bindings.wgsl Meshlet fill cluster buffers rewritten (#15955) 2024-10-23 19:18:49 +00:00
meshlet_mesh_manager.rs Update hashbrown to 0.15 (#15801) 2024-12-10 19:45:50 +00:00
meshlet_mesh_material.wgsl Meshlet misc (#13761) 2024-06-10 13:06:08 +00:00
meshlet_preview.png Meshlet rendering (initial feature) (#10164) 2024-03-25 19:08:27 +00:00
mod.rs Remove the type parameter from check_visibility, and only invoke it once. (#16812) 2024-12-17 04:43:45 +00:00
persistent_buffer_impls.rs Meshlet new error projection (#15846) 2024-10-22 20:14:30 +00:00
persistent_buffer.rs Add core and alloc over std Lints (#15281) 2024-09-27 00:59:59 +00:00
pipelines.rs Native unclipped depth on supported platforms (#16095) 2024-12-03 17:30:14 +00:00
remap_1d_to_2d_dispatch.wgsl Meshlet fill cluster buffers rewritten (#15955) 2024-10-23 19:18:49 +00:00
resolve_render_targets.wgsl More triangles/vertices per meshlet (#15023) 2024-09-08 17:55:57 +00:00
resource_manager.rs Meshlet fill cluster buffers rewritten (#15955) 2024-10-23 19:18:49 +00:00
visibility_buffer_hardware_raster.wgsl Native unclipped depth on supported platforms (#16095) 2024-12-03 17:30:14 +00:00
visibility_buffer_raster_node.rs Native unclipped depth on supported platforms (#16095) 2024-12-03 17:30:14 +00:00
visibility_buffer_resolve.wgsl Meshlet fill cluster buffers rewritten (#15955) 2024-10-23 19:18:49 +00:00
visibility_buffer_software_raster.wgsl Native unclipped depth on supported platforms (#16095) 2024-12-03 17:30:14 +00:00