Skip to content

Commit e9d00d3

Browse files
authored
Make "None" interpolation mean default or nothing, depending on context (gfx-rs#146)
* Make no interpolation mean default or nothing, depending on context * Re-add Interpolation::Perspective
1 parent 6026e57 commit e9d00d3

File tree

5 files changed

+16
-31
lines changed

5 files changed

+16
-31
lines changed

src/front/glsl/mod.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,7 +1174,7 @@ impl<'a> Parser<'a> {
11741174
) -> (StorageClass, Option<Binding>, Option<Interpolation>) {
11751175
let mut storage = None;
11761176
let mut binding = None;
1177-
let mut interpolation = Interpolation::Perspective;
1177+
let mut interpolation = None;
11781178

11791179
for qualifier in qualifier.qualifiers {
11801180
match qualifier {
@@ -1243,25 +1243,20 @@ impl<'a> Parser<'a> {
12431243
}
12441244
}
12451245
TypeQualifierSpec::Interpolation(interpolation_qualifier) => {
1246-
interpolation = match interpolation_qualifier {
1246+
interpolation = Some(match interpolation_qualifier {
12471247
InterpolationQualifier::NoPerspective => Interpolation::Linear,
12481248
InterpolationQualifier::Flat => Interpolation::Flat,
12491249
InterpolationQualifier::Smooth => Interpolation::Perspective,
1250-
}
1250+
});
12511251
}
12521252
_ => unimplemented!(),
12531253
}
12541254
}
12551255

1256-
let class = storage.unwrap_or(StorageClass::Private);
1257-
12581256
(
1259-
class,
1257+
storage.unwrap_or(StorageClass::Private),
12601258
binding,
1261-
match class {
1262-
StorageClass::Input | StorageClass::Output => Some(interpolation),
1263-
_ => None,
1264-
},
1259+
interpolation,
12651260
)
12661261
}
12671262
}

src/front/glsl_new/parser.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -743,11 +743,6 @@ pomelo! {
743743

744744
let interpolation = d.type_qualifiers.iter().find_map(|tq| {
745745
if let TypeQualifier::Interpolation(i) = tq { Some(*i) } else { None }
746-
}).or_else(|| match class {
747-
StorageClass::Input | StorageClass::Output => {
748-
Some(Interpolation::Perspective)
749-
}
750-
_ => None,
751746
});
752747

753748
for (id, initializer) in d.ids_initializers {

src/front/spv.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2008,12 +2008,7 @@ impl<I: Iterator<Item = u32>> Parser<I> {
20082008
class,
20092009
binding,
20102010
ty,
2011-
interpolation: dec.interpolation.or_else(|| match class {
2012-
crate::StorageClass::Input | crate::StorageClass::Output => {
2013-
Some(crate::Interpolation::Perspective)
2014-
}
2015-
_ => None,
2016-
}),
2011+
interpolation: dec.interpolation,
20172012
};
20182013
self.lookup_variable.insert(
20192014
id,

src/front/wgsl.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,7 @@ impl Parser {
508508
"flat" => Ok(crate::Interpolation::Flat),
509509
"centroid" => Ok(crate::Interpolation::Centroid),
510510
"sample" => Ok(crate::Interpolation::Sample),
511+
"perspective" => Ok(crate::Interpolation::Perspective),
511512
_ => Err(Error::UnknownDecoration(word)),
512513
}
513514
}
@@ -1557,7 +1558,7 @@ impl Parser {
15571558
// read decorations
15581559
let mut binding = None;
15591560
// Perspective is the default qualifier.
1560-
let mut interpolation = crate::Interpolation::Perspective;
1561+
let mut interpolation = None;
15611562
if lexer.skip(Token::DoubleParen('[')) {
15621563
let (mut bind_index, mut bind_set) = (None, None);
15631564
self.scopes.push(Scope::Decoration);
@@ -1578,7 +1579,10 @@ impl Parser {
15781579
bind_set = Some(lexer.next_uint_literal()?);
15791580
}
15801581
"interpolate" => {
1581-
interpolation = Self::get_interpolation(lexer.next_ident()?)?;
1582+
if interpolation.is_some() {
1583+
return Err(Error::UnknownDecoration(lexer.next_ident()?));
1584+
}
1585+
interpolation = Some(Self::get_interpolation(lexer.next_ident()?)?);
15821586
}
15831587
word => return Err(Error::UnknownDecoration(word)),
15841588
}
@@ -1667,12 +1671,7 @@ impl Parser {
16671671
class,
16681672
binding: binding.take(),
16691673
ty,
1670-
interpolation: match class {
1671-
crate::StorageClass::Input | crate::StorageClass::Output => {
1672-
Some(interpolation)
1673-
}
1674-
_ => None,
1675-
},
1674+
interpolation,
16761675
});
16771676
lookup_global_expression
16781677
.insert(name, crate::Expression::GlobalVariable(var_handle));

src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,9 @@ pub struct GlobalVariable {
341341
/// The type of this variable.
342342
pub ty: Handle<Type>,
343343
/// The interpolation qualifier, if any.
344-
/// Required for global outputs in vertex shaders
345-
/// and global inputs in fragment shaders.
344+
/// If the this `GlobalVariable` is a vertex output
345+
/// or fragment input, `None` corresponds to the
346+
/// `smooth`/`perspective` interpolation qualifier.
346347
pub interpolation: Option<Interpolation>,
347348
}
348349

0 commit comments

Comments
 (0)