dont hard code clustering limits on cpu side so they can be informed by Limits later (#19985)

# Objective

- prepare bevy_light for split
- make limits more dynamically configurable

## Solution

- use settings struct

## Testing

- 3d_scene, lighting
This commit is contained in:
atlv 2025-07-06 15:36:58 -04:00 committed by GitHub
parent baa88b98a3
commit 5b38989ac4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 20 additions and 10 deletions

View File

@ -20,8 +20,7 @@ use tracing::warn;
use super::{
ClusterConfig, ClusterFarZMode, ClusteredDecal, Clusters, GlobalClusterSettings,
GlobalVisibleClusterableObjects, ViewClusterBindings, VisibleClusterableObjects,
MAX_UNIFORM_BUFFER_CLUSTERABLE_OBJECTS,
GlobalVisibleClusterableObjects, VisibleClusterableObjects,
};
use crate::{
prelude::EnvironmentMapLight, ExtractedPointLight, LightProbe, PointLight, SpotLight,
@ -263,7 +262,7 @@ pub(crate) fn assign_objects_to_clusters(
}));
}
if clusterable_objects.len() > MAX_UNIFORM_BUFFER_CLUSTERABLE_OBJECTS
if clusterable_objects.len() > global_cluster_settings.max_uniform_buffer_clusterable_objects
&& !global_cluster_settings.supports_storage_buffers
{
clusterable_objects.sort_by_cached_key(|clusterable_object| {
@ -282,7 +281,9 @@ pub(crate) fn assign_objects_to_clusters(
let mut clusterable_objects_in_view_count = 0;
clusterable_objects.retain(|clusterable_object| {
// take one extra clusterable object to check if we should emit the warning
if clusterable_objects_in_view_count == MAX_UNIFORM_BUFFER_CLUSTERABLE_OBJECTS + 1 {
if clusterable_objects_in_view_count
== global_cluster_settings.max_uniform_buffer_clusterable_objects + 1
{
false
} else {
let clusterable_object_sphere = clusterable_object.sphere();
@ -298,17 +299,19 @@ pub(crate) fn assign_objects_to_clusters(
}
});
if clusterable_objects.len() > MAX_UNIFORM_BUFFER_CLUSTERABLE_OBJECTS
if clusterable_objects.len()
> global_cluster_settings.max_uniform_buffer_clusterable_objects
&& !*max_clusterable_objects_warning_emitted
{
warn!(
"MAX_UNIFORM_BUFFER_CLUSTERABLE_OBJECTS ({}) exceeded",
MAX_UNIFORM_BUFFER_CLUSTERABLE_OBJECTS
"max_uniform_buffer_clusterable_objects ({}) exceeded",
global_cluster_settings.max_uniform_buffer_clusterable_objects
);
*max_clusterable_objects_warning_emitted = true;
}
clusterable_objects.truncate(MAX_UNIFORM_BUFFER_CLUSTERABLE_OBJECTS);
clusterable_objects
.truncate(global_cluster_settings.max_uniform_buffer_clusterable_objects);
}
for (
@ -448,14 +451,17 @@ pub(crate) fn assign_objects_to_clusters(
(xy_count.x + x_overlap) * (xy_count.y + y_overlap) * z_count as f32;
}
if cluster_index_estimate > ViewClusterBindings::MAX_INDICES as f32 {
if cluster_index_estimate
> global_cluster_settings.view_cluster_bindings_max_indices as f32
{
// scale x and y cluster count to be able to fit all our indices
// we take the ratio of the actual indices over the index estimate.
// this is not guaranteed to be small enough due to overlapped tiles, but
// the conservative estimate is more than sufficient to cover the
// difference
let index_ratio = ViewClusterBindings::MAX_INDICES as f32 / cluster_index_estimate;
let index_ratio = global_cluster_settings.view_cluster_bindings_max_indices as f32
/ cluster_index_estimate;
let xy_ratio = index_ratio.sqrt();
requested_cluster_dimensions.x =

View File

@ -47,6 +47,8 @@ pub(crate) fn make_global_cluster_settings(world: &World) -> GlobalClusterSettin
GlobalClusterSettings {
supports_storage_buffers,
clustered_decals_are_usable,
max_uniform_buffer_clusterable_objects: MAX_UNIFORM_BUFFER_CLUSTERABLE_OBJECTS,
view_cluster_bindings_max_indices: ViewClusterBindings::MAX_INDICES,
}
}

View File

@ -43,6 +43,8 @@ mod test;
pub struct GlobalClusterSettings {
pub supports_storage_buffers: bool,
pub clustered_decals_are_usable: bool,
pub max_uniform_buffer_clusterable_objects: usize,
pub view_cluster_bindings_max_indices: usize,
}
/// Configure the far z-plane mode used for the furthest depth slice for clustered forward