Skip to content

Commit

Permalink
Check that all vertex outputs are consumed by the fragment shader
Browse files Browse the repository at this point in the history
  • Loading branch information
cwfitzgerald committed May 29, 2022
1 parent 16c7965 commit 12d9ef2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 17 additions & 0 deletions wgpu-core/src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down Expand Up @@ -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?
Expand Down
2 changes: 1 addition & 1 deletion wgpu/examples/cube/shader.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit 12d9ef2

Please sign in to comment.