Skip to main content

inspect_dxil/
inspect_dxil.rs

1//! `cargo run -p dxil-reader --example inspect_dxil -- shader.dxil`: print a Shader Model 6 shader's function count, signature
2//! sizes and bound resource ranges. The README's example is this file's body.
3fn main() -> Result<(), Box<dyn std::error::Error>> {
4    let path = std::env::args().nth(1).ok_or("usage: inspect <shader.dxil>")?;
5    let container = std::fs::read(path)?;
6    let parts = dxil_reader::parts(&container)?;
7    let module = dxil_reader::module(&parts, b"DXIL")?.ok_or("no DXIL part")?;
8    println!("{} functions", module.functions.len());
9
10    // The records the file stores for its entry point:
11    let (inputs, outputs) = dxil_reader::reflection::elements(&module)?;
12    println!(
13        "{} input and {} output signature elements",
14        inputs.len(),
15        outputs.len()
16    );
17    for (range, name, _) in dxil_reader::reflection::ranges(&module)? {
18        println!("{name}: class {} register {}", range.class, range.lower);
19    }
20    Ok(())
21}