fn prepare_batch<DrawDataT, CreateDrawDataFnT: Fn(&MeshAdvBatchDrawData) -> DrawDataT>(
        job_context: &PreparePerFrameContext<'prepare, '_, Self>,
        descriptor_set_allocator: &mut DescriptorSetAllocatorRef,
        transform_buffer: &ResourceArc<BufferResource>,
        batch: &MeshAdvBatchedPassInfo,
        batch_index: usize,
        push_submit_node: bool,
        per_batch_descriptor_set_index: usize,
        draw_data_binding: u32,
        transforms_binding: u32,
        dyn_resource_allocator_set: &DynResourceAllocatorSet,
        create_draw_data_fn: CreateDrawDataFnT,
    ) -> (ResourceArc<BufferResource>, DescriptorSetArc) {
        let draw_data_buffer_size =
            batch.draw_data.len() as u64 * std::mem::size_of::<DrawDataT>() as u64;
        let draw_data_buffer = dyn_resource_allocator_set.insert_buffer(
            job_context
                .device_context()
                .create_buffer(&RafxBufferDef {
                    size: draw_data_buffer_size,
                    memory_usage: RafxMemoryUsage::CpuToGpu,
                    resource_type: RafxResourceType::BUFFER,
                    always_mapped: true,
                    alignment: std::mem::size_of::<DrawDataT>() as u32,
                    ..Default::default()
                })
                .unwrap(),
        );
        let memory = draw_data_buffer.get_raw().buffer.mapped_memory().unwrap();
        unsafe {
            let dst =
                std::slice::from_raw_parts_mut::<DrawDataT>(memory as _, batch.draw_data.len());
            let src = batch.draw_data.get_all_unchecked();
            for i in 0..batch.draw_data.len() {
                dst[i] = create_draw_data_fn(&src[i]);
            }
        }

        let layout = &batch.pass.get_raw().descriptor_set_layouts[per_batch_descriptor_set_index];
        let mut dyn_descriptor_set = descriptor_set_allocator
            .create_dyn_descriptor_set_uninitialized(&layout)
            .unwrap();
        dyn_descriptor_set.set_buffer(draw_data_binding, &draw_data_buffer);
        dyn_descriptor_set.set_buffer(transforms_binding, transform_buffer);
        dyn_descriptor_set.flush(descriptor_set_allocator).unwrap();

        if push_submit_node {
            let view_packet = job_context
                .submit_packet()
                .view_submit_packet(batch.view_frame_index);
            view_packet.push_submit_node_into_render_phase(
                batch.phase,
                MeshAdvDrawCall::Batched(MeshAdvBatchedDrawCall {
                    batch_index: batch_index as u32,
                }),
                0,
                0.0,
            );
        }

        (
            draw_data_buffer,
            dyn_descriptor_set.descriptor_set().clone(),
        )
    }
// This is a helper function that, given a batch (i.e. opaque meshes, shadow pass meshes, in a view, etc.)
// we produce a draw data buffer, per-batch descriptor set, and optionally push a batch submit node
This is a helper function that, given a batch
we produce a draw data buffer, per-batch descriptor set, and optionally push a batch submit node
This is a helper function that given a batch we produce a draw data buffer per - batch descriptor set and optionally push a batch submit node
fn prepare_batch<DrawDataT, CreateDrawDataFnT: Fn(&MeshAdvBatchDrawData) -> DrawDataT>(
        job_context: &PreparePerFrameContext<'prepare, '_, Self>,
        descriptor_set_allocator: &mut DescriptorSetAllocatorRef,
        transform_buffer: &ResourceArc<BufferResource>,
        batch: &MeshAdvBatchedPassInfo,
        batch_index: usize,
        push_submit_node: bool,
        per_batch_descriptor_set_index: usize,
        draw_data_binding: u32,
        transforms_binding: u32,
        dyn_resource_allocator_set: &DynResourceAllocatorSet,
        create_draw_data_fn: CreateDrawDataFnT,
    ) -> (ResourceArc<BufferResource>, DescriptorSetArc) {
        let draw_data_buffer_size =
            batch.draw_data.len() as u64 * std::mem::size_of::<DrawDataT>() as u64;
        let draw_data_buffer = dyn_resource_allocator_set.insert_buffer(
            job_context
                .device_context()
                .create_buffer(&RafxBufferDef {
                    size: draw_data_buffer_size,
                    memory_usage: RafxMemoryUsage::CpuToGpu,
                    resource_type: RafxResourceType::BUFFER,
                    always_mapped: true,
                    alignment: std::mem::size_of::<DrawDataT>() as u32,
                    ..Default::default()
                })
                .unwrap(),
        );
        let memory = draw_data_buffer.get_raw().buffer.mapped_memory().unwrap();
        unsafe {
            let dst =
                std::slice::from_raw_parts_mut::<DrawDataT>(memory as _, batch.draw_data.len());
            let src = batch.draw_data.get_all_unchecked();
            for i in 0..batch.draw_data.len() {
                dst[i] = create_draw_data_fn(&src[i]);
            }
        }
        let layout = &batch.pass.get_raw().descriptor_set_layouts[per_batch_descriptor_set_index];
        let mut dyn_descriptor_set = descriptor_set_allocator
            .create_dyn_descriptor_set_uninitialized(&layout)
            .unwrap();
        dyn_descriptor_set.set_buffer(draw_data_binding, &draw_data_buffer);
        dyn_descriptor_set.set_buffer(transforms_binding, transform_buffer);
        dyn_descriptor_set.flush(descriptor_set_allocator).unwrap();
        if push_submit_node {
            let view_packet = job_context
                .submit_packet()
                .view_submit_packet(batch.view_frame_index);
            view_packet.push_submit_node_into_render_phase(
                batch.phase,
                MeshAdvDrawCall::Batched(MeshAdvBatchedDrawCall {
                    batch_index: batch_index as u32,
                }),
                0,
                0.0,
            );
        }
        (
            draw_data_buffer,
            dyn_descriptor_set.descriptor_set().clone(),
        )
    }
