[msl-out] Introduce finer distinctions to LocationMode.

Distinguish between vertex shader outputs and fragment shader inputs.
This change should have no visible effect.
This commit is contained in:
Jim Blandy
2022-04-12 12:55:00 -07:00
committed by Teodor Tanasoaia
parent 8afa5fe5e3
commit 4e4d918d39
2 changed files with 39 additions and 19 deletions

View File

@@ -165,11 +165,29 @@ pub enum EntryPointError {
MissingSizesBuffer,
}
/// Points in the MSL code where we might emit a pipeline input or output.
///
/// Note that, even though vertex shaders' outputs are always fragment
/// shaders' inputs, we still need to distinguish `VertexOutput` and
/// `FragmentInput`, since there are certain differences in the way
/// [`ResolvedBinding`s] are represented on either side.
///
/// [`ResolvedBinding`s]: ResolvedBinding
#[derive(Clone, Copy, Debug)]
enum LocationMode {
/// Input to the vertex shader.
VertexInput,
/// Output from the vertex shader.
VertexOutput,
/// Input to the fragment shader.
FragmentInput,
/// Output from the fragment shader.
FragmentOutput,
Intermediate,
/// Compute shader input or output.
Uniform,
}
@@ -243,22 +261,24 @@ impl Options {
} => 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: location,
interpolation: {
// unwrap: The verifier ensures that vertex shader outputs and fragment
// shader inputs always have fully specified interpolation, and that
// sampling is `None` only for Flat interpolation.
let interpolation = interpolation.unwrap();
let sampling = sampling.unwrap_or(crate::Sampling::Center);
Some(ResolvedInterpolation::from_binding(interpolation, sampling))
},
}),
LocationMode::VertexOutput | LocationMode::FragmentInput => {
Ok(ResolvedBinding::User {
prefix: if self.spirv_cross_compatibility {
"locn"
} else {
"loc"
},
index: location,
interpolation: {
// unwrap: The verifier ensures that vertex shader outputs and fragment
// shader inputs always have fully specified interpolation, and that
// sampling is `None` only for Flat interpolation.
let interpolation = interpolation.unwrap();
let sampling = sampling.unwrap_or(crate::Sampling::Center);
Some(ResolvedInterpolation::from_binding(interpolation, sampling))
},
})
}
LocationMode::Uniform => {
log::error!(
"Unexpected Binding::Location({}) for the Uniform mode",

View File

@@ -3331,11 +3331,11 @@ impl<W: Write> Writer<W> {
crate::ShaderStage::Vertex => (
"vertex",
LocationMode::VertexInput,
LocationMode::Intermediate,
LocationMode::VertexOutput,
),
crate::ShaderStage::Fragment { .. } => (
"fragment",
LocationMode::Intermediate,
LocationMode::FragmentInput,
LocationMode::FragmentOutput,
),
crate::ShaderStage::Compute { .. } => {