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>
impl CompiledArtifact<Hlsl>
sourcepub fn is_resource_used(
&self,
model: ExecutionModel,
binding: ResourceBinding,
) -> bool
Available on crate feature hlsl only.
pub fn is_resource_used( &self, model: ExecutionModel, binding: ResourceBinding, ) -> bool
hlsl only.Returns whether the set/binding combination provided in Compiler<Hlsl>::add_resource_binding
was used.
source§impl CompiledArtifact<Msl>
impl CompiledArtifact<Msl>
sourcepub fn is_resource_used(
&self,
model: ExecutionModel,
binding: ResourceBinding,
) -> bool
Available on crate feature msl only.
pub fn is_resource_used( &self, model: ExecutionModel, binding: ResourceBinding, ) -> bool
msl only.Returns whether the set/binding combination provided in Compiler<Msl>::add_resource_binding
was used.
sourcepub fn is_shader_input_used(&self, location: u32) -> bool
Available on crate feature msl only.
pub fn is_shader_input_used(&self, location: u32) -> bool
msl only.Returns whether the location provided in Compiler<Msl>::add_shader_input
was used.
sourcepub fn is_shader_output_used(&self, location: u32) -> bool
Available on crate feature msl only.
pub fn is_shader_output_used(&self, location: u32) -> bool
msl only.Returns whether the location provided in Compiler<Msl>::add_shader_output
was used.
sourcepub fn automatic_resource_binding(
&self,
handle: impl Into<Handle<VariableId>>,
tier: AutomaticResourceBindingTier,
) -> Result<Option<u32>, SpirvCrossError>
Available on crate feature msl only.
pub fn automatic_resource_binding( &self, handle: impl Into<Handle<VariableId>>, tier: AutomaticResourceBindingTier, ) -> Result<Option<u32>, SpirvCrossError>
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.
sourcepub fn variable_is_depth_or_compare(
&self,
variable: impl Into<Handle<VariableId>>,
) -> Result<bool, SpirvCrossError>
Available on crate feature msl only.
pub fn variable_is_depth_or_compare( &self, variable: impl Into<Handle<VariableId>>, ) -> Result<bool, SpirvCrossError>
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>>§
sourcepub fn required_extensions(&self) -> GlslExtensionsIter<'_> ⓘ
Available on crate feature glsl only.
pub fn required_extensions(&self) -> GlslExtensionsIter<'_> ⓘ
glsl only.Returns the list of required extensions in a GLSL shader.
If called after compilation this will contain any other extensions that the compiler used automatically, in addition to the user specified ones.
sourcepub fn is_rasterization_disabled(&self) -> bool
Available on crate feature msl only.
pub fn is_rasterization_disabled(&self) -> bool
msl only.Get whether the vertex shader requires rasterization to be disabled.
sourcepub fn buffer_requirements(&self) -> BufferRequirements
Available on crate feature msl only.
pub fn buffer_requirements(&self) -> BufferRequirements
msl only.Get information such as required buffers for the MSL shader
sourcepub fn combined_sampler_suffix(&self) -> CompilerStr<'_>
Available on crate feature msl only.
pub fn combined_sampler_suffix(&self) -> CompilerStr<'_>
msl only.Get the suffix for combined image samplers.
sourcepub unsafe fn create_handle<I>(&self, id: I) -> Handle<I>
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.
sourcepub unsafe fn create_handle_if_not_zero<I: Id>(
&self,
id: I,
) -> Option<Handle<I>>
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.
sourcepub fn handle_is_valid<I>(&self, handle: &Handle<I>) -> bool
pub fn handle_is_valid<I>(&self, handle: &Handle<I>) -> bool
Returns whether the given handle is valid for this compiler instance.
sourcepub fn yield_id<I: Id>(&self, handle: Handle<I>) -> Result<I, SpirvCrossError>
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.
sourcepub fn active_buffer_ranges(
&self,
handle: impl Into<Handle<VariableId>>,
) -> Result<&[BufferRange], SpirvCrossError>
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.
sourcepub fn hlsl_counter_buffer(
&self,
variable: impl Into<Handle<VariableId>>,
) -> Result<Option<Handle<VariableId>>, SpirvCrossError>
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.
sourcepub fn combined_image_samplers(
&self,
) -> Result<CombinedImageSamplerIter<'static>, SpirvCrossError>
pub fn combined_image_samplers( &self, ) -> Result<CombinedImageSamplerIter<'static>, SpirvCrossError>
Gets a remapping for the combined image samplers.
sourcepub fn specialization_constant_scalar<S: ConstantScalar>(
&self,
handle: Handle<ConstantId>,
column: u32,
row: u32,
) -> Result<S, SpirvCrossError>
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.
sourcepub fn specialization_constants(
&self,
) -> Result<SpecializationConstantIter<'static>, SpirvCrossError>
pub fn specialization_constants( &self, ) -> Result<SpecializationConstantIter<'static>, SpirvCrossError>
Query declared specialization constants.
sourcepub fn specialization_sub_constants(
&self,
constant: Handle<ConstantId>,
) -> Result<SpecializationSubConstantIter<'_>, SpirvCrossError>
pub fn specialization_sub_constants( &self, constant: Handle<ConstantId>, ) -> Result<SpecializationSubConstantIter<'_>, SpirvCrossError>
Get subconstants for composite type specialization constants.
sourcepub fn work_group_size_specialization_constants(
&self,
) -> WorkgroupSizeSpecializationConstants
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.
sourcepub fn specialization_constant_type(
&self,
constant: Handle<ConstantId>,
) -> Result<Handle<TypeId>, SpirvCrossError>
pub fn specialization_constant_type( &self, constant: Handle<ConstantId>, ) -> Result<Handle<TypeId>, SpirvCrossError>
Get the type of the specialization constant.
sourcepub fn specialization_constant_value<S: ConstantValue>(
&self,
handle: Handle<ConstantId>,
) -> Result<S, SpirvCrossError>
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.
sourcepub fn decoration<I: Id>(
&self,
id: Handle<I>,
decoration: Decoration,
) -> Result<Option<DecorationValue<'_>>, SpirvCrossError>
pub fn decoration<I: Id>( &self, id: Handle<I>, decoration: Decoration, ) -> Result<Option<DecorationValue<'_>>, SpirvCrossError>
Gets the value for decorations which take arguments.
sourcepub fn member_decoration_by_handle(
&self,
struct_type_id: Handle<TypeId>,
index: u32,
decoration: Decoration,
) -> Result<Option<DecorationValue<'_>>, SpirvCrossError>
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.
sourcepub fn member_decoration(
&self,
member: &StructMember<'_>,
decoration: Decoration,
) -> Result<Option<DecorationValue<'_>>, SpirvCrossError>
pub fn member_decoration( &self, member: &StructMember<'_>, decoration: Decoration, ) -> Result<Option<DecorationValue<'_>>, SpirvCrossError>
Gets the value for member decorations which take arguments.
sourcepub fn binary_offset_for_decoration(
&self,
variable: impl Into<Handle<VariableId>>,
decoration: Decoration,
) -> Result<Option<u32>, SpirvCrossError>
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.
sourcepub fn buffer_block_decorations(
&self,
variable: impl Into<Handle<VariableId>>,
) -> Result<Option<&[Decoration]>, SpirvCrossError>
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.
sourcepub fn declared_capabilities(&self) -> Result<&[Capability], SpirvCrossError>
pub fn declared_capabilities(&self) -> Result<&[Capability], SpirvCrossError>
Gets the list of all SPIR-V Capabilities which were declared in the SPIR-V module.
sourcepub fn declared_extensions(
&self,
) -> Result<ExtensionsIter<'static>, SpirvCrossError>
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.
sourcepub fn execution_model(&self) -> Result<ExecutionModel, SpirvCrossError>
pub fn execution_model(&self) -> Result<ExecutionModel, SpirvCrossError>
Get the execution model of the module.
sourcepub fn has_active_builtin(
&self,
builtin: BuiltIn,
storage_class: StorageClass,
proof: ActiveBuiltinsUpdatedProof,
) -> Result<bool, SpirvCrossError>
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.
sourcepub fn entry_points(&self) -> Result<EntryPointIter<'static>, SpirvCrossError>
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.
sourcepub fn cleansed_entry_point_name<'str>(
&self,
name: impl Into<CompilerStr<'str>>,
model: ExecutionModel,
) -> Result<Option<CompilerStr<'static>>, SpirvCrossError>
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.
sourcepub fn execution_modes(&self) -> Result<&[ExecutionMode], SpirvCrossError>
pub fn execution_modes(&self) -> Result<&[ExecutionMode], SpirvCrossError>
Query OpExecutionMode.
sourcepub fn execution_mode_arguments(
&self,
mode: ExecutionMode,
) -> Result<Option<ExecutionModeArguments>, SpirvCrossError>
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.
sourcepub fn name<I: Id>(
&self,
handle: Handle<I>,
) -> Result<Option<CompilerStr<'_>>, SpirvCrossError>
pub fn name<I: Id>( &self, handle: Handle<I>, ) -> Result<Option<CompilerStr<'_>>, SpirvCrossError>
Gets the identifier (OpName) of an ID.
sourcepub fn member_name(
&self,
struct_type: Handle<TypeId>,
index: u32,
) -> Result<Option<CompilerStr<'_>>, SpirvCrossError>
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”.
sourcepub fn remapped_declared_block_name(
&self,
handle: impl Into<Handle<VariableId>>,
) -> Result<Option<CompilerStr<'static>>, SpirvCrossError>
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.
sourcepub fn shader_resources(&self) -> Result<ShaderResources, SpirvCrossError>
pub fn shader_resources(&self) -> Result<ShaderResources, SpirvCrossError>
Query shader resources, use ids with reflection interface to modify or query binding points, etc.
sourcepub fn shader_resources_for_active_variables(
&self,
set: InterfaceVariableSet,
) -> Result<ShaderResources, SpirvCrossError>
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.
sourcepub fn active_interface_variables(
&self,
) -> Result<InterfaceVariableSet, SpirvCrossError>
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.
sourcepub fn type_description(
&self,
id: Handle<TypeId>,
) -> Result<Type<'_>, SpirvCrossError>
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.
sourcepub fn variable_type(
&self,
variable: impl Into<Handle<VariableId>>,
) -> Result<Handle<TypeId>, SpirvCrossError>
pub fn variable_type( &self, variable: impl Into<Handle<VariableId>>, ) -> Result<Handle<TypeId>, SpirvCrossError>
Get the underlying type of the variable.