diff --git a/Cargo.toml b/Cargo.toml index 4828485..a37a0c8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ prune = [] allow_deprecated = [] [dependencies] -naga = { version = "0.20", features = ["wgsl-in", "wgsl-out"] } +naga = { version = "22.1", features = ["wgsl-in", "wgsl-out"] } tracing = "0.1" regex = "1.8" regex-syntax = "0.8" @@ -31,6 +31,6 @@ once_cell = "1.17.0" indexmap = "2" [dev-dependencies] -wgpu = { version = "0.20", features = ["naga-ir"] } +wgpu = { version = "22", features = ["naga-ir"] } futures-lite = "1" tracing-subscriber = { version = "0.3", features = ["std", "fmt"] } diff --git a/src/compose/error.rs b/src/compose/error.rs index 171e3f3..7a98ed9 100644 --- a/src/compose/error.rs +++ b/src/compose/error.rs @@ -40,9 +40,7 @@ impl ErrSource { let Ok(PreprocessOutput { preprocessed_source: source, .. - }) = composer - .preprocessor - .preprocess(raw_source, defs, composer.validate) + }) = composer.preprocessor.preprocess(raw_source, defs) else { return Default::default(); }; @@ -78,7 +76,7 @@ pub enum ComposerErrorInner { WgslParseError(naga::front::wgsl::ParseError), #[cfg(feature = "glsl")] #[error("{0:?}")] - GlslParseError(naga::front::glsl::ParseError), + GlslParseError(naga::front::glsl::ParseErrors), #[error("naga_oil bug, please file a report: failed to convert imported module IR back into WGSL for use with WGSL shaders: {0}")] WgslBackError(naga::back::wgsl::Error), #[cfg(feature = "glsl")] diff --git a/src/compose/mod.rs b/src/compose/mod.rs index 3046131..af6672f 100644 --- a/src/compose/mod.rs +++ b/src/compose/mod.rs @@ -79,6 +79,7 @@ use indexmap::IndexMap; /// - a module `a` containing a function `f`, /// - a module `b` that imports `a`, and containing an `override a::f` function, /// - a module `c` that imports `a` and `b`, and containing an `override a::f` function, +/// /// then b and c both specify an override for `a::f`. /// the `override fn a::f` declared in module `b` may call to `a::f` within its body. /// the `override fn a::f` declared in module 'c' may call to `a::f` within its body, but the call will be redirected to `b::f`. @@ -126,10 +127,7 @@ use indexmap::IndexMap; /// /// codespan reporting for errors is available using the error `emit_to_string` method. this requires validation to be enabled, which is true by default. `Composer::non_validating()` produces a non-validating composer that is not able to give accurate error reporting. /// -use naga::{ - valid::{Capabilities, ShaderStages}, - EntryPoint, -}; +use naga::EntryPoint; use regex::Regex; use std::collections::{hash_map::Entry, BTreeMap, HashMap, HashSet}; use tracing::{debug, trace}; @@ -321,11 +319,6 @@ pub struct Composer { pub module_sets: HashMap, pub module_index: HashMap, pub capabilities: naga::valid::Capabilities, - /// The shader stages that the subgroup operations are valid for. - /// Used when creating a validator for the module. - /// See https://github.com/gfx-rs/wgpu/blob/d9c054c645af0ea9ef81617c3e762fbf0f3fecda/wgpu-core/src/device/mod.rs#L515 - /// for how to set this for proper subgroup ops support. - pub subgroup_stages: ShaderStages, preprocessor: Preprocessor, check_decoration_regex: Regex, undecorate_regex: Regex, @@ -347,7 +340,6 @@ impl Default for Composer { Self { validate: true, capabilities: Default::default(), - subgroup_stages: ShaderStages::empty(), module_sets: Default::default(), module_index: Default::default(), preprocessor: Preprocessor::default(), @@ -426,19 +418,9 @@ impl Composer { String::from_utf8(data_encoding::BASE32_NOPAD.decode(from.as_bytes()).unwrap()).unwrap() } - /// This creates a validator that properly detects subgroup support. + /// Shorthand for creating a naga validator. fn create_validator(&self) -> naga::valid::Validator { - let subgroup_operations = if self.capabilities.contains(Capabilities::SUBGROUP) { - use naga::valid::SubgroupOperationSet as S; - S::BASIC | S::VOTE | S::ARITHMETIC | S::BALLOT | S::SHUFFLE | S::SHUFFLE_RELATIVE - } else { - naga::valid::SubgroupOperationSet::empty() - }; - let mut validator = - naga::valid::Validator::new(naga::valid::ValidationFlags::all(), self.capabilities); - validator.subgroup_stages(self.subgroup_stages); - validator.subgroup_operations(subgroup_operations); - validator + naga::valid::Validator::new(naga::valid::ValidationFlags::all(), self.capabilities) } fn undecorate(&self, string: &str) -> String { @@ -1342,7 +1324,7 @@ impl Composer { imports, } = self .preprocessor - .preprocess(&module_set.sanitized_source, shader_defs, self.validate) + .preprocess(&module_set.sanitized_source, shader_defs) .map_err(|inner| ComposerError { inner, source: ErrSource::Module { @@ -1435,15 +1417,10 @@ impl Composer { /// purges any existing modules /// See https://github.com/gfx-rs/wgpu/blob/d9c054c645af0ea9ef81617c3e762fbf0f3fecda/wgpu-core/src/device/mod.rs#L515 /// for how to set the subgroup_stages value. - pub fn with_capabilities( - self, - capabilities: naga::valid::Capabilities, - subgroup_stages: naga::valid::ShaderStages, - ) -> Self { + pub fn with_capabilities(self, capabilities: naga::valid::Capabilities) -> Self { Self { capabilities, validate: self.validate, - subgroup_stages, ..Default::default() } } @@ -1697,7 +1674,7 @@ impl Composer { imports, } = self .preprocessor - .preprocess(&sanitized_source, &shader_defs, self.validate) + .preprocess(&sanitized_source, &shader_defs) .map_err(|inner| ComposerError { inner, source: ErrSource::Constructing { diff --git a/src/compose/preprocess.rs b/src/compose/preprocess.rs index 45c3759..f9e0a04 100644 --- a/src/compose/preprocess.rs +++ b/src/compose/preprocess.rs @@ -233,7 +233,6 @@ impl Preprocessor { &self, shader_str: &str, shader_defs: &HashMap, - validate_len: bool, ) -> Result { let mut declared_imports = IndexMap::new(); let mut used_imports = IndexMap::new(); @@ -241,9 +240,6 @@ impl Preprocessor { let mut final_string = String::new(); let mut offset = 0; - #[cfg(debug)] - let len = shader_str.len(); - // this code broadly stolen from bevy_render::ShaderProcessor let mut lines = shader_str.lines(); let mut lines = lines.replace_comments().zip(shader_str.lines()).peekable(); @@ -371,14 +367,6 @@ impl Preprocessor { scope.finish(offset)?; - #[cfg(debug)] - if validate_len { - let revised_len = final_string.len(); - assert_eq!(len, revised_len); - } - #[cfg(not(debug))] - let _ = validate_len; - Ok(PreprocessOutput { preprocessed_source: final_string, imports: used_imports.into_values().collect(), @@ -576,7 +564,6 @@ fn vertex( let result_missing = processor.preprocess( WGSL, &[("TEXTURE".to_owned(), ShaderDefValue::Bool(true))].into(), - true, ); let expected: Result = @@ -677,7 +664,6 @@ fn vertex( .preprocess( WGSL, &[("TEXTURE".to_string(), ShaderDefValue::Int(3))].into(), - true, ) .unwrap(); assert_eq!(result_eq.preprocessed_source, EXPECTED_EQ); @@ -686,12 +672,11 @@ fn vertex( .preprocess( WGSL, &[("TEXTURE".to_string(), ShaderDefValue::Int(7))].into(), - true, ) .unwrap(); assert_eq!(result_neq.preprocessed_source, EXPECTED_NEQ); - let result_missing = processor.preprocess(WGSL, &Default::default(), true); + let result_missing = processor.preprocess(WGSL, &Default::default()); let expected_err: Result< (Option, String, Vec), @@ -705,7 +690,6 @@ fn vertex( let result_wrong_type = processor.preprocess( WGSL, &[("TEXTURE".to_string(), ShaderDefValue::Bool(true))].into(), - true, ); let expected_err: Result< @@ -814,7 +798,6 @@ fn vertex( .preprocess( WGSL, &[("TEXTURE".to_string(), ShaderDefValue::Bool(true))].into(), - true, ) .unwrap(); assert_eq!(result_eq.preprocessed_source, EXPECTED_EQ); @@ -823,7 +806,6 @@ fn vertex( .preprocess( WGSL, &[("TEXTURE".to_string(), ShaderDefValue::Bool(false))].into(), - true, ) .unwrap(); assert_eq!(result_neq.preprocessed_source, EXPECTED_NEQ); @@ -919,7 +901,6 @@ fn vertex( .preprocess( WGSL, &[("TEXTURE".to_string(), ShaderDefValue::Bool(true))].into(), - true, ) .unwrap(); assert_eq!(result_eq.preprocessed_source, EXPECTED_EQ); @@ -928,12 +909,11 @@ fn vertex( .preprocess( WGSL, &[("TEXTURE".to_string(), ShaderDefValue::Bool(false))].into(), - true, ) .unwrap(); assert_eq!(result_neq.preprocessed_source, EXPECTED_NEQ); - let result_missing = processor.preprocess(WGSL, &[].into(), true); + let result_missing = processor.preprocess(WGSL, &[].into()); let expected_err: Result< (Option, String, Vec), ComposerErrorInner, @@ -946,7 +926,6 @@ fn vertex( let result_wrong_type = processor.preprocess( WGSL, &[("TEXTURE".to_string(), ShaderDefValue::Int(7))].into(), - true, ); let expected_err: Result< @@ -1031,7 +1010,6 @@ fn vertex( ("SECOND_VALUE".to_string(), ShaderDefValue::Int(3)), ] .into(), - true, ) .unwrap(); assert_eq!(result.preprocessed_source, EXPECTED_REPLACED); @@ -1060,7 +1038,7 @@ defined .. } = processor.get_preprocessor_metadata(&WGSL, true).unwrap(); println!("defines: {:?}", shader_defs); - let result = processor.preprocess(&WGSL, &shader_defs, true).unwrap(); + let result = processor.preprocess(&WGSL, &shader_defs).unwrap(); assert_eq!(result.preprocessed_source, EXPECTED); } @@ -1103,7 +1081,7 @@ bool: false .. } = processor.get_preprocessor_metadata(&WGSL, true).unwrap(); println!("defines: {:?}", shader_defs); - let result = processor.preprocess(&WGSL, &shader_defs, true).unwrap(); + let result = processor.preprocess(&WGSL, &shader_defs).unwrap(); assert_eq!(result.preprocessed_source, EXPECTED); } @@ -1135,9 +1113,7 @@ fn vertex( } "; let processor = Preprocessor::default(); - let result = processor - .preprocess(&WGSL_ELSE_IFDEF, &[].into(), true) - .unwrap(); + let result = processor.preprocess(&WGSL_ELSE_IFDEF, &[].into()).unwrap(); assert_eq!( result .preprocessed_source @@ -1214,7 +1190,7 @@ fn vertex( "; let processor = Preprocessor::default(); let result = processor - .preprocess(&WGSL_ELSE_IFDEF_NO_ELSE_FALLBACK, &[].into(), true) + .preprocess(&WGSL_ELSE_IFDEF_NO_ELSE_FALLBACK, &[].into()) .unwrap(); assert_eq!( result @@ -1265,7 +1241,6 @@ fn vertex( .preprocess( &WGSL_ELSE_IFDEF, &[("TEXTURE".to_string(), ShaderDefValue::Bool(true))].into(), - true, ) .unwrap(); assert_eq!( @@ -1314,7 +1289,6 @@ fn vertex( .preprocess( &WGSL_ELSE_IFDEF, &[("SECOND_TEXTURE".to_string(), ShaderDefValue::Bool(true))].into(), - true, ) .unwrap(); assert_eq!( @@ -1363,7 +1337,6 @@ fn vertex( .preprocess( &WGSL_ELSE_IFDEF, &[("THIRD_TEXTURE".to_string(), ShaderDefValue::Bool(true))].into(), - true, ) .unwrap(); assert_eq!( @@ -1416,7 +1389,6 @@ fn vertex( ("THIRD_TEXTURE".to_string(), ShaderDefValue::Bool(true)), ] .into(), - true, ) .unwrap(); assert_eq!( @@ -1471,7 +1443,6 @@ fn vertex( .preprocess( &WGSL_COMPLICATED_ELSE_IFDEF, &[("IS_DEFINED".to_string(), ShaderDefValue::Bool(true))].into(), - true, ) .unwrap(); assert_eq!( @@ -1504,7 +1475,7 @@ fail 3 const EXPECTED: &str = r"ok"; let processor = Preprocessor::default(); - let result = processor.preprocess(&INPUT, &[].into(), true).unwrap(); + let result = processor.preprocess(&INPUT, &[].into()).unwrap(); assert_eq!( result .preprocessed_source @@ -1536,11 +1507,7 @@ fail 3 const EXPECTED: &str = r"ok"; let processor = Preprocessor::default(); let result = processor - .preprocess( - &INPUT, - &[("x".to_owned(), ShaderDefValue::Int(2))].into(), - true, - ) + .preprocess(&INPUT, &[("x".to_owned(), ShaderDefValue::Int(2))].into()) .unwrap(); assert_eq!( result diff --git a/src/compose/test.rs b/src/compose/test.rs index 572c7ea..fbd7054 100644 --- a/src/compose/test.rs +++ b/src/compose/test.rs @@ -1339,6 +1339,7 @@ mod test { module: &shader_module, entry_point: "run_test", compilation_options: Default::default(), + cache: None, }); let bindgroup = device.create_bind_group(&BindGroupDescriptor { diff --git a/src/compose/tests/expected/err_validation_1.txt b/src/compose/tests/expected/err_validation_1.txt index b855cdd..0385c62 100644 --- a/src/compose/tests/expected/err_validation_1.txt +++ b/src/compose/tests/expected/err_validation_1.txt @@ -1,10 +1,10 @@ -error: failed to build a valid final module: Function [2] 'func' is invalid +error: failed to build a valid final module: Function [1] 'func' is invalid ┌─ tests/error_test/wgsl_valid_err.wgsl:7:1 │ 7 │ ╭ fn func() -> f32 { 8 │ │ return 1u; - │ │ ^^ naga::Expression [1] - │ ╰──────────────^ naga::Function [2] + │ │ ^^ naga::Expression [0] + │ ╰──────────────^ naga::Function [1] │ - = The `return` value Some([1]) does not match the function return value + = The `return` value Some([0]) does not match the function return value diff --git a/src/compose/tests/expected/err_validation_2.txt b/src/compose/tests/expected/err_validation_2.txt index 9bd41d1..edabfeb 100644 --- a/src/compose/tests/expected/err_validation_2.txt +++ b/src/compose/tests/expected/err_validation_2.txt @@ -1,10 +1,10 @@ -error: failed to build a valid final module: Function [1] 'valid_inc::func' is invalid +error: failed to build a valid final module: Function [0] 'valid_inc::func' is invalid ┌─ tests/error_test/wgsl_valid_err.wgsl:7:1 │ 7 │ ╭ fn func() -> f32 { 8 │ │ return 1u; - │ │ ^^ naga::Expression [1] - │ ╰──────────────^ naga::Function [1] + │ │ ^^ naga::Expression [0] + │ ╰──────────────^ naga::Function [0] │ - = The `return` value Some([1]) does not match the function return value + = The `return` value Some([0]) does not match the function return value diff --git a/src/derive.rs b/src/derive.rs index 058f276..8aeef3e 100644 --- a/src/derive.rs +++ b/src/derive.rs @@ -379,7 +379,7 @@ impl<'a> DerivedModule<'a> { pointer: map_expr!(pointer), fun, value: map_expr!(value), - result: map_expr!(result), + result: map_expr_opt!(result), } } Statement::WorkGroupUniformLoad { pointer, result } => {