Skip to main content

Crate nox_spirv

Crate nox_spirv 

Source
Expand description

Compact SPIR-V reflection library written in pure-Rust with zero dependencies and minimal allocations.

§Allocation policy

§Usage

use nox_spirv::op;
use nox_spirv::Module;
use nox_spirv::reflect::{Reflector, ResourceType};
 
let spirv: &[u32] = ...;
let module = Module::new(spirv).unwrap();
let mut reflector = Reflector::new(module).unwrap();
reflector.set_entry_point(c"main", op::ExecutionModel::FRAGMENT).unwrap();
for ubo in reflector.resources_for_type(ResourceType::UniformBuffer).unwrap() {
    match ubo {
        Ok(ubo) => {
            let mut set = None;
            let mut binding = None;
            for dec in reflector.decorations(ubo.variable_id) {
                if let op::Decoration::DescriptorSet { descriptor_set } = dec.decoration {
                    set = Some(descriptor_set);
                } else if let op::Decoration::Binding { binding_point } = dec.decoration {
                    binding = Some(binding_point);
                }
            }
            println!("Uniform buffer (set {}, binding {}): {}",
                set.unwrap(), binding.unwrap(), ubo.name.unwrap_or_default(),
            );
        },
        Err(err) => eprintln!("parse error: {err}")
    }
}
for pc in reflector.resources_for_type(ResourceType::PushConstant).unwrap() {
    match pc {
        Ok(pc) => {
            let offset = pc.offset.unwrap();
            let size = reflector
                .type_description(pc.base_type_id)
                .unwrap().size_hint.declared();
            println!("Push constant (offset {offset}, size {size}): {}", pc.name.unwrap_or_default());
        },
        Err(err) => eprintln!("parse error: {err}"),
    }
}

Modules§

op
SPIR-V Op-types and enumerations.
reflect
Contains everything reflection relevant.
stream
SPIR-V streams.

Structs§

CompilerStr
Represents a string inside SPIR-V.
Module
Represents a SPIR-V module.
ParseContext
A parse context used when parsing a Literal.

Enums§

Literal
Specifies the value of a literal constant.
ParseError
Indicates that the SPIR-V code passed to a module is invalid.

Constants§

VERSION_1_0
SPIR_V version 1.0
VERSION_1_1
SPIR_V version 1.1
VERSION_1_2
SPIR_V version 1.2
VERSION_1_3
SPIR_V version 1.3
VERSION_1_4
SPIR_V version 1.4
VERSION_1_5
SPIR_V version 1.5
VERSION_1_6
SPIR_V version 1.6

Traits§

Word
A trait for types, which can be trivially created from a u32.
WordExt
An extension auto-trait for Word.

Type Aliases§

ParseResult
The Result from a parsing operation,