Skip to main content

Reflector

Struct Reflector 

Source
pub struct Reflector<'a> { /* private fields */ }
Expand description

Reflects SPIR-V code through a module.

§Example

use nox_spirv::op;
use nox_spirv::Module;
use nox_spirv::reflect::{Reflector, ResourceType};
 
let spirv: &[u32] = ...;
let module = Module::new(spirv).unwrap();
let mut reflector = Reflector::new(module).unwrap();
reflector.set_entry_point(c"main", op::ExecutionModel::FRAGMENT).unwrap();
for push_constant in reflector.resources_for_type(ResourceType::PushConstant).unwrap() {
    let push_constant = push_constant.unwrap();
    let size = reflector
        .type_description(push_constant.base_type_id)
        .unwrap().size_hint.declared();
    println!("Push constant (size {size}): {}", push_constant.name.unwrap_or_default());
}

Implementations§

Source§

impl<'a> Reflector<'a>

Source

pub fn new(module: Module<'a>) -> ReflectResult<Reflector<'a>>

Creates a reflector from a module.

Automatically calls parse_full.

Source

pub fn variables(&self) -> impl Iterator<Item = ReflectResult<Variable>>

Returns an iterator over all variables.

Source

pub fn set_entry_point( &mut self, name: &CStr, execution_model: ExecutionModel, ) -> ReflectResult<()>

Sets the entry point to reflect.

This must be set before reflecting any resources.

Source

pub fn spec_constants( &self, ) -> impl Iterator<Item = ReflectResult<SpecConstant>>

Returns an iterator over the statically known values and constant ids of all specialization constants.

Source

pub fn constant(&self, id: Id) -> ReflectResult<Constant<'a>>

Gets a specific constant with id.

Source

pub fn name( &self, id: Id, struct_member: Option<u32>, ) -> ReflectResult<Option<CompilerStr<'a>>>

Returns a name assigned to an Id, or optionally to a struct member of a struct.

Source

pub fn resources_for_type( &self, ty: ResourceType, ) -> ReflectResult<impl Iterator<Item = ReflectResult<Resource<'a>>>>

Returns an iterator over all resources of type.

Entry point must be set before calling this function.

If the SPIR-V version is >= 1.4, the resources are filtered to only include ones used by the current entry point.

Source

pub fn decorations(&self, target_id: Id) -> impl Iterator<Item = Decorate<'a>>

Returns all decorations added to a given Id.

Source

pub fn type_description(&self, id: Id) -> ReflectResult<Type<'a>>

Gets a type description of a given Id pointing to a type.

The description notably contains a hint of its size, which can be resolved to a known size when needed.

Auto Trait Implementations§

§

impl<'a> Freeze for Reflector<'a>

§

impl<'a> RefUnwindSafe for Reflector<'a>

§

impl<'a> Send for Reflector<'a>

§

impl<'a> Sync for Reflector<'a>

§

impl<'a> Unpin for Reflector<'a>

§

impl<'a> UnsafeUnpin for Reflector<'a>

§

impl<'a> UnwindSafe for Reflector<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.