From cc3a8ac73773e2223c3d45fbc1b22607026e2ec0 Mon Sep 17 00:00:00 2001 From: teoxoy <28601907+teoxoy@users.noreply.github.com> Date: Thu, 16 Feb 2023 21:44:29 +0100 Subject: [PATCH] add `Capabilities::MULTISAMPLED_SHADING` --- benches/criterion.rs | 2 +- fuzz/fuzz_targets/ir.rs | 2 +- src/valid/interface.rs | 9 +++++++++ src/valid/mod.rs | 9 ++++++++- tests/snapshots.rs | 4 ++-- tests/wgsl-errors.rs | 2 +- 6 files changed, 22 insertions(+), 6 deletions(-) diff --git a/benches/criterion.rs b/benches/criterion.rs index ad00cb59e9..624744555f 100644 --- a/benches/criterion.rs +++ b/benches/criterion.rs @@ -149,7 +149,7 @@ fn backends(c: &mut Criterion) { let inputs = { let mut validator = naga::valid::Validator::new( naga::valid::ValidationFlags::empty(), - naga::valid::Capabilities::empty(), + naga::valid::Capabilities::default(), ); let input_modules = gather_modules(); input_modules diff --git a/fuzz/fuzz_targets/ir.rs b/fuzz/fuzz_targets/ir.rs index 86b7a6aa6e..ae1d907474 100644 --- a/fuzz/fuzz_targets/ir.rs +++ b/fuzz/fuzz_targets/ir.rs @@ -5,6 +5,6 @@ fuzz_target!(|module: naga::Module| { use naga::valid as v; // Check if the module validates without errors. //TODO: may also fuzz the flags and capabilities - let mut validator = v::Validator::new(v::ValidationFlags::all(), v::Capabilities::empty()); + let mut validator = v::Validator::new(v::ValidationFlags::all(), v::Capabilities::default()); let _result = validator.validate(&module); }); diff --git a/src/valid/interface.rs b/src/valid/interface.rs index 41f2666120..7ba60515c6 100644 --- a/src/valid/interface.rs +++ b/src/valid/interface.rs @@ -141,6 +141,7 @@ impl VaryingContext<'_> { Bi::CullDistance => Capabilities::CULL_DISTANCE, Bi::PrimitiveIndex => Capabilities::PRIMITIVE_INDEX, Bi::ViewIndex => Capabilities::MULTIVIEW, + Bi::SampleIndex => Capabilities::MULTISAMPLED_SHADING, _ => Capabilities::empty(), }; if !self.capabilities.contains(required) { @@ -312,6 +313,14 @@ impl VaryingContext<'_> { // qualifiers, so we won't complain about that here. let _ = sampling; + let required = match sampling { + Some(crate::Sampling::Sample) => Capabilities::MULTISAMPLED_SHADING, + _ => Capabilities::empty(), + }; + if !self.capabilities.contains(required) { + return Err(VaryingError::UnsupportedCapability(required)); + } + match ty_inner.scalar_kind() { Some(crate::ScalarKind::Float) => { if needs_interpolation && interpolation.is_none() { diff --git a/src/valid/mod.rs b/src/valid/mod.rs index ab4d81cb16..9d9c3f8855 100644 --- a/src/valid/mod.rs +++ b/src/valid/mod.rs @@ -84,7 +84,6 @@ impl Default for ValidationFlags { bitflags::bitflags! { /// Allowed IR capabilities. #[must_use] - #[derive(Default)] #[cfg_attr(feature = "serialize", derive(serde::Serialize))] #[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] pub struct Capabilities: u16 { @@ -110,6 +109,14 @@ bitflags::bitflags! { const MULTIVIEW = 0x200; /// Support for `early_depth_test`. const EARLY_DEPTH_TEST = 0x400; + /// Support for [`Builtin::SampleIndex`] and [`Sampling::Sample`]. + const MULTISAMPLED_SHADING = 0x800; + } +} + +impl Default for Capabilities { + fn default() -> Self { + Self::MULTISAMPLED_SHADING } } diff --git a/tests/snapshots.rs b/tests/snapshots.rs index cc2b300558..7fea12200c 100644 --- a/tests/snapshots.rs +++ b/tests/snapshots.rs @@ -98,7 +98,7 @@ fn check_targets(module: &naga::Module, name: &str, targets: Targets) { let capabilities = if params.god_mode { naga::valid::Capabilities::all() } else { - naga::valid::Capabilities::empty() + naga::valid::Capabilities::default() }; let dest = PathBuf::from(root).join(BASE_DIR_OUT); @@ -589,7 +589,7 @@ fn convert_spv(name: &str, adjust_coordinate_space: bool, targets: Targets) { check_targets(&module, name, targets); naga::valid::Validator::new( naga::valid::ValidationFlags::all(), - naga::valid::Capabilities::empty(), + naga::valid::Capabilities::default(), ) .validate(&module) .unwrap(); diff --git a/tests/wgsl-errors.rs b/tests/wgsl-errors.rs index f7c86b403e..d76252ced5 100644 --- a/tests/wgsl-errors.rs +++ b/tests/wgsl-errors.rs @@ -903,7 +903,7 @@ fn validation_error(source: &str) -> Result