diff --git a/src/back/glsl/features.rs b/src/back/glsl/features.rs index 9699f98e1..0404ee03f 100644 --- a/src/back/glsl/features.rs +++ b/src/back/glsl/features.rs @@ -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) diff --git a/src/back/glsl/mod.rs b/src/back/glsl/mod.rs index 97b40f546..f58e6a728 100644 --- a/src/back/glsl/mod.rs +++ b/src/back/glsl/mod.rs @@ -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, }; diff --git a/src/back/msl/mod.rs b/src/back/msl/mod.rs index 0e402e2dd..385e7460c 100644 --- a/src/back/msl/mod.rs +++ b/src/back/msl/mod.rs @@ -183,21 +183,21 @@ impl Options { ) -> Result { 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) } diff --git a/src/back/msl/writer.rs b/src/back/msl/writer.rs index 086f23768..79a811482 100644 --- a/src/back/msl/writer.rs +++ b/src/back/msl/writer.rs @@ -1821,7 +1821,7 @@ impl Writer { 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 Writer { 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 Writer { writeln!(self.out, " }};")?; } _ => { - if let Some(crate::Binding::Location(..)) = arg.binding { + if let Some(crate::Binding::Location { .. }) = arg.binding { writeln!( self.out, "{}const auto {} = {}.{};", diff --git a/src/back/spv/writer.rs b/src/back/spv/writer.rs index 4b1502a8b..123c0d36c 100644 --- a/src/back/spv/writer.rs +++ b/src/back/spv/writer.rs @@ -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), diff --git a/src/front/glsl/parser.rs b/src/front/glsl/parser.rs index 10eacb5e3..d20a9302f 100644 --- a/src/front/glsl/parser.rs +++ b/src/front/glsl/parser.rs @@ -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; } diff --git a/src/front/spv/function.rs b/src/front/spv/function.rs index 5a5725632..fef875d56 100644 --- a/src/front/spv/function.rs +++ b/src/front/spv/function.rs @@ -213,9 +213,10 @@ impl> super::Parser { }); 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 } diff --git a/src/front/spv/mod.rs b/src/front/spv/mod.rs index e76b86c74..a0943eed5 100644 --- a/src/front/spv/mod.rs +++ b/src/front/spv/mod.rs @@ -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)), } } diff --git a/src/front/wgsl/mod.rs b/src/front/wgsl/mod.rs index 8b4853406..2bd5497fd 100644 --- a/src/front/wgsl/mod.rs +++ b/src/front/wgsl/mod.rs @@ -500,8 +500,8 @@ impl BindingParser { fn finish<'a>(self) -> Result, 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( diff --git a/src/lib.rs b/src/lib.rs index 151591dc4..918f285ce 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -465,7 +465,7 @@ pub enum Binding { /// Built-in shader variable. BuiltIn(BuiltIn), /// Indexed location. - Location(u32, Option), + Location { location: u32, interpolation: Option }, } /// Pipeline binding information for global resources. diff --git a/src/proc/mod.rs b/src/proc/mod.rs index 55266d2bd..a6d6809a4 100644 --- a/src/proc/mod.rs +++ b/src/proc/mod.rs @@ -212,7 +212,7 @@ impl crate::Binding { pub fn to_built_in(&self) -> Option { match *self { Self::BuiltIn(bi) => Some(bi), - Self::Location(..) => None, + Self::Location { .. } => None, } } } diff --git a/src/valid/analyzer.rs b/src/valid/analyzer.rs index 52e00818f..7b0fff4df 100644 --- a/src/valid/analyzer.rs +++ b/src/valid/analyzer.rs @@ -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 { diff --git a/src/valid/interface.rs b/src/valid/interface.rs index 1299b3821..350939a07 100644 --- a/src/valid/interface.rs +++ b/src/valid/interface.rs @@ -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 }); } diff --git a/tests/out/shadow.ron b/tests/out/shadow.ron index 8f603ad07..fe4976907 100644 --- a/tests/out/shadow.ron +++ b/tests/out/shadow.ron @@ -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: [