1558: Update naga to 57b3256020 r=kvark a=kvark

**Connections**
Needed for #1510
Picks up https://github.com/gfx-rs/naga/pull/1039 and https://github.com/gfx-rs/naga/pull/916

**Description**
Updates Naga to latest on Git. Refactors the use of `ResourceBinding` and Metal's binding map.
Also enables safe bound check handling on Vulkan (`Restrict` policy, cc @jimblandy).

**Testing**
Examples.


Co-authored-by: Dzmitry Malyshau <kvarkus@gmail.com>
This commit is contained in:
bors[bot]
2021-06-27 05:45:16 +00:00
committed by GitHub
9 changed files with 61 additions and 48 deletions

4
Cargo.lock generated
View File

@@ -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",

View File

@@ -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]

View File

@@ -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]

View File

@@ -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<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;
}
}
@@ -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;
}
}
@@ -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;
}
}

View File

@@ -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 {
@@ -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
@@ -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);
}
}
@@ -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 {
@@ -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) {}

View File

@@ -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 {

View File

@@ -728,6 +728,7 @@ impl crate::Adapter<super::Api> for super::Adapter {
lang_version: (1, 0),
flags,
capabilities: Some(capabilities.iter().cloned().collect()),
index_bounds_check_policy: naga::back::IndexBoundsCheckPolicy::Restrict,
}
};

View File

@@ -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]]

View File

@@ -1146,6 +1146,8 @@ impl crate::Context for Context {
lang_version: (1, 0),
flags: spv::WriterFlags::empty(),
capabilities: None,
index_bounds_check_policy:
naga::back::IndexBoundsCheckPolicy::UndefinedBehavior,
};
let analysis = Validator::new(
naga::valid::ValidationFlags::empty(),