| 1 |
/*! |
| 2 |
Interpolation defaults. |
| 3 |
*/ |
| 4 |
|
| 5 |
impl crate::Binding { |
| 6 |
/// Apply the usual default interpolation for `ty` to `binding`. |
| 7 |
/// |
| 8 |
/// This function is a utility front ends may use to satisfy the Naga IR's |
| 9 |
/// requirement, meant to ensure that input languages' policies have been |
| 10 |
/// applied appropriately, that all I/O `Binding`s from the vertex shader to the |
| 11 |
/// fragment shader must have non-`None` `interpolation` values. |
| 12 |
/// |
| 13 |
/// All the shader languages Naga supports have similar rules: |
| 14 |
/// perspective-correct, center-sampled interpolation is the default for any |
| 15 |
/// binding that can vary, and everything else either defaults to flat, or |
| 16 |
/// requires an explicit flat qualifier/attribute/what-have-you. |
| 17 |
/// |
| 18 |
/// If `binding` is not a [`Location`] binding, or if its [`interpolation`] is |
| 19 |
/// already set, then make no changes. Otherwise, set `binding`'s interpolation |
| 20 |
/// and sampling to reasonable defaults depending on `ty`, the type of the value |
| 21 |
/// being interpolated: |
| 22 |
/// |
| 23 |
/// - If `ty` is a floating-point scalar, vector, or matrix type, then |
| 24 |
/// default to [`Perspective`] interpolation and [`Center`] sampling. |
| 25 |
/// |
| 26 |
/// - If `ty` is an integral scalar or vector, then default to [`Flat`] |
| 27 |
/// interpolation, which has no associated sampling. |
| 28 |
/// |
| 29 |
/// - For any other types, make no change. Such types are not permitted as |
| 30 |
/// user-defined IO values, and will probably be flagged by the verifier |
| 31 |
/// |
| 32 |
/// When structs appear in input or output types, each member ought to have its |
| 33 |
/// own [`Binding`], so structs are simply covered by the third case. |
| 34 |
/// |
| 35 |
/// [`Binding`]: crate::Binding |
| 36 |
/// [`Location`]: crate::Binding::Location |
| 37 |
/// [`interpolation`]: crate::Binding::Location::interpolation |
| 38 |
/// [`Perspective`]: crate::Interpolation::Perspective |
| 39 |
/// [`Flat`]: crate::Interpolation::Flat |
| 40 |
/// [`Center`]: crate::Sampling::Center |
| 41 |
pub fn apply_default_interpolation(&mut self, ty: &crate::TypeInner) { |
| 42 |
if let crate::Binding::Location { |
| 43 |
location: _, |
| 44 |
interpolation: ref mut interpolation @ None, |
| 45 |
ref mut sampling, |
| 46 |
blend_src: _, |
| 47 |
} = *self |
| 48 |
{ |
| 49 |
match ty.scalar_kind() { |
| 50 |
Some(crate::ScalarKind::Float) => { |
| 51 |
*interpolation = Some(crate::Interpolation::Perspective); |
| 52 |
*sampling = Some(crate::Sampling::Center); |
| 53 |
} |
| 54 |
Some(crate::ScalarKind::Sint | crate::ScalarKind::Uint) => { |
| 55 |
*interpolation = Some(crate::Interpolation::Flat); |
| 56 |
*sampling = None; |
| 57 |
} |
| 58 |
Some(_) | None => {} |
| 59 |
} |
| 60 |
} |
| 61 |
} |
| 62 |
} |