### Example usage of d3dasm::parse Source: https://docs.rs/d3dasm/latest/d3dasm/fn.parse.html Reads a binary file and prints each parsed shader. The example is not tested. ```rust let data = std::fs::read("shader.bin").unwrap(); for shader in d3dasm::parse(&data) { print!("{shader}"); } ``` -------------------------------- ### Quick start: parse and disassemble a shader Source: https://docs.rs/d3dasm/latest/d3dasm/index.html Reads a shader binary file, parses it with d3dasm::parse, then iterates over the parsed shaders. For each shader, it prints the shader model version using the program() method, and then prints the full disassembly via the Display trait. Note that chunks are parsed lazily; only the shader program is decoded in the loop, while remaining chunks are parsed on demand during display. ```rust let data = std::fs::read("shader.bin").unwrap(); let shaders = d3dasm::parse(&data); for shader in &shaders { // Structured access to parsed chunks. // Chunks are parsed lazily — only the shader program is decoded here. if let Some(program) = shader.program() { println!("SM {}.{}", program.version_major, program.version_minor); } // Full disassembly via Display (parses remaining chunks on demand). print!("{shader}"); } ``` -------------------------------- ### impl Any for T Source: https://docs.rs/d3dasm/latest/d3dasm/struct.Shader.html Provides the type_id method to get the TypeId of the value. ```APIDOC ## impl Any for T ### Description Provides the `type_id` method to get the `TypeId` of the value. ### Method `fn type_id(&self) -> TypeId` ### Parameters - `&self` - The value to get the type ID of. ### Returns - `TypeId` - The `TypeId` of `self`. ``` -------------------------------- ### Shader::resource_def Source: https://docs.rs/d3dasm/latest/d3dasm/struct.Shader.html Returns resource definitions (constant buffers, bindings, creator string). ```APIDOC ## Shader::resource_def ### Description Returns resource definitions (constant buffers, bindings, creator string). ### Method resource_def ### Signature pub fn resource_def(&self) -> Option<&ResourceDef<'a>> ### Parameters None ### Returns - **Option<&ResourceDef<'a>>** - The resource definitions, if present. ``` -------------------------------- ### Shader::dxil Source: https://docs.rs/d3dasm/latest/d3dasm/struct.Shader.html Returns DXIL bytecode (SM6.0+, DXIL chunk) if present. ```APIDOC ## dxil ### Description Returns DXIL bytecode (SM6.0+, DXIL chunk) if present. ### Method `pub fn dxil(&self) -> Option<&DxilData>` ### Parameters None. ### Returns - `Option<&DxilData>` - DXIL bytecode if available, otherwise `None`. ``` -------------------------------- ### Shader::program Source: https://docs.rs/d3dasm/latest/d3dasm/struct.Shader.html Returns the decoded shader program (SM4/SM5 instructions), if present. ```APIDOC ## Shader::program ### Description Returns the decoded shader program (SM4/SM5 instructions), if present. ### Method program ### Signature pub fn program(&self) -> Option<&Program> ### Parameters None ### Returns - **Option<&Program>** - The decoded shader program, if present. ``` -------------------------------- ### Shader::from_container Source: https://docs.rs/d3dasm/latest/d3dasm/struct.Shader.html Wraps a DxbcContainer into a Shader. No chunks are parsed until accessed. ```APIDOC ## Shader::from_container ### Description Wraps a DxbcContainer into a Shader. No chunks are parsed until accessed. ### Method from_container ### Signature pub fn from_container(container: DxbcContainer<'a>) -> Self ### Parameters - **container** (DxbcContainer<'a>) - Required - The DXBC container to wrap. ### Returns - **Self** - A new Shader instance. ``` -------------------------------- ### Shader Display Implementation Source: https://docs.rs/d3dasm/latest/d3dasm/index.html Full disassembly via the Display trait. Parses remaining chunks on demand and formats the shader as human-readable text. ```APIDOC ## Shader Display Implementation ### Description Full disassembly via the Display trait. Parses remaining chunks on demand and formats the shader as human-readable text. ### Trait Implementation `impl fmt::Display for Shader` ### Usage ```rust print!("{shader}"); ``` ``` -------------------------------- ### Shader methods: from_container, chunk_at, find_by_fourcc Source: https://docs.rs/d3dasm/latest/src/d3dasm/lib.rs.html Provides core methods for wrapping a DxbcContainer, lazily parsing chunks by index, and finding chunks by fourcc. from_container initializes the parsed vector without parsing any chunks. ```rust impl<'a> Shader<'a> { /// Wrap a [`DxbcContainer`]. No chunks are parsed until accessed. pub fn from_container(container: DxbcContainer<'a>) -> Self { let parsed = (0..container.chunks.len()) .map(|_| OnceCell::new()) .collect(); Self { container, parsed } } /// Parse and return the chunk at `index`, caching the result. fn chunk_at(&self, index: usize) -> &ChunkData<'a> { self.parsed[index].get_or_init(|| self.container.chunks[index].parse()) } /// Find the first chunk whose fourcc matches, parsing it on demand. fn find_by_fourcc(&self, fourccs: &[&[u8; 4]]) -> Option<&ChunkData<'a>> { for (i, raw) in self.container.chunks.iter().enumerate() { if fourccs.iter().any(|f| raw.fourcc == **f) { return Some(self.chunk_at(i)); } } None } } ``` -------------------------------- ### Shader::feature_info Source: https://docs.rs/d3dasm/latest/d3dasm/struct.Shader.html Returns shader feature info flags (SFI0 chunk) if present. ```APIDOC ## feature_info ### Description Returns shader feature info flags (SFI0 chunk) if present. ### Method `pub fn feature_info(&self) -> Option<&ShaderFeatureInfo>` ### Parameters None. ### Returns - `Option<&ShaderFeatureInfo>` - Shader feature info if available, otherwise `None`. ``` -------------------------------- ### Shader::input_signature Source: https://docs.rs/d3dasm/latest/d3dasm/struct.Shader.html Returns input signature elements. ```APIDOC ## Shader::input_signature ### Description Returns input signature elements. ### Method input_signature ### Signature pub fn input_signature(&self) -> Option<&Signature<'a>> ### Parameters None ### Returns - **Option<&Signature<'a>>** - The input signature elements, if present. ``` -------------------------------- ### impl Display for Shader<'a> Source: https://docs.rs/d3dasm/latest/d3dasm/struct.Shader.html Provides the Display trait implementation for the Shader struct, allowing it to be formatted for user-facing output. ```APIDOC ## impl Display for Shader<'a> ### Description Provides the Display trait implementation for the Shader struct, allowing it to be formatted for user-facing output. ### Method `fn fmt(&self, f: &mut Formatter<'_>) -> Result` ### Parameters - `&self` - The Shader instance. - `f` (`&mut Formatter<'_>`) - The formatter to write the display representation to. ### Returns - `Result` - The result of the formatting operation. ``` -------------------------------- ### Shader accessors: offset, size, program, resource_def Source: https://docs.rs/d3dasm/latest/src/d3dasm/lib.rs.html Provides public accessors for container metadata and typed chunk access. offset returns byte offset in source file, size returns total container size, program returns decoded shader program (SHEX/SHDR), resource_def returns resource definitions (RDEF). ```rust impl<'a> Shader<'a> { /// Byte offset of this container in the source file. pub fn offset(&self) -> usize { self.container.offset_in_file } /// Total size of the DXBC container in bytes. pub fn size(&self) -> u32 { self.container.total_size } /// The decoded shader program (SM4/SM5 instructions), if present. pub fn program(&self) -> Option<&dxbc::shex::Program> { match self.find_by_fourcc(&[b"SHEX", b"SHDR"])? { ChunkData::Shader(p) => Some(p), _ => None, } } /// Resource definitions (constant buffers, bindings, creator string). pub fn resource_def(&self) -> Option<&dxbc::chunks::ResourceDef<'a>> { match self.find_by_fourcc(&[b"RDEF"])? { ChunkData::Rdef(rd) => Some(rd), _ => None, } } } ``` -------------------------------- ### Shader::container Source: https://docs.rs/d3dasm/latest/d3dasm/struct.Shader.html Access to the underlying DxbcContainer for advanced use. ```APIDOC ## container ### Description Access to the underlying `DxbcContainer` for advanced use. ### Method `pub fn container(&self) -> &DxbcContainer<'a>` ### Parameters None. ### Returns - `&DxbcContainer<'a>` - Reference to the underlying container. ``` -------------------------------- ### Shader::output_signature Source: https://docs.rs/d3dasm/latest/d3dasm/struct.Shader.html Returns output signature elements. ```APIDOC ## Shader::output_signature ### Description Returns output signature elements. ### Method output_signature ### Signature pub fn output_signature(&self) -> Option<&Signature<'a>> ### Parameters None ### Returns - **Option<&Signature<'a>>** - The output signature elements, if present. ``` -------------------------------- ### Shader::size Source: https://docs.rs/d3dasm/latest/d3dasm/struct.Shader.html Returns the total size of the DXBC container in bytes. ```APIDOC ## Shader::size ### Description Returns the total size of the DXBC container in bytes. ### Method size ### Signature pub fn size(&self) -> u32 ### Parameters None ### Returns - **u32** - The total size of the DXBC container in bytes. ``` -------------------------------- ### dxbc re-export Source: https://docs.rs/d3dasm/latest/src/d3dasm/lib.rs.html Re-exports the dxbc backend for callers that need lower-level access. ```APIDOC ## dxbc re-export ### Description Re-exports the dxbc backend for callers that need lower-level access. ### Usage ```rust use d3dasm::dxbc; ``` ``` -------------------------------- ### Shader::program Source: https://docs.rs/d3dasm/latest/d3dasm/index.html Provides structured access to the parsed shader program chunk. Returns an optional reference to the program, which is decoded lazily. ```APIDOC ## Shader::program ### Description Provides structured access to the parsed shader program chunk. Returns an optional reference to the program, which is decoded lazily. ### Method Signature `pub fn program(&self) -> Option<&Program>` ### Returns - `Option<&Program>` - The parsed program chunk if available, otherwise `None`. ### Example ```rust if let Some(program) = shader.program() { println!("SM {}.{}", program.version_major, program.version_minor); } ``` ``` -------------------------------- ### parse Source: https://docs.rs/d3dasm/latest/d3dasm/all.html The parse function is a public function in the d3dasm crate. Its purpose and signature are not detailed in the source. ```APIDOC ## parse ### Description The parse function is a public function in the d3dasm crate. ### Type Function ### Parameters No parameters are documented in the source. ### Returns No return type is documented in the source. ``` -------------------------------- ### impl TryInto for T where U: TryFrom Source: https://docs.rs/d3dasm/latest/d3dasm/struct.Shader.html Provides the try_into method to perform a fallible conversion from T to U. ```APIDOC ## impl TryInto for T where U: TryFrom ### Description Performs the conversion from `T` to `U`, returning a `Result`. ### Associated Type - `type Error = >::Error` - The type returned in the event of a conversion error. ### Method `fn try_into(self) -> Result>::Error>` ### Parameters - `self` - The value to convert. ### Returns - `Result>::Error>` - The result of the conversion. ``` -------------------------------- ### impl TryFrom for T where U: Into Source: https://docs.rs/d3dasm/latest/d3dasm/struct.Shader.html Provides the try_from method to perform a fallible conversion from U to T. ```APIDOC ## impl TryFrom for T where U: Into ### Description Performs the conversion from `U` to `T`, returning a `Result`. ### Associated Type - `type Error = !` - The type returned in the event of a conversion error. ### Method `fn try_from(value: U) -> Result` ### Parameters - `value: U` - The value to convert. ### Returns - `Result` - The result of the conversion. ``` -------------------------------- ### Shader struct Source: https://docs.rs/d3dasm/latest/d3dasm/ A parsed DXBC shader container with typed chunk access and formatting. Provides methods to access shader program information and implements Display for full disassembly. ```APIDOC ## Struct: Shader ### Description A parsed DXBC shader container with typed chunk access and formatting. Provides methods to access shader program information and implements Display for full disassembly. ### Methods #### program() Returns the shader program chunk if available. **Returns** - `Option` - The shader program chunk, or `None` if not present. **Example** ```rust if let Some(program) = shader.program() { println!("SM {}.{}", program.version_major, program.version_minor); } ``` #### Display implementation Provides full disassembly output when the shader is formatted with `print!` or `format!`. **Example** ```rust print!("{shader}"); ``` ``` -------------------------------- ### parse(data: &[u8]) -> Vec> Source: https://docs.rs/d3dasm/latest/d3dasm/fn.parse.html Parses all DXBC shaders found in a raw byte buffer. Scans for DXBC container headers and parses each one into a Shader. Returns an empty Vec if no containers are found. ```APIDOC ## Function: parse ### Description Parses all DXBC shaders found in a raw byte buffer. Scans for DXBC container headers and parses each one into a `Shader`. Returns an empty `Vec` if no containers are found. ### Signature ```rust pub fn parse(data: &[u8]) -> Vec> ``` ### Parameters - **data** (`&[u8]`) - Required - The raw byte buffer to scan for DXBC shaders. ### Return Value - `Vec>` - A vector of parsed `Shader` objects. Empty if no DXBC containers are found. ### Example ```rust let data = std::fs::read("shader.bin").unwrap(); for shader in d3dasm::parse(&data) { print!("{shader}"); } ``` ``` -------------------------------- ### impl From for T Source: https://docs.rs/d3dasm/latest/d3dasm/struct.Shader.html Provides the from method to convert a value into itself. ```APIDOC ## impl From for T ### Description Provides the `from` method to convert a value into itself. ### Method `fn from(t: T) -> T` ### Parameters - `t: T` - The value to convert. ### Returns - `T` - The value unchanged. ``` -------------------------------- ### Shader::stats Source: https://docs.rs/d3dasm/latest/d3dasm/struct.Shader.html Returns shader statistics (instruction counts, register usage, etc.) if present. ```APIDOC ## stats ### Description Returns shader statistics (instruction counts, register usage, etc.) if present. ### Method `pub fn stats(&self) -> Option<&ShaderStats>` ### Parameters None. ### Returns - `Option<&ShaderStats>` - Shader statistics if available, otherwise `None`. ``` -------------------------------- ### Shader signature accessors: input, output, patch constant Source: https://docs.rs/d3dasm/latest/src/d3dasm/lib.rs.html Provides typed accessors for shader signatures. input_signature returns input signature elements (ISGN/ISG1), output_signature returns output signature elements (OSGN/OSG1/OSG5), patch_constant_signature returns patch constant signature elements (PCSG/PSG1). ```rust impl<'a> Shader<'a> { /// Input signature elements. pub fn input_signature(&self) -> Option<&dxbc::chunks::Signature<'a>> { match self.find_by_fourcc(&[b"ISGN", b"ISG1"])? { ChunkData::InputSignature(s) => Some(s), _ => None, } } /// Output signature elements. pub fn output_signature(&self) -> Option<&dxbc::chunks::Signature<'a>> { match self.find_by_fourcc(&[b"OSGN", b"OSG1", b"OSG5"])? { ChunkData::OutputSignature(s) => Some(s), _ => None, } } /// Patch constant signature elements (hull/domain shaders). pub fn patch_constant_signature(&self) -> Option<&dxbc::chunks::Signature<'a>> { match self.find_by_fourcc(&[b"PCSG", b"PSG1"])? { ChunkData::PatchConstantSignature(s) => Some(s), _ => None, } } } ``` -------------------------------- ### impl ToString for T where T: Display + ?Sized Source: https://docs.rs/d3dasm/latest/d3dasm/struct.Shader.html Provides the to_string method to convert a value to a String. ```APIDOC ## impl ToString for T where T: Display + ?Sized ### Description Converts the given value to a `String`. ### Method `fn to_string(&self) -> String` ### Parameters - `&self` - The value to convert. ### Returns - `String` - The string representation of the value. ``` -------------------------------- ### impl Debug for Shader<'a> Source: https://docs.rs/d3dasm/latest/d3dasm/struct.Shader.html Provides the Debug trait implementation for the Shader struct, allowing it to be formatted using the Debug formatter. ```APIDOC ## impl Debug for Shader<'a> ### Description Provides the Debug trait implementation for the Shader struct, allowing it to be formatted using the Debug formatter. ### Method `fn fmt(&self, f: &mut Formatter<'_>) -> Result` ### Parameters - `&self` - The Shader instance. - `f` (`&mut Formatter<'_>`) - The formatter to write the debug representation to. ### Returns - `Result` - The result of the formatting operation. ``` -------------------------------- ### Shader struct definition and Debug implementation Source: https://docs.rs/d3dasm/latest/src/d3dasm/lib.rs.html Defines the Shader struct with a DxbcContainer and lazily parsed chunks using OnceCell. The Debug implementation shows parsed chunk count and total chunks. ```rust pub struct Shader<'a> { /// The underlying DXBC container (chunk table + raw data). container: DxbcContainer<'a>, /// Lazily parsed chunks, one cell per container chunk index. parsed: Vec>>, } impl fmt::Debug for Shader<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("Shader") .field("container", &self.container) .field( "parsed_count", &self.parsed.iter().filter(|c| c.get().is_some()).count(), ) .field("total_chunks", &self.container.chunks.len()) .finish() } } ``` -------------------------------- ### impl Into for T Source: https://docs.rs/d3dasm/latest/d3dasm/struct.Shader.html Provides the into method to convert a value into another type. ```APIDOC ## impl Into for T ### Description Provides the `into` method to convert a value into another type. ### Method `fn into(self) -> U` ### Parameters - `self` - The value to convert. ### Returns - `U` - The converted value. ``` -------------------------------- ### Shader::root_signature Source: https://docs.rs/d3dasm/latest/d3dasm/struct.Shader.html Returns the D3D12 root signature (RTS0 chunk) if present. ```APIDOC ## root_signature ### Description Returns the D3D12 root signature (RTS0 chunk) if present. ### Method `pub fn root_signature(&self) -> Option<&RootSignature>` ### Parameters None. ### Returns - `Option<&RootSignature>` - Root signature if available, otherwise `None`. ``` -------------------------------- ### Shader::offset Source: https://docs.rs/d3dasm/latest/d3dasm/struct.Shader.html Returns the byte offset of this container in the source file. ```APIDOC ## Shader::offset ### Description Returns the byte offset of this container in the source file. ### Method offset ### Signature pub fn offset(&self) -> usize ### Parameters None ### Returns - **usize** - The byte offset of this container in the source file. ``` -------------------------------- ### Shader::chunks Source: https://docs.rs/d3dasm/latest/d3dasm/struct.Shader.html Iterate over all parsed chunks, parsing any that haven't been yet. ```APIDOC ## chunks ### Description Iterate over all parsed chunks, parsing any that haven't been yet. ### Method `pub fn chunks(&self) -> impl Iterator>` ### Parameters None. ### Returns - `impl Iterator>` - Iterator over chunk data references. ``` -------------------------------- ### impl ToString for T Source: https://docs.rs/d3dasm/latest/d3dasm/struct.Shader.html Provides the to_string method to convert a value to a String. ```APIDOC ## impl ToString for T ### Description Provides the `to_string` method to convert a value to a `String`. ### Method `fn to_string(&self) -> String` ### Parameters - `&self` - The value to convert. ### Returns - `String` - The string representation of the value. ``` -------------------------------- ### impl Borrow for T Source: https://docs.rs/d3dasm/latest/d3dasm/struct.Shader.html Provides the borrow method to immutably borrow from an owned value. ```APIDOC ## impl Borrow for T ### Description Provides the `borrow` method to immutably borrow from an owned value. ### Method `fn borrow(&self) -> &T` ### Parameters - `&self` - The value to borrow from. ### Returns - `&T` - An immutable reference to the value. ``` -------------------------------- ### Shader::patch_constant_signature Source: https://docs.rs/d3dasm/latest/d3dasm/struct.Shader.html Returns patch constant signature elements (hull/domain shaders). ```APIDOC ## Shader::patch_constant_signature ### Description Returns patch constant signature elements (hull/domain shaders). ### Method patch_constant_signature ### Signature pub fn patch_constant_signature(&self) -> Option<&Signature<'a>> ### Parameters None ### Returns - **Option<&Signature<'a>>** - The patch constant signature elements, if present. ``` -------------------------------- ### impl BorrowMut for T Source: https://docs.rs/d3dasm/latest/d3dasm/struct.Shader.html Provides the borrow_mut method to mutably borrow from an owned value. ```APIDOC ## impl BorrowMut for T ### Description Provides the `borrow_mut` method to mutably borrow from an owned value. ### Method `fn borrow_mut(&mut self) -> &mut T` ### Parameters - `&mut self` - The value to mutably borrow from. ### Returns - `&mut T` - A mutable reference to the value. ``` -------------------------------- ### Function signature: pub fn parse(data: &[u8]) -> Vec> Source: https://docs.rs/d3dasm/latest/d3dasm/fn.parse.html Signature of the parse function. It takes a byte slice and returns a vector of Shader references. ```rust pub fn parse(data: &[u8]) -> Vec> ``` -------------------------------- ### Shader::hash Source: https://docs.rs/d3dasm/latest/d3dasm/struct.Shader.html Returns the shader hash (HASH or XHSH chunk) if present. ```APIDOC ## hash ### Description Returns the shader hash (HASH or XHSH chunk) if present. ### Method `pub fn hash(&self) -> Option<&ShaderHash>` ### Parameters None. ### Returns - `Option<&ShaderHash>` - Shader hash if available, otherwise `None`. ``` -------------------------------- ### d3dasm::parse Source: https://docs.rs/d3dasm/latest/d3dasm/index.html Parses all DXBC shaders found in a raw byte buffer. Returns a collection of Shader objects. ```APIDOC ## d3dasm::parse ### Description Parses all DXBC shaders found in a raw byte buffer. Returns a collection of Shader objects. ### Function Signature `pub fn parse(data: &[u8]) -> Vec` ### Parameters - **data** (`&[u8]`) - Required - The raw byte buffer containing DXBC shader data. ### Returns - `Vec` - A vector of parsed Shader objects. ### Example ```rust let data = std::fs::read("shader.bin").unwrap(); let shaders = d3dasm::parse(&data); ``` ``` -------------------------------- ### Shader::debug_name Source: https://docs.rs/d3dasm/latest/d3dasm/struct.Shader.html Returns the debug name (ILDN chunk) if present. ```APIDOC ## debug_name ### Description Returns the debug name (ILDN chunk) if present. ### Method `pub fn debug_name(&self) -> Option<&DebugName>` ### Parameters None. ### Returns - `Option<&DebugName>` - Debug name if available, otherwise `None`. ``` -------------------------------- ### Shader Source: https://docs.rs/d3dasm/latest/d3dasm/all.html The Shader struct represents a shader object in the d3dasm library. It is a public struct that users can instantiate and use. ```APIDOC ## Shader ### Description The Shader struct represents a shader object in the d3dasm library. ### Type Struct ### Fields No fields are documented in the source. ### Methods No methods are documented in the source. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.