fn prepare_batch < DrawDataT , CreateDrawDataFnT : Fn ( & MeshAdvBatchDrawData ) -> DrawDataT > ( job_context : & PreparePerFrameContext < ' prepare , ' _ , Self > , descriptor_set_allocator : & mut DescriptorSetAllocatorRef , transform_buffer : & ResourceArc < BufferResource > , batch : & MeshAdvBatchedPassInfo , batch_index : usize , push_submit_node : bool , per_batch_descriptor_set_index : usize , draw_data_binding : u32 , transforms_binding : u32 , dyn_resource_allocator_set : & DynResourceAllocatorSet , create_draw_data_fn : CreateDrawDataFnT , ) -> ( ResourceArc < BufferResource > , DescriptorSetArc ) { let draw_data_buffer_size = batch . draw_data . len ( ) as u64 * std :: mem :: size_of :: < DrawDataT > ( ) as u64 ; let draw_data_buffer = dyn_resource_allocator_set . insert_buffer ( job_context . device_context ( ) . create_buffer ( & RafxBufferDef { size : draw_data_buffer_size , memory_usage : RafxMemoryUsage :: CpuToGpu , resource_type : RafxResourceType :: BUFFER , always_mapped : true , alignment : std :: mem :: size_of :: < DrawDataT > ( ) as u32 , .. Default :: default ( ) } ) . unwrap ( ) , ) ; let memory = draw_data_buffer . get_raw ( ) . buffer . mapped_memory ( ) . unwrap ( ) ; unsafe { let dst = std :: slice :: from_raw_parts_mut :: < DrawDataT > ( memory as _ , batch . draw_data . len ( ) ) ; let src = batch . draw_data . get_all_unchecked ( ) ; for i in 0 .. batch . draw_data . len ( ) { dst [ i ] = create_draw_data_fn ( & src [ i ] ) ; } } let layout = & batch . pass . get_raw ( ) . descriptor_set_layouts [ per_batch_descriptor_set_index ] ; let mut dyn_descriptor_set = descriptor_set_allocator . create_dyn_descriptor_set_uninitialized ( & layout ) . unwrap ( ) ; dyn_descriptor_set . set_buffer ( draw_data_binding , & draw_data_buffer ) ; dyn_descriptor_set . set_buffer ( transforms_binding , transform_buffer ) ; dyn_descriptor_set . flush ( descriptor_set_allocator ) . unwrap ( ) ; if push_submit_node { let view_packet = job_context . submit_packet ( ) . view_submit_packet ( batch . view_frame_index ) ; view_packet . push_submit_node_into_render_phase ( batch . phase , MeshAdvDrawCall :: Batched ( MeshAdvBatchedDrawCall { batch_index : batch_index as u32 , } ) , 0 , 0.0 , ) ; } ( draw_data_buffer , dyn_descriptor_set . descriptor_set ( ) . clone ( ) , ) }
This is a helper function that, given a batch (i.e.
This is a helper function that given a batch ( i . e .
job_context
&PreparePerFrameContext<'prepare, '_, Self>
descriptor_set_allocator
&mut DescriptorSetAllocatorRef
transform_buffer
&ResourceArc<BufferResource>
batch
&MeshAdvBatchedPassInfo
batch_index
usize
push_submit_node
bool
per_batch_descriptor_set_index
usize
draw_data_binding
u32
transforms_binding
u32
dyn_resource_allocator_set
&DynResourceAllocatorSet
create_draw_data_fn
CreateDrawDataFnT
job_context
&PreparePerFrameContext<'prepare, '_, Self>
descriptor_set_allocator
&mut DescriptorSetAllocatorRef
transform_buffer
&ResourceArc<BufferResource>
batch
&MeshAdvBatchedPassInfo
batch_index
usize
push_submit_node
bool
per_batch_descriptor_set_index
usize
draw_data_binding
u32
transforms_binding
u32
dyn_resource_allocator_set
&DynResourceAllocatorSet
create_draw_data_fn
CreateDrawDataFnT