From 0945889dd7244adbcfdc8b2e66a354e590683ef4 Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Mon, 15 Mar 2021 10:25:10 -0400 Subject: [PATCH] [msl] filter out entry points based on the bindings --- src/back/msl/mod.rs | 18 ++++++++++++------ src/back/msl/writer.rs | 25 +++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/src/back/msl/mod.rs b/src/back/msl/mod.rs index f95ff8f3c9..177a945967 100644 --- a/src/back/msl/mod.rs +++ b/src/back/msl/mod.rs @@ -73,8 +73,6 @@ pub enum Error { Utf8(#[from] FromUtf8Error), #[error(transparent)] Type(#[from] TypifyError), - #[error("bind source for {0:?} is missing from the map")] - MissingBindTarget(BindSource), #[error("bind target {0:?} is empty")] UnimplementedBindTarget(BindTarget), #[error("composing of {0:?} is not implemented yet")] @@ -89,6 +87,12 @@ pub enum Error { Validation, } +#[derive(Debug, thiserror::Error)] +pub enum EntryPointError { + #[error("bind source for {0:?} is missing from the map")] + MissingBinding(BindSource), +} + #[derive(Clone, Copy, Debug)] enum LocationMode { VertexInput, @@ -154,7 +158,7 @@ impl Options { &self, stage: crate::ShaderStage, res_binding: &crate::ResourceBinding, - ) -> Result { + ) -> Result { let source = BindSource { stage, group: res_binding.group, @@ -166,7 +170,7 @@ impl Options { prefix: "fake", index: 0, }), - None => Err(Error::MissingBindTarget(source)), + None => Err(EntryPointError::MissingBinding(source)), } } } @@ -232,8 +236,10 @@ impl ResolvedBinding { /// for the use of the result. pub struct TranslationInfo { /// Mapping of the entry point names. Each item in the array - /// corresponds to an entry point in `module.entry_points.iter()`. - pub entry_point_names: Vec, + /// corresponds to an entry point index. + /// + ///Note: Some entry points may fail translation because of missing bindings. + pub entry_point_names: Vec>, } pub fn write_string( diff --git a/src/back/msl/writer.rs b/src/back/msl/writer.rs index 39d3e1e19c..97e563fc2d 100644 --- a/src/back/msl/writer.rs +++ b/src/back/msl/writer.rs @@ -1179,6 +1179,27 @@ impl Writer { for (ep_index, ep) in module.entry_points.iter().enumerate() { let fun = &ep.function; let fun_info = analysis.get_entry_point(ep_index); + // skip this entry point if any global bindings are missing + if !options.fake_missing_bindings { + if let Some(err) = module + .global_variables + .iter() + .find_map(|(var_handle, var)| { + if !fun_info[var_handle].is_empty() { + if let Some(ref br) = var.binding { + if let Err(e) = options.resolve_global_binding(ep.stage, br) { + return Some(e); + } + } + } + None + }) + { + info.entry_point_names.push(Err(err)); + continue; + } + } + self.typifier.resolve_all( &fun.expressions, &module.types, @@ -1192,7 +1213,7 @@ impl Writer { )?; let fun_name = &self.names[&NameKey::EntryPoint(ep_index as _)]; - info.entry_point_names.push(fun_name.clone()); + info.entry_point_names.push(Ok(fun_name.clone())); let stage_out_name = format!("{}Output", fun_name); let stage_in_name = format!("{}Input", fun_name); @@ -1340,7 +1361,7 @@ impl Writer { write!(self.out, "{} ", separator)?; tyvar.try_fmt(&mut self.out)?; if let Some(ref binding) = var.binding { - let resolved = options.resolve_global_binding(ep.stage, binding)?; + let resolved = options.resolve_global_binding(ep.stage, binding).unwrap(); resolved.try_fmt_decorated(&mut self.out, "")?; } if let Some(value) = var.init {