Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

msl: handle the case of missing binding #2175

Merged
merged 1 commit into from
Dec 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/back/msl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,10 @@ pub enum Error {
#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
pub enum EntryPointError {
#[error("global '{0}' doesn't have a binding")]
MissingBinding(String),
#[error("mapping of {0:?} is missing")]
MissingBinding(crate::ResourceBinding),
MissingBindTarget(crate::ResourceBinding),
#[error("mapping for push constants is missing")]
MissingPushConstants,
#[error("mapping for sizes buffer is missing")]
Expand Down Expand Up @@ -303,7 +305,7 @@ impl Options {
index: 0,
interpolation: None,
}),
None => Err(EntryPointError::MissingBinding(res_binding.clone())),
None => Err(EntryPointError::MissingBindTarget(res_binding.clone())),
}
}

Expand Down
63 changes: 41 additions & 22 deletions src/back/msl/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3399,33 +3399,52 @@ impl<W: Write> Writer<W> {
if fun_info[var_handle].is_empty() {
continue;
}
if let Some(ref br) = var.binding {
let good = match options.per_stage_map[ep.stage].resources.get(br) {
Some(target) => {
let binding_ty = match module.types[var.ty].inner {
crate::TypeInner::BindingArray { base, .. } => {
&module.types[base].inner
match var.space {
crate::AddressSpace::Uniform
| crate::AddressSpace::Storage { .. }
| crate::AddressSpace::Handle => {
let br = match var.binding {
Some(ref br) => br,
None => {
let var_name = var.name.clone().unwrap_or_default();
ep_error =
Some(super::EntryPointError::MissingBinding(var_name));
break;
}
};
let good = match options.per_stage_map[ep.stage].resources.get(br) {
Some(target) => {
let binding_ty = match module.types[var.ty].inner {
crate::TypeInner::BindingArray { base, .. } => {
&module.types[base].inner
}
ref ty => ty,
};
match *binding_ty {
crate::TypeInner::Image { .. } => target.texture.is_some(),
crate::TypeInner::Sampler { .. } => {
target.sampler.is_some()
}
_ => target.buffer.is_some(),
}
ref ty => ty,
};
match *binding_ty {
crate::TypeInner::Image { .. } => target.texture.is_some(),
crate::TypeInner::Sampler { .. } => target.sampler.is_some(),
_ => target.buffer.is_some(),
}
None => false,
};
if !good {
ep_error =
Some(super::EntryPointError::MissingBindTarget(br.clone()));
break;
}
None => false,
};
if !good {
ep_error = Some(super::EntryPointError::MissingBinding(br.clone()));
break;
}
}
if var.space == crate::AddressSpace::PushConstant {
if let Err(e) = options.resolve_push_constants(ep.stage) {
ep_error = Some(e);
break;
crate::AddressSpace::PushConstant => {
if let Err(e) = options.resolve_push_constants(ep.stage) {
ep_error = Some(e);
break;
}
}
crate::AddressSpace::Function
| crate::AddressSpace::Private
| crate::AddressSpace::WorkGroup => {}
}
}
if supports_array_length {
Expand Down