it starts at least

This commit is contained in:
2026-10-02 23:39:36 +01:00
parent 663f67ae3c
commit 55fc36812a
20 changed files with 637 additions and 512 deletions
@@ -44,9 +44,11 @@ pub struct GpuInstanceGeometryIds {
#[derive(Clone, Copy, Default, PartialEq, Pod, Zeroable)]
#[repr(C)]
pub struct GpuInstanceTapeIds {
aabb_buffer_id: u32,
aabb_buffer_offset: u32,
aabb_count: u32,
aabb_buffer_id: u32,
aabb_buffer_offset: u32,
aabb_count: u32,
metadata_buffer_id: u32,
metadata_buffer_offset: u32,
}
/// A world-from-local affine transform, stored transposed as three rows.
@@ -103,6 +105,7 @@ pub struct InstanceState {
pub vertex_buffers: RetainedBindingArray<BufferId, Buffer>,
pub index_buffers: RetainedBindingArray<BufferId, Buffer>,
pub aabb_buffers: RetainedBindingArray<BufferId, Buffer>,
pub tape_metadata_buffers: RetainedBindingArray<BufferId, Buffer>,
pub transforms: AtomicSparseBufferVec<GpuTransform>,
pub previous_frame_transforms: AtomicSparseBufferVec<GpuTransform>,
pub geometry_ids: AtomicSparseBufferVec<GpuInstanceGeometryIds>,
@@ -123,6 +126,7 @@ impl InstanceState {
vertex_buffers: RetainedBindingArray::new(),
index_buffers: RetainedBindingArray::new(),
aabb_buffers: RetainedBindingArray::new(),
tape_metadata_buffers: RetainedBindingArray::new(),
transforms: storage_buffer("solari_transforms"),
previous_frame_transforms: storage_buffer("solari_previous_frame_transforms"),
geometry_ids: storage_buffer("solari_geometry_ids"),
@@ -467,20 +471,32 @@ impl InstanceState {
tape_id: AssetId<Tape>,
instance: &mut Instance,
) -> bool {
bevy_log::debug!("Resolving tape instance {tape_id}");
bevy_log::info!("Resolving tape instance {tape_id}");
let slot = instance.slot;
let (Some(aabb_slice), Some(material_slot), Some(blas_address)) = (
let (Some(aabb_slice), Some(metadata_slice), Some(material_slot), Some(blas_address)) = (
inputs.tape_allocator.tape_aabb_slice(&tape_id),
inputs.tape_allocator.tape_metadata_slice(&tape_id),
inputs.assets.material_slots.get(&instance.material),
inputs.tape_blas_manager.device_address(&tape_id),
) else {
bevy_log::info!("Deactivating tape instance {tape_id}");
self.deactivate_instance(lights, entity, instance);
return false;
};
bevy_log::info!("Tape {tape_id} aabb_slice: {:?}", aabb_slice.range);
bevy_log::info!("Tape {tape_id} metadata_slice: {:?}", metadata_slice.range);
bevy_log::info!("Tape {tape_id} material_slot: {material_slot}");
bevy_log::info!("Tape {tape_id} blas_address: {blas_address}");
let aabb_buffer_key = aabb_slice.buffer.id();
let metadata_buffer_key = metadata_slice.buffer.id();
let capacity = MAX_TAPE_SLAB_COUNT.get();
if !self.aabb_buffers.has_room(&aabb_buffer_key, capacity) {
if !self.aabb_buffers.has_room(&aabb_buffer_key, capacity)
|| !self
.tape_metadata_buffers
.has_room(&metadata_buffer_key, capacity)
{
once!(warn!(
"Solari scene needs more than {} tape slabs. Instances past that limit will not \
be rendered.",
@@ -495,7 +511,13 @@ impl InstanceState {
.aabb_buffers
.acquire(aabb_buffer_key, capacity, || aabb_slice.buffer.clone())
.expect("aabb slab binding array had room but handed out no slot");
instance.buffers = Some((aabb_buffer_key, aabb_buffer_key));
let metadata_buffer_id = self
.tape_metadata_buffers
.acquire(metadata_buffer_key, capacity, || {
metadata_slice.buffer.clone()
})
.expect("tape metadata slab binding array had room but handed out no slot");
instance.buffers = Some((aabb_buffer_key, metadata_buffer_key));
self.release_tape_buffers(previous_buffers);
let aabb_count = (aabb_slice.range.len()) as u32;
@@ -505,6 +527,8 @@ impl InstanceState {
aabb_buffer_id,
aabb_buffer_offset: aabb_slice.range.start,
aabb_count,
metadata_buffer_id,
metadata_buffer_offset: metadata_slice.range.start,
},
);
self.material_ids.grow_and_set(slot, material_slot);
@@ -525,6 +549,8 @@ impl InstanceState {
}
*/
bevy_log::info!("Tape {tape_id} resolved");
true
}
@@ -583,8 +609,9 @@ impl InstanceState {
}
fn release_tape_buffers(&mut self, buffers: Option<(BufferId, BufferId)>) {
if let Some((aabb_key, _)) = buffers {
if let Some((aabb_key, metadata_key)) = buffers {
self.aabb_buffers.release(&aabb_key);
self.tape_metadata_buffers.release(&metadata_key);
}
}