Struct CompiledArtifact

Source
pub struct CompiledArtifact<T> { /* private fields */ }
Expand description

The output of a SPIRV-Cross compilation.

CompiledArtifact implements Display with the value of the compiled source code.

Reflection is still available, but the Compiler instance can no longer be mutated once compiled.

Implementations§

Source§

impl CompiledArtifact<Hlsl>

Source

pub fn is_resource_used( &self, model: ExecutionModel, binding: ResourceBinding, ) -> bool

Available on crate feature hlsl only.

Returns whether the set/binding combination provided in Compiler<Hlsl>::add_resource_binding was used.

Source§

impl CompiledArtifact<Msl>

Source

pub fn is_resource_used( &self, model: ExecutionModel, binding: ResourceBinding, ) -> bool

Available on crate feature msl only.

Returns whether the set/binding combination provided in Compiler<Msl>::add_resource_binding was used.

Source

pub fn is_shader_input_used(&self, location: u32) -> bool

Available on crate feature msl only.

Returns whether the location provided in Compiler<Msl>::add_shader_input was used.

Source

pub fn is_shader_output_used(&self, location: u32) -> bool

Available on crate feature msl only.

Returns whether the location provided in Compiler<Msl>::add_shader_output was used.

Source

pub fn automatic_resource_binding( &self, handle: impl Into<Handle<VariableId>>, tier: AutomaticResourceBindingTier, ) -> Result<Option<u32>, SpirvCrossError>

Available on crate feature msl only.

For a variable resource ID, report the automatically assigned resource index.

If the descriptor set was part of an argument buffer, report the [[id(N)]], or [[buffer/texture/sampler]] binding for other resources.

If the resource was a combined image sampler, report the image binding for AutomaticResourceBindingTier::Primary, or the sampler half for AutomaticResourceBindingTier::Secondary.

If no binding exists, None is returned.

Source

pub fn variable_is_depth_or_compare( &self, variable: impl Into<Handle<VariableId>>, ) -> Result<bool, SpirvCrossError>

Available on crate feature msl only.

Query if a variable ID was used as a depth resource.

This is meaningful for MSL since descriptor types depend on this knowledge. Cases which return true:

  • Images which are declared with depth = 1 image type.
  • Samplers which are statically used at least once with Dref opcodes.
  • Images which are statically used at least once with Dref opcodes.

Methods from Deref<Target = Compiler<T>>§

Source

pub unsafe fn create_handle<I>(&self, id: I) -> Handle<I>

Create a handle for the given ID tagged with this compiler instance.

§Safety

When creating a handle, the ID must be valid for the compilation.

Source

pub unsafe fn create_handle_if_not_zero<I: Id>( &self, id: I, ) -> Option<Handle<I>>

Create a handle for the given ID tagged with this compiler instance, if the provided ID is not zero.

§Safety

When creating a handle, the ID must be valid for the compilation.

Source

pub fn handle_is_valid<I>(&self, handle: &Handle<I>) -> bool

Returns whether the given handle is valid for this compiler instance.

Source

pub fn yield_id<I: Id>(&self, handle: Handle<I>) -> Result<I, SpirvCrossError>

Yield the value of the handle, if it originated from the same compiler instance, otherwise return SpirvCrossError::InvalidHandle.

Source

pub fn active_buffer_ranges( &self, handle: impl Into<Handle<VariableId>>, ) -> Result<&[BufferRange], SpirvCrossError>

Returns a list of which members of a struct are potentially in use by a SPIR-V shader. The granularity of this analysis is per-member of a struct. This can be used for Buffer (UBO), BufferBlock/StorageBuffer (SSBO) and PushConstant blocks.

Source

pub fn hlsl_counter_buffer( &self, variable: impl Into<Handle<VariableId>>, ) -> Result<Option<Handle<VariableId>>, SpirvCrossError>

Queries if a buffer object has a neighbor “counter” buffer. If so, the ID of that counter buffer will be returned.

If SPV_GOOGLE_hlsl_functionality is used, this can be used even with a stripped SPIR-V module. Otherwise, this query is purely based on OpName identifiers as found in the SPIR-V module, and will only return true if OpSource was reported HLSL. To rely on this functionality, ensure that the SPIR-V module is not stripped.

Source

pub fn combined_image_samplers( &self, ) -> Result<CombinedImageSamplerIter<'static>, SpirvCrossError>

Gets a remapping for the combined image samplers.

Source

pub fn specialization_constant_scalar<S: ConstantScalar>( &self, handle: Handle<ConstantId>, column: u32, row: u32, ) -> Result<S, SpirvCrossError>

Get the value of the specialization value at the given column and row.

The type is inferred from the return value, and is not type-checked against the input SPIR-V.

If the inferred type differs from what is expected, an indeterminate but initialized value will be returned.

Compiler::specialization_constant_value is more efficient and easier to use in most cases, which will handle row and column for vector and matrix scalars. This function remains to deal with more esoteric matrix shapes, or for getting only a single element of a vector or matrix.

