msl: support unsized array not in structures (#2459)

This commit is contained in:
Dzmitry Malyshau authored and GitHub committed 2022-02-06 05:33:20 +00:00
1 parent 3e0305d27d
commit 6b4f1b843f
5 files changed
+28 -25

No files matched your search

Generated
+1 -1
View File
@@ -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",
+1 -1
View File
@@ -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"]
+2 -2
View File
@@ -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"]
+21 -18
View File
@@ -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);
}
}
_ => {}
}
}
+3 -3
View File
@@ -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"]