pub fn yuyv_buffer_to_vulkan_image(
        &self,
        buf: &[u8],
        after: impl GpuFuture,
        queue: Arc<Queue>,
        buffer: &CpuBufferPool<u8>,
        output: Arc<AttachmentImage>,
    ) -> Result<impl GpuFuture> {
        use vulkano::device::DeviceOwned;
        if queue.device() != &self.device || buffer.device() != &self.device {
            return Err(anyhow!("Device mismatch"));
        }
        if let Some(queue) = after.queue() {
            if !queue.is_same(&queue) {
                return Err(anyhow!("Queue mismatch"));
            }
        }
        // Submit the source image to GPU
        let subbuffer = buffer
            .chunk(buf.iter().copied())
            .map_err(|e| ConverterError::Anyhow(e.into()))?;
        let mut cmdbuf =
            AutoCommandBufferBuilder::primary(self.device.clone(), queue.family(), OneTimeSubmit)?;
        cmdbuf.copy_buffer_to_image(subbuffer, self.src.clone())?;
        // Build a pipeline to do yuyv -> rgb
        let vertex_buffer = CpuAccessibleBuffer::<[Vertex]>::from_iter(
            self.device.clone(),
            BufferUsage::vertex_buffer(),
            false,
            [
                Vertex {
                    position: [-1.0, -1.0],
                },
                Vertex {
                    position: [-1.0, 1.0],
                },
                Vertex {
                    position: [1.0, -1.0],
                },
                Vertex {
                    position: [1.0, 1.0],
                },
            ]
            .iter()
            .cloned(),
        )
        .unwrap();
        let framebuffer = Arc::new(
            Framebuffer::start(self.render_pass.clone())
                .add(ImageView::new(output)?)?
                .build()?,
        );
        cmdbuf
            .begin_render_pass(
                framebuffer,
                SubpassContents::Inline,
                [vulkano::format::ClearValue::None],
            )
            .map_err(|e| ConverterError::Anyhow(e.into()))?
            .bind_pipeline_graphics(self.pipeline.clone())
            .bind_descriptor_sets(
                PipelineBindPoint::Graphics,
                self.pipeline.layout().clone(),
                0,
                self.desc_set.clone(),
            )
            .bind_vertex_buffers(0, vertex_buffer.clone())
            .draw(vertex_buffer.len() as u32, 1, 0, 0)
            .map_err(|e| ConverterError::Anyhow(e.into()))?
            .end_render_pass()
            .map_err(|e| ConverterError::Anyhow(e.into()))?;
        Ok(after.then_execute(
            queue,
            cmdbuf
                .build()
                .map_err(|e| ConverterError::Anyhow(e.into()))?,
        )?)
    }
/// receives a buffer containing a YUYV image, upload it to GPU,
/// and convert it to RGBA8.
///
/// Returns a GPU future representing the operation, and an image.
/// You must make sure the previous conversion is completed before
/// calling this function again.
receives a buffer containing a YUYV image, upload it to GPU,
and convert it to RGBA8.

Returns a GPU future representing the operation, and an image.
You must make sure the previous conversion is completed before
calling this function again.
receives a buffer containing a YUYV image upload it to GPU and convert it to RGBA8 . Returns a GPU future representing the operation and an image . You must make sure the previous conversion is completed before calling this function again .
pub fn yuyv_buffer_to_vulkan_image(
        &self,
        buf: &[u8],
        after: impl GpuFuture,
        queue: Arc<Queue>,
        buffer: &CpuBufferPool<u8>,
        output: Arc<AttachmentImage>,
    ) -> Result<impl GpuFuture> {
        use vulkano::device::DeviceOwned;
        if queue.device() != &self.device || buffer.device() != &self.device {
            return Err(anyhow!("Device mismatch"));
        }
        if let Some(queue) = after.queue() {
            if !queue.is_same(&queue) {
                return Err(anyhow!("Queue mismatch"));
            }
        }
        // Submit the source image to GPU
        let subbuffer = buffer
            .chunk(buf.iter().copied())
            .map_err(|e| ConverterError::Anyhow(e.into()))?;
        let mut cmdbuf =
            AutoCommandBufferBuilder::primary(self.device.clone(), queue.family(), OneTimeSubmit)?;
        cmdbuf.copy_buffer_to_image(subbuffer, self.src.clone())?;
        // Build a pipeline to do yuyv -> rgb
        let vertex_buffer = CpuAccessibleBuffer::<[Vertex]>::from_iter(
            self.device.clone(),
            BufferUsage::vertex_buffer(),
            false,
            [
                Vertex {
                    position: [-1.0, -1.0],
                },
                Vertex {
                    position: [-1.0, 1.0],
                },
                Vertex {
                    position: [1.0, -1.0],
                },
                Vertex {
                    position: [1.0, 1.0],
                },
            ]
            .iter()
            .cloned(),
        )
        .unwrap();
        let framebuffer = Arc::new(
            Framebuffer::start(self.render_pass.clone())
                .add(ImageView::new(output)?)?
                .build()?,
        );
        cmdbuf
            .begin_render_pass(
                framebuffer,
                SubpassContents::Inline,
                [vulkano::format::ClearValue::None],
            )
            .map_err(|e| ConverterError::Anyhow(e.into()))?
            .bind_pipeline_graphics(self.pipeline.clone())
            .bind_descriptor_sets(
                PipelineBindPoint::Graphics,
                self.pipeline.layout().clone(),
                0,
                self.desc_set.clone(),
            )
            .bind_vertex_buffers(0, vertex_buffer.clone())
            .draw(vertex_buffer.len() as u32, 1, 0, 0)
            .map_err(|e| ConverterError::Anyhow(e.into()))?
            .end_render_pass()
            .map_err(|e| ConverterError::Anyhow(e.into()))?;
        Ok(after.then_execute(
            queue,
            cmdbuf
                .build()
                .map_err(|e| ConverterError::Anyhow(e.into()))?,
        )?)
    }
