#[repr(transparent)]
pub struct FunctionReflection<'r> { /* private fields */ }
Expand description

[docs.microsoft.com] ID3D11FunctionReflection

A function-reflection interface accesses function info.

Example

let d3dc = d3d::Compiler::load_system(47).unwrap();
let shader = d3dc.compile_from_file(
    r"test\data\library.hlsl", None, None, (), "lib_5_0",
    d3d::Compile::Debug, d3d::CompileEffect::None
).unwrap();
let lib : d3d11::LibraryReflection = d3dc.reflect_library(&shader).unwrap();

let scale4 : d3d11::FunctionReflection = lib.functions().unwrap().find(|f|
    f.get_desc().unwrap().name.to_bytes() == b"scale4"
).unwrap();

See Also

Implementations

Allow access as a raw winapi pointer type.

[docs.microsoft.com] ID3D11FunctionReflection::GetConstantBufferByIndex

Gets a constant buffer by index for a function.

Example
let valid = scale4.get_constant_buffer_by_index(0);
println!("{:#?}", valid.get_desc().unwrap());

let invalid = scale4.get_constant_buffer_by_index(1);
assert_eq!(Some(E::FAIL), invalid.get_desc().err().map(|e| e.kind()));
Output
ShaderBufferDesc {
    name: Some(
        "ExampleCBuffer",
    ),
    type: CT::CBuffer,
    variables: 1,
    size: 16,
    flags: CBF::None,
}

[docs.microsoft.com] ID3D11FunctionReflection::GetConstantBufferByName

Gets a constant buffer by name for a function.

Example
let valid = scale4.get_constant_buffer_by_name("ExampleCBuffer");
println!("{:#?}", valid.get_desc().unwrap());

let invalid = scale4.get_constant_buffer_by_name("Nonexistant");
assert_eq!(Some(E::FAIL), invalid.get_desc().err().map(|e| e.kind()));

let invalid = scale4.get_constant_buffer_by_name("Non\0existant");
assert_eq!(Some(E::FAIL), invalid.get_desc().err().map(|e| e.kind()));
Output
ShaderBufferDesc {
    name: Some(
        "ExampleCBuffer",
    ),
    type: CT::CBuffer,
    variables: 1,
    size: 16,
    flags: CBF::None,
}

[docs.microsoft.com] ID3D11FunctionReflection::GetDesc

Fills the function descriptor structure for the function.

Example
println!("{:#?}", scale4.get_desc().unwrap());
Output
FunctionDesc {
    version: 4293918800,
    creator: "Microsoft (R) HLSL Shader Compiler 10.1",
    flags: Compile::{Debug|NoPreshader},
    constant_buffers: 1,
    bound_resources: 1,
    instruction_count: 2,
    ...,
    name: "scale4",
    function_parameter_count: 1,
    has_return: true,
    has_10_level_9_vertex_shader: false,
    has_10_level_9_pixel_shader: false,
}

[docs.microsoft.com] ID3D11FunctionReflection::GetFunctionParameter

Gets the function parameter reflector.

Arguments
  • parameter_index - A 0-based parameter index less than self.get_desc().unwrap().function_parameter_count, or -1 to get the return value “parameter”.
Returns
Example
let ret = scale4.get_function_parameter(-1).get_desc().unwrap();
assert_eq!(ret.name.as_ref().unwrap().to_bytes(),   b"scale4");
assert_eq!(ret.ty,      d3d::SVT::Float);
assert_eq!(ret.class,   d3d::SVC::Vector);
assert_eq!(ret.rows,    1);
assert_eq!(ret.columns, 4);
println!("{:#?}", ret);

let v = scale4.get_function_parameter( 0).get_desc().unwrap();
assert_eq!(v.name.as_ref().unwrap().to_bytes(),   b"v");
assert_eq!(v.ty,        d3d::SVT::Float);
assert_eq!(v.class,     d3d::SVC::Vector);
assert_eq!(v.rows,      1);
assert_eq!(v.columns,   4);
println!("{:#?}", v);

assert_eq!(E::FAIL, scale4.get_function_parameter(-2).get_desc().unwrap_err().kind());
assert_eq!(E::FAIL, scale4.get_function_parameter( 1).get_desc().unwrap_err().kind());
Output
ParameterDesc {
    name: Some(
        "scale4",
    ),
    semantic_name: None,
    ty: SVT::Float,
    class: SVC::Vector,
    rows: 1,
    columns: 4,
    interpolation_mode: Interpolation::Undefined,
    flags: PF::Out,
    first_in_register: 4294967295,
    first_in_component: 4294967295,
    first_out_register: 0,
    first_out_component: 0,
}
ParameterDesc {
    name: Some(
        "v",
    ),
    semantic_name: None,
    ty: SVT::Float,
    class: SVC::Vector,
    rows: 1,
    columns: 4,
    interpolation_mode: Interpolation::Undefined,
    flags: PF::In,
    first_in_register: 0,
    first_in_component: 0,
    first_out_register: 4294967295,
    first_out_component: 4294967295,
}

[docs.microsoft.com] ID3D11FunctionReflection::GetResourceBindingDesc

Gets a description of how a resource is bound to a function.

Errors
  • E::INVALIDARG - If resource_index >= self.get_desc().unwrap().bound_resources
Example
for i in 0..scale4.get_desc().unwrap().bound_resources {
    println!("{:#?}", scale4.get_resource_binding_desc(i).unwrap());
}

// out of bounds
assert_eq!(
    scale4.get_resource_binding_desc(100).err().map(|err| err.kind()),
    Some(E::INVALIDARG)
);
Output
ShaderInputBindDesc {
    name: "ExampleCBuffer",
    ty: SIT::CBuffer,
    bind_point: 0,
    bind_count: 1,
    flags: SIF::None,
    return_type: ReturnType(0),
    dimension: SrvDimension::Unknown,
    num_samples: 0,
}

[docs.microsoft.com] ID3D11FunctionReflection::GetResourceBindingDescByName

Gets a description of how a resource is bound to a function.

Errors
Example
println!("{:#?}", scale4.get_resource_binding_desc_by_name("ExampleCBuffer").unwrap());

assert_eq!(
    scale4.get_resource_binding_desc_by_name("Nonexistant").err().map(|err| err.kind()),
    Some(E::INVALIDARG)
);

assert_eq!(
    scale4.get_resource_binding_desc_by_name("Non\0existant").err().map(|err| err.kind()),
    Some(E::INVALIDARG)
);
Output
ShaderInputBindDesc {
    name: "ExampleCBuffer",
    ty: SIT::CBuffer,
    bind_point: 0,
    bind_count: 1,
    flags: SIF::None,
    return_type: ReturnType(0),
    dimension: SrvDimension::Unknown,
    num_samples: 0,
}

[docs.microsoft.com] ID3D11FunctionReflection::GetVariableByName

Gets a variable by name.

Example
println!("{:#?}", scale4.get_variable_by_name("scale").get_desc().unwrap());

assert_eq!(
    scale4.get_variable_by_name("v").get_desc().err().map(|err| err.kind()),
    Some(E::FAIL) // parameter vars don't count
);

assert_eq!(
    scale4.get_variable_by_name("\0").get_desc().err().map(|err| err.kind()),
    Some(E::FAIL)
);
Output
ShaderVariableDesc {
    name: "scale",
    start_offset: 0,
    size: 4,
    flags: SVF::Used,
    default_value: 0x0000000000000000,
    start_texture: 4294967295,
    texture_size: 0,
    start_sampler: 4294967295,
    sampler_size: 0,
}

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.