Skip to content

Commit

Permalink
[spirv-out] Fix adding illegal decorators on fragment outputs.
Browse files Browse the repository at this point in the history
Furthermore, fix allowing to add `Centroid` and `Sample` decorator to vertex inputs.
Fixes gfx-rs#2270
  • Loading branch information
Wumpf committed Mar 19, 2023
1 parent 6db8da7 commit d3ccbf6
Showing 1 changed file with 24 additions and 20 deletions.
44 changes: 24 additions & 20 deletions src/back/spv/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1407,12 +1407,17 @@ impl Writer {
} => {
self.decorate(id, Decoration::Location, &[location]);

// The Vulkan spec says: VUID-StandaloneSpirv-Flat-06202
//
// > The Flat, NoPerspective, Sample, and Centroid decorations
// > must not be used on variables with the Input storage class in
// > a vertex shader
if class != spirv::StorageClass::Input || stage != crate::ShaderStage::Vertex {
let no_decorations =
// VUID-StandaloneSpirv-Flat-06202
// > The Flat, NoPerspective, Sample, and Centroid decorations
// > must not be used on variables with the Input storage class in a vertex shader
(class == spirv::StorageClass::Input && stage == crate::ShaderStage::Vertex) ||
// VUID-StandaloneSpirv-Flat-06201
// > The Flat, NoPerspective, Sample, and Centroid decorations
// > must not be used on variables with the Output storage class in a fragment shader
(class == spirv::StorageClass::Output && stage == crate::ShaderStage::Fragment);

if !no_decorations {
match interpolation {
// Perspective-correct interpolation is the default in SPIR-V.
None | Some(crate::Interpolation::Perspective) => (),
Expand All @@ -1423,20 +1428,19 @@ impl Writer {
self.decorate(id, Decoration::NoPerspective, &[]);
}
}
}

match sampling {
// Center sampling is the default in SPIR-V.
None | Some(crate::Sampling::Center) => (),
Some(crate::Sampling::Centroid) => {
self.decorate(id, Decoration::Centroid, &[]);
}
Some(crate::Sampling::Sample) => {
self.require_any(
"per-sample interpolation",
&[spirv::Capability::SampleRateShading],
)?;
self.decorate(id, Decoration::Sample, &[]);
match sampling {
// Center sampling is the default in SPIR-V.
None | Some(crate::Sampling::Center) => (),
Some(crate::Sampling::Centroid) => {
self.decorate(id, Decoration::Centroid, &[]);
}
Some(crate::Sampling::Sample) => {
self.require_any(
"per-sample interpolation",
&[spirv::Capability::SampleRateShading],
)?;
self.decorate(id, Decoration::Sample, &[]);
}
}
}
}
Expand Down

0 comments on commit d3ccbf6

Please sign in to comment.