pub(super) fn init_shm_formats(&mut self) -> Result<(), Error> {
        let instance = self.device.instance.raw();
        let phy = self.device.phy;

        for format in formats() {
            if let Some((vk_format, _)) = fourcc_to_vk(format) {
                let shm = match fourcc_to_wl(format) {
                    Some(format) => format,
                    None => continue,
                };

                let mut image_format_properties2 = vk::ImageFormatProperties2::builder();
                let format_info = vk::PhysicalDeviceImageFormatInfo2::builder()
                    .format(vk_format)
                    .tiling(vk::ImageTiling::OPTIMAL)
                    .ty(vk::ImageType::TYPE_2D)
                    .usage(TEXTURE_USAGE);

                let image_format_properties = match unsafe {
                    instance.get_physical_device_image_format_properties2(
                        phy,
                        &format_info,
                        &mut image_format_properties2,
                    )
                } {
                    Ok(_) => image_format_properties2.image_format_properties,
                    Err(vk::Result::ERROR_FORMAT_NOT_SUPPORTED) => continue,
                    Err(result) => return Err(VkError::from(result).into()),
                };

                // Check if the format supports the texture usage feature flags.
                let mut format_properties2 = vk::FormatProperties2::builder();
                unsafe { instance.get_physical_device_format_properties2(phy, vk_format, &mut format_properties2) };

                if format_properties2
                    .format_properties
                    .optimal_tiling_features
                    .contains(TEXTURE_FEATURES)
                {
                    self.formats.shm_format_info.push(ShmFormatInfo {
                        shm,
                        vk: vk_format,
                        max_extent: vk::Extent2D {
                            width: image_format_properties.max_extent.width,
                            height: image_format_properties.max_extent.height,
                        },
                    });

                    self.formats.shm_formats.push(shm);
                }
            }
        }

        // Ensure the required wl_shm formats are available
        if !self
            .formats
            .shm_formats
            .iter()
            .any(|format| format == &wl_shm::Format::Argb8888 || format == &wl_shm::Format::Xrgb8888)
        {
            return Err(Error::MissingMandatoryFormats);
        }

        Ok(())
    }
/// Tests which wl_shm formats are supported for the renderer.
///
/// This function will go through the list of known formats and test if the texture image usage and format
/// features are supported.
///
/// # Errors
///
/// This function will return [`Err`] if the mandatory wl_shm formats are not supported or some other
/// error occurs.
Tests which wl_shm formats are supported for the renderer.
This function will go through the list of known formats and test if the texture image usage and format
features are supported.
Tests which wl_shm formats are supported for the renderer . This function will go through the list of known formats and test if the texture image usage and format features are supported .
pub(super) fn init_shm_formats(&mut self) -> Result<(), Error> {
        let instance = self.device.instance.raw();
        let phy = self.device.phy;
        for format in formats() {
            if let Some((vk_format, _)) = fourcc_to_vk(format) {
                let shm = match fourcc_to_wl(format) {
                    Some(format) => format,
                    None => continue,
                };
                let mut image_format_properties2 = vk::ImageFormatProperties2::builder();
                let format_info = vk::PhysicalDeviceImageFormatInfo2::builder()
                    .format(vk_format)
                    .tiling(vk::ImageTiling::OPTIMAL)
                    .ty(vk::ImageType::TYPE_2D)
                    .usage(TEXTURE_USAGE);
                let image_format_properties = match unsafe {
                    instance.get_physical_device_image_format_properties2(
                        phy,
                        &format_info,
                        &mut image_format_properties2,
                    )
                } {
                    Ok(_) => image_format_properties2.image_format_properties,
                    Err(vk::Result::ERROR_FORMAT_NOT_SUPPORTED) => continue,
                    Err(result) => return Err(VkError::from(result).into()),
                };
                // Check if the format supports the texture usage feature flags.
                let mut format_properties2 = vk::FormatProperties2::builder();
                unsafe { instance.get_physical_device_format_properties2(phy, vk_format, &mut format_properties2) };
                if format_properties2
                    .format_properties
                    .optimal_tiling_features
                    .contains(TEXTURE_FEATURES)
                {
                    self.formats.shm_format_info.push(ShmFormatInfo {
                        shm,
                        vk: vk_format,
                        max_extent: vk::Extent2D {
                            width: image_format_properties.max_extent.width,
                            height: image_format_properties.max_extent.height,
                        },
                    });
                    self.formats.shm_formats.push(shm);
                }
            }
        }
        // Ensure the required wl_shm formats are available
        if !self
            .formats
            .shm_formats
            .iter()
            .any(|format| format == &wl_shm::Format::Argb8888 || format == &wl_shm::Format::Xrgb8888)
        {
            return Err(Error::MissingMandatoryFormats);
        }
        Ok(())
    }
pub ( super ) fn init_shm_formats ( & mut self ) -> Result < ( ) , Error > { let instance = self . device . instance . raw ( ) ; let phy = self . device . phy ; for format in formats ( ) { if let Some ( ( vk_format , _ ) ) = fourcc_to_vk ( format ) { let shm = match fourcc_to_wl ( format ) { Some ( format ) => format , None => continue , } ; let mut image_format_properties2 = vk :: ImageFormatProperties2 :: builder ( ) ; let format_info = vk :: PhysicalDeviceImageFormatInfo2 :: builder ( ) . format ( vk_format ) . tiling ( vk :: ImageTiling :: OPTIMAL ) . ty ( vk :: ImageType :: TYPE_2D ) . usage ( TEXTURE_USAGE ) ; let image_format_properties = match unsafe { instance . get_physical_device_image_format_properties2 ( phy , & format_info , & mut image_format_properties2 , ) } { Ok ( _ ) => image_format_properties2 . image_format_properties , Err ( vk :: Result :: ERROR_FORMAT_NOT_SUPPORTED ) => continue , Err ( result ) => return Err ( VkError :: from ( result ) . into ( ) ) , } ; // Check if the format supports the texture usage feature flags. let mut format_properties2 = vk :: FormatProperties2 :: builder ( ) ; unsafe { instance . get_physical_device_format_properties2 ( phy , vk_format , & mut format_properties2 ) } ; if format_properties2 . format_properties . optimal_tiling_features . contains ( TEXTURE_FEATURES ) { self . formats . shm_format_info . push ( ShmFormatInfo { shm , vk : vk_format , max_extent : vk :: Extent2D { width : image_format_properties . max_extent . width , height : image_format_properties . max_extent . height , } , } ) ; self . formats . shm_formats . push ( shm ) ; } } } // Ensure the required wl_shm formats are available if ! self . formats . shm_formats . iter ( ) . any ( | format | format == & wl_shm :: Format :: Argb8888 || format == & wl_shm :: Format :: Xrgb8888 ) { return Err ( Error :: MissingMandatoryFormats ) ; } Ok ( ( ) ) }
Tests which wl_shm formats are supported for the renderer.
Tests which wl_shm formats are supported for the renderer .
&mut self
errors
This function will return [`Err`] if the mandatory wl_shm formats are not supported or some other
error occurs.
This function will return [ ` Err ` ] if the mandatory wl_shm formats are not supported or some other error occurs .