diff --git a/Cargo.toml b/Cargo.toml index 8bb2020..9b8014f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "naga_oil" -version = "0.10.1" +version = "0.11.0" edition = "2021" license = "MIT OR Apache-2.0" description = "a crate for combining and manipulating shaders using naga IR" @@ -17,7 +17,7 @@ prune = [] allow_deprecated = [] [dependencies] -naga = { version = "0.13", features = ["wgsl-in", "wgsl-out", "clone", "span"] } +naga = { version = "0.14.1", features = ["wgsl-in", "wgsl-out", "clone", "span"] } tracing = "0.1" regex = "1.8" regex-syntax = "0.7" @@ -28,9 +28,9 @@ bit-set = "0.5" rustc-hash = "1.1.0" unicode-ident = "1" once_cell = "1.17.0" -indexmap = "1.9.3" +indexmap = "2" [dev-dependencies] -wgpu = { version = "0.17", features = ["naga"] } +wgpu = { version = "0.18", features = ["naga"] } futures-lite = "1" tracing-subscriber = { version = "0.3", features = ["std", "fmt"] } diff --git a/src/compose/test.rs b/src/compose/test.rs index 21908ff..5f6c533 100644 --- a/src/compose/test.rs +++ b/src/compose/test.rs @@ -1478,7 +1478,10 @@ mod test { let mut encoder = device.create_command_encoder(&CommandEncoderDescriptor { label: None }); - let mut pass = encoder.begin_compute_pass(&ComputePassDescriptor { label: None }); + let mut pass = encoder.begin_compute_pass(&ComputePassDescriptor { + label: None, + timestamp_writes: None, + }); pass.set_pipeline(&pipeline); pass.set_bind_group(0, &bindgroup, &[]); diff --git a/src/compose/tests/compute_test.wgsl b/src/compose/tests/compute_test.wgsl index 2878333..9eb0560 100644 --- a/src/compose/tests/compute_test.wgsl +++ b/src/compose/tests/compute_test.wgsl @@ -1,10 +1,10 @@ #import test_module @group(0) @binding(0) -var buffer: f32; +var buffer: f32; @compute @workgroup_size(1, 1, 1) fn run_test() { let res = test_module::entry_point(); buffer = res; -} \ No newline at end of file +} diff --git a/src/compose/tests/expected/atomics.txt b/src/compose/tests/expected/atomics.txt index 760d5f0..fe76456 100644 --- a/src/compose/tests/expected/atomics.txt +++ b/src/compose/tests/expected/atomics.txt @@ -1,4 +1,4 @@ -struct gen___atomic_compare_exchange_resultUint4_ { +struct _atomic_compare_exchange_resultUint4_ { old_value: u32, exchanged: bool, } @@ -27,7 +27,7 @@ fn entry_pointX_naga_oil_mod_XORSXG5C7NVXWI5LMMUX() -> f32 { let _e27: u32 = atomicExchange((&atomX_naga_oil_mod_XORSXG5C7NVXWI5LMMUX), _e25); let _e28: u32 = y; y = (_e28 + _e27); - let _e33: gen___atomic_compare_exchange_resultUint4_ = atomicCompareExchangeWeak((&atomX_naga_oil_mod_XORSXG5C7NVXWI5LMMUX), 12u, 0u); + let _e33: _atomic_compare_exchange_resultUint4_ = atomicCompareExchangeWeak((&atomX_naga_oil_mod_XORSXG5C7NVXWI5LMMUX), 12u, 0u); if _e33.exchanged { let _e36: u32 = y; y = (_e36 + _e33.old_value); diff --git a/src/compose/tests/expected/bad_identifiers.txt b/src/compose/tests/expected/bad_identifiers.txt index a67db37..120c896 100644 --- a/src/compose/tests/expected/bad_identifiers.txt +++ b/src/compose/tests/expected/bad_identifiers.txt @@ -10,16 +10,15 @@ e.fine_member = 4.0; fine: f32, fine_member: f32, - let _e11: f32 = bad_X_naga_oil_mod_XM5WG6YTBNRZQX; - let _e22: f32 = d.fine; - let _e25: f32 = e.fine_member; - let _e4: f32 = fineX_naga_oil_mod_XMZXHGX(1.0); - let _e6: f32 = bad_X_naga_oil_mod_XMZXHGX(2.0); - let _e9: f32 = fineX_naga_oil_mod_XM5WG6YTBNRZQX; - let a: f32 = (fineX_naga_oil_mod_XMNXW443UOMX + bad_X_naga_oil_mod_XMNXW443UOMX); - let b: f32 = (_e4 + _e6); - let c: f32 = (_e9 + _e11); - return ((((a + b) + c) + _e22) + _e25); + let _e1: f32 = fineX_naga_oil_mod_XMZXHGX(1.0); + let _e20: f32 = d.fine; + let _e23: f32 = e.fine_member; + let _e3: f32 = bad_X_naga_oil_mod_XMZXHGX(2.0); + let _e6: f32 = fineX_naga_oil_mod_XM5WG6YTBNRZQX; + let _e8: f32 = bad_X_naga_oil_mod_XM5WG6YTBNRZQX; + let b: f32 = (_e1 + _e3); + let c: f32 = (_e6 + _e8); + return ((((2.0 + b) + c) + _e20) + _e23); return in; return in_1; var d: IsFineX_naga_oil_mod_XON2HE5LDORZQX; diff --git a/src/compose/tests/expected/big_shaderdefs.txt b/src/compose/tests/expected/big_shaderdefs.txt index 45535e0..82491fa 100644 --- a/src/compose/tests/expected/big_shaderdefs.txt +++ b/src/compose/tests/expected/big_shaderdefs.txt @@ -1,7 +1,6 @@ fn fX_naga_oil_mod_XNVXWIX() -> f32 { - var x: f32; + var x: f32 = 0.0; - x = 0.0; x = 1.0; let _e3: f32 = x; return _e3; diff --git a/src/compose/tests/expected/dup_import.txt b/src/compose/tests/expected/dup_import.txt index 822ce70..8b7a946 100644 --- a/src/compose/tests/expected/dup_import.txt +++ b/src/compose/tests/expected/dup_import.txt @@ -4,9 +4,9 @@ let _e0: f32 = fX_naga_oil_mod_XMEX(); let _e1: f32 = fX_naga_oil_mod_XMIX(); - return (PIX_naga_oil_mod_XMNXW443UOMX * 1.0); - return (PIX_naga_oil_mod_XMNXW443UOMX * 2.0); return (_e0 * _e1); + return 3.1; + return 6.2; const PIX_naga_oil_mod_XMNXW443UOMX: f32 = 3.1; fn fX_naga_oil_mod_XMEX() -> f32 { fn fX_naga_oil_mod_XMIX() -> f32 { diff --git a/src/compose/tests/expected/glsl_call_wgsl.txt b/src/compose/tests/expected/glsl_call_wgsl.txt index f5caede..50498c1 100644 --- a/src/compose/tests/expected/glsl_call_wgsl.txt +++ b/src/compose/tests/expected/glsl_call_wgsl.txt @@ -10,7 +10,7 @@ fn wgsl_funcX_naga_oil_mod_XO5TXG3C7NVXWI5LMMUX() -> f32 { fn main_1() { let _e0: f32 = wgsl_funcX_naga_oil_mod_XO5TXG3C7NVXWI5LMMUX(); - gl_Position = vec4(_e0); + gl_Position = vec4(_e0); return; } diff --git a/src/compose/tests/expected/glsl_const_import.txt b/src/compose/tests/expected/glsl_const_import.txt index f46c308..c1fee8f 100644 --- a/src/compose/tests/expected/glsl_const_import.txt +++ b/src/compose/tests/expected/glsl_const_import.txt @@ -7,7 +7,7 @@ const my_constantX_naga_oil_mod_XMNXW23LPNYX: f32 = 0.5; var out_color: vec4; fn main_1() { - out_color = vec4(f32(1), my_constantX_naga_oil_mod_XMNXW23LPNYX, f32(0), f32(1)); + out_color = vec4(1.0, 0.5, 0.0, 1.0); return; } diff --git a/src/compose/tests/expected/glsl_wgsl_const_import.txt b/src/compose/tests/expected/glsl_wgsl_const_import.txt index 637c511..c1ab2a9 100644 --- a/src/compose/tests/expected/glsl_wgsl_const_import.txt +++ b/src/compose/tests/expected/glsl_wgsl_const_import.txt @@ -1,6 +1,6 @@ const my_constantX_naga_oil_mod_XMNXW23LPNYX: f32 = 0.5; fn main() -> vec4 { - return vec4(1.0, my_constantX_naga_oil_mod_XMNXW23LPNYX, 0.0, 1.0); + return vec4(1.0, 0.5, 0.0, 1.0); } diff --git a/src/compose/tests/expected/wgsl_glsl_const_import.txt b/src/compose/tests/expected/wgsl_glsl_const_import.txt index f46c308..c1fee8f 100644 --- a/src/compose/tests/expected/wgsl_glsl_const_import.txt +++ b/src/compose/tests/expected/wgsl_glsl_const_import.txt @@ -7,7 +7,7 @@ const my_constantX_naga_oil_mod_XMNXW23LPNYX: f32 = 0.5; var out_color: vec4; fn main_1() { - out_color = vec4(f32(1), my_constantX_naga_oil_mod_XMNXW23LPNYX, f32(0), f32(1)); + out_color = vec4(1.0, 0.5, 0.0, 1.0); return; } diff --git a/src/derive.rs b/src/derive.rs index 2cd9d45..5336915 100644 --- a/src/derive.rs +++ b/src/derive.rs @@ -634,21 +634,30 @@ impl<'a> DerivedModule<'a> { binding: r.binding.clone(), }); + let expressions = Rc::new(RefCell::new(Arena::new())); + let expr_map = Rc::new(RefCell::new(HashMap::new())); + let mut local_variables = Arena::new(); for (h_l, l) in func.local_variables.iter() { let new_local = LocalVariable { name: l.name.clone(), ty: self.import_type(&l.ty), - init: l.init.map(|c| self.import_const_expression(c)), + init: l.init.map(|c| { + self.import_expression( + c, + &func.expressions, + expr_map.clone(), + expressions.clone(), + false, + true, + ) + }), }; let span = func.local_variables.get_span(h_l); let new_h = local_variables.append(new_local, self.map_span(span)); assert_eq!(h_l, new_h); } - let expressions = Rc::new(RefCell::new(Arena::new())); - let expr_map = Rc::new(RefCell::new(HashMap::new())); - let body = self.import_block( &func.body, &func.expressions,