From 6b4f1b843f86f08c6eb04e5896b092e23ee233f0 Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Sun, 6 Feb 2022 00:33:20 -0500 Subject: [PATCH] msl: support unsized array not in structures (#2459) --- Cargo.lock | 2 +- wgpu-core/Cargo.toml | 2 +- wgpu-hal/Cargo.toml | 4 ++-- wgpu-hal/src/metal/device.rs | 39 +++++++++++++++++++----------------- wgpu/Cargo.toml | 6 +++--- 5 files changed, 28 insertions(+), 25 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e31b248186..20637239f1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1041,7 +1041,7 @@ dependencies = [ [[package]] name = "naga" version = "0.8.0" -source = "git+https://github.com/gfx-rs/naga?rev=0ce98d6#0ce98d6411ddadd078aaf3b5b1fff0b17be3b867" +source = "git+https://github.com/gfx-rs/naga?rev=8e2e39e#8e2e39e4d8fa5bbb657c3b170b4f6607d703e284" dependencies = [ "bit-set", "bitflags", diff --git a/wgpu-core/Cargo.toml b/wgpu-core/Cargo.toml index 330e73796d..4288c36f3e 100644 --- a/wgpu-core/Cargo.toml +++ b/wgpu-core/Cargo.toml @@ -38,7 +38,7 @@ thiserror = "1" [dependencies.naga] git = "https://github.com/gfx-rs/naga" -rev = "0ce98d6" +rev = "8e2e39e" #version = "0.8" features = ["span", "validate", "wgsl-in"] diff --git a/wgpu-hal/Cargo.toml b/wgpu-hal/Cargo.toml index 6482573435..1cc6074a05 100644 --- a/wgpu-hal/Cargo.toml +++ b/wgpu-hal/Cargo.toml @@ -88,14 +88,14 @@ js-sys = { version = "0.3" } [dependencies.naga] git = "https://github.com/gfx-rs/naga" -rev = "0ce98d6" +rev = "8e2e39e" #version = "0.8" # DEV dependencies [dev-dependencies.naga] git = "https://github.com/gfx-rs/naga" -rev = "0ce98d6" +rev = "8e2e39e" #version = "0.8" features = ["wgsl-in"] diff --git a/wgpu-hal/src/metal/device.rs b/wgpu-hal/src/metal/device.rs index 1d9808a573..e356cd0b35 100644 --- a/wgpu-hal/src/metal/device.rs +++ b/wgpu-hal/src/metal/device.rs @@ -116,43 +116,46 @@ impl super::Device { let mut sized_bindings = Vec::new(); let mut immutable_buffer_mask = 0; for (var_handle, var) in module.global_variables.iter() { - if var.space == naga::AddressSpace::WorkGroup { - let size = module.types[var.ty].inner.size(&module.constants); - wg_memory_sizes.push(size); - } - - if let naga::TypeInner::Struct { ref members, .. } = module.types[var.ty].inner { - let br = match var.binding { - Some(ref br) => br.clone(), - None => continue, - }; - - if !ep_info[var_handle].is_empty() { + match var.space { + naga::AddressSpace::WorkGroup => { + if !ep_info[var_handle].is_empty() { + let size = module.types[var.ty].inner.size(&module.constants); + wg_memory_sizes.push(size); + } + } + naga::AddressSpace::Uniform | naga::AddressSpace::Storage { .. } => { + let br = match var.binding { + Some(ref br) => br.clone(), + None => continue, + }; let storage_access_store = match var.space { naga::AddressSpace::Storage { access } => { access.contains(naga::StorageAccess::STORE) } _ => false, }; + // check for an immutable buffer - if !storage_access_store { + if !ep_info[var_handle].is_empty() && !storage_access_store { let psm = &layout.naga_options.per_stage_map[naga_stage]; let slot = psm.resources[&br].buffer.unwrap(); immutable_buffer_mask |= 1 << slot; } - } - // check for the unsized buffer - if let Some(member) = members.last() { + let mut dynamic_array_container_ty = var.ty; + if let naga::TypeInner::Struct { ref members, .. } = module.types[var.ty].inner + { + dynamic_array_container_ty = members.last().unwrap().ty; + } if let naga::TypeInner::Array { size: naga::ArraySize::Dynamic, .. - } = module.types[member.ty].inner + } = module.types[dynamic_array_container_ty].inner { - // Note: unwraps are fine, since the MSL is already generated sized_bindings.push(br); } } + _ => {} } } diff --git a/wgpu/Cargo.toml b/wgpu/Cargo.toml index 72c9a55f18..23d10e4737 100644 --- a/wgpu/Cargo.toml +++ b/wgpu/Cargo.toml @@ -137,20 +137,20 @@ env_logger = "0.8" [dependencies.naga] git = "https://github.com/gfx-rs/naga" -rev = "0ce98d6" +rev = "8e2e39e" #version = "0.8" optional = true # used to test all the example shaders [dev-dependencies.naga] git = "https://github.com/gfx-rs/naga" -rev = "0ce98d6" +rev = "8e2e39e" #version = "0.8" features = ["wgsl-in"] [target.'cfg(target_arch = "wasm32")'.dependencies.naga] git = "https://github.com/gfx-rs/naga" -rev = "0ce98d6" +rev = "8e2e39e" #version = "0.8" features = ["wgsl-out"]