Check that all vertex outputs are consumed by the fragment shader (#2704)

This commit is contained in:
Connor Fitzgerald 2022-05-29 19:38:11 -04:00 committed by GitHub
parent 16c796578c
commit c12ae0880f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 1 deletions

View File

@ -263,6 +263,8 @@ pub enum StageError {
#[source]
error: InputError,
},
#[error("location[{location}] is provided by the previous stage output but is not consumed as input by this stage.")]
InputNotConsumed { location: wgt::ShaderLocation },
}
fn map_storage_format_to_naga(format: wgt::TextureFormat) -> Option<naga::StorageFormat> {
@ -1158,6 +1160,21 @@ impl Interface {
}
}
// Check all vertex outputs and make sure the fragment shader consumes them.
if shader_stage == naga::ShaderStage::Fragment {
for &index in inputs.keys() {
// This is a linear scan, but the count should be low enough that this should be fine.
let found = entry_point.inputs.iter().any(|v| match *v {
Varying::Local { location, .. } => location == index,
Varying::BuiltIn(_) => false,
});
if !found {
return Err(StageError::InputNotConsumed { location: index });
}
}
}
if shader_stage == naga::ShaderStage::Vertex {
for output in entry_point.outputs.iter() {
//TODO: count builtins towards the limit?

View File

@ -30,6 +30,6 @@ fn fs_main(vertex: VertexOutput) -> @location(0) vec4<f32> {
}
@fragment
fn fs_wire() -> @location(0) vec4<f32> {
fn fs_wire(vertex: VertexOutput) -> @location(0) vec4<f32> {
return vec4<f32>(0.0, 0.5, 0.0, 0.5);
}