diff --git a/Cargo.lock b/Cargo.lock index 6f97c04c6d7..96dc128f83e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1018,8 +1018,8 @@ dependencies = [ [[package]] name = "naga" -version = "0.4.0" -source = "git+https://github.com/gfx-rs/naga?tag=gfx-26#e3827f8e0899377c0177faa1f106ec2f3f8a9e3e" +version = "0.5.0" +source = "git+https://github.com/gfx-rs/naga?rev=57b325602015ce6445749a4d8ee5d491edc818d7#57b325602015ce6445749a4d8ee5d491edc818d7" dependencies = [ "bit-set", "bitflags", diff --git a/wgpu-core/Cargo.toml b/wgpu-core/Cargo.toml index 1239f105b7e..c226235b706 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" -tag = "gfx-26" +rev = "57b325602015ce6445749a4d8ee5d491edc818d7" features = ["wgsl-in"] [dependencies.wgt] diff --git a/wgpu-hal/Cargo.toml b/wgpu-hal/Cargo.toml index 9fc1c2746da..34b62ca5f4e 100644 --- a/wgpu-hal/Cargo.toml +++ b/wgpu-hal/Cargo.toml @@ -48,11 +48,11 @@ core-graphics-types = "0.1" [dependencies.naga] git = "https://github.com/gfx-rs/naga" -tag = "gfx-26" +rev = "57b325602015ce6445749a4d8ee5d491edc818d7" [dev-dependencies.naga] git = "https://github.com/gfx-rs/naga" -tag = "gfx-26" +rev = "57b325602015ce6445749a4d8ee5d491edc818d7" features = ["wgsl-in"] [dev-dependencies] diff --git a/wgpu-hal/src/metal/command.rs b/wgpu-hal/src/metal/command.rs index 902274fc16b..e571fc848f7 100644 --- a/wgpu-hal/src/metal/command.rs +++ b/wgpu-hal/src/metal/command.rs @@ -64,9 +64,7 @@ impl super::CommandState { result_sizes.clear(); for br in stage_info.sized_bindings.iter() { // If it's None, this isn't the right time to update the sizes - let size = self - .storage_buffer_length_map - .get(&(br.group, br.binding))?; + let size = self.storage_buffer_length_map.get(br)?; result_sizes.push(*size); } Some((slot as _, result_sizes)) @@ -417,9 +415,11 @@ impl crate::CommandEncoder for super::CommandEncoder { offset, ); if let Some(size) = buf.binding_size { - self.state - .storage_buffer_length_map - .insert((group_index, buf.binding_location), size); + let br = naga::ResourceBinding { + group: group_index, + binding: buf.binding_location, + }; + self.state.storage_buffer_length_map.insert(br, size); changes_sizes_buffer = true; } } @@ -449,9 +449,11 @@ impl crate::CommandEncoder for super::CommandEncoder { offset, ); if let Some(size) = buf.binding_size { - self.state - .storage_buffer_length_map - .insert((group_index, buf.binding_location), size); + let br = naga::ResourceBinding { + group: group_index, + binding: buf.binding_location, + }; + self.state.storage_buffer_length_map.insert(br, size); changes_sizes_buffer = true; } } @@ -519,9 +521,11 @@ impl crate::CommandEncoder for super::CommandEncoder { offset, ); if let Some(size) = buf.binding_size { - self.state - .storage_buffer_length_map - .insert((group_index, buf.binding_location), size); + let br = naga::ResourceBinding { + group: group_index, + binding: buf.binding_location, + }; + self.state.storage_buffer_length_map.insert(br, size); changes_sizes_buffer = true; } } diff --git a/wgpu-hal/src/metal/device.rs b/wgpu-hal/src/metal/device.rs index 496c814c7f5..4d02f945643 100644 --- a/wgpu-hal/src/metal/device.rs +++ b/wgpu-hal/src/metal/device.rs @@ -384,6 +384,7 @@ impl crate::Device for super::Device { pc_limit: u32, sizes_buffer: Option, sizes_count: u8, + resources: naga::back::msl::BindingMap, } let mut stage_data = super::NAGA_STAGES.map(|&stage| StageInfo { @@ -393,8 +394,8 @@ impl crate::Device for super::Device { pc_limit: 0, sizes_buffer: None, sizes_count: 0, + resources: Default::default(), }); - let mut binding_map = std::collections::BTreeMap::default(); let mut bind_group_infos = arrayvec::ArrayVec::new(); // First, place the push constants @@ -487,12 +488,11 @@ impl crate::Device for super::Device { } } - let source = naga::back::msl::BindSource { - stage: info.stage, + let br = naga::ResourceBinding { group: group_index as u32, binding: entry.binding, }; - binding_map.insert(source, target); + info.resources.insert(br, target); } } @@ -524,31 +524,10 @@ impl crate::Device for super::Device { sizes_buffer: info .sizes_buffer .map(|buffer_index| buffer_index as naga::back::msl::Slot), + resources: Default::default(), }); - let naga_options = naga::back::msl::Options { - lang_version: match self.shared.private_caps.msl_version { - mtl::MTLLanguageVersion::V1_0 => (1, 0), - mtl::MTLLanguageVersion::V1_1 => (1, 1), - mtl::MTLLanguageVersion::V1_2 => (1, 2), - mtl::MTLLanguageVersion::V2_0 => (2, 0), - mtl::MTLLanguageVersion::V2_1 => (2, 1), - mtl::MTLLanguageVersion::V2_2 => (2, 2), - mtl::MTLLanguageVersion::V2_3 => (2, 3), - }, - binding_map, - inline_samplers: Default::default(), - spirv_cross_compatibility: false, - fake_missing_bindings: false, - per_stage_map: naga::back::msl::PerStageMap { - vs: per_stage_map.vs, - fs: per_stage_map.fs, - cs: per_stage_map.cs, - }, - }; - Ok(super::PipelineLayout { - naga_options, bind_group_infos, push_constants_infos: stage_data.map(|info| { info.pc_buffer.map(|buffer_index| super::PushConstantsInfo { @@ -557,6 +536,34 @@ impl crate::Device for super::Device { }) }), total_counters: stage_data.map(|info| info.counters.clone()), + naga_options: naga::back::msl::Options { + lang_version: match self.shared.private_caps.msl_version { + mtl::MTLLanguageVersion::V1_0 => (1, 0), + mtl::MTLLanguageVersion::V1_1 => (1, 1), + mtl::MTLLanguageVersion::V1_2 => (1, 2), + mtl::MTLLanguageVersion::V2_0 => (2, 0), + mtl::MTLLanguageVersion::V2_1 => (2, 1), + mtl::MTLLanguageVersion::V2_2 => (2, 2), + mtl::MTLLanguageVersion::V2_3 => (2, 3), + }, + inline_samplers: Default::default(), + spirv_cross_compatibility: false, + fake_missing_bindings: false, + per_stage_map: naga::back::msl::PerStageMap { + vs: naga::back::msl::PerStageResources { + resources: stage_data.vs.resources, + ..per_stage_map.vs + }, + fs: naga::back::msl::PerStageResources { + resources: stage_data.fs.resources, + ..per_stage_map.fs + }, + cs: naga::back::msl::PerStageResources { + resources: stage_data.cs.resources, + ..per_stage_map.cs + }, + }, + }, }) } unsafe fn destroy_pipeline_layout(&self, _pipeline_layout: super::PipelineLayout) {} diff --git a/wgpu-hal/src/metal/mod.rs b/wgpu-hal/src/metal/mod.rs index 2a9ea125490..bb0720ae9c0 100644 --- a/wgpu-hal/src/metal/mod.rs +++ b/wgpu-hal/src/metal/mod.rs @@ -666,8 +666,7 @@ struct CommandState { index: Option, raw_wg_size: mtl::MTLSize, stage_infos: MultiStageData, - //TODO: use `naga::ResourceBinding` for keys - storage_buffer_length_map: fxhash::FxHashMap<(u32, u32), wgt::BufferSize>, + storage_buffer_length_map: fxhash::FxHashMap, } pub struct CommandEncoder { diff --git a/wgpu/Cargo.toml b/wgpu/Cargo.toml index e1ae2adb6a4..5e0f5efbeef 100644 --- a/wgpu/Cargo.toml +++ b/wgpu/Cargo.toml @@ -73,19 +73,19 @@ env_logger = "0.8" [dependencies.naga] git = "https://github.com/gfx-rs/naga" -tag = "gfx-26" +rev = "57b325602015ce6445749a4d8ee5d491edc818d7" optional = true # used to test all the example shaders [dev-dependencies.naga] git = "https://github.com/gfx-rs/naga" -tag = "gfx-26" +rev = "57b325602015ce6445749a4d8ee5d491edc818d7" features = ["wgsl-in"] # used to generate SPIR-V for the Web target [target.'cfg(target_arch = "wasm32")'.dependencies.naga] git = "https://github.com/gfx-rs/naga" -tag = "gfx-26" +rev = "57b325602015ce6445749a4d8ee5d491edc818d7" features = ["wgsl-in", "spv-out"] [[example]]