From d9a6b4fa4a6051ccf169b7ab92ecf0db739b7903 Mon Sep 17 00:00:00 2001 From: Jim Blandy Date: Tue, 22 Jul 2025 15:07:01 -0700 Subject: [PATCH] [naga, wgpu-core] Add some docs for Naga validator creation. --- naga/src/valid/mod.rs | 14 +++++++++++++- wgpu-core/src/device/mod.rs | 14 +++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/naga/src/valid/mod.rs b/naga/src/valid/mod.rs index 6b4b514c6..fe45d3bfb 100644 --- a/naga/src/valid/mod.rs +++ b/naga/src/valid/mod.rs @@ -459,7 +459,19 @@ impl crate::TypeInner { } impl Validator { - /// Construct a new validator instance. + /// Create a validator for Naga [`Module`]s. + /// + /// 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`. + /// + /// [`Module`]: crate::Module pub fn new(flags: ValidationFlags, capabilities: Capabilities) -> Self { let subgroup_operations = if capabilities.contains(Capabilities::SUBGROUP) { use SubgroupOperationSet as S; diff --git a/wgpu-core/src/device/mod.rs b/wgpu-core/src/device/mod.rs index a57714900..0780e7ccf 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -383,7 +383,19 @@ impl WebGpuError for MissingDownlevelFlags { } } -/// Create a validator with the given validation flags. +/// Create a validator for Naga [`Module`]s. +/// +/// Create a Naga [`Validator`] that ensures that each [`naga::Module`] +/// presented to it is valid, and uses no features not included in +/// `features` and `downlevel`. +/// +/// The validator can only catch invalid modules and feature misuse +/// reliably when the `flags` argument includes all the flags in +/// [`ValidationFlags::default()`]. +/// +/// [`Validator`]: naga::valid::Validator +/// [`Module`]: naga::Module +/// [`ValidationFlags::default()`]: naga::valid::ValidationFlags::default pub fn create_validator( features: wgt::Features, downlevel: wgt::DownlevelFlags,