Skip to content

Commit

Permalink
Merge #1558
Browse files Browse the repository at this point in the history
1558: Update naga to 57b3256 r=kvark a=kvark

**Connections**
Needed for #1510
Picks up gfx-rs/naga#1039

**Description**
Updates Naga to latest on Git. Refactors the use of `ResourceBinding` and Metal's binding map.

**Testing**
Examples.


Co-authored-by: Dzmitry Malyshau <[email protected]>
  • Loading branch information
bors[bot] and kvark authored Jun 27, 2021
2 parents ebe2152 + 5288482 commit d273a20
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 48 deletions.
4 changes: 2 additions & 2 deletions 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 @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions wgpu-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
28 changes: 16 additions & 12 deletions wgpu-hal/src/metal/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -417,9 +415,11 @@ impl crate::CommandEncoder<super::Api> 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;
}
}
Expand Down Expand Up @@ -449,9 +449,11 @@ impl crate::CommandEncoder<super::Api> 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;
}
}
Expand Down Expand Up @@ -519,9 +521,11 @@ impl crate::CommandEncoder<super::Api> 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;
}
}
Expand Down
59 changes: 33 additions & 26 deletions wgpu-hal/src/metal/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ impl crate::Device<super::Api> for super::Device {
pc_limit: u32,
sizes_buffer: Option<super::ResourceIndex>,
sizes_count: u8,
resources: naga::back::msl::BindingMap,
}

let mut stage_data = super::NAGA_STAGES.map(|&stage| StageInfo {
Expand All @@ -393,8 +394,8 @@ impl crate::Device<super::Api> 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
Expand Down Expand Up @@ -487,12 +488,11 @@ impl crate::Device<super::Api> 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);
}
}

Expand Down Expand Up @@ -524,31 +524,10 @@ impl crate::Device<super::Api> 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 {
Expand All @@ -557,6 +536,34 @@ impl crate::Device<super::Api> 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) {}
Expand Down
3 changes: 1 addition & 2 deletions wgpu-hal/src/metal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -666,8 +666,7 @@ struct CommandState {
index: Option<IndexState>,
raw_wg_size: mtl::MTLSize,
stage_infos: MultiStageData<PipelineStageInfo>,
//TODO: use `naga::ResourceBinding` for keys
storage_buffer_length_map: fxhash::FxHashMap<(u32, u32), wgt::BufferSize>,
storage_buffer_length_map: fxhash::FxHashMap<naga::ResourceBinding, wgt::BufferSize>,
}

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

0 comments on commit d273a20

Please sign in to comment.