Skip to main content

Crate dxbc_reader

Crate dxbc_reader 

Source
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), the reflection and signature chunks as the records the file holds (reflection), and the compiler’s own counters (statistics).

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::RegisterRange;
pub use decode::Selection;
pub use decode::decode;
pub use decode::opcode_name;
pub use interfaces::ClassInstance;
pub use interfaces::ClassType;
pub use interfaces::InterfaceSlots;
pub use interfaces::Interfaces;
pub use interfaces::interfaces;
pub use level9::ConstantMapping;
pub use level9::Level9;
pub use level9::RuntimeConstant;
pub use level9::SamplerMapping;
pub use level9::ScalarMapping;
pub use level9::level9;
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;
pub use statistics::Statistics;
pub use statistics::statistics;

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.
interfaces
The IFCE part of a Shader Model 5 program with class linkage (dynamic shader linkage): the classes that implement its interfaces, the class instances its constant buffers hold, and which function tables each interface slot can be bound to.
level9
The Aon9 part of a container compiled for a Direct3D 9 feature level (ps_4_0_level_9_1 and the like): the Shader Model 2 program the runtime runs on such hardware, and the tables that map the Shader Model 4 program’s constant buffers, samplers and resources onto Direct3D 9 registers.
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.
statistics
The STAT part of a Shader Model 4 or 5 container: the compiler’s counts of what the program does, as 32-bit words.

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.
GlobalFlags
The flags of a dcl_globalFlags declaration (its control bits). The names are the ones Microsoft’s disassembler prints; the games’ programs set bits 0 to 5.
OperandFormat
The operands of one opcode, destinations first as they are stored.
Options
How the listing is written: the switches of Microsoft’s D3D_DISASM_* flags that this disassembler writes. Options::default is D3DDisassemble with no flags.
SyncFlags
What a sync instruction waits for (control bits 0 to 3; the listing of Microsoft’s disassembler adds a suffix for each: _t, _g, _ugroup, _uglobal).
TextureRead
One instruction of a program that reads a texture (a shader resource view, t<n>).

Enums§

InfoReturn
The type a resinfo or sample_info instruction returns (the _uint and _rcpfloat suffixes of Microsoft’s listing; none suffix is a float).
OperandClass
What an operand of an instruction carries.

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 SHEX or SHDR part) as 32-bit little-endian words, for decode(). Refuses what parts refuses and a container without that part (a DXIL one among them).
disassemble
The listing of a DXBC container’s Shader Model 4 or 5 program as Microsoft’s disassembler writes it with no flags, its lines ending in \n (the disassembler’s blob also ends in a zero byte, which is not part of the text).
disassemble_with
The listing of a DXBC container as disassemble writes it, with options.
operand_format
The operand format of opcode (the opcode token’s low 11 bits, see opcode_name). None for the opcodes without one: declarations, which Declared types, and call, callc, label and interface_call, whose operands are not registers a program declares.
parts
The container’s parts (its DXBC directory).
texture_reads
Every texture read of program (an instruction with a t<n> operand that samples, gathers, queries the level of detail of or loads it), in program order. An instruction that reads a raw or structured buffer or an unordered-access view through a u or g register names no texture and is not listed.

Type Aliases§

Result
The reader’s result: an Error naming the word where reading failed.