pub fn allocate_writer(
        &self,
        queue_family_index: u32,
        command_pool_create_flags: vk::CommandPoolCreateFlags,
        delay_submission_by_frame_count: u64,
    ) -> VkResult<DynCommandWriter> {
        let mut guard = self.inner.lock().unwrap();

        // Determine what frame this will be committed in
        let submits_in_frame_index = guard.current_frame_index + delay_submission_by_frame_count;

        // Build a key to search for an existing writer to reuse
        let meta = PendingCommandPoolMeta {
            submits_in_frame_index,
            command_pool_meta: CommandPoolMeta {
                queue_family_index,
                command_pool_create_flags,
            },
        };

        log::trace!("DynCommandWriterAllocator::allocate_writer {:?}", meta);

        Self::drain_drop_rx(&mut *guard);

        // Try to find something in the pending collection and reuse it
        if let Some(writers) = guard.pending_writers.get_mut(&meta) {
            if let Some(writer) = writers.pop() {
                log::trace!(
                    "DynCommandWriterAllocator::allocate_writer {:?} reusing pending writer DynCommandWriter({})",
                    meta,
                    writer.writer_id
                );
                assert_eq!(writer.submits_in_frame_index, submits_in_frame_index);
                return Ok(DynCommandWriter::new(writer, guard.drop_tx.clone()));
            }
        }

        // If we don't have a "dirty" writer for this frame yet, try to reuse an existing unused one
        if let Some(writers) = guard.unused_writers.get_mut(&meta.command_pool_meta) {
            if let Some(mut writer) = writers.pop() {
                log::trace!(
                    "DynCommandWriterAllocator::allocate_writer {:?} reusing unused writer DynCommandWriter({})",
                    meta,
                    writer.writer_id
                );
                writer.submits_in_frame_index = submits_in_frame_index;
                return Ok(DynCommandWriter::new(writer, guard.drop_tx.clone()));
            }
        }

        let writer_id = guard.next_writer_id;
        guard.next_writer_id += 1;

        log::trace!(
            "DynCommandWriterAllocator::allocate_writer {:?} creating new DynCommandWriter({})",
            meta,
            writer_id
        );

        // Did not find a suitable writer, create a new one
        let pool = CommandPool::new(
            &guard.device_context,
            queue_family_index,
            command_pool_create_flags,
        )?;

        let inner = DynCommandWriterInner {
            device_context: guard.device_context.clone(),
            pool,
            submits_in_frame_index,
            writer_id,
        };

        Ok(DynCommandWriter::new(inner, guard.drop_tx.clone()))
    }
/// Allocates a writer. Writers wrap CommandPools. The parameters match inputs for
/// CommandPool::new. `delay_submission_by_frame_count` indicates how many frames will pass
/// before the commands will be submitted (which affects how long-lived they will be). DO NOT
/// submit command buffers earlier than this as the writers are pooled.
///
/// The common case for delay_submission_by_frame_count is to pass 0. You might pass 1 if for
/// example, you are building a command buffer for frame N + 1 while frame N is not yet
/// submitted.
Allocates a writer.

