diff --git a/Cargo.lock b/Cargo.lock index dfc2f1a90..96327702b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -964,7 +964,7 @@ dependencies = [ [[package]] name = "naga" version = "0.5.0" -source = "git+https://github.com/gfx-rs/naga?rev=a7ac13a#a7ac13a61d63620b8a0821db9176ed467fc282f7" +source = "git+https://github.com/gfx-rs/naga?rev=300039e#300039e24703bc823cc932985947dfda66616e1e" dependencies = [ "bit-set", "bitflags", diff --git a/player/tests/data/buffer-zero-init-for-binding.wgsl b/player/tests/data/buffer-zero-init-for-binding.wgsl index 8083b65de..d99e1407a 100644 --- a/player/tests/data/buffer-zero-init-for-binding.wgsl +++ b/player/tests/data/buffer-zero-init-for-binding.wgsl @@ -4,7 +4,7 @@ struct InOutBuffer { }; [[group(0), binding(0)]] -var buffer: [[access(read_write)]] InOutBuffer; +var buffer: InOutBuffer; [[stage(compute), workgroup_size(1)]] fn main([[builtin(global_invocation_id)]] global_id: vec3) { diff --git a/wgpu-core/Cargo.toml b/wgpu-core/Cargo.toml index 6810e90d1..36c23b6eb 100644 --- a/wgpu-core/Cargo.toml +++ b/wgpu-core/Cargo.toml @@ -36,7 +36,7 @@ thiserror = "1" [dependencies.naga] git = "https://github.com/gfx-rs/naga" -rev = "a7ac13a" +rev = "300039e" features = ["wgsl-in"] [dependencies.wgt] diff --git a/wgpu-core/src/validation.rs b/wgpu-core/src/validation.rs index a6e53396c..6c5e72e8b 100644 --- a/wgpu-core/src/validation.rs +++ b/wgpu-core/src/validation.rs @@ -325,7 +325,14 @@ impl Resource { wgt::BufferBindingType::Storage { read_only } => { let mut global_use = GlobalUse::READ | GlobalUse::QUERY; global_use.set(GlobalUse::WRITE, !read_only); - (naga::StorageClass::Storage, global_use) + let mut naga_access = naga::StorageAccess::LOAD; + naga_access.set(naga::StorageAccess::STORE, !read_only); + ( + naga::StorageClass::Storage { + access: naga_access, + }, + global_use, + ) } }; if self.class != class { @@ -432,16 +439,26 @@ impl Resource { } => { let naga_format = map_storage_format_to_naga(format) .ok_or(BindingError::BadStorageFormat(format))?; - let usage = match access { - wgt::StorageTextureAccess::ReadOnly => { - GlobalUse::READ | GlobalUse::QUERY + let (naga_access, usage) = match access { + wgt::StorageTextureAccess::ReadOnly => ( + naga::StorageAccess::LOAD, + GlobalUse::READ | GlobalUse::QUERY, + ), + wgt::StorageTextureAccess::WriteOnly => ( + naga::StorageAccess::STORE, + GlobalUse::WRITE | GlobalUse::QUERY, + ), + wgt::StorageTextureAccess::ReadWrite => { + (naga::StorageAccess::all(), GlobalUse::all()) } - wgt::StorageTextureAccess::WriteOnly => { - GlobalUse::WRITE | GlobalUse::QUERY - } - wgt::StorageTextureAccess::ReadWrite => GlobalUse::all(), }; - (naga::ImageClass::Storage(naga_format), usage) + ( + naga::ImageClass::Storage { + format: naga_format, + access: naga_access, + }, + usage, + ) } _ => return Err(BindingError::WrongType), }; @@ -474,7 +491,7 @@ impl Resource { ResourceType::Buffer { size } => BindingType::Buffer { ty: match self.class { naga::StorageClass::Uniform => wgt::BufferBindingType::Uniform, - naga::StorageClass::Storage => wgt::BufferBindingType::Storage { + naga::StorageClass::Storage { .. } => wgt::BufferBindingType::Storage { read_only: !shader_usage.contains(GlobalUse::WRITE), }, _ => return Err(BindingError::WrongType), @@ -517,7 +534,7 @@ impl Resource { view_dimension, multisampled: multi, }, - naga::ImageClass::Storage(format) => BindingType::StorageTexture { + naga::ImageClass::Storage { format, .. } => BindingType::StorageTexture { access: if shader_usage == GlobalUse::WRITE || shader_usage.is_empty() { wgt::StorageTextureAccess::WriteOnly } else if !features diff --git a/wgpu-hal/Cargo.toml b/wgpu-hal/Cargo.toml index 426d768fe..858395a7f 100644 --- a/wgpu-hal/Cargo.toml +++ b/wgpu-hal/Cargo.toml @@ -65,11 +65,11 @@ core-graphics-types = "0.1" [dependencies.naga] git = "https://github.com/gfx-rs/naga" -rev = "a7ac13a" +rev = "300039e" [dev-dependencies.naga] git = "https://github.com/gfx-rs/naga" -rev = "a7ac13a" +rev = "300039e" features = ["wgsl-in"] [dev-dependencies] diff --git a/wgpu-hal/src/gles/device.rs b/wgpu-hal/src/gles/device.rs index bf47814de..ec858bf0d 100644 --- a/wgpu-hal/src/gles/device.rs +++ b/wgpu-hal/src/gles/device.rs @@ -28,7 +28,7 @@ impl CompilationContext<'_> { } let register = match var.class { naga::StorageClass::Uniform => super::BindingRegister::UniformBuffers, - naga::StorageClass::Storage => super::BindingRegister::StorageBuffers, + naga::StorageClass::Storage { .. } => super::BindingRegister::StorageBuffers, _ => continue, }; @@ -48,10 +48,12 @@ impl CompilationContext<'_> { for (name, mapping) in reflection_info.texture_mapping { let var = &module.global_variables[mapping.texture]; - let register = if var.storage_access.is_empty() { - super::BindingRegister::Textures - } else { - super::BindingRegister::Images + let register = match module.types[var.ty].inner { + naga::TypeInner::Image { + class: naga::ImageClass::Storage { .. }, + .. + } => super::BindingRegister::Images, + _ => super::BindingRegister::Textures, }; let tex_br = var.binding.as_ref().unwrap(); diff --git a/wgpu-hal/src/metal/device.rs b/wgpu-hal/src/metal/device.rs index 66ddddccc..fa7f20d22 100644 --- a/wgpu-hal/src/metal/device.rs +++ b/wgpu-hal/src/metal/device.rs @@ -114,10 +114,14 @@ impl super::Device { Some(ref br) => br.clone(), None => continue, }; - // check for an immutable buffer - if !ep_info[var_handle].is_empty() - && !var.storage_access.contains(naga::StorageAccess::STORE) + let storage_access_store = if let naga::StorageClass::Storage { access } = var.class { + access.contains(naga::StorageAccess::STORE) + } else { + false + }; + // check for an immutable buffer + 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; diff --git a/wgpu/Cargo.toml b/wgpu/Cargo.toml index 821694c07..b9669c299 100644 --- a/wgpu/Cargo.toml +++ b/wgpu/Cargo.toml @@ -75,13 +75,13 @@ env_logger = "0.8" [dependencies.naga] git = "https://github.com/gfx-rs/naga" -rev = "a7ac13a" +rev = "300039e" optional = true # used to test all the example shaders [dev-dependencies.naga] git = "https://github.com/gfx-rs/naga" -rev = "a7ac13a" +rev = "300039e" features = ["wgsl-in"] [[example]] diff --git a/wgpu/examples/boids/compute.wgsl b/wgpu/examples/boids/compute.wgsl index e0c6e9e71..68be4894e 100644 --- a/wgpu/examples/boids/compute.wgsl +++ b/wgpu/examples/boids/compute.wgsl @@ -20,8 +20,8 @@ struct Particles { }; [[group(0), binding(0)]] var params : SimParams; -[[group(0), binding(1)]] var particlesSrc : [[access(read)]] Particles; -[[group(0), binding(2)]] var particlesDst : [[access(read_write)]] Particles; +[[group(0), binding(1)]] var particlesSrc : Particles; +[[group(0), binding(2)]] var particlesDst : Particles; // https://github.com/austinEng/Project6-Vulkan-Flocking/blob/master/data/shaders/computeparticles/particle.comp [[stage(compute), workgroup_size(64)]] diff --git a/wgpu/examples/hello-compute/shader.wgsl b/wgpu/examples/hello-compute/shader.wgsl index 2ac9b864b..9a14f9065 100644 --- a/wgpu/examples/hello-compute/shader.wgsl +++ b/wgpu/examples/hello-compute/shader.wgsl @@ -4,7 +4,7 @@ struct PrimeIndices { }; // this is used as both input and output for convenience [[group(0), binding(0)]] -var v_indices: [[access(read_write)]] PrimeIndices; +var v_indices: PrimeIndices; // The Collatz Conjecture states that for any integer n: // If n is even, n = n/2 diff --git a/wgpu/examples/shadow/shader.wgsl b/wgpu/examples/shadow/shader.wgsl index 49b4bb911..8fbd5b5b9 100644 --- a/wgpu/examples/shadow/shader.wgsl +++ b/wgpu/examples/shadow/shader.wgsl @@ -55,7 +55,7 @@ struct Lights { }; [[group(0), binding(1)]] -var s_lights: [[access(read)]] Lights; +var s_lights: Lights; [[group(0), binding(2)]] var t_shadow: texture_depth_2d_array; [[group(0), binding(3)]] diff --git a/wgpu/tests/vertex_indices/draw.vert.wgsl b/wgpu/tests/vertex_indices/draw.vert.wgsl index 69babbcd4..5161ef29b 100644 --- a/wgpu/tests/vertex_indices/draw.vert.wgsl +++ b/wgpu/tests/vertex_indices/draw.vert.wgsl @@ -4,7 +4,7 @@ struct Indices { }; // this is used as both input and output for convenience [[group(0), binding(0)]] -var indices: [[access(read_write)]] Indices; +var indices: Indices; [[stage(vertex)]] fn vs_main([[builtin(instance_index)]] instance: u32, [[builtin(vertex_index)]] index: u32) -> [[builtin(position)]] vec4 {