pub struct Validator {Show 15 fields
flags: ValidationFlags,
capabilities: Capabilities,
subgroup_stages: ShaderStages,
subgroup_operations: SubgroupOperationSet,
types: Vec<TypeInfo>,
layouter: Layouter,
location_mask: BitSet,
blend_src_mask: BitSet,
ep_resource_bindings: FastHashSet<ResourceBinding>,
switch_values: FastHashSet<SwitchValue>,
valid_expression_list: Vec<Handle<Expression>>,
valid_expression_set: HandleSet<Expression>,
override_ids: FastHashSet<u16>,
overrides_resolved: bool,
needs_visit: HandleSet<Expression>,
}Fields§
§flags: ValidationFlags§capabilities: Capabilities§subgroup_stages: ShaderStages§subgroup_operations: SubgroupOperationSet§types: Vec<TypeInfo>§layouter: Layouter§location_mask: BitSet§blend_src_mask: BitSet§ep_resource_bindings: FastHashSet<ResourceBinding>§switch_values: FastHashSet<SwitchValue>§valid_expression_list: Vec<Handle<Expression>>§valid_expression_set: HandleSet<Expression>§override_ids: FastHashSet<u16>§overrides_resolved: boolTreat overrides whose initializers are not fully-evaluated constant expressions as errors.
needs_visit: HandleSet<Expression>A checklist of expressions that must be visited by a specific kind of statement.
For example:
CallResultexpressions must be visited by aCallstatement.AtomicResultexpressions must be visited by anAtomicstatement.
Be sure not to remove any Expression handle from this set unless
you’ve explicitly checked that it is the right kind of expression for
the visiting Statement.
Implementations§
Source§impl Validator
impl Validator
pub(super) fn validate_const_expression( &self, handle: Handle<Expression>, gctx: GlobalCtx<'_>, mod_info: &ModuleInfo, global_expr_kind: &ExpressionKindTracker, ) -> Result<(), ConstExpressionError>
pub(super) fn validate_expression( &self, root: Handle<Expression>, expression: &Expression, function: &Function, module: &Module, info: &FunctionInfo, mod_info: &ModuleInfo, expr_kind: &ExpressionKindTracker, ) -> Result<ShaderStages, ExpressionError>
fn global_var_ty( module: &Module, function: &Function, expr: Handle<Expression>, ) -> Result<Handle<Type>, ExpressionError>
pub fn validate_literal(&self, literal: Literal) -> Result<(), LiteralError>
Source§impl Validator
impl Validator
fn validate_call( &mut self, function: Handle<Function>, arguments: &[Handle<Expression>], result: Option<Handle<Expression>>, context: &BlockContext<'_>, ) -> Result<ShaderStages, WithSpan<CallError>>
fn emit_expression( &mut self, handle: Handle<Expression>, context: &BlockContext<'_>, ) -> Result<(), WithSpan<FunctionError>>
fn validate_atomic( &mut self, pointer: Handle<Expression>, fun: &AtomicFunction, value: Handle<Expression>, result: Option<Handle<Expression>>, span: Span, context: &BlockContext<'_>, ) -> Result<(), WithSpan<FunctionError>>
fn validate_subgroup_operation( &mut self, op: &SubgroupOperation, collective_op: &CollectiveOperation, argument: Handle<Expression>, result: Handle<Expression>, context: &BlockContext<'_>, ) -> Result<(), WithSpan<FunctionError>>
fn validate_subgroup_gather( &mut self, mode: &GatherMode, argument: Handle<Expression>, result: Handle<Expression>, context: &BlockContext<'_>, ) -> Result<(), WithSpan<FunctionError>>
fn validate_block_impl( &mut self, statements: &Block, context: &BlockContext<'_>, ) -> Result<BlockInfo, WithSpan<FunctionError>>
fn validate_block( &mut self, statements: &Block, context: &BlockContext<'_>, ) -> Result<BlockInfo, WithSpan<FunctionError>>
fn validate_local_var( &self, var: &LocalVariable, gctx: GlobalCtx<'_>, fun_info: &FunctionInfo, local_expr_kind: &ExpressionKindTracker, ) -> Result<(), LocalVariableError>
pub(super) fn validate_function( &mut self, fun: &Function, module: &Module, mod_info: &ModuleInfo, entry_point: bool, ) -> Result<FunctionInfo, WithSpan<FunctionError>>
Source§impl Validator
impl Validator
Sourcepub(super) fn validate_module_handles(
module: &Module,
) -> Result<(), ValidationError>
pub(super) fn validate_module_handles( module: &Module, ) -> Result<(), ValidationError>
Validates that all handles within module are:
- Valid, in the sense that they contain indices within each arena structure inside the
crate::Moduletype. - No arena contents contain any items that have forward dependencies; that is, the value associated with a handle only may contain references to handles in the same arena that were constructed before it.
By validating the above conditions, we free up subsequent logic to assume that handle accesses are infallible.
§Errors
Errors returned by this method are intentionally sparse, for simplicity of implementation. It is expected that only buggy frontends or fuzzers should ever emit IR that fails this validation pass.
fn validate_type_handle( handle: Handle<Type>, types: &UniqueArena<Type>, ) -> Result<(), InvalidHandleError>
fn validate_constant_handle( handle: Handle<Constant>, constants: &Arena<Constant>, ) -> Result<(), InvalidHandleError>
fn validate_global_variable_handle( handle: Handle<GlobalVariable>, global_variables: &Arena<GlobalVariable>, ) -> Result<(), InvalidHandleError>
fn validate_override_handle( handle: Handle<Override>, overrides: &Arena<Override>, ) -> Result<(), InvalidHandleError>
fn validate_expression_handle( handle: Handle<Expression>, expressions: &Arena<Expression>, ) -> Result<(), InvalidHandleError>
fn validate_function_handle( handle: Handle<Function>, functions: &Arena<Function>, ) -> Result<(), InvalidHandleError>
Sourcefn validate_type_handles(
(handle, ty): (Handle<Type>, &Type),
overrides: &Arena<Override>,
) -> Result<Option<Handle<Expression>>, InvalidHandleError>
fn validate_type_handles( (handle, ty): (Handle<Type>, &Type), overrides: &Arena<Override>, ) -> Result<Option<Handle<Expression>>, InvalidHandleError>
Validate all handles that occur in ty, whose handle is handle.
If ty refers to any expressions, return the highest-indexed expression
handle that it uses. This is used for detecting cycles between the
expression and type arenas.
fn validate_entry_point_index( entry_point_index: usize, entry_points: &[EntryPoint], ) -> Result<(), InvalidHandleError>
Sourcefn validate_const_expression_handles(
(handle, expression): (Handle<Expression>, &Expression),
constants: &Arena<Constant>,
overrides: &Arena<Override>,
) -> Result<Option<Handle<Type>>, InvalidHandleError>
fn validate_const_expression_handles( (handle, expression): (Handle<Expression>, &Expression), constants: &Arena<Constant>, overrides: &Arena<Override>, ) -> Result<Option<Handle<Type>>, InvalidHandleError>
Validate all handles that occur in expression, whose handle is handle.
If expression refers to any Types, return the highest-indexed type
handle that it uses. This is used for detecting cycles between the
expression and type arenas.
fn validate_expression_handles( (handle, expression): (Handle<Expression>, &Expression), constants: &Arena<Constant>, overrides: &Arena<Override>, types: &UniqueArena<Type>, local_variables: &Arena<LocalVariable>, global_variables: &Arena<GlobalVariable>, functions: &Arena<Function>, current_function: Option<Handle<Function>>, ) -> Result<(), InvalidHandleError>
fn validate_block_handles( block: &Block, expressions: &Arena<Expression>, functions: &Arena<Function>, ) -> Result<(), InvalidHandleError>
Source§impl Validator
impl Validator
pub(super) fn validate_global_var( &self, var: &GlobalVariable, gctx: GlobalCtx<'_>, mod_info: &ModuleInfo, global_expr_kind: &ExpressionKindTracker, ) -> Result<(), GlobalVariableError>
Sourcefn validate_mesh_output_type(
&mut self,
ep: &EntryPoint,
module: &Module,
ty: Handle<Type>,
mesh_output_type: MeshOutputType,
) -> Result<(), WithSpan<EntryPointError>>
fn validate_mesh_output_type( &mut self, ep: &EntryPoint, module: &Module, ty: Handle<Type>, mesh_output_type: MeshOutputType, ) -> Result<(), WithSpan<EntryPointError>>
Validate the mesh shader output type ty, used as mesh_output_type.
pub(super) fn validate_entry_point( &mut self, ep: &EntryPoint, module: &Module, mod_info: &ModuleInfo, ) -> Result<FunctionInfo, WithSpan<EntryPointError>>
Source§impl Validator
impl Validator
const fn require_type_capability( &self, capability: Capabilities, ) -> Result<(), TypeError>
Sourcepub(super) const fn check_width(
&self,
scalar: Scalar,
) -> Result<Result<(), PushConstantError>, WidthError>
pub(super) const fn check_width( &self, scalar: Scalar, ) -> Result<Result<(), PushConstantError>, WidthError>
Check whether scalar is a permitted scalar width.
If scalar is not a width allowed by the selected Capabilities,
return an error explaining why.
If scalar is allowed, return a PushConstantCompatibility result
that says whether scalar is allowed specifically in push constants.
pub(super) fn reset_types(&mut self, size: usize)
pub(super) fn validate_type( &self, handle: Handle<Type>, gctx: GlobalCtx<'_>, ) -> Result<TypeInfo, TypeError>
Source§impl Validator
impl Validator
Sourcepub fn new(flags: ValidationFlags, capabilities: Capabilities) -> Self
pub fn new(flags: ValidationFlags, capabilities: Capabilities) -> Self
Create a validator for Naga Modules.
The flags argument indicates which stages of validation the
returned Validator should perform. Skipping stages can make
validation somewhat faster, but the validator may not reject some
invalid modules. Regardless of flags, validation always returns
a usable ModuleInfo value on success.
If flags contains everything in ValidationFlags::default(),
then the returned Naga Validator will reject any Module
that would use capabilities not included in capabilities.
pub fn subgroup_stages(&mut self, stages: ShaderStages) -> &mut Self
pub fn subgroup_operations( &mut self, operations: SubgroupOperationSet, ) -> &mut Self
fn validate_constant( &self, handle: Handle<Constant>, gctx: GlobalCtx<'_>, mod_info: &ModuleInfo, global_expr_kind: &ExpressionKindTracker, ) -> Result<(), ConstantError>
fn validate_override( &mut self, handle: Handle<Override>, gctx: GlobalCtx<'_>, mod_info: &ModuleInfo, ) -> Result<(), OverrideError>
Sourcepub fn validate(
&mut self,
module: &Module,
) -> Result<ModuleInfo, WithSpan<ValidationError>>
pub fn validate( &mut self, module: &Module, ) -> Result<ModuleInfo, WithSpan<ValidationError>>
Check the given module to be valid.
Sourcepub fn validate_resolved_overrides(
&mut self,
module: &Module,
) -> Result<ModuleInfo, WithSpan<ValidationError>>
pub fn validate_resolved_overrides( &mut self, module: &Module, ) -> Result<ModuleInfo, WithSpan<ValidationError>>
Check the given module to be valid, requiring overrides to be resolved.
This is the same as validate, except that any override
whose value is not a fully-evaluated constant expression is
treated as an error.