diff --git a/Cargo.lock b/Cargo.lock index 807a7fafad..e31b248186 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=81dc674#81dc67402a743b4dc6b2d24c0d306cd18799238b" +source = "git+https://github.com/gfx-rs/naga?rev=0ce98d6#0ce98d6411ddadd078aaf3b5b1fff0b17be3b867" dependencies = [ "bit-set", "bitflags", diff --git a/cts_runner/examples/hello-compute.js b/cts_runner/examples/hello-compute.js index 2f30c376e8..246b0aa513 100644 --- a/cts_runner/examples/hello-compute.js +++ b/cts_runner/examples/hello-compute.js @@ -4,13 +4,10 @@ const numbers = [1, 4, 3, 295]; const device = await adapter.requestDevice(); -const shaderCode = `@block -struct PrimeIndices { - data: @stride(4) array; -}; // this is used as both input and output for convenience +const shaderCode = ` @group(0) @binding(0) -var v_indices: PrimeIndices; +var v_indices: array; // this is used as both input and output for convenience // The Collatz Conjecture states that for any integer n: // If n is even, n = n/2 // If n is odd, n = 3n+1 @@ -41,7 +38,7 @@ fn collatz_iterations(n_base: u32) -> u32{ @stage(compute) @workgroup_size(1) fn main(@builtin(global_invocation_id) global_id: vec3) { - v_indices.data[global_id.x] = collatz_iterations(v_indices.data[global_id.x]); + v_indices[global_id.x] = collatz_iterations(v_indices[global_id.x]); }`; const shaderModule = device.createShaderModule({ diff --git a/player/tests/data/zero-init-buffer-for-binding.wgsl b/player/tests/data/zero-init-buffer-for-binding.wgsl index aee562cf9c..884cf8afb4 100644 --- a/player/tests/data/zero-init-buffer-for-binding.wgsl +++ b/player/tests/data/zero-init-buffer-for-binding.wgsl @@ -1,13 +1,9 @@ -struct InOutBuffer { - data: @stride(4) array; -}; - @group(0) @binding(0) -var buffer: InOutBuffer; +var buffer: array; @stage(compute) @workgroup_size(1) fn main(@builtin(global_invocation_id) global_id: vec3) { - buffer.data[global_id.x] = buffer.data[global_id.x] + global_id.x; + buffer[global_id.x] = buffer[global_id.x] + global_id.x; } diff --git a/wgpu-core/Cargo.toml b/wgpu-core/Cargo.toml index 53ec9ef4e3..330e73796d 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 = "81dc674" +rev = "0ce98d6" #version = "0.8" features = ["span", "validate", "wgsl-in"] diff --git a/wgpu-core/src/validation.rs b/wgpu-core/src/validation.rs index 32fbe8bbc1..b5f464efe6 100644 --- a/wgpu-core/src/validation.rs +++ b/wgpu-core/src/validation.rs @@ -25,7 +25,7 @@ struct Resource { name: Option, bind: naga::ResourceBinding, ty: ResourceType, - class: naga::StorageClass, + class: naga::AddressSpace, } #[derive(Clone, Copy, Debug)] @@ -181,9 +181,9 @@ pub enum BindingError { #[error("type on the shader side does not match the pipeline binding")] WrongType, #[error("storage class {binding:?} doesn't match the shader {shader:?}")] - WrongStorageClass { - binding: naga::StorageClass, - shader: naga::StorageClass, + WrongAddressSpace { + binding: naga::AddressSpace, + shader: naga::AddressSpace, }, #[error("buffer structure size {0}, added to one element of an unbound array, if it's the last field, ended up greater than the given `min_binding_size`")] WrongBufferSize(wgt::BufferSize), @@ -373,7 +373,7 @@ impl Resource { } => { let (class, global_use) = match ty { wgt::BufferBindingType::Uniform => { - (naga::StorageClass::Uniform, GlobalUse::READ) + (naga::AddressSpace::Uniform, GlobalUse::READ) } wgt::BufferBindingType::Storage { read_only } => { let mut global_use = GlobalUse::READ | GlobalUse::QUERY; @@ -381,7 +381,7 @@ impl Resource { let mut naga_access = naga::StorageAccess::LOAD; naga_access.set(naga::StorageAccess::STORE, !read_only); ( - naga::StorageClass::Storage { + naga::AddressSpace::Storage { access: naga_access, }, global_use, @@ -389,7 +389,7 @@ impl Resource { } }; if self.class != class { - return Err(BindingError::WrongStorageClass { + return Err(BindingError::WrongAddressSpace { binding: class, shader: self.class, }); @@ -540,8 +540,8 @@ impl Resource { Ok(match self.ty { ResourceType::Buffer { size } => BindingType::Buffer { ty: match self.class { - naga::StorageClass::Uniform => wgt::BufferBindingType::Uniform, - naga::StorageClass::Storage { .. } => wgt::BufferBindingType::Storage { + naga::AddressSpace::Uniform => wgt::BufferBindingType::Uniform, + naga::AddressSpace::Storage { .. } => wgt::BufferBindingType::Storage { read_only: !shader_usage.contains(GlobalUse::WRITE), }, _ => return Err(BindingError::WrongType), @@ -905,6 +905,9 @@ impl Interface { class, }, naga::TypeInner::Sampler { comparison } => ResourceType::Sampler { comparison }, + naga::TypeInner::Array { stride, .. } => ResourceType::Buffer { + size: wgt::BufferSize::new(stride as u64).unwrap(), + }, ref other => { log::error!("Unexpected resource type: {:?}", other); continue; @@ -915,7 +918,7 @@ impl Interface { name: var.name.clone(), bind, ty, - class: var.class, + class: var.space, }, Default::default(), ); diff --git a/wgpu-hal/Cargo.toml b/wgpu-hal/Cargo.toml index 5bd4823112..6482573435 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 = "81dc674" +rev = "0ce98d6" #version = "0.8" # DEV dependencies [dev-dependencies.naga] git = "https://github.com/gfx-rs/naga" -rev = "81dc674" +rev = "0ce98d6" #version = "0.8" features = ["wgsl-in"] diff --git a/wgpu-hal/src/gles/device.rs b/wgpu-hal/src/gles/device.rs index 47998364a7..628eaf0929 100644 --- a/wgpu-hal/src/gles/device.rs +++ b/wgpu-hal/src/gles/device.rs @@ -33,9 +33,9 @@ impl CompilationContext<'_> { if ep_info[handle].is_empty() { continue; } - let register = match var.class { - naga::StorageClass::Uniform => super::BindingRegister::UniformBuffers, - naga::StorageClass::Storage { .. } => super::BindingRegister::StorageBuffers, + let register = match var.space { + naga::AddressSpace::Uniform => super::BindingRegister::UniformBuffers, + naga::AddressSpace::Storage { .. } => super::BindingRegister::StorageBuffers, _ => continue, }; diff --git a/wgpu-hal/src/metal/device.rs b/wgpu-hal/src/metal/device.rs index 61df226502..1d9808a573 100644 --- a/wgpu-hal/src/metal/device.rs +++ b/wgpu-hal/src/metal/device.rs @@ -116,7 +116,7 @@ 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.class == naga::StorageClass::WorkGroup { + if var.space == naga::AddressSpace::WorkGroup { let size = module.types[var.ty].inner.size(&module.constants); wg_memory_sizes.push(size); } @@ -128,8 +128,8 @@ impl super::Device { }; if !ep_info[var_handle].is_empty() { - let storage_access_store = match var.class { - naga::StorageClass::Storage { access } => { + let storage_access_store = match var.space { + naga::AddressSpace::Storage { access } => { access.contains(naga::StorageAccess::STORE) } _ => false, diff --git a/wgpu/Cargo.toml b/wgpu/Cargo.toml index f7564e4a4b..72c9a55f18 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 = "81dc674" +rev = "0ce98d6" #version = "0.8" optional = true # used to test all the example shaders [dev-dependencies.naga] git = "https://github.com/gfx-rs/naga" -rev = "81dc674" +rev = "0ce98d6" #version = "0.8" features = ["wgsl-in"] [target.'cfg(target_arch = "wasm32")'.dependencies.naga] git = "https://github.com/gfx-rs/naga" -rev = "81dc674" +rev = "0ce98d6" #version = "0.8" features = ["wgsl-out"] diff --git a/wgpu/examples/boids/compute.wgsl b/wgpu/examples/boids/compute.wgsl index 4277b5aefa..ab1eeaea3f 100644 --- a/wgpu/examples/boids/compute.wgsl +++ b/wgpu/examples/boids/compute.wgsl @@ -13,26 +13,22 @@ struct SimParams { rule3Scale : f32; }; -struct Particles { - particles : @stride(16) array; -}; - @group(0) @binding(0) var params : SimParams; -@group(0) @binding(1) var particlesSrc : Particles; -@group(0) @binding(2) var particlesDst : Particles; +@group(0) @binding(1) var particlesSrc : array; +@group(0) @binding(2) var particlesDst : array; // https://github.com/austinEng/Project6-Vulkan-Flocking/blob/master/data/shaders/computeparticles/particle.comp @stage(compute) @workgroup_size(64) fn main(@builtin(global_invocation_id) global_invocation_id: vec3) { - let total = arrayLength(&particlesSrc.particles); + let total = arrayLength(&particlesSrc); let index = global_invocation_id.x; if (index >= total) { return; } - var vPos : vec2 = particlesSrc.particles[index].pos; - var vVel : vec2 = particlesSrc.particles[index].vel; + var vPos : vec2 = particlesSrc[index].pos; + var vVel : vec2 = particlesSrc[index].vel; var cMass : vec2 = vec2(0.0, 0.0); var cVel : vec2 = vec2(0.0, 0.0); @@ -49,8 +45,8 @@ fn main(@builtin(global_invocation_id) global_invocation_id: vec3) { continue; } - let pos = particlesSrc.particles[i].pos; - let vel = particlesSrc.particles[i].vel; + let pos = particlesSrc[i].pos; + let vel = particlesSrc[i].vel; if (distance(pos, vPos) < params.rule1Distance) { cMass += pos; @@ -100,5 +96,5 @@ fn main(@builtin(global_invocation_id) global_invocation_id: vec3) { } // Write back - particlesDst.particles[index] = Particle(vPos, vVel); + particlesDst[index] = Particle(vPos, vVel); } diff --git a/wgpu/examples/hello-compute/shader.wgsl b/wgpu/examples/hello-compute/shader.wgsl index 4bcaf40b8f..7421e3cf47 100644 --- a/wgpu/examples/hello-compute/shader.wgsl +++ b/wgpu/examples/hello-compute/shader.wgsl @@ -1,10 +1,6 @@ -struct PrimeIndices { - data: @stride(4) array; -}; // this is used as both input and output for convenience - @group(0) @binding(0) -var v_indices: PrimeIndices; +var v_indices: array; // this is used as both input and output for convenience // The Collatz Conjecture states that for any integer n: // If n is even, n = n/2 @@ -38,5 +34,5 @@ fn collatz_iterations(n_base: u32) -> u32{ @stage(compute) @workgroup_size(1) fn main(@builtin(global_invocation_id) global_id: vec3) { - v_indices.data[global_id.x] = collatz_iterations(v_indices.data[global_id.x]); + v_indices[global_id.x] = collatz_iterations(v_indices[global_id.x]); } diff --git a/wgpu/examples/shadow/shader.wgsl b/wgpu/examples/shadow/shader.wgsl index bc70a93a22..088608378c 100644 --- a/wgpu/examples/shadow/shader.wgsl +++ b/wgpu/examples/shadow/shader.wgsl @@ -49,21 +49,12 @@ struct Light { color: vec4; }; -struct Lights { - data: @stride(96) array; -}; - -// Used when storage types are not supported -struct LightsWithoutStorage { - data: array; -}; - @group(0) @binding(1) -var s_lights: Lights; +var s_lights: array; @group(0) @binding(1) -var u_lights: LightsWithoutStorage; +var u_lights: array; // Used when storage types are not supported @group(0) @binding(2) var t_shadow: texture_depth_2d_array; @@ -93,7 +84,7 @@ fn fs_main(in: VertexOutput) -> @location(0) vec4 { // accumulate color var color: vec3 = c_ambient; for(var i = 0u; i < min(u_globals.num_lights.x, c_max_lights); i += 1u) { - let light = s_lights.data[i]; + let light = s_lights[i]; // project into the light space let shadow = fetch_shadow(i, light.proj * in.world_position); // compute Lambertian diffuse term @@ -114,7 +105,7 @@ fn fs_main_without_storage(in: VertexOutput) -> @location(0) vec4 { for(var i = 0u; i < min(u_globals.num_lights.x, c_max_lights); i += 1u) { // This line is the only difference from the entrypoint above. It uses the lights // uniform instead of the lights storage buffer - let light = u_lights.data[i]; + let light = u_lights[i]; let shadow = fetch_shadow(i, light.proj * in.world_position); let light_dir = normalize(light.pos.xyz - in.world_position.xyz); let diffuse = max(0.0, dot(normal, light_dir)); diff --git a/wgpu/tests/vertex_indices/draw.vert.wgsl b/wgpu/tests/vertex_indices/draw.vert.wgsl index 197c4dbb51..26e07e4254 100644 --- a/wgpu/tests/vertex_indices/draw.vert.wgsl +++ b/wgpu/tests/vertex_indices/draw.vert.wgsl @@ -1,14 +1,10 @@ -struct Indices { - arr: array; -}; // this is used as both input and output for convenience - @group(0) @binding(0) -var indices: Indices; +var indices: array; // this is used as both input and output for convenience @stage(vertex) fn vs_main(@builtin(instance_index) instance: u32, @builtin(vertex_index) index: u32) -> @builtin(position) vec4 { let idx = instance * 3u + index; - indices.arr[idx] = idx; + indices[idx] = idx; return vec4(0.0, 0.0, 0.0, 1.0); }