fn format_from_id(doc: &parse::Spirv, searched: u32, ignore_first_array: bool) -> (String, usize) {
    for instruction in doc.instructions.iter() {
        match instruction {
            &parse::Instruction::TypeInt {
                result_id,
                width,
                signedness,
            } if result_id == searched => {
                assert!(!ignore_first_array);
                return (match (width, signedness) {
                    (8, true) => "R8Sint",
                    (8, false) => "R8Uint",
                    (16, true) => "R16Sint",
                    (16, false) => "R16Uint",
                    (32, true) => "R32Sint",
                    (32, false) => "R32Uint",
                    (64, true) => "R64Sint",
                    (64, false) => "R64Uint",
                    _ => panic!(),
                }.to_owned(),
                        1);
            },
            &parse::Instruction::TypeFloat { result_id, width } if result_id == searched => {
                assert!(!ignore_first_array);
                return (match width {
                    32 => "R32Sfloat",
                    64 => "R64Sfloat",
                    _ => panic!(),
                }.to_owned(),
                        1);
            },
            &parse::Instruction::TypeVector {
                result_id,
                component_id,
                count,
            } if result_id == searched => {
                assert!(!ignore_first_array);
                let (format, sz) = format_from_id(doc, component_id, false);
                assert!(format.starts_with("R32"));
                assert_eq!(sz, 1);
                let format = if count == 1 {
                    format
                } else if count == 2 {
                    format!("R32G32{}", &format[3 ..])
                } else if count == 3 {
                    format!("R32G32B32{}", &format[3 ..])
                } else if count == 4 {
                    format!("R32G32B32A32{}", &format[3 ..])
                } else {
                    panic!("Found vector type with more than 4 elements")
                };
                return (format, sz);
            },
            &parse::Instruction::TypeMatrix {
                result_id,
                column_type_id,
                column_count,
            } if result_id == searched => {
                assert!(!ignore_first_array);
                let (format, sz) = format_from_id(doc, column_type_id, false);
                return (format, sz * column_count as usize);
            },
            &parse::Instruction::TypeArray {
                result_id,
                type_id,
                length_id,
            } if result_id == searched => {
                if ignore_first_array {
                    return format_from_id(doc, type_id, false);
                }

                let (format, sz) = format_from_id(doc, type_id, false);
                let len = doc.instructions
                    .iter()
                    .filter_map(|e| match e {
                                    &parse::Instruction::Constant {
                                        result_id,
                                        ref data,
                                        ..
                                    } if result_id == length_id => Some(data.clone()),
                                    _ => None,
                                })
                    .next()
                    .expect("failed to find array length");
                let len = len.iter().rev().fold(0u64, |a, &b| (a << 32) | b as u64);
                return (format, sz * len as usize);
            },
            &parse::Instruction::TypePointer { result_id, type_id, .. }
                if result_id == searched => {
                return format_from_id(doc, type_id, ignore_first_array);
            },
            _ => (),
        }
    }

    panic!("Type #{} not found or invalid", searched)
}
/// Returns the vulkano `Format` and number of occupied locations from an id.
///
/// If `ignore_first_array` is true, the function expects the outermost instruction to be
/// `OpTypeArray`. If it's the case, the OpTypeArray will be ignored. If not, the function will
/// panic.
Returns the vulkano `Format` and number of occupied locations from an id.
If `ignore_first_array` is true, the function expects the outermost instruction to be
`OpTypeArray`. If it's the case, the OpTypeArray will be ignored. If not, the function will
panic.
Returns the vulkano ` Format ` and number of occupied locations from an id . If ` ignore_first_array ` is true the function expects the outermost instruction to be ` OpTypeArray ` . If it ' s the case the OpTypeArray will be ignored . If not the function will panic .
fn format_from_id(doc: &parse::Spirv, searched: u32, ignore_first_array: bool) -> (String, usize) {
    for instruction in doc.instructions.iter() {
        match instruction {
            &parse::Instruction::TypeInt {
                result_id,
                width,
                signedness,
            } if result_id == searched => {
                assert!(!ignore_first_array);
                return (match (width, signedness) {
                    (8, true) => "R8Sint",
                    (8, false) => "R8Uint",
                    (16, true) => "R16Sint",
                    (16, false) => "R16Uint",
                    (32, true) => "R32Sint",
                    (32, false) => "R32Uint",
                    (64, true) => "R64Sint",
                    (64, false) => "R64Uint",
                    _ => panic!(),
                }.to_owned(),
                        1);
            },
            &parse::Instruction::TypeFloat { result_id, width } if result_id == searched => {
                assert!(!ignore_first_array);
                return (match width {
                    32 => "R32Sfloat",
                    64 => "R64Sfloat",
                    _ => panic!(),
                }.to_owned(),
                        1);
            },
            &parse::Instruction::TypeVector {
                result_id,
                component_id,
                count,
            } if result_id == searched => {
                assert!(!ignore_first_array);
                let (format, sz) = format_from_id(doc, component_id, false);
                assert!(format.starts_with("R32"));
                assert_eq!(sz, 1);
                let format = if count == 1 {
                    format
                } else if count == 2 {
                    format!("R32G32{}", &format[3 ..])
                } else if count == 3 {
                    format!("R32G32B32{}", &format[3 ..])
                } else if count == 4 {
                    format!("R32G32B32A32{}", &format[3 ..])
                } else {
                    panic!("Found vector type with more than 4 elements")
                };
                return (format, sz);
            },
            &parse::Instruction::TypeMatrix {
                result_id,
                column_type_id,
                column_count,
            } if result_id == searched => {
                assert!(!ignore_first_array);
                let (format, sz) = format_from_id(doc, column_type_id, false);
                return (format, sz * column_count as usize);
            },
            &parse::Instruction::TypeArray {
                result_id,
                type_id,
                length_id,
            } if result_id == searched => {
                if ignore_first_array {
                    return format_from_id(doc, type_id, false);
                }
                let (format, sz) = format_from_id(doc, type_id, false);
                let len = doc.instructions
                    .iter()
                    .filter_map(|e| match e {
                                    &parse::Instruction::Constant {
                                        result_id,
                                        ref data,
                                        ..
                                    } if result_id == length_id => Some(data.clone()),
                                    _ => None,
                                })
                    .next()
                    .expect("failed to find array length");
                let len = len.iter().rev().fold(0u64, |a, &b| (a << 32) | b as u64);
                return (format, sz * len as usize);
            },
            &parse::Instruction::TypePointer { result_id, type_id, .. }
                if result_id == searched => {
                return format_from_id(doc, type_id, ignore_first_array);
            },
            _ => (),
        }
    }
    panic!("Type #{} not found or invalid", searched)
}
fn format_from_id ( doc : & parse :: Spirv , searched : u32 , ignore_first_array : bool ) -> ( String , usize ) { for instruction in doc . instructions . iter ( ) { match instruction { & parse :: Instruction :: TypeInt { result_id , width , signedness , } if result_id == searched => { assert ! ( ignore_first_array ) ; return ( match ( width , signedness ) { ( 8 , true ) => " " , ( 8 , false ) => " " , ( 16 , true ) => " " , ( 16 , false ) => " " , ( 32 , true ) => " " , ( 32 , false ) => " " , ( 64 , true ) => " " , ( 64 , false ) => " " , _ => panic ! ( ) , } . to_owned ( ) , 1 ) ; } , & parse :: Instruction :: TypeFloat { result_id , width } if result_id == searched => { assert ! ( ignore_first_array ) ; return ( match width { 32 => " " , 64 => " " , _ => panic ! ( ) , } . to_owned ( ) , 1 ) ; } , & parse :: Instruction :: TypeVector { result_id , component_id , count , } if result_id == searched => { assert ! ( ignore_first_array ) ; let ( format , sz ) = format_from_id ( doc , component_id , false ) ; assert ! ( format starts_with ( " " ) ) ; assert_eq ! ( sz 1 ) ; let format = if count == 1 { format } else if count == 2 { format ! ( " " format [ 3 ] ) } else if count == 3 { format ! ( " " format [ 3 ] ) } else if count == 4 { format ! ( " " format [ 3 ] ) } else { panic ! ( " " ) } ; return ( format , sz ) ; } , & parse :: Instruction :: TypeMatrix { result_id , column_type_id , column_count , } if result_id == searched => { assert ! ( ignore_first_array ) ; let ( format , sz ) = format_from_id ( doc , column_type_id , false ) ; return ( format , sz * column_count as usize ) ; } , & parse :: Instruction :: TypeArray { result_id , type_id , length_id , } if result_id == searched => { if ignore_first_array { return format_from_id ( doc , type_id , false ) ; } let ( format , sz ) = format_from_id ( doc , type_id , false ) ; let len = doc . instructions . iter ( ) . filter_map ( | e | match e { & parse :: Instruction :: Constant { result_id , ref data , .. } if result_id == length_id => Some ( data . clone ( ) ) , _ => None , } ) . next ( ) . expect ( " " ) ; let len = len . iter ( ) . rev ( ) . fold ( 0u64 , | a , & b | ( a << 32 ) | b as u64 ) ; return ( format , sz * len as usize ) ; } , & parse :: Instruction :: TypePointer { result_id , type_id , .. } if result_id == searched => { return format_from_id ( doc , type_id , ignore_first_array ) ; } , _ => ( ) , } } panic ! ( " " searched ) }
Returns the vulkano `Format` and number of occupied locations from an id.
Returns the vulkano ` Format ` and number of occupied locations from an id .
doc
&parse::Spirv
searched
u32
ignore_first_array
bool
doc
&parse::Spirv
searched
u32
ignore_first_array
bool