Skip to main content

decode

Function decode 

Source
pub fn decode(words: &[u32]) -> Result<Decoded>
Expand description

Decode a complete token stream: version token, length, then declarations and instructions to its end.

Examples found in repository?
examples/inspect_dxbc.rs (line 7)
3fn main() -> Result<(), Box<dyn std::error::Error>> {
4    let path = std::env::args().nth(1).ok_or("usage: inspect <shader.dxbc>")?;
5    let container = std::fs::read(path)?;
6    let code = dxbc_reader::code(&container)?; // the SHDR/SHEX part as 32-bit words
7    let program = dxbc_reader::decode(&code)?;
8    println!(
9        "{} with {} instructions",
10        program.target(),
11        program.instructions.len()
12    );
13
14    // Reflection and signatures straight from the container:
15    if let Some(rdef) = dxbc_reader::rdef(&container)? {
16        for binding in &rdef.bindings {
17            println!("{} at register {}", binding.name, binding.register);
18        }
19    }
20    let (stage, inputs, outputs) = dxbc_reader::signature_elements(&container)?;
21    println!("{stage:?}: {} inputs, {} outputs", inputs.len(), outputs.len());
22    Ok(())
23}