Skip to content

Commit

Permalink
bevy_pbr2: Fix comments about data in cluster bindings, max lights, etc
Browse files Browse the repository at this point in the history
  • Loading branch information
superdump committed Dec 13, 2021
1 parent 7807f0a commit 021a030
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
11 changes: 6 additions & 5 deletions pipelined/bevy_pbr2/src/render/light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -878,15 +878,16 @@ const CLUSTER_COUNT_MASK: u32 = (1 << 8) - 1;
const POINT_LIGHT_INDEX_MASK: u32 = (1 << 8) - 1;

// NOTE: With uniform buffer max binding size as 16384 bytes
// that means we can fit say 128 point lights in one uniform
// buffer, which means the count can be at most 128 so it
// needs 7 bits, use 8 for convenience.
// that means we can fit say 256 point lights in one uniform
// buffer, which means the count can be at most 256 so it
// needs 8 bits.
// 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
// 16384 values. lod2(16384) = 21 bits.
// 16384 values. log2(16384) = 14 bits.
// This means we can pack the offset into the upper 24 bits of a u32
// and the count into the lower 8 bits.
// FIXME: Probably there are endianness concerns here????!!!!!
// NOTE: This assumes CPU and GPU endianness are the same which is true
// for all common and tested x86/ARM CPUs and AMD/NVIDIA/Intel/Apple/etc GPUs
fn pack_offset_and_count(offset: usize, count: usize) -> u32 {
((offset as u32 & CLUSTER_OFFSET_MASK) << CLUSTER_COUNT_SIZE)
| (count as u32 & CLUSTER_COUNT_MASK)
Expand Down
11 changes: 5 additions & 6 deletions pipelined/bevy_pbr2/src/render/mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ impl FromWorld for MeshPipeline {
ty: BufferBindingType::Uniform,
has_dynamic_offset: false,
// NOTE: Static size for uniform buffers. GpuPointLight has a padded
// size of 128 bytes, so 16384 / 128 = 128 point lights max
// size of 64 bytes, so 16384 / 64 = 256 point lights max
min_binding_size: BufferSize::new(16384),
},
count: None,
Expand All @@ -257,8 +257,7 @@ impl FromWorld for MeshPipeline {
ty: BindingType::Buffer {
ty: BufferBindingType::Uniform,
has_dynamic_offset: false,
// NOTE: With 128 point lights max, indices need 7 bits. Use u8 for
// convenience.
// NOTE: With 256 point lights max, indices need 8 bits so use u8
min_binding_size: BufferSize::new(16384),
},
count: None,
Expand All @@ -270,10 +269,10 @@ impl FromWorld for MeshPipeline {
ty: BindingType::Buffer {
ty: BufferBindingType::Uniform,
has_dynamic_offset: false,
// NOTE: The offset needs to address 16384 indices, which needs 21 bits.
// The count can be at most all 128 lights so 7 bits.
// NOTE: The offset needs to address 16384 indices, which needs 14 bits.
// The count can be at most all 256 lights so 8 bits.
// Pack the offset into the upper 24 bits and the count into the
// lower 8 bits for convenience.
// lower 8 bits.
min_binding_size: BufferSize::new(16384),
},
count: None,
Expand Down

0 comments on commit 021a030

Please sign in to comment.