Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce the clusterable object UBO size below 16384 for WebGL 2. #16069

Merged
merged 3 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions crates/bevy_pbr/src/cluster/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,13 @@ mod assign;
#[cfg(test)]
mod test;

// NOTE: this must be kept in sync with the same constants in pbr.frag
pub const MAX_UNIFORM_BUFFER_CLUSTERABLE_OBJECTS: usize = 256;
// NOTE: this must be kept in sync with the same constants in
// `mesh_view_types.wgsl`.
pub const MAX_UNIFORM_BUFFER_CLUSTERABLE_OBJECTS: usize = 204;
cart marked this conversation as resolved.
Show resolved Hide resolved
// Make sure that the clusterable object buffer doesn't overflow the maximum
// size of a UBO on WebGL 2.
const _: () =
assert!(size_of::<GpuClusterableObject>() * MAX_UNIFORM_BUFFER_CLUSTERABLE_OBJECTS <= 16384);

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

// NOTE: With uniform buffer max binding size as 16384 bytes
// that means we can fit 256 clusterable objects in one uniform
// buffer, which means the count can be at most 256 so it
// that means we can fit 204 clusterable objects in one uniform
// buffer, which means the count can be at most 204 so it
// needs 9 bits.
Copy link

Choose a reason for hiding this comment

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

@pcwalton you only need 8 now, right?

// The array of indices can also use u8 and that means the
// offset in to the array of indices needs to be able to address
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_pbr/src/render/mesh_view_types.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ struct ClusterOffsetsAndCounts {
};
#else
struct ClusterableObjects {
data: array<ClusterableObject, 256u>,
data: array<ClusterableObject, 204u>,
};
struct ClusterLightIndexLists {
// each u32 contains 4 u8 indices into the ClusterableObjects array
Expand Down