Skip to content

Commit

Permalink
msl: support unsized array not in structures (#2459)
Browse files Browse the repository at this point in the history
  • Loading branch information
kvark authored Feb 6, 2022
1 parent 3e0305d commit 6b4f1b8
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion wgpu-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
4 changes: 2 additions & 2 deletions wgpu-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
39 changes: 21 additions & 18 deletions wgpu-hal/src/metal/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
_ => {}
}
}

Expand Down
6 changes: 3 additions & 3 deletions wgpu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down

0 comments on commit 6b4f1b8

Please sign in to comment.