Source

pub fn specialization_constants( &self, ) -> Result<SpecializationConstantIter<'static>, SpirvCrossError>

Query declared specialization constants.

Source

pub fn specialization_sub_constants( &self, constant: Handle<ConstantId>, ) -> Result<SpecializationSubConstantIter<'_>, SpirvCrossError>

Get subconstants for composite type specialization constants.

Source

pub fn work_group_size_specialization_constants( &self, ) -> WorkgroupSizeSpecializationConstants

In SPIR-V, the compute work group size can be represented by a constant vector, in which case the LocalSize execution mode is ignored.

This constant vector can be a constant vector, specialization constant vector, or partly specialized constant vector. To modify and query work group dimensions which are specialization constants, constant values must be modified directly via Compiler::set_specialization_constant_value rather than using LocalSize directly. This function will return which constants should be modified.

To modify dimensions which are not specialization constants, set_execution_mode should be used directly. Arguments to set_execution_mode which are specialization constants are effectively ignored during compilation. NOTE: This is somewhat different from how SPIR-V works. In SPIR-V, the constant vector will completely replace LocalSize, while in this interface, LocalSize is only ignored for specialization constants.

The specialization constant will be written to x, y and z arguments. If the component is not a specialization constant, a zeroed out struct will be written. The return value is the constant ID of the builtin WorkGroupSize, but this is not expected to be useful for most use cases.

If LocalSizeId is used, there is no uvec3 value representing the workgroup size, so the return value is 0, but x, y and z are written as normal if the components are specialization constants.

Source

pub fn specialization_constant_type( &self, constant: Handle<ConstantId>, ) -> Result<Handle<TypeId>, SpirvCrossError>

Get the type of the specialization constant.

Source

pub fn specialization_constant_value<S: ConstantValue>( &self, handle: Handle<ConstantId>, ) -> Result<S, SpirvCrossError>

Get the value of the specialization value.

The type is inferred from the return value, and is not type-checked against the input SPIR-V.

If the output type dimensions are too large for the constant, SpirvCrossError::IndexOutOfBounds will be returned.

If the inferred type differs from what is expected, an indeterminate but initialized value will be returned.

Source

pub fn decoration<I: Id>( &self, id: Handle<I>, decoration: Decoration, ) -> Result<Option<DecorationValue<'_>>, SpirvCrossError>

Gets the value for decorations which take arguments.

Source

pub fn member_decoration_by_handle( &self, struct_type_id: Handle<TypeId>, index: u32, decoration: Decoration, ) -> Result<Option<DecorationValue<'_>>, SpirvCrossError>

Gets the value for member decorations which take arguments.

Source

pub fn member_decoration( &self, member: &StructMember<'_>, decoration: Decoration, ) -> Result<Option<DecorationValue<'_>>, SpirvCrossError>

Gets the value for member decorations which take arguments.

Source

pub fn binary_offset_for_decoration( &self, variable: impl Into<Handle<VariableId>>, decoration: Decoration, ) -> Result<Option<u32>, SpirvCrossError>

Gets the offset in SPIR-V words (uint32_t) for a decoration which was originally declared in the SPIR-V binary. The offset will point to one or more uint32_t literals which can be modified in-place before using the SPIR-V binary.

Note that adding or removing decorations using the reflection API will not change the behavior of this function. If the decoration was declared, returns an offset into the provided SPIR-V binary buffer, otherwise returns None.

If the decoration does not have any value attached to it (e.g. DecorationRelaxedPrecision), this function will also return None.

Source

pub fn buffer_block_decorations( &self, variable: impl Into<Handle<VariableId>>, ) -> Result<Option<&[Decoration]>, SpirvCrossError>

Get the decorations for a buffer block resource.

If the variable handle is not a handle to with struct base type, returns SpirvCrossError::InvalidArgument.

Source

pub fn declared_capabilities(&self) -> Result<&[Capability], SpirvCrossError>

Gets the list of all SPIR-V Capabilities which were declared in the SPIR-V module.

Source

pub fn declared_extensions( &self, ) -> Result<ExtensionsIter<'static>, SpirvCrossError>

Gets the list of all SPIR-V extensions which were declared in the SPIR-V module.

Source

pub fn execution_model(&self) -> Result<ExecutionModel, SpirvCrossError>

Get the execution model of the module.

Source

pub fn has_active_builtin( &self, builtin: BuiltIn, storage_class: StorageClass, proof: ActiveBuiltinsUpdatedProof, ) -> Result<bool, SpirvCrossError>

Return whether the builtin is used or not.

Requires Compiler::update_active_builtins to be called first, proof of which is required to call this function.

Source

pub fn entry_points(&self) -> Result<EntryPointIter<'static>, SpirvCrossError>

All operations work on the current entry point.

Entry points can be swapped out with Compiler::set_entry_point.

Entry points should be set right after creating the compiler as some reflection functions traverse the graph from the entry point.

Resource reflection also depends on the entry point. By default, the current entry point is set to the first OpEntryPoint which appears in the SPIR-V module. Some shader languages restrict the names that can be given to entry points, and the corresponding backend will automatically rename an entry point name when compiling, if it is illegal.

For example, the common entry point name main() is illegal in MSL, and is renamed to an alternate name by the MSL backend.

Given the original entry point name contained in the SPIR-V, this function returns the name, as updated by the backend, if called after compilation.

If the name is not illegal, and has not been renamed this function will simply return the original name.

Source

pub fn cleansed_entry_point_name<'str>( &self, name: impl Into<CompilerStr<'str>>, model: ExecutionModel, ) -> Result<Option<CompilerStr<'static>>, SpirvCrossError>

