Skip to content

Commit 5b38989

Browse files
authored
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
1 parent baa88b9 commit 5b38989

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

crates/bevy_pbr/src/cluster/assign.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ use tracing::warn;
2020

2121
use super::{
2222
ClusterConfig, ClusterFarZMode, ClusteredDecal, Clusters, GlobalClusterSettings,
23-
GlobalVisibleClusterableObjects, ViewClusterBindings, VisibleClusterableObjects,
24-
MAX_UNIFORM_BUFFER_CLUSTERABLE_OBJECTS,
23+
GlobalVisibleClusterableObjects, VisibleClusterableObjects,
2524
};
2625
use crate::{
2726
prelude::EnvironmentMapLight, ExtractedPointLight, LightProbe, PointLight, SpotLight,
@@ -263,7 +262,7 @@ pub(crate) fn assign_objects_to_clusters(
263262
}));
264263
}
265264

266-
if clusterable_objects.len() > MAX_UNIFORM_BUFFER_CLUSTERABLE_OBJECTS
265+
if clusterable_objects.len() > global_cluster_settings.max_uniform_buffer_clusterable_objects
267266
&& !global_cluster_settings.supports_storage_buffers
268267
{
269268
clusterable_objects.sort_by_cached_key(|clusterable_object| {
@@ -282,7 +281,9 @@ pub(crate) fn assign_objects_to_clusters(
282281
let mut clusterable_objects_in_view_count = 0;
283282
clusterable_objects.retain(|clusterable_object| {
284283
// take one extra clusterable object to check if we should emit the warning
285-
if clusterable_objects_in_view_count == MAX_UNIFORM_BUFFER_CLUSTERABLE_OBJECTS + 1 {
284+
if clusterable_objects_in_view_count
285+
== global_cluster_settings.max_uniform_buffer_clusterable_objects + 1
286+
{
286287
false
287288
} else {
288289
let clusterable_object_sphere = clusterable_object.sphere();
@@ -298,17 +299,19 @@ pub(crate) fn assign_objects_to_clusters(
298299
}
299300
});
300301

301-
if clusterable_objects.len() > MAX_UNIFORM_BUFFER_CLUSTERABLE_OBJECTS
302+
if clusterable_objects.len()
303+
> global_cluster_settings.max_uniform_buffer_clusterable_objects
302304
&& !*max_clusterable_objects_warning_emitted
303305
{
304306
warn!(
305-
"MAX_UNIFORM_BUFFER_CLUSTERABLE_OBJECTS ({}) exceeded",
306-
MAX_UNIFORM_BUFFER_CLUSTERABLE_OBJECTS
307+
"max_uniform_buffer_clusterable_objects ({}) exceeded",
308+
global_cluster_settings.max_uniform_buffer_clusterable_objects
307309
);
308310
*max_clusterable_objects_warning_emitted = true;
309311
}
310312

311-
clusterable_objects.truncate(MAX_UNIFORM_BUFFER_CLUSTERABLE_OBJECTS);
313+
clusterable_objects
314+
.truncate(global_cluster_settings.max_uniform_buffer_clusterable_objects);
312315
}
313316

314317
for (
@@ -448,14 +451,17 @@ pub(crate) fn assign_objects_to_clusters(
448451
(xy_count.x + x_overlap) * (xy_count.y + y_overlap) * z_count as f32;
449452
}
450453

451-
if cluster_index_estimate > ViewClusterBindings::MAX_INDICES as f32 {
454+
if cluster_index_estimate
455+
> global_cluster_settings.view_cluster_bindings_max_indices as f32
456+
{
452457
// scale x and y cluster count to be able to fit all our indices
453458

454459
// we take the ratio of the actual indices over the index estimate.
455460
// this is not guaranteed to be small enough due to overlapped tiles, but
456461
// the conservative estimate is more than sufficient to cover the
457462
// difference
458-
let index_ratio = ViewClusterBindings::MAX_INDICES as f32 / cluster_index_estimate;
463+
let index_ratio = global_cluster_settings.view_cluster_bindings_max_indices as f32
464+
/ cluster_index_estimate;
459465
let xy_ratio = index_ratio.sqrt();
460466

461467
requested_cluster_dimensions.x =

crates/bevy_pbr/src/cluster/extract_and_prepare.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ pub(crate) fn make_global_cluster_settings(world: &World) -> GlobalClusterSettin
4747
GlobalClusterSettings {
4848
supports_storage_buffers,
4949
clustered_decals_are_usable,
50+
max_uniform_buffer_clusterable_objects: MAX_UNIFORM_BUFFER_CLUSTERABLE_OBJECTS,
51+
view_cluster_bindings_max_indices: ViewClusterBindings::MAX_INDICES,
5052
}
5153
}
5254

crates/bevy_pbr/src/cluster/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ mod test;
4343
pub struct GlobalClusterSettings {
4444
pub supports_storage_buffers: bool,
4545
pub clustered_decals_are_usable: bool,
46+
pub max_uniform_buffer_clusterable_objects: usize,
47+
pub view_cluster_bindings_max_indices: usize,
4648
}
4749

4850
/// Configure the far z-plane mode used for the furthest depth slice for clustered forward

0 commit comments

Comments
 (0)