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
IFCEpart 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
Aon9part of a container compiled for a Direct3D 9 feature level (ps_4_0_level_9_1and 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
STATpart 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.
- Global
Flags - The flags of a
dcl_globalFlagsdeclaration (its control bits). The names are the ones Microsoft’s disassembler prints; the games’ programs set bits 0 to 5. - Operand
Format - 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::defaultisD3DDisassemblewith no flags. - Sync
Flags - What a
syncinstruction waits for (control bits 0 to 3; the listing of Microsoft’s disassembler adds a suffix for each:_t,_g,_ugroup,_uglobal). - Texture
Read - One instruction of a program that reads a texture (a shader resource view,
t<n>).
Enums§
- Info
Return - The type a
resinfoorsample_infoinstruction returns (the_uintand_rcpfloatsuffixes of Microsoft’s listing; none suffix is a float). - Operand
Class - 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
SHEXorSHDRpart) as 32-bit little-endian words, fordecode(). Refuses whatpartsrefuses and a container without that part (aDXILone among them). - disassemble
- The listing of a
DXBCcontainer’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
DXBCcontainer asdisassemblewrites it, withoptions. - operand_
format - The operand format of
opcode(the opcode token’s low 11 bits, seeopcode_name).Nonefor the opcodes without one: declarations, whichDeclaredtypes, andcall,callc,labelandinterface_call, whose operands are not registers a program declares. - parts
- The container’s parts (its
DXBCdirectory). - texture_
reads - Every texture read of
program(an instruction with at<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 auorgregister names no texture and is not listed.