pub fn yuyv_buffer_to_vulkan_image ( & self , buf : & [ u8 ] , after : impl GpuFuture , queue : Arc < Queue > , buffer : & CpuBufferPool < u8 > , output : Arc < AttachmentImage > , ) -> Result < impl GpuFuture > { use vulkano :: device :: DeviceOwned ; if queue . device ( ) != & self . device || buffer . device ( ) != & self . device { return Err ( anyhow ! ( " " ) ) ; } if let Some ( queue ) = after . queue ( ) { if ! queue . is_same ( & queue ) { return Err ( anyhow ! ( " " ) ) ; } } // Submit the source image to GPU let subbuffer = buffer . chunk ( buf . iter ( ) . copied ( ) ) . map_err ( | e | ConverterError :: Anyhow ( e . into ( ) ) ) ? ; let mut cmdbuf = AutoCommandBufferBuilder :: primary ( self . device . clone ( ) , queue . family ( ) , OneTimeSubmit ) ? ; cmdbuf . copy_buffer_to_image ( subbuffer , self . src . clone ( ) ) ? ; // Build a pipeline to do yuyv -> rgb let vertex_buffer = CpuAccessibleBuffer :: < [ Vertex ] > :: from_iter ( self . device . clone ( ) , BufferUsage :: vertex_buffer ( ) , false , [ Vertex { position : [ - 1.0 , - 1.0 ] , } , Vertex { position : [ - 1.0 , 1.0 ] , } , Vertex { position : [ 1.0 , - 1.0 ] , } , Vertex { position : [ 1.0 , 1.0 ] , } , ] . iter ( ) . cloned ( ) , ) . unwrap ( ) ; let framebuffer = Arc :: new ( Framebuffer :: start ( self . render_pass . clone ( ) ) . add ( ImageView :: new ( output ) ? ) ? . build ( ) ? , ) ; cmdbuf . begin_render_pass ( framebuffer , SubpassContents :: Inline , [ vulkano :: format :: ClearValue :: None ] , ) . map_err ( | e | ConverterError :: Anyhow ( e . into ( ) ) ) ? . bind_pipeline_graphics ( self . pipeline . clone ( ) ) . bind_descriptor_sets ( PipelineBindPoint :: Graphics , self . pipeline . layout ( ) . clone ( ) , 0 , self . desc_set . clone ( ) , ) . bind_vertex_buffers ( 0 , vertex_buffer . clone ( ) ) . draw ( vertex_buffer . len ( ) as u32 , 1 , 0 , 0 ) . map_err ( | e | ConverterError :: Anyhow ( e . into ( ) ) ) ? . end_render_pass ( ) . map_err ( | e | ConverterError :: Anyhow ( e . into ( ) ) ) ? ; Ok ( after . then_execute ( queue , cmdbuf . build ( ) . map_err ( | e | ConverterError :: Anyhow ( e . into ( ) ) ) ? , ) ? ) }
receives a buffer containing a YUYV image, upload it to GPU,
and convert it to RGBA8.
receives a buffer containing a YUYV image upload it to GPU and convert it to RGBA8 .
&self
buf
&[u8]
after
impl GpuFuture
queue
Arc<Queue>
buffer
&CpuBufferPool<u8>
output
Arc<AttachmentImage>
&self
buf
&[u8]
after
impl GpuFuture
queue
Arc<Queue>
buffer
&CpuBufferPool<u8>
output
Arc<AttachmentImage>