Get the cleansed name of the entry point for the given original name.

Source

pub fn execution_modes(&self) -> Result<&[ExecutionMode], SpirvCrossError>

Query OpExecutionMode.

Source

pub fn execution_mode_arguments( &self, mode: ExecutionMode, ) -> Result<Option<ExecutionModeArguments>, SpirvCrossError>

Get arguments used by the execution mode.

If the execution mode is unused, returns None.

LocalSizeId query returns an ID. If LocalSizeId execution mode is not used, it returns None. LocalSize always returns a literal. If execution mode is LocalSizeId, the literal (spec constant or not) is still returned.

Source

pub fn name<I: Id>( &self, handle: Handle<I>, ) -> Result<Option<CompilerStr<'_>>, SpirvCrossError>

Gets the identifier (OpName) of an ID.

Source

pub fn member_name( &self, struct_type: Handle<TypeId>, index: u32, ) -> Result<Option<CompilerStr<'_>>, SpirvCrossError>

Given a struct type ID, obtain the identifier for member number “index”.

Source

pub fn remapped_declared_block_name( &self, handle: impl Into<Handle<VariableId>>, ) -> Result<Option<CompilerStr<'static>>, SpirvCrossError>

When declaring buffer blocks in GLSL, the name declared in the GLSL source might not be the same as the name declared in the SPIR-V module due to naming conflicts. In this case, SPIRV-Cross needs to find a fallback-name, and it might only be possible to know this name after compiling to GLSL.

This is particularly important for HLSL input and UAVs which tends to reuse the same block type for multiple distinct blocks. For these cases it is not possible to modify the name of the type itself because it might be unique. Instead, you can use this interface to check after compilation which name was actually used if your input SPIR-V tends to have this problem.

For other names like remapped names for variables, etc., it’s generally enough to query the name of the variables after compiling, block names are an exception to this rule. handle should be a handle to a variable with a Block-like type.

This also applies to HLSL cbuffers.

Source

pub fn shader_resources(&self) -> Result<ShaderResources, SpirvCrossError>

Query shader resources, use ids with reflection interface to modify or query binding points, etc.

Source

pub fn shader_resources_for_active_variables( &self, set: InterfaceVariableSet, ) -> Result<ShaderResources, SpirvCrossError>

Query shader resources, but only return the variables which are part of active_variables. E.g.: get_shader_resources(get_active_variables()) to only return the variables which are statically accessed.

Source

pub fn active_interface_variables( &self, ) -> Result<InterfaceVariableSet, SpirvCrossError>

Returns a set of all global variables which are statically accessed by the control flow graph from the current entry point. Only variables which change the interface for a shader are returned, that is, variables with storage class of Input, Output, Uniform, UniformConstant, PushConstant and AtomicCounter storage classes are returned.

To use the returned set as the filter for which variables are used during compilation, this set can be moved to set_enabled_interface_variables().

The return object is opaque to Rust, but its contents inspected by using InterfaceVariableSet::to_handles. There is no way to modify the contents or use your own InterfaceVariableSet.

Source

pub fn type_description( &self, id: Handle<TypeId>, ) -> Result<Type<'_>, SpirvCrossError>

Get the type description for the given type ID.

In most cases, a base_type_id should be passed in unless pointer specifics are desired.

Atomics are represented as TypeInner::Pointer { storage: StorageClass::AtomicCounter, ... }, usually with a scalar base type.

Source

pub fn variable_type( &self, variable: impl Into<Handle<VariableId>>, ) -> Result<Handle<TypeId>, SpirvCrossError>

Get the underlying type of the variable.

Trait Implementations§

Source§

impl<T> AsRef<str> for CompiledArtifact<T>

Source§

fn as_ref(&self) -> &str

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<'a, T> Deref for CompiledArtifact<T>

Source§

type Target = Compiler<T>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<T> Display for CompiledArtifact<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for CompiledArtifact<T>

§

impl<T> RefUnwindSafe for CompiledArtifact<T>
where T: RefUnwindSafe,

§

impl<T> Send for CompiledArtifact<T>
where T: Send,

§

impl<T> !Sync for CompiledArtifact<T>

§

impl<T> Unpin for CompiledArtifact<T>
where T: Unpin,

§

impl<T> UnwindSafe for CompiledArtifact<T>
where T: UnwindSafe,

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.