Skip to content

Commit d9a6b4f

Browse files
committed
[naga, wgpu-core] Add some docs for Naga validator creation.
1 parent 1c43ac2 commit d9a6b4f

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

naga/src/valid/mod.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,19 @@ impl crate::TypeInner {
459459
}
460460

461461
impl Validator {
462-
/// Construct a new validator instance.
462+
/// Create a validator for Naga [`Module`]s.
463+
///
464+
/// The `flags` argument indicates which stages of validation the
465+
/// returned `Validator` should perform. Skipping stages can make
466+
/// validation somewhat faster, but the validator may not reject some
467+
/// invalid modules. Regardless of `flags`, validation always returns
468+
/// a usable [`ModuleInfo`] value on success.
469+
///
470+
/// If `flags` contains everything in `ValidationFlags::default()`,
471+
/// then the returned Naga [`Validator`] will reject any [`Module`]
472+
/// that would use capabilities not included in `capabilities`.
473+
///
474+
/// [`Module`]: crate::Module
463475
pub fn new(flags: ValidationFlags, capabilities: Capabilities) -> Self {
464476
let subgroup_operations = if capabilities.contains(Capabilities::SUBGROUP) {
465477
use SubgroupOperationSet as S;

wgpu-core/src/device/mod.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,19 @@ impl WebGpuError for MissingDownlevelFlags {
383383
}
384384
}
385385

386-
/// Create a validator with the given validation flags.
386+
/// Create a validator for Naga [`Module`]s.
387+
///
388+
/// Create a Naga [`Validator`] that ensures that each [`naga::Module`]
389+
/// presented to it is valid, and uses no features not included in
390+
/// `features` and `downlevel`.
391+
///
392+
/// The validator can only catch invalid modules and feature misuse
393+
/// reliably when the `flags` argument includes all the flags in
394+
/// [`ValidationFlags::default()`].
395+
///
396+
/// [`Validator`]: naga::valid::Validator
397+
/// [`Module`]: naga::Module
398+
/// [`ValidationFlags::default()`]: naga::valid::ValidationFlags::default
387399
pub fn create_validator(
388400
features: wgt::Features,
389401
downlevel: wgt::DownlevelFlags,

0 commit comments

Comments
 (0)