From 021a03009e6e5b46f2e281eb993cd4a19f04ec7e Mon Sep 17 00:00:00 2001 From: Robert Swain Date: Mon, 13 Dec 2021 20:36:30 +0100 Subject: [PATCH] bevy_pbr2: Fix comments about data in cluster bindings, max lights, etc --- pipelined/bevy_pbr2/src/render/light.rs | 11 ++++++----- pipelined/bevy_pbr2/src/render/mesh.rs | 11 +++++------ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/pipelined/bevy_pbr2/src/render/light.rs b/pipelined/bevy_pbr2/src/render/light.rs index 8a758aec5b102..a1c3d68045f3f 100644 --- a/pipelined/bevy_pbr2/src/render/light.rs +++ b/pipelined/bevy_pbr2/src/render/light.rs @@ -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) diff --git a/pipelined/bevy_pbr2/src/render/mesh.rs b/pipelined/bevy_pbr2/src/render/mesh.rs index 115b12fa5f530..9367661d7cd1f 100644 --- a/pipelined/bevy_pbr2/src/render/mesh.rs +++ b/pipelined/bevy_pbr2/src/render/mesh.rs @@ -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, @@ -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, @@ -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,