spirv_utils

Struct RawModule

Source
pub struct RawModule { /* private fields */ }
Expand description

Minimal representation of a SPIR-V module.

Implementations§

Source§

impl RawModule

Source

pub fn load_module<P: AsRef<Path>>(path: P) -> Result<RawModule>

Load a module from a file

Examples found in repository?
examples/dump_variables.rs (line 14)
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
fn main() {
    let mut args = env::args_os();
    args.next();

    let filename = args.next();

    let module = if let Some(filename) = filename {
        spirv_utils::RawModule::load_module(filename).unwrap()
    } else {
        spirv_utils::RawModule::load_module("examples/vert.spv").unwrap()
    };

    for inst in module.instructions() {
        if let instruction::Instruction::Variable { result_id, storage_class, .. } = *inst {
            if let Some(name) = get_name(&module, result_id.into()) {
                println!("Variable {: <15} {:?}", name, storage_class);
            }
        }
    }
}
Source

pub fn read_module<R: Read>(reader: R) -> Result<RawModule>

Read a module

Source

pub fn instructions<'a>(&'a self) -> &'a [Instruction]

Gets the instructions in the module

Examples found in repository?
examples/dump_variables.rs (line 19)
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
fn main() {
    let mut args = env::args_os();
    args.next();

    let filename = args.next();

    let module = if let Some(filename) = filename {
        spirv_utils::RawModule::load_module(filename).unwrap()
    } else {
        spirv_utils::RawModule::load_module("examples/vert.spv").unwrap()
    };

    for inst in module.instructions() {
        if let instruction::Instruction::Variable { result_id, storage_class, .. } = *inst {
            if let Some(name) = get_name(&module, result_id.into()) {
                println!("Variable {: <15} {:?}", name, storage_class);
            }
        }
    }
}
Source

pub fn def_index<I: Into<Id>>(&self, id: I) -> Option<usize>

Gets the index of the instruction that defines the given id, if any

Source

pub fn use_indices<'a, I: Into<Id>>(&'a self, id: I) -> Option<&'a [usize]>

Gets the indices of the instructions that use the given id

Source

pub fn def<'a, I: Into<Id>>(&'a self, id: I) -> Option<&'a Instruction>

Gets the instruction that defines the given Id, if any

Source

pub fn uses<'a, I: Into<Id>>(&'a self, id: I) -> Uses<'a>

Returns an iterator over the uses of the given Id

Examples found in repository?
examples/dump_variables.rs (line 29)
28
29
30
31
32
33
34
35
36
fn get_name<'a>(module: &'a spirv_utils::RawModule, id: desc::Id) -> Option<&'a str> {
    module.uses(id).filter_map(|inst| {
        if let instruction::Instruction::Name { ref name, .. } = *inst {
            Some(&name[..])
        } else {
            None
        }
    }).next()
}

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.