Skip to content

Commit 17a076f

Browse files
callymElabajaba
andauthored
Upgrade to WGPU 22 (#98)
This currently doesn't pass the tests, I think because `naga` removed the `PartialEq` implementation on a bunch of types (gfx-rs/wgpu#5818) --------- Co-authored-by: Elabajaba <[email protected]>
1 parent 7031ca1 commit 17a076f

File tree

8 files changed

+29
-86
lines changed

8 files changed

+29
-86
lines changed

Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ prune = []
1717
allow_deprecated = []
1818

1919
[dependencies]
20-
naga = { version = "0.20", features = ["wgsl-in", "wgsl-out"] }
20+
naga = { version = "22.1", features = ["wgsl-in", "wgsl-out"] }
2121
tracing = "0.1"
2222
regex = "1.8"
2323
regex-syntax = "0.8"
@@ -31,6 +31,6 @@ once_cell = "1.17.0"
3131
indexmap = "2"
3232

3333
[dev-dependencies]
34-
wgpu = { version = "0.20", features = ["naga-ir"] }
34+
wgpu = { version = "22", features = ["naga-ir"] }
3535
futures-lite = "1"
3636
tracing-subscriber = { version = "0.3", features = ["std", "fmt"] }

src/compose/error.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ impl ErrSource {
4040
let Ok(PreprocessOutput {
4141
preprocessed_source: source,
4242
..
43-
}) = composer
44-
.preprocessor
45-
.preprocess(raw_source, defs, composer.validate)
43+
}) = composer.preprocessor.preprocess(raw_source, defs)
4644
else {
4745
return Default::default();
4846
};
@@ -78,7 +76,7 @@ pub enum ComposerErrorInner {
7876
WgslParseError(naga::front::wgsl::ParseError),
7977
#[cfg(feature = "glsl")]
8078
#[error("{0:?}")]
81-
GlslParseError(naga::front::glsl::ParseError),
79+
GlslParseError(naga::front::glsl::ParseErrors),
8280
#[error("naga_oil bug, please file a report: failed to convert imported module IR back into WGSL for use with WGSL shaders: {0}")]
8381
WgslBackError(naga::back::wgsl::Error),
8482
#[cfg(feature = "glsl")]

src/compose/mod.rs

+7-30
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ use indexmap::IndexMap;
7979
/// - a module `a` containing a function `f`,
8080
/// - a module `b` that imports `a`, and containing an `override a::f` function,
8181
/// - a module `c` that imports `a` and `b`, and containing an `override a::f` function,
82+
///
8283
/// then b and c both specify an override for `a::f`.
8384
/// the `override fn a::f` declared in module `b` may call to `a::f` within its body.
8485
/// 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;
126127
///
127128
/// 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.
128129
///
129-
use naga::{
130-
valid::{Capabilities, ShaderStages},
131-
EntryPoint,
132-
};
130+
use naga::EntryPoint;
133131
use regex::Regex;
134132
use std::collections::{hash_map::Entry, BTreeMap, HashMap, HashSet};
135133
use tracing::{debug, trace};
@@ -321,11 +319,6 @@ pub struct Composer {
321319
pub module_sets: HashMap<String, ComposableModuleDefinition>,
322320
pub module_index: HashMap<usize, String>,
323321
pub capabilities: naga::valid::Capabilities,
324-
/// The shader stages that the subgroup operations are valid for.
325-
/// Used when creating a validator for the module.
326-
/// See https://github.com/gfx-rs/wgpu/blob/d9c054c645af0ea9ef81617c3e762fbf0f3fecda/wgpu-core/src/device/mod.rs#L515
327-
/// for how to set this for proper subgroup ops support.
328-
pub subgroup_stages: ShaderStages,
329322
preprocessor: Preprocessor,
330323
check_decoration_regex: Regex,
331324
undecorate_regex: Regex,
@@ -347,7 +340,6 @@ impl Default for Composer {
347340
Self {
348341
validate: true,
349342
capabilities: Default::default(),
350-
subgroup_stages: ShaderStages::empty(),
351343
module_sets: Default::default(),
352344
module_index: Default::default(),
353345
preprocessor: Preprocessor::default(),
@@ -426,19 +418,9 @@ impl Composer {
426418
String::from_utf8(data_encoding::BASE32_NOPAD.decode(from.as_bytes()).unwrap()).unwrap()
427419
}
428420

429-
/// This creates a validator that properly detects subgroup support.
421+
/// Shorthand for creating a naga validator.
430422
fn create_validator(&self) -> naga::valid::Validator {
431-
let subgroup_operations = if self.capabilities.contains(Capabilities::SUBGROUP) {
432-
use naga::valid::SubgroupOperationSet as S;
433-
S::BASIC | S::VOTE | S::ARITHMETIC | S::BALLOT | S::SHUFFLE | S::SHUFFLE_RELATIVE
434-
} else {
435-
naga::valid::SubgroupOperationSet::empty()
436-
};
437-
let mut validator =
438-
naga::valid::Validator::new(naga::valid::ValidationFlags::all(), self.capabilities);
439-
validator.subgroup_stages(self.subgroup_stages);
440-
validator.subgroup_operations(subgroup_operations);
441-
validator
423+
naga::valid::Validator::new(naga::valid::ValidationFlags::all(), self.capabilities)
442424
}
443425

444426
fn undecorate(&self, string: &str) -> String {
@@ -1342,7 +1324,7 @@ impl Composer {
13421324
imports,
13431325
} = self
13441326
.preprocessor
1345-
.preprocess(&module_set.sanitized_source, shader_defs, self.validate)
1327+
.preprocess(&module_set.sanitized_source, shader_defs)
13461328
.map_err(|inner| ComposerError {
13471329
inner,
13481330
source: ErrSource::Module {
@@ -1435,15 +1417,10 @@ impl Composer {
14351417
/// purges any existing modules
14361418
/// See https://github.com/gfx-rs/wgpu/blob/d9c054c645af0ea9ef81617c3e762fbf0f3fecda/wgpu-core/src/device/mod.rs#L515
14371419
/// for how to set the subgroup_stages value.
1438-
pub fn with_capabilities(
1439-
self,
1440-
capabilities: naga::valid::Capabilities,
1441-
subgroup_stages: naga::valid::ShaderStages,
1442-
) -> Self {
1420+
pub fn with_capabilities(self, capabilities: naga::valid::Capabilities) -> Self {
14431421
Self {
14441422
capabilities,
14451423
validate: self.validate,
1446-
subgroup_stages,
14471424
..Default::default()
14481425
}
14491426
}
@@ -1697,7 +1674,7 @@ impl Composer {
16971674
imports,
16981675
} = self
16991676
.preprocessor
1700-
.preprocess(&sanitized_source, &shader_defs, self.validate)
1677+
.preprocess(&sanitized_source, &shader_defs)
17011678
.map_err(|inner| ComposerError {
17021679
inner,
17031680
source: ErrSource::Constructing {

src/compose/preprocess.rs

+8-41
Original file line numberDiff line numberDiff line change
@@ -233,17 +233,13 @@ impl Preprocessor {
233233
&self,
234234
shader_str: &str,
235235
shader_defs: &HashMap<String, ShaderDefValue>,
236-
validate_len: bool,
237236
) -> Result<PreprocessOutput, ComposerErrorInner> {
238237
let mut declared_imports = IndexMap::new();
239238
let mut used_imports = IndexMap::new();
240239
let mut scope = Scope::new();
241240
let mut final_string = String::new();
242241
let mut offset = 0;
243242

244-
#[cfg(debug)]
245-
let len = shader_str.len();
246-
247243
// this code broadly stolen from bevy_render::ShaderProcessor
248244
let mut lines = shader_str.lines();
249245
let mut lines = lines.replace_comments().zip(shader_str.lines()).peekable();
@@ -371,14 +367,6 @@ impl Preprocessor {
371367

372368
scope.finish(offset)?;
373369

374-
#[cfg(debug)]
375-
if validate_len {
376-
let revised_len = final_string.len();
377-
assert_eq!(len, revised_len);
378-
}
379-
#[cfg(not(debug))]
380-
let _ = validate_len;
381-
382370
Ok(PreprocessOutput {
383371
preprocessed_source: final_string,
384372
imports: used_imports.into_values().collect(),
@@ -576,7 +564,6 @@ fn vertex(
576564
let result_missing = processor.preprocess(
577565
WGSL,
578566
&[("TEXTURE".to_owned(), ShaderDefValue::Bool(true))].into(),
579-
true,
580567
);
581568

582569
let expected: Result<Preprocessor, ComposerErrorInner> =
@@ -677,7 +664,6 @@ fn vertex(
677664
.preprocess(
678665
WGSL,
679666
&[("TEXTURE".to_string(), ShaderDefValue::Int(3))].into(),
680-
true,
681667
)
682668
.unwrap();
683669
assert_eq!(result_eq.preprocessed_source, EXPECTED_EQ);
@@ -686,12 +672,11 @@ fn vertex(
686672
.preprocess(
687673
WGSL,
688674
&[("TEXTURE".to_string(), ShaderDefValue::Int(7))].into(),
689-
true,
690675
)
691676
.unwrap();
692677
assert_eq!(result_neq.preprocessed_source, EXPECTED_NEQ);
693678

694-
let result_missing = processor.preprocess(WGSL, &Default::default(), true);
679+
let result_missing = processor.preprocess(WGSL, &Default::default());
695680

696681
let expected_err: Result<
697682
(Option<String>, String, Vec<ImportDefWithOffset>),
@@ -705,7 +690,6 @@ fn vertex(
705690
let result_wrong_type = processor.preprocess(
706691
WGSL,
707692
&[("TEXTURE".to_string(), ShaderDefValue::Bool(true))].into(),
708-
true,
709693
);
710694

711695
let expected_err: Result<
@@ -814,7 +798,6 @@ fn vertex(
814798
.preprocess(
815799
WGSL,
816800
&[("TEXTURE".to_string(), ShaderDefValue::Bool(true))].into(),
817-
true,
818801
)
819802
.unwrap();
820803
assert_eq!(result_eq.preprocessed_source, EXPECTED_EQ);
@@ -823,7 +806,6 @@ fn vertex(
823806
.preprocess(
824807
WGSL,
825808
&[("TEXTURE".to_string(), ShaderDefValue::Bool(false))].into(),
826-
true,
827809
)
828810
.unwrap();
829811
assert_eq!(result_neq.preprocessed_source, EXPECTED_NEQ);
@@ -919,7 +901,6 @@ fn vertex(
919901
.preprocess(
920902
WGSL,
921903
&[("TEXTURE".to_string(), ShaderDefValue::Bool(true))].into(),
922-
true,
923904
)
924905
.unwrap();
925906
assert_eq!(result_eq.preprocessed_source, EXPECTED_EQ);
@@ -928,12 +909,11 @@ fn vertex(
928909
.preprocess(
929910
WGSL,
930911
&[("TEXTURE".to_string(), ShaderDefValue::Bool(false))].into(),
931-
true,
932912
)
933913
.unwrap();
934914
assert_eq!(result_neq.preprocessed_source, EXPECTED_NEQ);
935915

936-
let result_missing = processor.preprocess(WGSL, &[].into(), true);
916+
let result_missing = processor.preprocess(WGSL, &[].into());
937917
let expected_err: Result<
938918
(Option<String>, String, Vec<ImportDefWithOffset>),
939919
ComposerErrorInner,
@@ -946,7 +926,6 @@ fn vertex(
946926
let result_wrong_type = processor.preprocess(
947927
WGSL,
948928
&[("TEXTURE".to_string(), ShaderDefValue::Int(7))].into(),
949-
true,
950929
);
951930

952931
let expected_err: Result<
@@ -1031,7 +1010,6 @@ fn vertex(
10311010
("SECOND_VALUE".to_string(), ShaderDefValue::Int(3)),
10321011
]
10331012
.into(),
1034-
true,
10351013
)
10361014
.unwrap();
10371015
assert_eq!(result.preprocessed_source, EXPECTED_REPLACED);
@@ -1060,7 +1038,7 @@ defined
10601038
..
10611039
} = processor.get_preprocessor_metadata(&WGSL, true).unwrap();
10621040
println!("defines: {:?}", shader_defs);
1063-
let result = processor.preprocess(&WGSL, &shader_defs, true).unwrap();
1041+
let result = processor.preprocess(&WGSL, &shader_defs).unwrap();
10641042
assert_eq!(result.preprocessed_source, EXPECTED);
10651043
}
10661044

@@ -1103,7 +1081,7 @@ bool: false
11031081
..
11041082
} = processor.get_preprocessor_metadata(&WGSL, true).unwrap();
11051083
println!("defines: {:?}", shader_defs);
1106-
let result = processor.preprocess(&WGSL, &shader_defs, true).unwrap();
1084+
let result = processor.preprocess(&WGSL, &shader_defs).unwrap();
11071085
assert_eq!(result.preprocessed_source, EXPECTED);
11081086
}
11091087

@@ -1135,9 +1113,7 @@ fn vertex(
11351113
}
11361114
";
11371115
let processor = Preprocessor::default();
1138-
let result = processor
1139-
.preprocess(&WGSL_ELSE_IFDEF, &[].into(), true)
1140-
.unwrap();
1116+
let result = processor.preprocess(&WGSL_ELSE_IFDEF, &[].into()).unwrap();
11411117
assert_eq!(
11421118
result
11431119
.preprocessed_source
@@ -1214,7 +1190,7 @@ fn vertex(
12141190
";
12151191
let processor = Preprocessor::default();
12161192
let result = processor
1217-
.preprocess(&WGSL_ELSE_IFDEF_NO_ELSE_FALLBACK, &[].into(), true)
1193+
.preprocess(&WGSL_ELSE_IFDEF_NO_ELSE_FALLBACK, &[].into())
12181194
.unwrap();
12191195
assert_eq!(
12201196
result
@@ -1265,7 +1241,6 @@ fn vertex(
12651241
.preprocess(
12661242
&WGSL_ELSE_IFDEF,
12671243
&[("TEXTURE".to_string(), ShaderDefValue::Bool(true))].into(),
1268-
true,
12691244
)
12701245
.unwrap();
12711246
assert_eq!(
@@ -1314,7 +1289,6 @@ fn vertex(
13141289
.preprocess(
13151290
&WGSL_ELSE_IFDEF,
13161291
&[("SECOND_TEXTURE".to_string(), ShaderDefValue::Bool(true))].into(),
1317-
true,
13181292
)
13191293
.unwrap();
13201294
assert_eq!(
@@ -1363,7 +1337,6 @@ fn vertex(
13631337
.preprocess(
13641338
&WGSL_ELSE_IFDEF,
13651339
&[("THIRD_TEXTURE".to_string(), ShaderDefValue::Bool(true))].into(),
1366-
true,
13671340
)
13681341
.unwrap();
13691342
assert_eq!(
@@ -1416,7 +1389,6 @@ fn vertex(
14161389
("THIRD_TEXTURE".to_string(), ShaderDefValue::Bool(true)),
14171390
]
14181391
.into(),
1419-
true,
14201392
)
14211393
.unwrap();
14221394
assert_eq!(
@@ -1471,7 +1443,6 @@ fn vertex(
14711443
.preprocess(
14721444
&WGSL_COMPLICATED_ELSE_IFDEF,
14731445
&[("IS_DEFINED".to_string(), ShaderDefValue::Bool(true))].into(),
1474-
true,
14751446
)
14761447
.unwrap();
14771448
assert_eq!(
@@ -1504,7 +1475,7 @@ fail 3
15041475

15051476
const EXPECTED: &str = r"ok";
15061477
let processor = Preprocessor::default();
1507-
let result = processor.preprocess(&INPUT, &[].into(), true).unwrap();
1478+
let result = processor.preprocess(&INPUT, &[].into()).unwrap();
15081479
assert_eq!(
15091480
result
15101481
.preprocessed_source
@@ -1536,11 +1507,7 @@ fail 3
15361507
const EXPECTED: &str = r"ok";
15371508
let processor = Preprocessor::default();
15381509
let result = processor
1539-
.preprocess(
1540-
&INPUT,
1541-
&[("x".to_owned(), ShaderDefValue::Int(2))].into(),
1542-
true,
1543-
)
1510+
.preprocess(&INPUT, &[("x".to_owned(), ShaderDefValue::Int(2))].into())
15441511
.unwrap();
15451512
assert_eq!(
15461513
result

src/compose/test.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1339,6 +1339,7 @@ mod test {
13391339
module: &shader_module,
13401340
entry_point: "run_test",
13411341
compilation_options: Default::default(),
1342+
cache: None,
13421343
});
13431344

13441345
let bindgroup = device.create_bind_group(&BindGroupDescriptor {
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
error: failed to build a valid final module: Function [2] 'func' is invalid
1+
error: failed to build a valid final module: Function [1] 'func' is invalid
22
┌─ tests/error_test/wgsl_valid_err.wgsl:7:1
33
44
7 │ ╭ fn func() -> f32 {
55
8 │ │ return 1u;
6-
│ │ ^^ naga::Expression [1]
7-
│ ╰──────────────^ naga::Function [2]
6+
│ │ ^^ naga::Expression [0]
7+
│ ╰──────────────^ naga::Function [1]
88
9-
= The `return` value Some([1]) does not match the function return value
9+
= The `return` value Some([0]) does not match the function return value
1010

Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
error: failed to build a valid final module: Function [1] 'valid_inc::func' is invalid
1+
error: failed to build a valid final module: Function [0] 'valid_inc::func' is invalid
22
┌─ tests/error_test/wgsl_valid_err.wgsl:7:1
33
44
7 │ ╭ fn func() -> f32 {
55
8 │ │ return 1u;
6-
│ │ ^^ naga::Expression [1]
7-
│ ╰──────────────^ naga::Function [1]
6+
│ │ ^^ naga::Expression [0]
7+
│ ╰──────────────^ naga::Function [0]
88
9-
= The `return` value Some([1]) does not match the function return value
9+
= The `return` value Some([0]) does not match the function return value
1010

0 commit comments

Comments
 (0)