Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}