Skip to content

Commit 897404e

Browse files
authoredOct 24, 2024
Reduce the clusterable object UBO size below 16384 for WebGL 2. (bevyengine#16069)
The PCSS PR bevyengine#13497 increased the size of clusterable objects from 64 bytes to 80 bytes but didn't decrease the UBO size to compensate, so we blew past the 16kB limit on WebGL 2. This commit fixes the issue by lowering the maximum number of clusterable objects to 204, which puts us under the 16kB limit again. Closes bevyengine#15998.
1 parent 9274bfe commit 897404e

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed
 

‎crates/bevy_pbr/src/cluster/mod.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,13 @@ mod assign;
3333
#[cfg(test)]
3434
mod test;
3535

36-
// NOTE: this must be kept in sync with the same constants in pbr.frag
37-
pub const MAX_UNIFORM_BUFFER_CLUSTERABLE_OBJECTS: usize = 256;
36+
// NOTE: this must be kept in sync with the same constants in
37+
// `mesh_view_types.wgsl`.
38+
pub const MAX_UNIFORM_BUFFER_CLUSTERABLE_OBJECTS: usize = 204;
39+
// Make sure that the clusterable object buffer doesn't overflow the maximum
40+
// size of a UBO on WebGL 2.
41+
const _: () =
42+
assert!(size_of::<GpuClusterableObject>() * MAX_UNIFORM_BUFFER_CLUSTERABLE_OBJECTS <= 16384);
3843

3944
// NOTE: Clustered-forward rendering requires 3 storage buffer bindings so check that
4045
// at least that many are supported using this constant and SupportedBindingType::from_device()
@@ -811,8 +816,8 @@ impl ViewClusterBuffers {
811816
}
812817

813818
// NOTE: With uniform buffer max binding size as 16384 bytes
814-
// that means we can fit 256 clusterable objects in one uniform
815-
// buffer, which means the count can be at most 256 so it
819+
// that means we can fit 204 clusterable objects in one uniform
820+
// buffer, which means the count can be at most 204 so it
816821
// needs 9 bits.
817822
// The array of indices can also use u8 and that means the
818823
// offset in to the array of indices needs to be able to address

‎crates/bevy_pbr/src/render/mesh_view_types.wgsl

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ struct ClusterOffsetsAndCounts {
105105
};
106106
#else
107107
struct ClusterableObjects {
108-
data: array<ClusterableObject, 256u>,
108+
data: array<ClusterableObject, 204u>,
109109
};
110110
struct ClusterLightIndexLists {
111111
// each u32 contains 4 u8 indices into the ClusterableObjects array

0 commit comments

Comments
 (0)
Please sign in to comment.