Change Binding::Location to a struct-style enum variant.

This commit makes no other changes. This is in preparation for adding a third
field, at which point tuple variants start to get obscure.
This commit is contained in:
Jim Blandy 2021-04-08 20:23:40 -07:00 committed by Dzmitry Malyshau
parent 45ee5f5113
commit 99a9e1e78e
14 changed files with 46 additions and 30 deletions

View File

@ -288,7 +288,10 @@ impl<'a, W> Writer<'a, W> {
}
}
_ => {
if let Some(&Binding::Location(_, Some(interpolation))) = binding {
if let Some(&Binding::Location {
interpolation: Some(interpolation),
..
}) = binding {
match interpolation {
Interpolation::Linear => {
self.features.request(Features::NOPERSPECTIVE_QUALIFIER)

View File

@ -242,7 +242,7 @@ struct VaryingName<'a> {
impl fmt::Display for VaryingName<'_> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self.binding {
Binding::Location(location, _) => {
Binding::Location { location, .. } => {
let prefix = match (self.stage, self.output) {
(ShaderStage::Compute, _) => unreachable!(),
// pipeline to vertex
@ -794,7 +794,7 @@ impl<'a, W: Write> Writer<'a, W> {
}
_ => {
let (location, interpolation) = match binding {
Some(&Binding::Location(location, interpolation)) => (location, interpolation),
Some(&Binding::Location { location, interpolation }) => (location, interpolation),
_ => return Ok(()),
};
// Write the interpolation modifier if needed
@ -825,7 +825,7 @@ impl<'a, W: Write> Writer<'a, W> {
// Finally write the global name and end the global with a `;` and a newline
// Leading space is important
let vname = VaryingName {
binding: &Binding::Location(location, None),
binding: &Binding::Location { location, interpolation: None },
stage: self.entry_point.stage,
output,
};

View File

@ -183,21 +183,21 @@ impl Options {
) -> Result<ResolvedBinding, Error> {
match *binding {
crate::Binding::BuiltIn(built_in) => Ok(ResolvedBinding::BuiltIn(built_in)),
crate::Binding::Location(index, _) => match mode {
LocationMode::VertexInput => Ok(ResolvedBinding::Attribute(index)),
LocationMode::FragmentOutput => Ok(ResolvedBinding::Color(index)),
crate::Binding::Location { location, .. } => match mode {
LocationMode::VertexInput => Ok(ResolvedBinding::Attribute(location)),
LocationMode::FragmentOutput => Ok(ResolvedBinding::Color(location)),
LocationMode::Intermediate => Ok(ResolvedBinding::User {
prefix: if self.spirv_cross_compatibility {
"locn"
} else {
"loc"
},
index,
index: location,
}),
LocationMode::Uniform => {
log::error!(
"Unexpected Binding::Location({}) for the Uniform mode",
index
location
);
Err(Error::Validation)
}

View File

@ -1821,7 +1821,7 @@ impl<W: Write> Writer<W> {
writeln!(self.out, "struct {} {{", stage_in_name)?;
for &(ref name_key, ty, binding) in argument_members.iter() {
let binding = match binding {
Some(ref binding @ &crate::Binding::Location(..)) => binding,
Some(ref binding @ &crate::Binding::Location { .. }) => binding,
_ => continue,
};
varying_count += 1;
@ -2044,7 +2044,7 @@ impl<W: Write> Writer<W> {
if member_index != 0 {
write!(self.out, ", ")?;
}
if let Some(crate::Binding::Location(..)) = member.binding {
if let Some(crate::Binding::Location { .. }) = member.binding {
write!(self.out, "{}.", varyings_member_name)?;
}
write!(self.out, "{}", name)?;
@ -2052,7 +2052,7 @@ impl<W: Write> Writer<W> {
writeln!(self.out, " }};")?;
}
_ => {
if let Some(crate::Binding::Location(..)) = arg.binding {
if let Some(crate::Binding::Location { .. }) = arg.binding {
writeln!(
self.out,
"{}const auto {} = {}.{};",

View File

@ -1090,7 +1090,7 @@ impl Writer {
use spirv::{BuiltIn, Decoration};
match *binding {
crate::Binding::Location(location, interpolation) => {
crate::Binding::Location { location, interpolation } => {
self.decorate(id, Decoration::Location, &[location]);
let interp_decoration = match interpolation {
Some(crate::Interpolation::Linear) => Some(Decoration::NoPerspective),

View File

@ -614,9 +614,9 @@ pomelo! {
}
layout_qualifier ::= Layout LeftParen layout_qualifier_id_list(l) RightParen {
if let Some(&(_, loc)) = l.iter().find(|&q| q.0.as_str() == "location") {
if let Some(&(_, location)) = l.iter().find(|&q| q.0.as_str() == "location") {
let interpolation = None; //TODO
StructLayout::Binding(Binding::Location(loc, interpolation))
StructLayout::Binding(Binding::Location { location, interpolation })
} else if let Some(&(_, binding)) = l.iter().find(|&q| q.0.as_str() == "binding") {
let group = if let Some(&(_, set)) = l.iter().find(|&q| q.0.as_str() == "set") {
set
@ -1133,7 +1133,7 @@ pomelo! {
let interpolation = d.type_qualifiers.iter().find_map(|tq| {
if let TypeQualifier::Interpolation(interp) = *tq { Some(interp) } else { None }
});
if let Some(Binding::Location(_, ref mut interp)) = binding {
if let Some(Binding::Location { interpolation: ref mut interp, .. }) = binding {
*interp = interpolation;
}

View File

@ -213,9 +213,10 @@ impl<I: Iterator<Item = u32>> super::Parser<I> {
});
let mut arg = arg.clone();
if ep.stage == crate::ShaderStage::Fragment {
if let Some(crate::Binding::Location(_, ref mut interpolation @ None)) =
arg.binding
{
if let Some(crate::Binding::Location {
interpolation: ref mut interpolation @ None,
..
}) = arg.binding {
*interpolation = Some(crate::Interpolation::Perspective);
// default
}

View File

@ -251,10 +251,10 @@ impl Decoration {
} => map_builtin(built_in).map(crate::Binding::BuiltIn),
Decoration {
built_in: None,
location: Some(loc),
location: Some(location),
interpolation,
..
} => Ok(crate::Binding::Location(loc, interpolation)),
} => Ok(crate::Binding::Location { location, interpolation }),
_ => Err(Error::MissingDecoration(spirv::Decoration::Location)),
}
}

View File

@ -500,8 +500,8 @@ impl BindingParser {
fn finish<'a>(self) -> Result<Option<crate::Binding>, Error<'a>> {
match (self.location, self.built_in, self.interpolation) {
(None, None, None) => Ok(None),
(Some(loc), None, interpolation) => {
Ok(Some(crate::Binding::Location(loc, interpolation)))
(Some(location), None, interpolation) => {
Ok(Some(crate::Binding::Location { location, interpolation }))
}
(None, Some(bi), None) => Ok(Some(crate::Binding::BuiltIn(bi))),
(location, built_in, interpolation) => Err(Error::InconsistentBinding(

View File

@ -465,7 +465,7 @@ pub enum Binding {
/// Built-in shader variable.
BuiltIn(BuiltIn),
/// Indexed location.
Location(u32, Option<Interpolation>),
Location { location: u32, interpolation: Option<Interpolation> },
}
/// Pipeline binding information for global resources.

View File

@ -212,7 +212,7 @@ impl crate::Binding {
pub fn to_built_in(&self) -> Option<crate::BuiltIn> {
match *self {
Self::BuiltIn(bi) => Some(bi),
Self::Location(..) => None,
Self::Location { .. } => None,
}
}
}

View File

@ -344,7 +344,10 @@ impl FunctionInfo {
_ => false,
},
// only flat inputs are uniform
Some(crate::Binding::Location(_, Some(crate::Interpolation::Flat))) => true,
Some(crate::Binding::Location {
interpolation: Some(crate::Interpolation::Flat),
..
}) => true,
_ => false,
};
Uniformity {

View File

@ -206,7 +206,7 @@ impl VaryingContext<'_> {
return Err(VaryingError::InvalidBuiltInType(built_in));
}
}
crate::Binding::Location(location, interpolation) => {
crate::Binding::Location { location, interpolation } => {
if !self.location_mask.insert(location as usize) {
return Err(VaryingError::BindingCollision { location });
}

View File

@ -1517,17 +1517,26 @@
(
name: Some("in_normal_fs"),
ty: 2,
binding: Some(Location(0, Some(Perspective))),
binding: Some(Location(
location: 0,
interpolation: Some(Perspective),
)),
),
(
name: Some("in_position_fs"),
ty: 4,
binding: Some(Location(1, Some(Perspective))),
binding: Some(Location(
location: 1,
interpolation: Some(Perspective),
)),
),
],
result: Some((
ty: 4,
binding: Some(Location(0, None)),
binding: Some(Location(
location: 0,
interpolation: None,
)),
)),
local_variables: [],
expressions: [