Expand description
A reader of Shader Model 4 and 5 programs as Direct3D stores them in a DXBC container: the token stream of any
stage (decode), and the reflection and signature chunks as the records the file holds (reflection).
It reads and checks bytes and never interprets them for an API: a register binding is the RDEF record’s own
numbers, a signature element its stored name, index and masks. Mapping those into a graphics API’s vocabulary is
the caller’s choice. Everything it can’t read (a truncated instruction, an out-of-range table, a cyclic type) is an
Error naming the 32-bit word where it happened; it never panics on untrusted input.
let container = std::fs::read("shader.dxbc").expect("a compiled shader");
let code = dxbc_reader::code(&container)?;
let program = dxbc_reader::decode(&code)?;
println!("{} with {} instructions", program.target(), program.instructions.len());Re-exports§
pub use decode::Declaration;pub use decode::Declared;pub use decode::Decoded;pub use decode::Index;pub use decode::Instruction;pub use decode::Operand;pub use decode::ProgramType;pub use decode::Register;pub use decode::Selection;pub use decode::decode;pub use decode::opcode_name;pub use reflection::Rdef;pub use reflection::RdefBinding;pub use reflection::RdefBuffer;pub use reflection::RdefMember;pub use reflection::RdefType;pub use reflection::RdefVariable;pub use reflection::SignatureElement;pub use reflection::patch_signature_elements;pub use reflection::program_type;pub use reflection::rdef;pub use reflection::rdef_target;pub use reflection::signature;pub use reflection::signature_elements;
Modules§
- decode
- The token-level decoder of Shader Model 4 and 5 programs: any stage’s version token, declarations as typed records, and instructions as an opcode, its control bits, its extended tokens and its operands. It decides nothing about which instructions a caller can use: they are all returned, and the caller refuses what it cannot handle. A token it cannot read at all (an operand register type it has no name for, a truncated instruction) is an error naming the word.
- reflection
- The reflection (
RDEF) and signature (ISGN,OSGN,ISG1,OSG1,OSG5,PCSG,PSG1) parts of a Shader Model 4 or 5 container, as the records they store: resource bindings, constant buffers with their variables and type trees, and signature elements, each with D3D’s own numbers (D3D_SHADER_INPUT_TYPE,D3D_NAME, …) and the word it starts at. What the numbers mean for a graphics API is the caller’s to decide.
Structs§
- Error
- Something the reader can’t read: the 32-bit word of the container’s chunk or token stream where it is, and what.
Functions§
- chunk
- The container’s one part of kind
tag: an error where it has none, or more than one. - code
- The program’s token stream (its
SHEXorSHDRpart) as 32-bit little-endian words, fordecode(). - parts
- The container’s parts (its
DXBCdirectory).