/// As `from_words`, but does not parse the code. Instead, you must provide the needed
/// information yourself. This can be useful if you've already done parsing yourself and
/// want to prevent Vulkano from doing it a second time.
///
/// # Safety
///
/// - The SPIR-V code is not validated at all.
/// - The provided information must match what the SPIR-V code contains.
As `from_words`, but does not parse the code. Instead, you must provide the needed
information yourself. This can be useful if you've already done parsing yourself and
want to prevent Vulkano from doing it a second time.
As ` from_words ` but does not parse the code . Instead you must provide the needed information yourself . This can be useful if you ' ve already done parsing yourself and want to prevent Vulkano from doing it a second time .
pub unsafe fn from_words_with_data<'a>(
        device: Arc<Device>,
        words: &[u32],
        spirv_version: Version,
        spirv_capabilities: impl IntoIterator<Item = &'a Capability>,
        spirv_extensions: impl IntoIterator<Item = &'a str>,
        entry_points: impl IntoIterator<Item = (String, ExecutionModel, EntryPointInfo)>,
    ) -> Result<Arc<ShaderModule>, ShaderCreationError> {
        if let Err(reason) = check_spirv_version(&device, spirv_version) {
            return Err(ShaderCreationError::SpirvVersionNotSupported {
                version: spirv_version,
                reason,
            });
        }
        for capability in spirv_capabilities {
            if let Err(reason) = check_spirv_capability(&device, capability.clone()) {
                return Err(ShaderCreationError::SpirvCapabilityNotSupported {
                    capability: capability.clone(),
                    reason,
                });
            }
        }
        for extension in spirv_extensions {
            if let Err(reason) = check_spirv_extension(&device, extension) {
                return Err(ShaderCreationError::SpirvExtensionNotSupported {
                    extension: extension.to_owned(),
                    reason,
                });
            }
        }
        let handle = {
            let infos = ash::vk::ShaderModuleCreateInfo {
                flags: ash::vk::ShaderModuleCreateFlags::empty(),
                code_size: words.len() * mem::size_of::<u32>(),
                p_code: words.as_ptr(),
                ..Default::default()
            };
            let fns = device.fns();
            let mut output = MaybeUninit::uninit();
            check_errors(fns.v1_0.create_shader_module(
                device.internal_object(),
                &infos,
                ptr::null(),
                output.as_mut_ptr(),
            ))?;
            output.assume_init()
        };
        let entries = entry_points.into_iter().collect::<Vec<_>>();
        let entry_points = entries
            .iter()
            .filter_map(|(name, _, _)| Some(name))
            .collect::<HashSet<_>>()
            .iter()
            .map(|name| {
                (
                    (*name).clone(),
                    entries
                        .iter()
                        .filter_map(|(entry_name, entry_model, info)| {
                            if &entry_name == name {
                                Some((*entry_model, info.clone()))
                            } else {
                                None
                            }
                        })
                        .collect::<HashMap<_, _>>(),
                )
            })
            .collect();
        Ok(Arc::new(ShaderModule {
            handle,
            device,
            entry_points,
        }))
    }
pub unsafe fn from_words_with_data < ' a > ( device : Arc < Device > , words : & [ u32 ] , spirv_version : Version , spirv_capabilities : impl IntoIterator < Item = & ' a Capability > , spirv_extensions : impl IntoIterator < Item = & ' a str > , entry_points : impl IntoIterator < Item = ( String , ExecutionModel , EntryPointInfo ) > , ) -> Result < Arc < ShaderModule > , ShaderCreationError > { if let Err ( reason ) = check_spirv_version ( & device , spirv_version ) { return Err ( ShaderCreationError :: SpirvVersionNotSupported { version : spirv_version , reason , } ) ; } for capability in spirv_capabilities { if let Err ( reason ) = check_spirv_capability ( & device , capability . clone ( ) ) { return Err ( ShaderCreationError :: SpirvCapabilityNotSupported { capability : capability . clone ( ) , reason , } ) ; } } for extension in spirv_extensions { if let Err ( reason ) = check_spirv_extension ( & device , extension ) { return Err ( ShaderCreationError :: SpirvExtensionNotSupported { extension : extension . to_owned ( ) , reason , } ) ; } } let handle = { let infos = ash :: vk :: ShaderModuleCreateInfo { flags : ash :: vk :: ShaderModuleCreateFlags :: empty ( ) , code_size : words . len ( ) * mem :: size_of :: < u32 > ( ) , p_code : words . as_ptr ( ) , .. Default :: default ( ) } ; let fns = device . fns ( ) ; let mut output = MaybeUninit :: uninit ( ) ; check_errors ( fns . v1_0 . create_shader_module ( device . internal_object ( ) , & infos , ptr :: null ( ) , output . as_mut_ptr ( ) , ) ) ? ; output . assume_init ( ) } ; let entries = entry_points . into_iter ( ) . collect :: < Vec < _ > > ( ) ; let entry_points = entries . iter ( ) . filter_map ( | ( name , _ , _ ) | Some ( name ) ) . collect :: < HashSet < _ > > ( ) . iter ( ) . map ( | name | { ( ( * name ) . clone ( ) , entries . iter ( ) . filter_map ( | ( entry_name , entry_model , info ) | { if & entry_name == name { Some ( ( * entry_model , info . clone ( ) ) ) } else { None } } ) . collect :: < HashMap < _ , _ > > ( ) , ) } ) . collect ( ) ; Ok ( Arc :: new ( ShaderModule { handle , device , entry_points , } ) ) }
As `from_words`, but does not parse the code.
As ` from_words ` but does not parse the code .
device
Arc<Device>
words
&[u32]
spirv_version
Version
spirv_capabilities
impl IntoIterator<Item = &'a Capability>
spirv_extensions
impl IntoIterator<Item = &'a str>
entry_points
impl IntoIterator<Item = (String, ExecutionModel, EntryPointInfo)>
safety
The SPIR-V code is not validated at all.
The provided information must match what the SPIR-V code contains.
The SPIR - V code is not validated at all . The provided information must match what the SPIR - V code contains .