Skip to main content

nox_spirv/
lib.rs

1//! Compact SPIR-V reflection library written in pure-Rust with zero dependencies and minimal
2//! allocations.
3//!
4//! # Allocation policy
5//! - Strings and arrays are just slices to the SPIR-V passed to [`Module`].
6//! - Only [`decorations`][1] and [`instructions streams`][2] with a [`result id`][3] are cached using
7//!   an extra allocation.
8//! - Parsing is mostly done on-demand.
9//! 
10//! [1]: op::Decoration
11//! [2]: stream::InstructionStream
12//! [3]: op::IdResult
13//! # Usage 
14//! ``` rust
15//! use nox_spirv::op;
16//! use nox_spirv::Module;
17//! use nox_spirv::reflect::{Reflector, ResourceType};
18//! 
19//! let spirv: &[u32] = ...;
20//! let module = Module::new(spirv).unwrap();
21//! let mut reflector = Reflector::new(module).unwrap();
22//! reflector.set_entry_point(c"main", op::ExecutionModel::FRAGMENT).unwrap();
23//! for ubo in reflector.resources_for_type(ResourceType::UniformBuffer).unwrap() {
24//!     match ubo {
25//!         Ok(ubo) => {
26//!             let mut set = None;
27//!             let mut binding = None;
28//!             for dec in reflector.decorations(ubo.variable_id) {
29//!                 if let op::Decoration::DescriptorSet { descriptor_set } = dec.decoration {
30//!                     set = Some(descriptor_set);
31//!                 } else if let op::Decoration::Binding { binding_point } = dec.decoration {
32//!                     binding = Some(binding_point);
33//!                 }
34//!             }
35//!             println!("Uniform buffer (set {}, binding {}): {}",
36//!                 set.unwrap(), binding.unwrap(), ubo.name.unwrap_or_default(),
37//!             );
38//!         },
39//!         Err(err) => eprintln!("parse error: {err}")
40//!     }
41//! }
42//! for pc in reflector.resources_for_type(ResourceType::PushConstant).unwrap() {
43//!     match pc {
44//!         Ok(pc) => {
45//!             let offset = pc.offset.unwrap();
46//!             let size = reflector
47//!                 .type_description(pc.base_type_id)
48//!                 .unwrap().size_hint.declared();
49//!             println!("Push constant (offset {offset}, size {size}): {}", pc.name.unwrap_or_default());
50//!         },
51//!         Err(err) => eprintln!("parse error: {err}"),
52//!     }
53//! }
54//! ```
55
56mod core;
57pub mod stream;
58pub mod op;
59mod module;
60pub mod reflect;
61
62pub use {
63    core::*,
64    module::*,
65};