rspirv/lib.rs
1//! Library APIs for SPIR-V module processing functionalities.
2//!
3//! This library provides:
4//!
5//! * The whole SPIR-V [grammar](grammar/index.html) (instruction layouts
6//! and their operands)
7//! * A [data representation](dr/index.html) of SPIR-V modules and its
8//! loader and builder
9//! * A [structured representation](sr/index.html) of SPIR-V modules
10//! (under developing)
11//! * SPIR-V [binary](binary/index.html) module decoding and parsing
12//! functionalities
13//!
14//! The data representation (DR) focuses on presenting the data within a
15//! SPIR-V module; it uses plain vectors to hold data of SPIR-V instructions,
16//! following the instructions' layouts defined in the grammar. DR has little
17//! structure; only bare structures need for representing modules, functions,
18//! and blocks are adopted.
19//!
20//! The structured representation (SR) focuses on presenting the structure
21//! within a SPIR-V module; it tries to links as much information as possible.
22//! Types, values, instructions, decorations and so on have their dedicated
23//! structs. The purpose of SR is to facilitate SPIR-V analysis and
24//! transformations.
25//!
26//! # Examples
27//!
28//! Building a SPIR-V module, assembling it, parsing it, and then
29//! disassembling it:
30//!
31//! ```
32//! use rspirv::binary::Assemble;
33//! use rspirv::binary::Disassemble;
34//!
35//! // Building
36//! let mut b = rspirv::dr::Builder::new();
37//! b.memory_model(spirv::AddressingModel::Logical, spirv::MemoryModel::GLSL450);
38//! let void = b.type_void();
39//! let voidf = b.type_function(void, vec![void]);
40//! b.begin_function(void,
41//! None,
42//! (spirv::FunctionControl::DONT_INLINE |
43//! spirv::FunctionControl::CONST),
44//! voidf)
45//! .unwrap();
46//! b.begin_block(None).unwrap();
47//! b.ret().unwrap();
48//! b.end_function().unwrap();
49//! let module = b.module();
50//!
51//! // Assembling
52//! let code = module.assemble();
53//! assert!(code.len() > 20); // Module header contains 5 words
54//! assert_eq!(spirv::MAGIC_NUMBER, code[0]);
55//!
56//! // Parsing
57//! let mut loader = rspirv::dr::Loader::new();
58//! rspirv::binary::parse_words(&code, &mut loader).unwrap();
59//! let module = loader.module();
60//!
61//! // Disassembling
62//! assert_eq!(module.disassemble(),
63//! "; SPIR-V\n\
64//! ; Version: 1.6\n\
65//! ; Generator: rspirv\n\
66//! ; Bound: 5\n\
67//! OpMemoryModel Logical GLSL450\n\
68//! %1 = OpTypeVoid\n\
69//! %2 = OpTypeFunction %1 %1\n\
70//! %3 = OpFunction %1 DontInline|Const %2\n\
71//! %4 = OpLabel\n\
72//! OpReturn\n\
73//! OpFunctionEnd");
74//! ```
75
76pub use spirv;
77
78pub mod binary;
79pub mod dr;
80pub mod grammar;
81pub mod lift;
82pub mod sr;
83
84mod utils;