The common case for delay_submission_by_frame_count is to pass 0. You might pass 1 if for
example, you are building a command buffer for frame N + 1 while frame N is not yet
submitted.
Allocates a writer . The common case for delay_submission_by_frame_count is to pass 0 . You might pass 1 if for example you are building a command buffer for frame N + 1 while frame N is not yet submitted .
pub fn allocate_writer(
        &self,
        queue_family_index: u32,
        command_pool_create_flags: vk::CommandPoolCreateFlags,
        delay_submission_by_frame_count: u64,
    ) -> VkResult<DynCommandWriter> {
        let mut guard = self.inner.lock().unwrap();
        // Determine what frame this will be committed in
        let submits_in_frame_index = guard.current_frame_index + delay_submission_by_frame_count;
        // Build a key to search for an existing writer to reuse
        let meta = PendingCommandPoolMeta {
            submits_in_frame_index,
            command_pool_meta: CommandPoolMeta {
                queue_family_index,
                command_pool_create_flags,
            },
        };
        log::trace!("DynCommandWriterAllocator::allocate_writer {:?}", meta);
        Self::drain_drop_rx(&mut *guard);
        // Try to find something in the pending collection and reuse it
        if let Some(writers) = guard.pending_writers.get_mut(&meta) {
            if let Some(writer) = writers.pop() {
                log::trace!(
                    "DynCommandWriterAllocator::allocate_writer {:?} reusing pending writer DynCommandWriter({})",
                    meta,
                    writer.writer_id
                );
                assert_eq!(writer.submits_in_frame_index, submits_in_frame_index);
                return Ok(DynCommandWriter::new(writer, guard.drop_tx.clone()));
            }
        }
        // If we don't have a "dirty" writer for this frame yet, try to reuse an existing unused one
        if let Some(writers) = guard.unused_writers.get_mut(&meta.command_pool_meta) {
            if let Some(mut writer) = writers.pop() {
                log::trace!(
                    "DynCommandWriterAllocator::allocate_writer {:?} reusing unused writer DynCommandWriter({})",
                    meta,
                    writer.writer_id
                );
                writer.submits_in_frame_index = submits_in_frame_index;
                return Ok(DynCommandWriter::new(writer, guard.drop_tx.clone()));
            }
        }
        let writer_id = guard.next_writer_id;
        guard.next_writer_id += 1;
        log::trace!(
            "DynCommandWriterAllocator::allocate_writer {:?} creating new DynCommandWriter({})",
            meta,
            writer_id
        );
        // Did not find a suitable writer, create a new one
        let pool = CommandPool::new(
            &guard.device_context,
            queue_family_index,
            command_pool_create_flags,
        )?;
        let inner = DynCommandWriterInner {
            device_context: guard.device_context.clone(),
            pool,
            submits_in_frame_index,
            writer_id,
        };
        Ok(DynCommandWriter::new(inner, guard.drop_tx.clone()))
    }
pub fn allocate_writer ( & self , queue_family_index : u32 , command_pool_create_flags : vk :: CommandPoolCreateFlags , delay_submission_by_frame_count : u64 , ) -> VkResult < DynCommandWriter > { let mut guard = self . inner . lock ( ) . unwrap ( ) ; // Determine what frame this will be committed in let submits_in_frame_index = guard . current_frame_index + delay_submission_by_frame_count ; // Build a key to search for an existing writer to reuse let meta = PendingCommandPoolMeta { submits_in_frame_index , command_pool_meta : CommandPoolMeta { queue_family_index , command_pool_create_flags , } , } ; log :: trace ! ( " " meta ) ; Self :: drain_drop_rx ( & mut * guard ) ; // Try to find something in the pending collection and reuse it if let Some ( writers ) = guard . pending_writers . get_mut ( & meta ) { if let Some ( writer ) = writers . pop ( ) { log :: trace ! ( " " meta writer writer_id ) ; assert_eq ! ( writer submits_in_frame_index submits_in_frame_index ) ; return Ok ( DynCommandWriter :: new ( writer , guard . drop_tx . clone ( ) ) ) ; } } // If we don't have a "dirty" writer for this frame yet, try to reuse an existing unused one if let Some ( writers ) = guard . unused_writers . get_mut ( & meta . command_pool_meta ) { if let Some ( mut writer ) = writers . pop ( ) { log :: trace ! ( " " meta writer writer_id ) ; writer . submits_in_frame_index = submits_in_frame_index ; return Ok ( DynCommandWriter :: new ( writer , guard . drop_tx . clone ( ) ) ) ; } } let writer_id = guard . next_writer_id ; guard . next_writer_id += 1 ; log :: trace ! ( " " meta writer_id ) ; // Did not find a suitable writer, create a new one let pool = CommandPool :: new ( & guard . device_context , queue_family_index , command_pool_create_flags , ) ? ; let inner = DynCommandWriterInner { device_context : guard . device_context . clone ( ) , pool , submits_in_frame_index , writer_id , } ; Ok ( DynCommandWriter :: new ( inner , guard . drop_tx . clone ( ) ) ) }
Allocates a writer.
Allocates a writer .
&self
queue_family_index
u32
command_pool_create_flags
vk::CommandPoolCreateFlags
delay_submission_by_frame_count
u64
&self
queue_family_index
u32
command_pool_create_flags
vk::CommandPoolCreateFlags
delay_submission_by_frame_count
u64